大网数据广告活动
Web 标准与前端开发

XRRigidTransform: XRRigidTransform() constructor

· 52CE 我爱测

The **`XRRigidTransform()`** constructor creates 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.

WebXR Device API

The XRRigidTransform() constructor creates 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.

Syntax

new XRRigidTransform()
new XRRigidTransform(position)
new XRRigidTransform(position, orientation)

Parameters

  • position
    • : An object 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 invalid, the position used is assumed to be {x: 0, y: 0, z: 0, w: 1}. w must always be 1.
  • orientation
    • : An object 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.

Return value

A new 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 position and facing in the direction indicated by orientation.

Exceptions

  • TypeError
    • : Thrown if the value of the w coordinate in the specified position is not 1.0.

Examples

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 XRReferenceSpace.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 XRSession.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.

Specifications

Browser compatibility

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。