DOMPoint

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译!
您也可以阅读此文章的English (US)版。

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

A DOMPoint represents a 2D or 3D point in a coordinate system.

In general, a positive x component represents a position right of the origin, a positive y component upwards from the origin, and a positive z component outwards from the screen (in other words, opposite the direction that the user is facing).

It inherits from its parent, DOMPointReadOnly.

Constructor

DOMPoint()
Creates a new DOMPoint object.

Methods

DOMPoint inherits methods from its parent, DOMPointReadOnly.

DOMPointReadOnly.fromPoint
Translates the position/perspective of a DOMPoint to a new position (doesn't appear to be supported anywhere yet.)

Properties

DOMPoint inherits properties from its parent, DOMPointReadOnly.

DOMPointReadOnly.x Read only
The x coordinate of the DOMPoint.
DOMPointReadOnly.y Read only
The y coordinate of the DOMPoint.
DOMPointReadOnly.z Read only
The z coordinate of the DOMPoint.
DOMPointReadOnly.w Read only
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

Specification Status Comment
Geometry Interfaces Module Level 1
The definition of 'DOMPoint' in that specification.
Candidate Recommendation Latest spec version is an ED.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support No support

 
(Yes)
 
No support

No support

No support
Feature Android Firefox Mobile (Gecko) Firefox OS (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support No support (Yes) No support No support No support No support No support

See also

文档标签和贡献者