DOMPoint - Web APIs 编辑

A DOMPoint object represents a 2D or 3D point in a coordinate system; it includes values for the coordinates in up to three dimensions, as well as an optional perspective value. DOMPoint is based on DOMPointReadOnly but allows its properties' values to be changed.

In general, a positive x component represents a position to the right of the origin, a positive y component is downward from the origin, and a positive z component extends outward from the screen (in other words, toward the user).

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.

Static methods

DOMPoint.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 WebXR Device API, DOMPointReadOnly values are used to represent positions and orientations. In the following snippet, the pose of the XR device (such as a VR headset or phone with AR capabilities) can be retrieved by calling using XRFrame.getViewerPose() during an XRSession animation frame, then accessing the resulting XRPose's transform property, which contains two DOMPointReadOnly attributes: position as a vector and orientation as a quaternion.

function onXRFrame(time, xrFrame) {
  let viewerPose = xrFrame.getViewerPose(xrReferenceSpace);

  if (viewerPose) {
    let position = viewerPose.transform.position;
    let orientation = viewerPose.transform.orientation;

    console.log('XR Viewer Position: {x: ' + roundToTwo(position.x)
                                 + ', y: ' + roundToTwo(position.y)
                                 + ', z: ' + roundToTwo(position.z));

    console.log('XR Viewer Orientation: {x: ' + roundToTwo(orientation.x)
                                    + ', y: ' + roundToTwo(orientation.y)
                                    + ', z: ' + roundToTwo(orientation.z)
                                    + ', w: ' + roundToTwo(orientation.w));
  }
}

Specifications

SpecificationStatusComment
Geometry Interfaces Module Level 1
The definition of 'DOMPoint' in that specification.
Candidate Recommendation

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:109 次

字数:6215

最后编辑:6年前

编辑次数:0 次

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