Coordinate System Synchronization with Holographic Remoting and the OpenXR API
本文是根据官方示例的学习笔记
https://docs.microsoft.com/en-us/windows/mixed-reality/develop/native/holographic-remoting-coordinate-system-synchronization-openxr
为了结合计算机视觉相关任务,统一眼镜端坐标系和渲染的虚拟世界坐标系是十分必要的。 官方示例:
https://github.com/microsoft/HoloLens2ForCV
1. 创建眼镜端中的用户坐标系统
调用xrCreateReferenceSpace 中用 XR_REMOTING_REFERENCE_SPACE_TYPE_USER_MSFT 参数创建用户坐标系
xr::SpaceHandle space;
XrReferenceSpaceCreateInfo createInfo{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
createInfo.referenceSpaceType = static_cast<XrReferenceSpaceType>(XR_REMOTING_REFERENCE_SPACE_TYPE_USER_MSFT);
createInfo.poseInReferenceSpace = xr::math::Pose::Translation({0.0f, 0.0f, 0.0f});
CHECK_XRCMD(xrCreateReferenceSpace(m_session.Get(), &createInfo, space.Put()));
2. 获取眼镜坐标参数
在SampleRemoteOpenXR示例中,viewProjections 包含了眼镜坐标的基本信息。
std::vector<xr::math::ViewProjection> viewProjections(viewCount);
for (uint32_t i = 0; i < viewCount; i++) {
viewProjections[i] = {m_renderResources->Views[i].pose, m_renderResources->Views[i].fov, m_nearFar};
}
眼镜的前方是Z轴正方向,右手法则。
左眼的方向,FOV,位置:
const DirectX::XMMATRIX spaceToView = xr::math::LoadXrPose(viewProjections[0].Pose);
const DirectX::XMVECTOR a = spaceToView.r[0];
float x1 = DirectX::XMVectorGetX(a);
float x2 = DirectX::XMVectorGetY(a);
float x3 = DirectX::XMVectorGetZ(a);
const DirectX::XMVECTOR b = spaceToView.r[1];
float y1 = DirectX::XMVectorGetX(b);
float y2 = DirectX::XMVectorGetY(b);
float y3 = DirectX::XMVectorGetZ(b);
const DirectX::XMVECTOR c = spaceToView.r[2];
float z1 = DirectX::XMVectorGetX(c);
float z2 = DirectX::XMVectorGetY(c);
float z3 = DirectX::XMVectorGetZ(c);
float Left_FOV_up = viewProjections[0].Fov.angleUp;
float Left_FOV_right = viewProjections[0].Fov.angleRight;
float Left_Pos_X = viewProjections[0].Pose.position.x;
float Left_Pos_Y = viewProjections[0].Pose.position.y;
float Left_Pos_Z = viewProjections[0].Pose.position.z;
同理,右眼:
const DirectX::XMMATRIX spaceToView = xr::math::LoadXrPose(viewProjections[1].Pose);
const DirectX::XMVECTOR a = spaceToView.r[0];
float x1 = DirectX::XMVectorGetX(a);
float x2 = DirectX::XMVectorGetY(a);
float x3 = DirectX::XMVectorGetZ(a);
const DirectX::XMVECTOR b = spaceToView.r[1];
float y1 = DirectX::XMVectorGetX(b);
float y2 = DirectX::XMVectorGetY(b);
float y3 = DirectX::XMVectorGetZ(b);
const DirectX::XMVECTOR c = spaceToView.r[2];
float z1 = DirectX::XMVectorGetX(c);
float z2 = DirectX::XMVectorGetY(c);
float z3 = DirectX::XMVectorGetZ(c);
float Right_FOV_up = viewProjections[1].Fov.angleUp;
float Right_FOV_right = viewProjections[1].Fov.angleRight;
float Right_Pos_X = viewProjections[1].Pose.position.x;
float Right_Pos_Y = viewProjections[1].Pose.position.y;
float Right_Pos_Z = viewProjections[1].Pose.position.z;
**未完待续**去看看官方给的那一大坨文件
|