mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-24 14:49:27 +00:00
Baseline working openvr code
This commit is contained in:
parent
e239d106f5
commit
ba91478fad
23 changed files with 1463 additions and 457 deletions
172
Engine/source/platform/input/openVR/openVRProvider.h
Normal file
172
Engine/source/platform/input/openVR/openVRProvider.h
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
|
||||
#ifndef _OPENVRDEVICE_H_
|
||||
#define _OPENVRDEVICE_H_
|
||||
|
||||
#include "math/mQuat.h"
|
||||
#include "math/mPoint4.h"
|
||||
#include "math/util/frustum.h"
|
||||
#include "core/util/tSingleton.h"
|
||||
|
||||
#include "gfx/gfxDevice.h"
|
||||
#include "gfx/gfxVertexBuffer.h"
|
||||
#include "gfx/gfxPrimitiveBuffer.h"
|
||||
#include "gfx/gfxTarget.h"
|
||||
|
||||
#include "platform/input/IInputDevice.h"
|
||||
#include "platform/input/event.h"
|
||||
#include "platform/output/IDisplayDevice.h"
|
||||
|
||||
#include <openvr.h>
|
||||
|
||||
class OpenVRHMDDevice;
|
||||
|
||||
struct OpenVRRenderState
|
||||
{
|
||||
vr::IVRSystem *mHMD;
|
||||
|
||||
FovPort mEyeFov[2];
|
||||
MatrixF mEyePose[2];
|
||||
MatrixF mHMDPose;
|
||||
|
||||
RectI mEyeViewport[2];
|
||||
GFXTextureTargetRef mStereoRT;
|
||||
GFXTextureTargetRef mEyeRT[2];
|
||||
|
||||
GFXTexHandle mStereoRenderTextures[2];
|
||||
GFXTexHandle mStereoDepthTextures[2];
|
||||
|
||||
GFXVertexBufferHandle<GFXVertexPTTT> mDistortionVerts;
|
||||
GFXPrimitiveBufferHandle mDistortionInds;
|
||||
|
||||
bool setupRenderTargets(U32 mode);
|
||||
void setupDistortion();
|
||||
|
||||
void renderDistortion(U32 eye);
|
||||
|
||||
void renderPreview();
|
||||
|
||||
void reset(vr::IVRSystem* hmd);
|
||||
};
|
||||
|
||||
class OpenVRProvider : public IDisplayDevice, public IInputDevice
|
||||
{
|
||||
public:
|
||||
|
||||
enum DataDifferences {
|
||||
DIFF_NONE = 0,
|
||||
DIFF_ROT = (1 << 0),
|
||||
DIFF_ROTAXISX = (1 << 1),
|
||||
DIFF_ROTAXISY = (1 << 2),
|
||||
DIFF_ACCEL = (1 << 3),
|
||||
DIFF_ANGVEL = (1 << 4),
|
||||
DIFF_MAG = (1 << 5),
|
||||
DIFF_POS = (1 << 6),
|
||||
DIFF_STATUS = (1 << 7),
|
||||
|
||||
DIFF_ROTAXIS = (DIFF_ROTAXISX | DIFF_ROTAXISY),
|
||||
DIFF_RAW = (DIFF_ACCEL | DIFF_ANGVEL | DIFF_MAG),
|
||||
};
|
||||
|
||||
OpenVRProvider();
|
||||
~OpenVRProvider();
|
||||
|
||||
static void staticInit();
|
||||
|
||||
bool enable();
|
||||
bool disable();
|
||||
|
||||
bool getActive() { return mHMD != NULL; }
|
||||
|
||||
/// @name Input handling
|
||||
/// {
|
||||
void buildInputCodeTable();
|
||||
virtual bool process();
|
||||
/// }
|
||||
|
||||
/// @name Display handling
|
||||
/// {
|
||||
virtual bool providesFrameEyePose() const;
|
||||
virtual void getFrameEyePose(IDevicePose *pose, U32 eye) const;
|
||||
|
||||
virtual bool providesEyeOffsets() const;
|
||||
/// Returns eye offset not taking into account any position tracking info
|
||||
virtual void getEyeOffsets(Point3F *dest) const;
|
||||
|
||||
virtual bool providesFovPorts() const;
|
||||
virtual void getFovPorts(FovPort *out) const;
|
||||
|
||||
virtual bool providesProjectionOffset() const;
|
||||
virtual const Point2F& getProjectionOffset() const;
|
||||
|
||||
virtual void getStereoViewports(RectI *out) const;
|
||||
virtual void getStereoTargets(GFXTextureTarget **out) const;
|
||||
|
||||
virtual void setDrawCanvas(GuiCanvas *canvas);
|
||||
|
||||
virtual void setCurrentConnection(GameConnection *connection);
|
||||
virtual GameConnection* getCurrentConnection();
|
||||
|
||||
virtual GFXTexHandle getPreviewTexture();
|
||||
|
||||
virtual void onStartFrame();
|
||||
virtual void onEndFrame();
|
||||
|
||||
virtual void onEyeRendered(U32 index);
|
||||
|
||||
bool _handleDeviceEvent(GFXDevice::GFXDeviceEventType evt);
|
||||
/// }
|
||||
|
||||
/// @name OpenVR handling
|
||||
/// {
|
||||
void processVREvent(const vr::VREvent_t & event);
|
||||
|
||||
void updateTrackedPoses();
|
||||
void submitInputChanges();
|
||||
|
||||
void resetSensors();
|
||||
/// }
|
||||
|
||||
/// @name OpenVR state
|
||||
/// {
|
||||
vr::IVRSystem *mHMD;
|
||||
vr::IVRRenderModels *mRenderModels;
|
||||
String mDriver;
|
||||
String mDisplay;
|
||||
vr::TrackedDevicePose_t mTrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
|
||||
IDevicePose mCurrentDevicePose[vr::k_unMaxTrackedDeviceCount];
|
||||
IDevicePose mPreviousInputTrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
|
||||
U32 mValidPoseCount;
|
||||
|
||||
char mDeviceClassChar[vr::k_unMaxTrackedDeviceCount];
|
||||
|
||||
OpenVRRenderState mHMDRenderState;
|
||||
/// }
|
||||
|
||||
GuiCanvas* mDrawCanvas;
|
||||
GameConnection* mGameConnection;
|
||||
|
||||
static U32 OVR_SENSORROT[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_SENSORROTANG[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_SENSORVELOCITY[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_SENSORANGVEL[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_SENSORMAGNETOMETER[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_SENSORPOSITION[vr::k_unMaxTrackedDeviceCount];
|
||||
|
||||
static U32 OVR_BUTTONPRESSED[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_BUTTONTOUCHED[vr::k_unMaxTrackedDeviceCount];
|
||||
|
||||
static U32 OVR_AXISNONE[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_AXISTRACKPAD[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_AXISJOYSTICK[vr::k_unMaxTrackedDeviceCount];
|
||||
static U32 OVR_AXISTRIGGER[vr::k_unMaxTrackedDeviceCount];
|
||||
|
||||
|
||||
public:
|
||||
// For ManagedSingleton.
|
||||
static const char* getSingletonName() { return "OpenVRProvider"; }
|
||||
};
|
||||
|
||||
/// Returns the OculusVRDevice singleton.
|
||||
#define OCULUSVRDEV ManagedSingleton<OpenVRProvider>::instance()
|
||||
|
||||
#endif // _OCULUSVRDEVICE_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue