oculusVRDevice.h
Engine/source/platform/input/oculusVR/oculusVRDevice.h
Classes:
class
Public Defines
define
define
OCULUSVRDEV() <>::instance()
Returns the OculusVRDevice singleton.
Detailed Description
Public Defines
DEFAULT_RIFT_UNIT() 0
OCULUSVRDEV() <>::instance()
Returns the OculusVRDevice singleton.
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 _OCULUSVRDEVICE_H_ 25#define _OCULUSVRDEVICE_H_ 26 27#include "platform/input/oculusVR/oculusVRConstants.h" 28#include "platform/input/oculusVR/oculusVRHMDDevice.h" 29#include "platform/input/oculusVR/oculusVRSensorDevice.h" 30#include "platform/input/IInputDevice.h" 31#include "platform/input/event.h" 32#include "platform/output/IDisplayDevice.h" 33#include "core/util/tSingleton.h" 34#include "math/mQuat.h" 35#include "math/mPoint4.h" 36#include "gfx/gfxDevice.h" 37#include "OVR_CAPI_0_8_0.h" 38 39#define DEFAULT_RIFT_UNIT 0 40 41class OculusVRDevice : public IInputDevice, public IDisplayDevice 42{ 43public: 44 static bool smEnableDevice; 45 46 // If no HMD is present simulate it being available 47 static bool smSimulateHMD; 48 49 // Type of rotation events to broadcast 50 static bool smGenerateAngleAxisRotationEvents; 51 static bool smGenerateEulerRotationEvents; 52 static bool smGeneratePositionEvents; 53 54 // Broadcast sensor rotation as axis 55 static bool smGenerateRotationAsAxisEvents; 56 57 // The maximum sensor angle when used as an axis event 58 // as measured from a vector pointing straight up (in degrees) 59 static F32 smMaximumAxisAngle; 60 61 // Broadcast sensor raw data: acceleration, angular velocity, magnetometer reading 62 static bool smGenerateSensorRawEvents; 63 64 // Indicates that a whole frame event should be generated and frames 65 // should be buffered. 66 static bool smGenerateWholeFrameEvents; 67 68 /// Determines desired pixel density for render target 69 static F32 smDesiredPixelDensity; 70 71 /// Determined if the window is moved to the oculus display 72 static bool smWindowDebug; 73 74 static F32 smPositionTrackingScale; 75 76protected: 77 78 // Discovered HMD devices 79 Vector<OculusVRHMDDevice*> mHMDDevices; 80 81 /// Is the device active 82 bool mActive; 83 84 /// Which HMD is the active one 85 U32 mActiveDeviceId; 86 87 /// Device id we need to use to hook up with oculus 88 ovrGraphicsLuid mLuid; 89 90protected: 91 void cleanUp(); 92 93 /// Build out the codes used for controller actions with the 94 /// Input Event Manager 95 void buildCodeTable(); 96 97 void addHMDDevice(ovrHmd hmd, ovrGraphicsLuid luid); 98 99 void createSimulatedHMD(); 100 101public: 102 OculusVRDevice(); 103 ~OculusVRDevice(); 104 105 static void staticInit(); 106 107 bool enable(); 108 void disable(); 109 110 bool getActive() { return mActive; } 111 void setActive(bool state) { mActive = state; } 112 113 bool process(); 114 115 // IDisplayDevice 116 virtual bool providesFrameEyePose() const; 117 virtual void getFrameEyePose(DisplayPose *outPose, U32 eyeId) const; 118 virtual bool providesEyeOffsets() const; 119 virtual bool providesFovPorts() const { return true; } 120 virtual void getEyeOffsets(Point3F *dest) const; 121 virtual void getFovPorts(FovPort *out) const; 122 virtual bool providesProjectionOffset() const; 123 virtual const Point2F& getProjectionOffset() const; 124 virtual void getStereoViewports(RectI *out) const; 125 virtual void getStereoTargets(GFXTextureTarget **out) const; 126 virtual void onStartFrame(); 127 128 // HMDs 129 U32 getHMDCount() const { return mHMDDevices.size(); } 130 OculusVRHMDDevice* getHMDDevice(U32 index) const; 131 F32 getHMDCurrentIPD(U32 index); 132 void setHMDCurrentIPD(U32 index, F32 ipd); 133 134 // Sensors 135 U32 getSensorCount() const { return mHMDDevices.size(); } 136 const OculusVRSensorDevice* getSensorDevice(U32 index) const; 137 EulerF getSensorEulerRotation(U32 index); 138 VectorF getSensorAcceleration(U32 index); 139 EulerF getSensorAngularVelocity(U32 index); 140 bool getSensorYawCorrection(U32 index); 141 void setSensorYawCorrection(U32 index, bool state); 142 bool getSensorMagnetometerCalibrated(U32 index); 143 144 void setOptimalDisplaySize(U32 idx, GuiCanvas *canvas); 145 void resetAllSensors(); 146 147 bool isDiplayingWarning(); 148 void dismissWarning(); 149 150 String dumpMetrics(U32 idx); 151 152 153 void setDrawCanvas(GuiCanvas *canvas); 154 155 virtual void setCurrentConnection(GameConnection *connection); 156 virtual GameConnection* getCurrentConnection(); 157 158 GFXTexHandle getPreviewTexture(); 159 160 bool _handleDeviceEvent( GFXDevice::GFXDeviceEventType evt ); 161 162public: 163 // For ManagedSingleton. 164 static const char* getSingletonName() { return "OculusVRDevice"; } 165}; 166 167/// Returns the OculusVRDevice singleton. 168#define OCULUSVRDEV ManagedSingleton<OculusVRDevice>::instance() 169 170#endif // _OCULUSVRDEVICE_H_ 171