在虚幻引擎中使用运动控制器组件,C++而不是蓝图

Using a MotionController Component in Unreal with C++ instead of Blueprint

本文关键字:C++ 组件 控制器 运动控制 引擎 运动      更新时间:2023-10-16

在遍历了OculusInputDeviceIMotionControllerFMotionControllerSource数组后,我发现了一个基于ETrackingStatus的连接的Oculus左右触摸控制器。使用左右控制器,我可以使用IMotionControllerAPI获取位置和旋转,这Returns the calibration-space orientation of the requested controller's hand

以下是对 IMotionController API 的引用: https://docs.unrealengine.com/en-US/API/Runtime/HeadMountedDisplay/IMotionController/index.html

我想将位置/旋转应用于PosableMesh,以便网格显示Oculus控制器在现实中的位置。目前,使用下面的代码,3D模型从相机向下显示,因此映射比例已关闭。我想WorldToMetersScale可能会关闭。当我使用一个小数字时,控制器不会移动太多3D模型,但这可能会弄乱它。

FVector position;
FRotator rotation;
int id = tracker.deviceIndex;
FName srcName = tracker.motionControllerSource;
bool success = tracker.motionController->GetControllerOrientationAndPosition(id, srcName, rotation, position, 250.0f);
if (success)
{
poseMesh->SetWorldLocationAndRotation(position, rotation);
}

将相机位置添加到控制器位置似乎可以解决此问题:

// get camera reference during BeginPlay:
camManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
// TickComponent
poseMesh->SetWorldLocationAndRotation(camManager->GetCameraLocation() + position, rotation);