使用全像攝影遠端和Windows Mixed Reality API 協調系統同步處理
使用 Windows Mixed Reality API 時,使用者座標系統會包裝成SpatialStationaryFrameOfReference。
提示
您可以在 Holographic Remoting 範例 github 存放庫內的遠端和播放機範例中找到簡單的範例。
將 SampleRemoteApp.h 和 SamplePlayerMain.h 檔案內的批註取消批註 #define ENABLE_USER_COORDINATE_SYSTEM_SAMPLE
,以啟用範例程式碼。
在播放機應用程式中設定和更新使用者座標系統
若要設定和更新使用者座標系統,請在播放程式內容上呼叫 UpdateUserSpatialFrameOfReference
,並將 SpatialCoordinateSystem 傳遞給它。
SpatialCoordinateSystem可以是SpatialStationaryFrameOfReference、SpatialLocatorAttachedFrameOfReference或SpatialAnchor。
// 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
以避免在裝置追蹤遺失之後漂移,即使使用者座標系統尚未變更!
在遠端應用程式中取得使用者座標系統
若要存取使用者座標系統,請在遠端內容上呼叫 GetUserSpatialFrameOfReference
。
GetUserSpatialFrameOfReference
會傳回 SpatialStationaryFrameOfReference,代表使用者座標系統。
// In the Remote app:
winrt::Windows::Perception::Spatial::SpatialStationaryFrameOfReference spatialUserFrameOfReference = m_remoteContext.GetUserSpatialFrameOfReference();