VRPose: linearVelocity 属性

已弃用:此特性不再推荐。虽然某些浏览器可能仍然支持它,但它可能已经从相关的网络标准中删除,可能正在删除过程中,或者可能仅为兼容性目的而保留。请避免使用它,如果可能,请更新现有代码;请参阅本页底部的兼容性表格以指导您的决策。请注意,此特性可能随时停止工作。

非标准:此特性未标准化。我们不建议在生产环境中使用非标准特性,因为它们浏览器支持有限,并且可能会更改或被移除。但是,在没有标准选项的特定情况下,它们可以是合适的替代方案。

VRPose 接口中只读的 linearVelocity 属性会返回一个数组,该数组表示当前时间戳下 VRDisplay 的线性速度向量,单位为米/秒。

注意:此属性是旧的 WebVR API 的一部分。它已被 WebXR Device API 取代。

换句话说,即传感器在 xyz 轴上移动的当前速度。

一个 Float32Array,如果 VR 传感器无法提供线性速度数据,则返回 null

示例

js
// rendering loop for a VR scene
function drawVRScene() {
  // WebVR: Request the next frame of the animation
  vrSceneFrame = vrDisplay.requestAnimationFrame(drawVRScene);

  // Populate frameData with the data of the next frame to display
  vrDisplay.getFrameData(frameData);

  // Retrieve the linear velocity values for use in rendering
  // curFramePose is a VRPose object
  const curFramePose = frameData.pose;
  const linVel = curFramePose.linearVelocity;
  const lvx = linVel[0];
  const lvy = linVel[1];
  const lvz = linVel[2];

  // render the scene
  // …

  // WebVR: submit the rendered frame to the VR display
  vrDisplay.submitFrame();
}

规范

此属性是旧的 WebVR API 的一部分,已被 WebXR Device API 取代。它已不再是标准的开发方向。

在所有浏览器都实现新的 WebXR API 之前,建议依靠 A-FrameBabylon.jsThree.js 等框架,或 polyfill 来开发可在所有浏览器上运行的 WebXR 应用程序。有关更多信息,请阅读 Meta 的从 WebVR 移植到 WebXR 指南。

浏览器兼容性

另见