MCPcopy Create free account
hub / github.com/LibreVR/Revive / GetTrackingState

Method GetTrackingState

Revive/InputManager.cpp:253–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void InputManager::GetTrackingState(ovrSession session, ovrTrackingState* outState, double absTime)
254{
255 // Get the device poses
256 vr::ETrackingUniverseOrigin origin = vr::VRCompositor()->GetTrackingSpace();
257 vr::TrackedDevicePose_t poses[vr::k_unMaxTrackedDeviceCount];
258 if (absTime > 0.0f)
259 {
260 uint32_t predictionID = (uint32_t)floor(absTime * session->HmdDesc.DisplayRefreshRate);
261 vr::VRCompositor()->GetPosesForFrame(predictionID, poses, vr::k_unMaxTrackedDeviceCount);
262 }
263 else
264 {
265 vr::VRSystem()->GetDeviceToAbsoluteTrackingPose(origin, 0.0f, poses, vr::k_unMaxTrackedDeviceCount);
266 }
267
268 // Convert the head pose
269 outState->HeadPose = TrackedDevicePoseToOVRPose(poses[vr::k_unTrackedDeviceIndex_Hmd], m_LastPoses[vr::k_unTrackedDeviceIndex_Hmd], absTime);
270 outState->StatusFlags = TrackedDevicePoseToOVRStatusFlags(poses[vr::k_unTrackedDeviceIndex_Hmd]);
271
272 // Convert the hand poses
273 vr::TrackedDeviceIndex_t hands[] = { vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_LeftHand),
274 vr::VRSystem()->GetTrackedDeviceIndexForControllerRole(vr::TrackedControllerRole_RightHand) };
275 for (int i = 0; i < ovrHand_Count; i++)
276 {
277 if (hands[i] == vr::k_unTrackedDeviceIndexInvalid)
278 {
279 outState->HandPoses[i].ThePose = OVR::Posef::Identity();
280 continue;
281 }
282
283 // Apply a 45-degree offset to better fit the Oculus Touch pose
284 vr::TrackedDevicePose_t pose;
285 vr::HmdMatrix34_t offset = REV::Matrix4f(OVR::Matrix4f::RotationX(-MATH_FLOAT_PIOVER4));
286 vr::VRSystem()->ApplyTransform(&pose, &poses[hands[i]], &offset);
287
288 outState->HandPoses[i] = TrackedDevicePoseToOVRPose(pose, m_LastHandPose[i], absTime);
289 outState->HandStatusFlags[i] = TrackedDevicePoseToOVRStatusFlags(pose);
290 }
291
292 REV::Matrix4f calibratedOrigin = REV::Matrix4f(vr::VRSystem()->GetRawZeroPoseToStandingAbsoluteTrackingPose());
293 if (origin == vr::TrackingUniverseSeated)
294 calibratedOrigin *= REV::Matrix4f(vr::VRSystem()->GetSeatedZeroPoseToStandingAbsoluteTrackingPose()).Inverted();
295 outState->CalibratedOrigin.Orientation = OVR::Quatf(calibratedOrigin);
296 outState->CalibratedOrigin.Position = calibratedOrigin.GetTranslation();
297}
298
299ovrResult InputManager::GetDevicePoses(ovrSession session, ovrTrackedDeviceType* deviceTypes, int deviceCount, double absTime, ovrPoseStatef* outDevicePoses)
300{

Callers 1

ovr_GetTrackingStateFunction · 0.45

Calls 2

QuatfClass · 0.85
Matrix4fClass · 0.70

Tested by

no test coverage detected