이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 참여해서 번역을 마치도록 도와 주세요!
English (US)의 문서도 읽어보세요.
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 thew
perspective value. You can also use an existingDOMPoint
orDOMPointReadOnly
or aDOMPointInit
dictionary to create a new point by calling theDOMPoint.fromPoint()
static method.
Methods
DOMPoint
inherits methods from its parent, DOMPointReadOnly
.
fromPoint()
- Creates a new mutable
DOMPoint
object given an existing point or aDOMPointInit
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
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
Desktop | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome Full support 61 | Edge No support No | Firefox Full support 31 | IE No support No | Opera Full support 48 | Safari No support No | WebView Android Full support 58 | Chrome Android Full support 61 | Edge Mobile No support No | Firefox Android Full support 31 | Opera Android Full support 48 | Safari iOS No support No | Samsung Internet Android ? |
DOMPoint() constructor | Chrome Full support 61 | Edge No support No | Firefox Full support 31 | IE No support No | Opera Full support 48 | Safari No support No | WebView Android Full support 58 | Chrome Android Full support 61 | Edge Mobile No support No | Firefox Android Full support 31 | Opera Android Full support 48 | Safari iOS No support No | Samsung Internet Android ? |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.