XRRigidTransform
()
constructor creates and returns a new
XRRigidTransform
object, representing the position and orientation of a point or object.
Among other things,
XRRigidTransform
is used when providing a transform to translate between coordinate systems across spaces.
let xrRigidTransform = new XRRigidTransform(position, orientation);
位置
可选
DOMPointInit
which specifies the coordinates at which the point or object is located. These dimensions are specified in meters. If this parameter is left out or is not compatible with
DOMPointInit
, the position used is assumed to be
{x: 0, y: 0, z: 0, w: 1}
.
w
must
always
be 1.
orientation
可选
DOMPointInit
which specifies the direction in which the object is facing. The default value for
orientation
is
{x: 0, y: 0, z: 0, w: 1}
. The specified orientation gets normalized if it's not already.
新的
XRRigidTransform
object which has been initialized to represent a transform matrix that would adjust the position and orientation of an object from the origin to the specified
位置
and facing in the direction indicated by
orientation
.
TypeError
w
coordinate in the specified
位置
is not 1.0.
In this example, the beginning of the animation of a scene is shown, starting with a request for a reference space of a given type, then shifting the coordinate system based on a transform before requesting the first animation frame.
let animationFrameRequestID = 0;
xrSession.requestReferenceSpace("local-floor")
.then((refSpace) => {
xrReferenceSpace = refSpace.getOffsetReferenceSpace(
new XRRigidTransform(viewerPosition, viewerOrientation));
animationFrameRequestID = xrSession.requestAnimationFrame(drawFrame);
});
After requesting a reference space of type
local-floor
, the returned promise is eventually resolved, at which time we receive a new reference space object,
refSpace
. After creating an
XRRigidTransform
from the viewer's initial position and orientation, we pass the new transform into
getOffsetReferenceSpace()
to create
another
reference space, now offset so that its origin is located at the same place in space as the coordinates given by
viewerPosition
, with the orientation also revised in the same fashion.
Then
requestAnimationFrame()
is called to ask for a new animation frame to draw into. The
drawFrame()
callback will be executed when the system is ready to draw the next frame.
You can find more examples in Movement, orientation, and motion .
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebXR 设备 API
The definition of 'XRRigidTransform()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
XRRigidTransform()
构造函数
|
Chrome 79 | Edge 79 | Firefox 不支持 No | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 79 | Firefox Android 不支持 No | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 11.2 |
完整支持
不支持
XRRigidTransform
XRRigidTransform()
Navigator.xr
WebGLRenderingContext.makeXRCompatible()
XR
XRBoundedReferenceSpace
XRFrame
XRInputSource
XRInputSourceArray
XRInputSourceEvent
XRInputSourcesChangeEvent
XRPose
XRReferenceSpace
XRReferenceSpaceEvent
XRRenderState
XRSession
XRSessionEvent
XRSpace
XRView
XRViewerPose
XRViewport
XRWebGLLayer