oculusVRSensorData.cpp
Engine/source/platform/input/oculusVR/oculusVRSensorData.cpp
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "platform/input/oculusVR/oculusVRDevice.h" 25#include "platform/input/oculusVR/oculusVRSensorData.h" 26#include "platform/input/oculusVR/oculusVRUtil.h" 27#include "console/console.h" 28 29OculusVRSensorData::OculusVRSensorData() 30{ 31 reset(); 32} 33 34void OculusVRSensorData::reset() 35{ 36 mDataSet = false; 37 mStatusFlags = 0; 38} 39 40void OculusVRSensorData::setData(ovrTrackingState& data, const F32& maxAxisRadius) 41{ 42 // Sensor rotation & position 43 OVR::Posef pose = data.HeadPose.ThePose; 44 OVR::Quatf orientation = pose.Rotation; 45 OVR::Vector3f position = data.HeadPose.ThePose.Position; 46 47 mPosition = Point3F(-position.z, position.x, position.y); 48 mPosition *= OculusVRDevice::smPositionTrackingScale; 49 50 OVR::Matrix4f orientMat(orientation); 51 OculusVRUtil::convertRotation(orientMat.M, mRot); 52 mRotQuat.set(mRot); 53 54 // Sensor rotation in Euler format 55 OculusVRUtil::convertRotation(orientation, mRotEuler); // mRotEuler == pitch, roll, yaw FROM yaw, pitch, roll 56 57 //mRotEuler = EulerF(0,0,0); 58 float hmdYaw, hmdPitch, hmdRoll; 59 orientation.GetEulerAngles<OVR::Axis_Y, OVR::Axis_X, OVR::Axis_Z>(&hmdYaw, &hmdPitch, &hmdRoll); 60 61 // Sensor rotation as axis 62 OculusVRUtil::calculateAxisRotation(mRot, maxAxisRadius, mRotAxis); 63 64 // Sensor raw values 65 OVR::Vector3f accel = data.HeadPose.LinearAcceleration; 66 OculusVRUtil::convertAcceleration(accel, mAcceleration); 67 68 OVR::Vector3f angVel = data.HeadPose.AngularVelocity; 69 OculusVRUtil::convertAngularVelocity(angVel, mAngVelocity); 70 71 OVR::Vector3f mag = data.RawSensorData.Magnetometer; 72 OculusVRUtil::convertMagnetometer(mag, mMagnetometer); 73 74 mStatusFlags = data.StatusFlags; 75 mDataSet = true; 76} 77 78U32 OculusVRSensorData::compare(OculusVRSensorData* other, bool doRawCompare) 79{ 80 S32 result = DIFF_NONE; 81 82 // Check rotation 83 if(mRotEuler.x != other->mRotEuler.x || mRotEuler.y != other->mRotEuler.y || mRotEuler.z != other->mRotEuler.z || !mDataSet) 84 { 85 result |= DIFF_ROT; 86 } 87 88 // Check rotation as axis 89 if(mRotAxis.x != other->mRotAxis.x || !mDataSet) 90 { 91 result |= DIFF_ROTAXISX; 92 } 93 if(mRotAxis.y != other->mRotAxis.y || !mDataSet) 94 { 95 result |= DIFF_ROTAXISY; 96 } 97 98 // Check raw values 99 if(doRawCompare) 100 { 101 if(mAcceleration.x != other->mAcceleration.x || mAcceleration.y != other->mAcceleration.y || mAcceleration.z != other->mAcceleration.z || !mDataSet) 102 { 103 result |= DIFF_ACCEL; 104 } 105 if(mAngVelocity.x != other->mAngVelocity.x || mAngVelocity.y != other->mAngVelocity.y || mAngVelocity.z != other->mAngVelocity.z || !mDataSet) 106 { 107 result |= DIFF_ANGVEL; 108 } 109 if(mMagnetometer.x != other->mMagnetometer.x || mMagnetometer.y != other->mMagnetometer.y || mMagnetometer.z != other->mMagnetometer.z || !mDataSet) 110 { 111 result |= DIFF_MAG; 112 } 113 } 114 115 if (other->mStatusFlags != mStatusFlags) 116 { 117 result |= DIFF_STATUS; 118 } 119 120 return result; 121} 122