Baseline working openvr code

This commit is contained in:
James Urquhart 2016-04-17 22:19:42 +01:00
parent e239d106f5
commit ba91478fad
23 changed files with 1463 additions and 457 deletions

View file

@ -62,7 +62,7 @@ MODULE_END;
// OculusVRDevice
//-----------------------------------------------------------------------------
bool OculusVRDevice::smEnableDevice = true;
bool OculusVRDevice::smEnableDevice = false;
bool OculusVRDevice::smSimulateHMD = true;
@ -318,17 +318,6 @@ void OculusVRDevice::getEyeOffsets(Point3F *dest) const
hmd->getEyeOffsets(dest);
}
bool OculusVRDevice::providesFovPorts() const
{
if(!mHMDDevices.size())
return false;
const OculusVRHMDDevice* hmd = getHMDDevice(mActiveDeviceId);
if(!hmd)
return Point3F::Zero;
return true;
}
void OculusVRDevice::getFovPorts(FovPort *out) const
{
@ -562,6 +551,20 @@ GameConnection* OculusVRDevice::getCurrentConnection()
//-----------------------------------------------------------------------------
GFXTexHandle OculusVRDevice::getPreviewTexture()
{
if (!mHMDDevices.size())
return NULL;
OculusVRHMDDevice* hmd = getHMDDevice(mActiveDeviceId);
if (!hmd)
return NULL;
return hmd->getPreviewTexture();
}
//-----------------------------------------------------------------------------
DefineEngineFunction(isOculusVRDeviceActive, bool, (),,
"@brief Used to determine if the Oculus VR input device is active\n\n"

View file

@ -115,8 +115,8 @@ public:
virtual bool providesFrameEyePose() const;
virtual void getFrameEyePose(DisplayPose *outPose, U32 eyeId) const;
virtual bool providesEyeOffsets() const;
virtual bool providesFovPorts() const { return true; }
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;
@ -154,6 +154,8 @@ public:
virtual void setCurrentConnection(GameConnection *connection);
virtual GameConnection* getCurrentConnection();
GFXTexHandle getPreviewTexture();
bool _handleDeviceEvent( GFXDevice::GFXDeviceEventType evt );
public:

View file

@ -43,7 +43,6 @@
#include "OVR_CAPI_GL.h"
#define OCULUS_USE_GL
#endif
extern GFXTextureObject *gLastStereoTexture;
struct OculusTexture
{
@ -317,6 +316,14 @@ void OculusVRHMDDevice::dismissWarning()
//ovr_DismissHSWDisplay(mDevice);
}
GFXTexHandle OculusVRHMDDevice::getPreviewTexture()
{
if (!mIsValid || !mDevice)
return NULL;
return mDebugMirrorTextureHandle;
}
bool OculusVRHMDDevice::setupTargets()
{
// Create eye render buffers
@ -381,9 +388,6 @@ bool OculusVRHMDDevice::setupTargets()
mEyeRT[1] = mStereoRT;
mEyeViewport[1] = RectI(Point2I(mRenderLayer.Viewport[1].Pos.x, mRenderLayer.Viewport[1].Pos.y), Point2I(mRenderLayer.Viewport[1].Size.w, mRenderLayer.Viewport[1].Size.h));
gLastStereoTexture = NULL;
GFXD3D11Device* device = static_cast<GFXD3D11Device*>(GFX);
D3D11_TEXTURE2D_DESC dsDesc;
@ -453,7 +457,6 @@ bool OculusVRHMDDevice::setupTargets()
}
mDebugMirrorTextureHandle = object;
gLastStereoTexture = mDebugMirrorTextureHandle;
}
else
{
@ -673,10 +676,11 @@ void OculusVRHMDDevice::getFrameEyePose(DisplayPose *outPose, U32 eyeId) const
OVR::Quatf orientation = pose.Orientation;
const OVR::Vector3f position = pose.Position;
EulerF rotEuler;
OculusVRUtil::convertRotation(orientation, rotEuler);
MatrixF torqueMat(1);
OVR::Matrix4f mat(orientation);
OculusVRUtil::convertRotation(mat.M, torqueMat);
outPose->orientation = rotEuler;
outPose->orientation = QuatF(torqueMat);
outPose->position = Point3F(-position.x, position.z, -position.y);
}

View file

@ -185,6 +185,8 @@ public:
virtual void setCurrentConnection(GameConnection *connection) { mConnection = connection; }
virtual GameConnection* getCurrentConnection() { return mConnection; }
GFXTexHandle getPreviewTexture();
String dumpMetrics();
// Stereo RT

View file

@ -26,6 +26,7 @@
#include "platform/platformInput.h"
#include "console/simBase.h"
#include "console/engineAPI.h"
#include "math/mAngAxis.h"
#include "OVR_CAPI_0_8_0.h"
U32 OculusVRSensorDevice::OVR_SENSORROT[OculusVRConstants::MaxSensors] = {0};
@ -184,7 +185,8 @@ bool OculusVRSensorDevice::process(U32 deviceType, bool generateRotAsAngAxis, bo
{
if(generateRotAsAngAxis)
{
INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_ROT, OVR_SENSORROT[mActionCodeIndex], SI_MOVE, currentBuffer->mRotQuat);
AngAxisF axisAA(currentBuffer->mRotQuat);
INPUTMGR->buildInputEvent(deviceType, OculusVRConstants::DefaultOVRBase, SI_ROT, OVR_SENSORROT[mActionCodeIndex], SI_MOVE, axisAA);
}
if(generateRotAsEuler)

View file

@ -44,10 +44,7 @@ void convertRotation(const F32 inRotMat[4][4], MatrixF& outRotation)
void convertRotation(OVR::Quatf& inRotation, EulerF& outRotation)
{
F32 yaw, pitch, roll;
inRotation.GetEulerAngles<OVR::Axis_Y, OVR::Axis_X, OVR::Axis_Z>(&yaw, &pitch, &roll);
outRotation.x = -pitch;
outRotation.y = roll;
outRotation.z = -yaw;
inRotation.GetEulerAngles<OVR::Axis_X, OVR::Axis_Z, OVR::Axis_Y, OVR::Rotate_CW, OVR::Handed_R>(&outRotation.x, &outRotation.y, &outRotation.z);
}
void calculateAxisRotation(const MatrixF& inRotation, const F32& maxAxisRadius, Point2F& outRotation)