DOMPoint - Web API 接口参考 编辑

DOMPoint 对象表示坐标系中的2D 或3D 点;它包括三维度的坐标值以及可选的透视值。DOMPoint 基于 DOMPointReadOnly, 但允许更改其属性值。

通常, 正 x 分量表示原点右侧的位置, 正 y 分量从原点向下, 正 z 分量从屏幕向外延伸 (换言之, 朝向用户)。

Constructor

DOMPoint()
Creates and returns a new DOMPoint object given the values of zero or more of its coordinate components and optionally the w perspective value. You can also use an existing DOMPoint or DOMPointReadOnly or a DOMPointInit dictionary to create a new point by calling the DOMPoint.fromPoint() static method.

Methods

DOMPoint inherits methods from its parent, DOMPointReadOnly.

fromPoint()
Creates a new mutable DOMPoint object given an existing point or a DOMPointInit dictionary which provides the values for its properties.

Properties

DOMPoint inherits properties from its parent, DOMPointReadOnly.

DOMPoint.x
The x coordinate of the DOMPoint.
DOMPoint.y
The y coordinate of the DOMPoint.
DOMPoint.z
The z coordinate of the DOMPoint.
DOMPoint.w
The perspective value of the DOMPoint.

Examples

In the WebVR API, DOMPoint values are used to represent points in the coordinate space that the user's head mounted display exists in. In the following snippet, the position of the VR HMD can be retrieved by first grabbing a reference to the position sensor's current state using PositionSensorVRDevice.getState(), then accessing the resulting VRPositionState's position property, which returns a DOMPoint. Note below the usage of position.x, position.y, and position.z.

function setView() {
  var posState = gPositionSensor.getState();

  if (posState.hasPosition) {
    posPara.textContent = 'Position: x' + roundToTwo(posState.position.x) + " y"
                                        + roundToTwo(posState.position.y) + " z"
                                        + roundToTwo(posState.position.z);
    xPos = -posState.position.x * WIDTH * 2;
    yPos = posState.position.y * HEIGHT * 2;

    if (-posState.position.z > 0.01) {
      zPos = -posState.position.z;
    } else {
      zPos = 0.01;
    }
  }

  /* ... */

}

Note: See our positionsensorvrdevice demo for the full code.

Specifications

SpecificationStatusComment
Geometry Interfaces Module Level 1
DOMPoint
Candidate RecommendationLatest spec version is an ED.

Browser compatibility

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:42 次

字数:5467

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文