nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: Filename : Tracking_PoseState.h nuclear@0: Content : Describes the complete pose at a point in time, including derivatives nuclear@0: Created : May 13, 2014 nuclear@0: Authors : Dov Katz nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: *************************************************************************************/ nuclear@0: nuclear@0: #ifndef Tracking_PoseState_h nuclear@0: #define Tracking_PoseState_h nuclear@0: nuclear@0: #include "../Kernel/OVR_Math.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: // PoseState describes the complete pose, or a rigid body configuration, at a nuclear@0: // point in time, including first and second derivatives. It is used to specify nuclear@0: // instantaneous location and movement of the headset. nuclear@0: // SensorState is returned as a part of the sensor state. nuclear@0: nuclear@0: template nuclear@0: class PoseState nuclear@0: { nuclear@0: public: nuclear@0: typedef typename CompatibleTypes >::Type CompatibleType; nuclear@0: nuclear@0: PoseState() : TimeInSeconds(0.0) { } nuclear@0: PoseState(Pose pose, double time) : ThePose(pose), TimeInSeconds(time) { } nuclear@0: nuclear@0: // float <-> double conversion constructor. nuclear@0: explicit PoseState(const PoseState::OtherFloatType> &src) nuclear@0: : ThePose(src.ThePose), nuclear@0: AngularVelocity(src.AngularVelocity), LinearVelocity(src.LinearVelocity), nuclear@0: AngularAcceleration(src.AngularAcceleration), LinearAcceleration(src.LinearAcceleration), nuclear@0: TimeInSeconds(src.TimeInSeconds) nuclear@0: { } nuclear@0: nuclear@0: // C-interop support: PoseStatef <-> ovrPoseStatef nuclear@0: PoseState(const typename CompatibleTypes >::Type& src) nuclear@0: : ThePose(src.ThePose), nuclear@0: AngularVelocity(src.AngularVelocity), LinearVelocity(src.LinearVelocity), nuclear@0: AngularAcceleration(src.AngularAcceleration), LinearAcceleration(src.LinearAcceleration), nuclear@0: TimeInSeconds(src.TimeInSeconds) nuclear@0: { } nuclear@0: nuclear@0: operator typename CompatibleTypes >::Type() const nuclear@0: { nuclear@0: typename CompatibleTypes >::Type result; nuclear@0: result.ThePose = ThePose; nuclear@0: result.AngularVelocity = AngularVelocity; nuclear@0: result.LinearVelocity = LinearVelocity; nuclear@0: result.AngularAcceleration = AngularAcceleration; nuclear@0: result.LinearAcceleration = LinearAcceleration; nuclear@0: result.TimeInSeconds = TimeInSeconds; nuclear@0: return result; nuclear@0: } nuclear@0: nuclear@0: Pose ThePose; nuclear@0: Vector3 AngularVelocity; nuclear@0: Vector3 LinearVelocity; nuclear@0: Vector3 AngularAcceleration; nuclear@0: Vector3 LinearAcceleration; nuclear@0: // Absolute time of this state sample; always a double measured in seconds. nuclear@0: double TimeInSeconds; nuclear@0: nuclear@0: // ***** Helpers for Pose integration nuclear@0: nuclear@0: // Stores and integrates gyro angular velocity reading for a given time step. nuclear@0: void StoreAndIntegrateGyro(Vector3d angVel, double dt); nuclear@0: // Stores and integrates position/velocity from accelerometer reading for a given time step. nuclear@0: void StoreAndIntegrateAccelerometer(Vector3d linearAccel, double dt); nuclear@0: nuclear@0: // Performs integration of state by adding next state delta to it nuclear@0: // to produce a combined state change nuclear@0: void AdvanceByDelta(const PoseState& delta); nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: template nuclear@0: PoseState operator*(const OVR::Pose& trans, const PoseState& poseState) nuclear@0: { nuclear@0: PoseState result; nuclear@0: result.ThePose = trans * poseState.ThePose; nuclear@0: result.LinearVelocity = trans.Rotate(poseState.LinearVelocity); nuclear@0: result.LinearAcceleration = trans.Rotate(poseState.LinearAcceleration); nuclear@0: result.AngularVelocity = trans.Rotate(poseState.AngularVelocity); nuclear@0: result.AngularAcceleration = trans.Rotate(poseState.AngularAcceleration); nuclear@0: return result; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // External API returns pose as float, but uses doubles internally for quaternion precision. nuclear@0: typedef PoseState PoseStatef; nuclear@0: typedef PoseState PoseStated; nuclear@0: nuclear@0: nuclear@0: } // namespace OVR::Vision nuclear@0: nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: template<> struct CompatibleTypes > { typedef ovrPoseStatef Type; }; nuclear@0: template<> struct CompatibleTypes > { typedef ovrPoseStated Type; }; nuclear@0: nuclear@0: static_assert((sizeof(PoseState) == sizeof(Pose) + 4*sizeof(Vector3) + sizeof(double)), "sizeof(PoseState) failure"); nuclear@0: #ifdef OVR_CPU_X86_64 nuclear@0: static_assert((sizeof(PoseState) == sizeof(Pose) + 4*sizeof(Vector3) + sizeof(uint32_t) + sizeof(double)), "sizeof(PoseState) failure"); //TODO: Manually pad template. nuclear@0: #elif defined(OVR_OS_WIN32) // The Windows 32 bit ABI aligns 64 bit values on 64 bit boundaries nuclear@0: static_assert((sizeof(PoseState) == sizeof(Pose) + 4*sizeof(Vector3) + sizeof(uint32_t) + sizeof(double)), "sizeof(PoseState) failure"); nuclear@0: #else // Else Unix/Apple 32 bit ABI, which aligns 64 bit values on 32 bit boundaries. nuclear@0: static_assert((sizeof(PoseState) == sizeof(Pose) + 4*sizeof(Vector3) + sizeof(double)), "sizeof(PoseState) failure"); nuclear@0: #endif nuclear@0: } nuclear@0: nuclear@0: #endif // Tracking_PoseState_h