使用全息远程处理和 Windows Mixed Reality API 进行坐标系同步

使用 Windows Mixed Reality API 时,用户坐标系会包装到 SpatialStationaryFrameOfReference 中。

提示

可在全息远程处理示例 GitHub 存储库的远程和玩家示例中找到简单示例。 在 SampleRemoteApp.h 和 SamplePlayerMain.h 文件中取消注释 #define ENABLE_USER_COORDINATE_SYSTEM_SAMPLE 可启用示例代码。

设置和更新播放器应用中的用户坐标系统

若要设置和更新用户坐标系统,请在播放器上下文中调用 UpdateUserSpatialFrameOfReference 并将 SpatialCoordinateSystem 传递到其中。 例如,SpatialCoordinateSystem 可以是 SpatialStationaryFrameOfReferenceSpatialLocatorAttachedFrameOfReferenceSpatialAnchor

// In the Player app:

// Create a stationary frame of reference
winrt::Windows::Perception::Spatial::SpatialStationaryFrameOfReference spatialFrameOfReference = nullptr;
winrt::Windows::Perception::Spatial::SpatialLocator spatialLocator = winrt::Windows::Perception::Spatial::SpatialLocator::GetDefault();
if (spatialLocator != nullptr)
{
    spatialFrameOfReference = spatialLocator.CreateStationaryFrameOfReferenceAtCurrentLocation(float3(0.0f, 0.0f, 0.0f), quaternion(0, 0, 0, 1), 0.0);
}

...

// Update the user coordinate system with the coordinate system of the spatial frame of reference
try
{
    SpatialCoordinateSystem userCoordinateSystem = spatialFrameOfReference.CoordinateSystem();
    m_playerContext.UpdateUserSpatialFrameOfReference(userCoordinateSystem);
}
catch (...)
{
}

注意

对于示例 SpatialStationaryFrameOfReference,必须定期调用 UpdateUserSpatialFrameOfReference,以免失去设备跟踪后发生偏移,即使用户坐标系统尚未更改!

获取远程应用中的用户坐标系统

若要访问用户坐标系统,请在远程上下文中调用 GetUserSpatialFrameOfReferenceGetUserSpatialFrameOfReference 返回表示用户坐标系统的 SpatialStationaryFrameOfReference

// In the Remote app:
winrt::Windows::Perception::Spatial::SpatialStationaryFrameOfReference spatialUserFrameOfReference = m_remoteContext.GetUserSpatialFrameOfReference();

另请参阅