forked from LibreVR/Revive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
REV_Math.cpp
48 lines (41 loc) · 1.17 KB
/
REV_Math.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "REV_Math.h"
OVR::Matrix4f REV_HmdMatrixToOVRMatrix(vr::HmdMatrix34_t m)
{
OVR::Matrix4f r;
memcpy(r.M, m.m, sizeof(vr::HmdMatrix34_t));
return r;
}
OVR::Vector3f REV_HmdVectorToOVRVector(vr::HmdVector3_t v)
{
OVR::Vector3f r;
r.x = v.v[0];
r.y = v.v[1];
r.z = v.v[2];
return r;
}
vr::HmdMatrix34_t REV_OvrPoseToHmdMatrix(ovrPosef pose)
{
vr::HmdMatrix34_t result;
OVR::Matrix4f matrix(pose);
memcpy(result.m, matrix.M, sizeof(result.m));
return result;
}
ovrPoseStatef REV_TrackedDevicePoseToOVRPose(vr::TrackedDevicePose_t pose, double time)
{
ovrPoseStatef result = { 0 };
result.ThePose = OVR::Posef::Identity();
OVR::Matrix4f matrix;
if (pose.bPoseIsValid)
matrix = REV_HmdMatrixToOVRMatrix(pose.mDeviceToAbsoluteTracking);
else
return result;
result.ThePose.Orientation = OVR::Quatf(matrix);
result.ThePose.Position = matrix.GetTranslation();
result.AngularVelocity = REV_HmdVectorToOVRVector(pose.vAngularVelocity);
result.LinearVelocity = REV_HmdVectorToOVRVector(pose.vVelocity);
// TODO: Calculate acceleration.
result.AngularAcceleration = ovrVector3f();
result.LinearAcceleration = ovrVector3f();
result.TimeInSeconds = time;
return result;
}