oculusVRSensorDevice.h
Engine/source/platform/input/oculusVR/oculusVRSensorDevice.h
Classes:
class
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#ifndef _OCULUSVRSENSORDEVICE_H_ 25#define _OCULUSVRSENSORDEVICE_H_ 26 27#include "core/util/str.h" 28#include "math/mQuat.h" 29#include "math/mPoint2.h" 30#include "math/mPoint3.h" 31#include "math/mPoint4.h" 32#include "platform/input/oculusVR/oculusVRConstants.h" 33#include "platform/types.h" 34#include "OVR_CAPI.h" 35 36struct OculusVRSensorData; 37 38class OculusVRSensorDevice 39{ 40public: 41 // Action codes 42 static U32 OVR_SENSORROT[OculusVRConstants::MaxSensors]; // SI_ROT 43 44 static U32 OVR_SENSORROTANG[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF 45 46 static U32 OVR_SENSORROTAXISX[OculusVRConstants::MaxSensors]; // SI_AXIS 47 static U32 OVR_SENSORROTAXISY[OculusVRConstants::MaxSensors]; 48 49 static U32 OVR_SENSORACCELERATION[OculusVRConstants::MaxSensors]; // SI_POS 50 static U32 OVR_SENSORANGVEL[OculusVRConstants::MaxSensors]; // SI_POS but is EulerF 51 static U32 OVR_SENSORMAGNETOMETER[OculusVRConstants::MaxSensors]; // SI_POS 52 53 static U32 OVR_SENSORPOSITION[OculusVRConstants::MaxSensors]; 54 55protected: 56 bool mIsValid; 57 58 ovrHmd mDevice; 59 U32 mCurrentTrackingCaps; 60 U32 mSupportedTrackingCaps; 61 62 // From OVR::DeviceInfo 63 String mProductName; 64 String mManufacturer; 65 U32 mVersion; 66 67 // From OVR::SensorInfo 68 U16 mVendorId; 69 U16 mProductId; 70 String mSerialNumber; 71 72 // Has yaw correction been disabled by the control panel 73 bool mYawCorrectionDisabled; 74 75 // Has position tracking been disabled 76 bool mPositionTrackingDisabled; 77 78 // Last tracking status 79 U32 mLastStatus; 80 81 // Assigned by the OculusVRDevice 82 S32 mActionCodeIndex; 83 84 // Buffers to store data for sensor 85 OculusVRSensorData* mDataBuffer[2]; 86 87 // Points to the buffer that holds the previously collected data 88 // for the sensor 89 OculusVRSensorData* mPrevData; 90 91public: 92 OculusVRSensorDevice(); 93 virtual ~OculusVRSensorDevice(); 94 95 static void buildCodeTable(); 96 97 void cleanUp(); 98 99 // Set the sensor properties based on information from the OVR device 100 void set(ovrHmd sensor, S32 actionCodeIndex); 101 102 bool isValid() const {return mIsValid;} 103 104 bool process(U32 deviceType, bool generateRotAsAngAxis, bool generateRotAsEuler, bool generateRotationAsAxisEvents, bool generatePositionEvents, F32 maxAxisRadius, bool generateRawSensor); 105 106 void reset(); 107 108 // Has yaw correction been disabled using the control panel 109 bool getYawCorrectionUserDisabled() const { return mYawCorrectionDisabled; } 110 111 // Is yaw correction enabled 112 bool getYawCorrection() const; 113 114 // Position is valid 115 bool getHasValidPosition() const { return mLastStatus & ovrStatus_PositionTracked; } 116 117 // Set the yaw correction. Note: if magnetometer calibration data is not present, 118 // or user has disabled yaw correction in the control panel, this method will 119 // not enable it. 120 void setYawCorrection(bool state); 121 122 // Sets position tracking state 123 void setPositionTracking(bool state); 124 125 // Is magnetometer calibration data available for this sensor 126 bool getMagnetometerCalibrationAvailable() const; 127 128 // Is position tracking data available for this sensor 129 bool getOrientationTrackingAvailable() const; 130 131 // Is position tracking data available for this sensor 132 bool getPositionTrackingAvailable() const; 133 134 U32 getLastTrackingStatus() const { return mLastStatus; } 135 136 const char* getProductName() { return mProductName.c_str(); } 137 const char* getManufacturer() { return mManufacturer.c_str(); } 138 U32 getVersion() { return mVersion; } 139 U16 getVendorId() { return mVendorId; } 140 U16 getProductId() { return mProductId; } 141 const char* getSerialNumber() { return mSerialNumber; } 142 143 // Get the current rotation of the sensor. Uses prediction if set. 144 EulerF getEulerRotation(); 145 146 // Get the current rotation of the sensor. 147 EulerF getRawEulerRotation(); 148 149 // Get the current absolute acceleration reading, in m/s^2 150 VectorF getAcceleration(); 151 152 // Get the current angular velocity reading, in rad/s 153 EulerF getAngularVelocity(); 154 155 // Get the current position 156 Point3F getPosition(); 157 158 void updateTrackingCaps(); 159}; 160 161#endif // _OCULUSVRSENSORDEVICE_H_ 162