DOMPoint - 表示坐标系中的 2D 或 3D 点
DOMPoint 对象表示坐标系中的 2D 或 3D 点;它包括最多三维的坐标值,以及可选的透视值。DOMPoint 基于 DOMPointReadOnly,但允许更改其属性的值。
通常,正 x 分量表示原点右侧的位置,正 y 分量表示从原点向下,正 z 分量表示从屏幕向外延伸(换句话说,朝向用户)。
构造函数
DOMPoint()
给定零个或多个坐标分量的值以及可选的 w 透视值,创建并返回一个新的 DOMPoint 对象。您还可以使用现有的 DOMPoint 或 DOMPointReadOnly 或 DOMPointInit 字典通过调用 DOMPoint.fromPoint() 静态方法来创建新点。
方法
DOMPoint 从其父类 DOMPointReadOnly 继承了方法。
fromPoint()
在给定现有点或 DOMPointInit 字典的情况下创建新的可变 DOMPoint 对象,该字典提供其属性的值。
属性
DOMPoint 从其父类 DOMPointReadOnly 继承了属性。
DOMPoint.x
DOMPoint的 x 坐标。
DOMPoint.y
DOMPoint的 y 坐标。
DOMPoint.z
DOMPoint的 z 坐标。
DOMPoint.w
DOMPoint的透视值。
实例
在 WebVR API中,DOMPoint 值用于表示用户头戴式显示器所在的坐标空间中的点。在下面的片段中,位置可以通过首先使用 PositionSensorVRDevice.getState() 获取对位置传感器当前状态的引用来检索 VR HMD,然后访问生成的 VRPositionState position 属性,返回一个 DOMPoint 。请注意下面 position.x ,position.y 和 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;
}
}
/* ... */
}
注意:有关完整代码,请参阅我们的 positionsensorvrdevice 演示。
规范
| 规范 | 状态 | 备注 |
|---|---|---|
| Geometry Interfaces Module Level 1 DOMPoint 的定义 |
候选推荐 | Latest spec version is an ED. |
桌面浏览器兼容性
| 特性 | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| 基础支持 | 61 | 不支持 | 31 | 不支持 | 48 | 不支持 |
DOMPoint() constructor |
61 | 不支持 | 31 | 不支持 | 48 | 不支持 |
移动浏览器兼容性
| 特性 | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
|---|---|---|---|---|---|---|---|
| 基础支持 | 58 | 61 | 不支持 | 31 | 未知 | 48 | 不支持 |
DOMPoint() constructor |
58 | 61 | 不支持 | 31 | 未知 | 48 | 不支持 |