rev |
line source |
nuclear@0
|
1 /************************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 Filename : Tracking_PoseState.h
|
nuclear@0
|
4 Content : Describes the complete pose at a point in time, including derivatives
|
nuclear@0
|
5 Created : May 13, 2014
|
nuclear@0
|
6 Authors : Dov Katz
|
nuclear@0
|
7
|
nuclear@0
|
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
12 which is provided at the time of installation or download, or which
|
nuclear@0
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
14
|
nuclear@0
|
15 You may obtain a copy of the License at
|
nuclear@0
|
16
|
nuclear@0
|
17 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
18
|
nuclear@0
|
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
20 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
22 See the License for the specific language governing permissions and
|
nuclear@0
|
23 limitations under the License.
|
nuclear@0
|
24
|
nuclear@0
|
25 *************************************************************************************/
|
nuclear@0
|
26
|
nuclear@0
|
27 #ifndef Tracking_PoseState_h
|
nuclear@0
|
28 #define Tracking_PoseState_h
|
nuclear@0
|
29
|
nuclear@0
|
30 #include "../Kernel/OVR_Math.h"
|
nuclear@0
|
31
|
nuclear@0
|
32 namespace OVR {
|
nuclear@0
|
33
|
nuclear@0
|
34 // PoseState describes the complete pose, or a rigid body configuration, at a
|
nuclear@0
|
35 // point in time, including first and second derivatives. It is used to specify
|
nuclear@0
|
36 // instantaneous location and movement of the headset.
|
nuclear@0
|
37 // SensorState is returned as a part of the sensor state.
|
nuclear@0
|
38
|
nuclear@0
|
39 template<class T>
|
nuclear@0
|
40 class PoseState
|
nuclear@0
|
41 {
|
nuclear@0
|
42 public:
|
nuclear@0
|
43 typedef typename CompatibleTypes<Pose<T> >::Type CompatibleType;
|
nuclear@0
|
44
|
nuclear@0
|
45 PoseState() : TimeInSeconds(0.0) { }
|
nuclear@0
|
46 PoseState(Pose<T> pose, double time) : ThePose(pose), TimeInSeconds(time) { }
|
nuclear@0
|
47
|
nuclear@0
|
48 // float <-> double conversion constructor.
|
nuclear@0
|
49 explicit PoseState(const PoseState<typename Math<T>::OtherFloatType> &src)
|
nuclear@0
|
50 : ThePose(src.ThePose),
|
nuclear@0
|
51 AngularVelocity(src.AngularVelocity), LinearVelocity(src.LinearVelocity),
|
nuclear@0
|
52 AngularAcceleration(src.AngularAcceleration), LinearAcceleration(src.LinearAcceleration),
|
nuclear@0
|
53 TimeInSeconds(src.TimeInSeconds)
|
nuclear@0
|
54 { }
|
nuclear@0
|
55
|
nuclear@0
|
56 // C-interop support: PoseStatef <-> ovrPoseStatef
|
nuclear@0
|
57 PoseState(const typename CompatibleTypes<PoseState<T> >::Type& src)
|
nuclear@0
|
58 : ThePose(src.ThePose),
|
nuclear@0
|
59 AngularVelocity(src.AngularVelocity), LinearVelocity(src.LinearVelocity),
|
nuclear@0
|
60 AngularAcceleration(src.AngularAcceleration), LinearAcceleration(src.LinearAcceleration),
|
nuclear@0
|
61 TimeInSeconds(src.TimeInSeconds)
|
nuclear@0
|
62 { }
|
nuclear@0
|
63
|
nuclear@0
|
64 operator typename CompatibleTypes<PoseState<T> >::Type() const
|
nuclear@0
|
65 {
|
nuclear@0
|
66 typename CompatibleTypes<PoseState<T> >::Type result;
|
nuclear@0
|
67 result.ThePose = ThePose;
|
nuclear@0
|
68 result.AngularVelocity = AngularVelocity;
|
nuclear@0
|
69 result.LinearVelocity = LinearVelocity;
|
nuclear@0
|
70 result.AngularAcceleration = AngularAcceleration;
|
nuclear@0
|
71 result.LinearAcceleration = LinearAcceleration;
|
nuclear@0
|
72 result.TimeInSeconds = TimeInSeconds;
|
nuclear@0
|
73 return result;
|
nuclear@0
|
74 }
|
nuclear@0
|
75
|
nuclear@0
|
76 Pose<T> ThePose;
|
nuclear@0
|
77 Vector3<T> AngularVelocity;
|
nuclear@0
|
78 Vector3<T> LinearVelocity;
|
nuclear@0
|
79 Vector3<T> AngularAcceleration;
|
nuclear@0
|
80 Vector3<T> LinearAcceleration;
|
nuclear@0
|
81 // Absolute time of this state sample; always a double measured in seconds.
|
nuclear@0
|
82 double TimeInSeconds;
|
nuclear@0
|
83
|
nuclear@0
|
84 // ***** Helpers for Pose integration
|
nuclear@0
|
85
|
nuclear@0
|
86 // Stores and integrates gyro angular velocity reading for a given time step.
|
nuclear@0
|
87 void StoreAndIntegrateGyro(Vector3d angVel, double dt);
|
nuclear@0
|
88 // Stores and integrates position/velocity from accelerometer reading for a given time step.
|
nuclear@0
|
89 void StoreAndIntegrateAccelerometer(Vector3d linearAccel, double dt);
|
nuclear@0
|
90
|
nuclear@0
|
91 // Performs integration of state by adding next state delta to it
|
nuclear@0
|
92 // to produce a combined state change
|
nuclear@0
|
93 void AdvanceByDelta(const PoseState<T>& delta);
|
nuclear@0
|
94 };
|
nuclear@0
|
95
|
nuclear@0
|
96
|
nuclear@0
|
97 template<class T>
|
nuclear@0
|
98 PoseState<T> operator*(const OVR::Pose<T>& trans, const PoseState<T>& poseState)
|
nuclear@0
|
99 {
|
nuclear@0
|
100 PoseState<T> result;
|
nuclear@0
|
101 result.ThePose = trans * poseState.ThePose;
|
nuclear@0
|
102 result.LinearVelocity = trans.Rotate(poseState.LinearVelocity);
|
nuclear@0
|
103 result.LinearAcceleration = trans.Rotate(poseState.LinearAcceleration);
|
nuclear@0
|
104 result.AngularVelocity = trans.Rotate(poseState.AngularVelocity);
|
nuclear@0
|
105 result.AngularAcceleration = trans.Rotate(poseState.AngularAcceleration);
|
nuclear@0
|
106 return result;
|
nuclear@0
|
107 }
|
nuclear@0
|
108
|
nuclear@0
|
109
|
nuclear@0
|
110 // External API returns pose as float, but uses doubles internally for quaternion precision.
|
nuclear@0
|
111 typedef PoseState<float> PoseStatef;
|
nuclear@0
|
112 typedef PoseState<double> PoseStated;
|
nuclear@0
|
113
|
nuclear@0
|
114
|
nuclear@0
|
115 } // namespace OVR::Vision
|
nuclear@0
|
116
|
nuclear@0
|
117
|
nuclear@0
|
118 namespace OVR {
|
nuclear@0
|
119
|
nuclear@0
|
120 template<> struct CompatibleTypes<OVR::PoseState<float> > { typedef ovrPoseStatef Type; };
|
nuclear@0
|
121 template<> struct CompatibleTypes<OVR::PoseState<double> > { typedef ovrPoseStated Type; };
|
nuclear@0
|
122
|
nuclear@0
|
123 static_assert((sizeof(PoseState<double>) == sizeof(Pose<double>) + 4*sizeof(Vector3<double>) + sizeof(double)), "sizeof(PoseState<double>) failure");
|
nuclear@0
|
124 #ifdef OVR_CPU_X86_64
|
nuclear@0
|
125 static_assert((sizeof(PoseState<float>) == sizeof(Pose<float>) + 4*sizeof(Vector3<float>) + sizeof(uint32_t) + sizeof(double)), "sizeof(PoseState<float>) failure"); //TODO: Manually pad template.
|
nuclear@0
|
126 #elif defined(OVR_OS_WIN32) // The Windows 32 bit ABI aligns 64 bit values on 64 bit boundaries
|
nuclear@0
|
127 static_assert((sizeof(PoseState<float>) == sizeof(Pose<float>) + 4*sizeof(Vector3<float>) + sizeof(uint32_t) + sizeof(double)), "sizeof(PoseState<float>) failure");
|
nuclear@0
|
128 #else // Else Unix/Apple 32 bit ABI, which aligns 64 bit values on 32 bit boundaries.
|
nuclear@0
|
129 static_assert((sizeof(PoseState<float>) == sizeof(Pose<float>) + 4*sizeof(Vector3<float>) + sizeof(double)), "sizeof(PoseState<float>) failure");
|
nuclear@0
|
130 #endif
|
nuclear@0
|
131 }
|
nuclear@0
|
132
|
nuclear@0
|
133 #endif // Tracking_PoseState_h
|