本页内容

Qt Quick 3D - XR自由形式传送示例

演示如何在Qt Quick 3D XR中实现简单的移动功能。

带有绿色传送光弧和目标标记的网格房间

概述

本示例展示了如何通过简单的自由形式传送系统(一种非连续式的移动方式)在虚拟环境中移动到指定位置。

控制

导航时,请使用右控制器上的摇杆:

  • 将摇杆向前推以瞄准,松开即可传送。
  • 将摇杆向侧面移动可进行旋转。

实现

传送逻辑在FreeformTeleporter 组件中实现。

FreeformTeleporter {
    id: teleporter

    view: xrView
    originNode: xrOrigin
    cameraNode: xrOrigin.camera
    beamHandle: xrRightController

    rotationTriggerValue: xrRightController.xValue
    teleportTriggerValue: xrRightController.yValue

    onDoTeleportation: (cameraOriginPosition)=> {
                           xrOrigin.position = cameraOriginPosition
                       }
    onDoRotation: (cameraOriginRotation, cameraOriginPosition)=> {
                      xrOrigin.rotation = cameraOriginRotation
                      xrOrigin.position = cameraOriginPosition
                  }
}

FreeformTeleporter组件有以下需要设置的属性:

QtObject xrView

xrView 属性可访问XrView 的内置光线拾取功能。您可以使用任何实现了rayPick 方法的对象。例如,View3D 在原型设计中可能很有用。

Node originNode

originNode 属性指定了自由形式传送器将操作的节点。在 XR 中,通过移动XrOrigin 来实现人工移动。因此,我们将XrView 的 xrOrigin 作为originNode 使用。

Node cameraNode

cameraNode 属性提供摄像机的位置。在旋转时,它定义旋转中心;在传送时,它定义将放置在选定位置上的目标位置。在本示例中,我们使用之前创建的、经过追踪的XrCamera 。

注意:在XR中 ,XrOrigin 定义了场景与用户参考空间之间的关系。该参考空间通常锚定在用户周围的物理空间中。 更改“XrOrigin ”的位置将改变物理位置与场景坐标之间的映射关系。“XrCamera ”用于追踪用户头部位置。当用户在物理空间中移动时,“XrCamera ”的位置和方向将相对于“XrOrigin ”发生变化。

Node beamHandle

beamHandle 属性表示作为传送光束起点的节点。在此示例中,我们将右侧控制器用作beamHandle。

示例项目 @ code.qt.io

另请参阅 《 Qt Quick 3D Xr 中的移动方式》。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.