Oculus VR DK2 Support

- Updated to work with 0.5.x SDK
- Uses Oculus Rendering rather than PostFX
- Stereo rendering refactored so more rendering info is grabbed from the DisplayDevice
- Implements an Offscreen Canvas for in-game gui with oculus
- Message dialogs and metrics display can now go to the OffScreen Canvas (if oculus demo is setup correctly)
This commit is contained in:
James Urquhart 2015-05-06 23:07:48 +01:00
parent b3170bcddf
commit 3a457749ec
56 changed files with 2654 additions and 1426 deletions

View file

@ -279,6 +279,7 @@ Camera::Camera()
mLastAbsoluteYaw = 0.0f;
mLastAbsolutePitch = 0.0f;
mLastAbsoluteRoll = 0.0f;
// For NewtonFlyMode
mNewtonRotation = false;
@ -379,6 +380,57 @@ void Camera::getCameraTransform(F32* pos, MatrixF* mat)
mat->mul( gCamFXMgr.getTrans() );
}
void Camera::getEyeCameraTransform(IDisplayDevice *displayDevice, U32 eyeId, MatrixF *outMat)
{
// The camera doesn't support a third person mode,
// so we want to override the default ShapeBase behavior.
ShapeBase * obj = dynamic_cast<ShapeBase*>(static_cast<SimObject*>(mOrbitObject));
if(obj && static_cast<ShapeBaseData*>(obj->getDataBlock())->observeThroughObject)
obj->getEyeCameraTransform(displayDevice, eyeId, outMat);
else
{
Parent::getEyeCameraTransform(displayDevice, eyeId, outMat);
}
}
DisplayPose Camera::calcCameraDeltaPose(GameConnection *con, DisplayPose inPose)
{
// NOTE: this is intended to be similar to updateMove
DisplayPose outPose;
outPose.orientation = EulerF(0,0,0);
outPose.position = inPose.position;
// Pitch
outPose.orientation.x = (inPose.orientation.x - mLastAbsolutePitch);
// Constrain the range of mRot.x
while (outPose.orientation.x < -M_PI_F)
outPose.orientation.x += M_2PI_F;
while (outPose.orientation.x > M_PI_F)
outPose.orientation.x -= M_2PI_F;
// Yaw
outPose.orientation.z = (inPose.orientation.z - mLastAbsoluteYaw);
// Constrain the range of mRot.z
while (outPose.orientation.z < -M_PI_F)
outPose.orientation.z += M_2PI_F;
while (outPose.orientation.z > M_PI_F)
outPose.orientation.z -= M_2PI_F;
// Bank
if (mDataBlock->cameraCanBank)
{
outPose.orientation.y = (inPose.orientation.y - mLastAbsoluteRoll);
}
// Constrain the range of mRot.y
while (outPose.orientation.y > M_PI_F)
outPose.orientation.y -= M_2PI_F;
return outPose;
}
//----------------------------------------------------------------------------
F32 Camera::getCameraFov()
@ -547,6 +599,7 @@ void Camera::processTick(const Move* move)
mLastAbsoluteYaw = emove->rotZ[emoveIndex];
mLastAbsolutePitch = emove->rotX[emoveIndex];
mLastAbsoluteRoll = emove->rotY[emoveIndex];
// Bank
mRot.y = emove->rotY[emoveIndex];

View file

@ -113,6 +113,7 @@ class Camera: public ShapeBase
F32 mLastAbsoluteYaw; ///< Stores that last absolute yaw value as passed in by ExtendedMove
F32 mLastAbsolutePitch; ///< Stores that last absolute pitch value as passed in by ExtendedMove
F32 mLastAbsoluteRoll; ///< Stores that last absolute roll value as passed in by ExtendedMove
/// @name NewtonFlyMode
/// @{
@ -235,6 +236,8 @@ class Camera: public ShapeBase
virtual void processTick( const Move* move );
virtual void interpolateTick( F32 delta);
virtual void getCameraTransform( F32* pos,MatrixF* mat );
virtual void getEyeCameraTransform( IDisplayDevice *display, U32 eyeId, MatrixF *outMat );
virtual DisplayPose calcCameraDeltaPose(GameConnection *con, DisplayPose inPose);
virtual void writePacketData( GameConnection* conn, BitStream* stream );
virtual void readPacketData( GameConnection* conn, BitStream* stream );

View file

@ -39,6 +39,9 @@
#include "scene/sceneManager.h"
#define __SCENEMANAGER_H__
#endif
#ifndef _IDISPLAYDEVICE_H_
#include "platform/output/IDisplayDevice.h"
#endif
class NetConnection;
class ProcessList;
@ -418,6 +421,7 @@ public:
// Not implemented here, but should return the Camera to world transformation matrix
virtual void getCameraTransform (F32 *pos, MatrixF *mat ) { *mat = MatrixF::Identity; }
virtual void getEyeCameraTransform ( IDisplayDevice *device, U32 eyeId, MatrixF *mat ) { *mat = MatrixF::Identity; }
/// Returns the water object we are colliding with, it is up to derived
/// classes to actually set this object.

View file

@ -235,6 +235,7 @@ GameConnection::GameConnection()
GameConnection::~GameConnection()
{
setDisplayDevice(NULL);
delete mAuthInfo;
for(U32 i = 0; i < mConnectArgc; i++)
dFree(mConnectArgv[i]);
@ -673,6 +674,30 @@ bool GameConnection::getControlCameraTransform(F32 dt, MatrixF* mat)
return true;
}
bool GameConnection::getControlCameraEyeTransforms(IDisplayDevice *display, MatrixF *transforms)
{
GameBase* obj = getCameraObject();
if(!obj)
return false;
GameBase* cObj = obj;
while((cObj = cObj->getControlObject()) != 0)
{
if(cObj->useObjsEyePoint())
obj = cObj;
}
// Perform operation on left & right eyes. For each we need to calculate the world space
// of the rotated eye offset and add that onto the camera world space.
for (U32 i=0; i<2; i++)
{
obj->getEyeCameraTransform(display, i, &transforms[i]);
}
return true;
}
bool GameConnection::getControlCameraDefaultFov(F32 * fov)
{
//find the last control object in the chain (client->player->turret->whatever...)

View file

@ -269,6 +269,10 @@ public:
bool getControlCameraTransform(F32 dt,MatrixF* mat);
bool getControlCameraVelocity(Point3F *vel);
/// Returns the eye transforms for the control object, using supplemental information
/// from the provided IDisplayDevice.
bool getControlCameraEyeTransforms(IDisplayDevice *display, MatrixF *transforms);
bool getControlCameraDefaultFov(F32 *fov);
bool getControlCameraFov(F32 *fov);
bool setControlCameraFov(F32 fov);
@ -280,8 +284,8 @@ public:
void setFirstPerson(bool firstPerson);
bool hasDisplayDevice() const { return mDisplayDevice != NULL; }
const IDisplayDevice* getDisplayDevice() const { return mDisplayDevice; }
void setDisplayDevice(IDisplayDevice* display) { mDisplayDevice = display; }
IDisplayDevice* getDisplayDevice() const { return mDisplayDevice; }
void setDisplayDevice(IDisplayDevice* display) { if (mDisplayDevice) mDisplayDevice->setDrawCanvas(NULL); mDisplayDevice = display; }
void clearDisplayDevice() { mDisplayDevice = NULL; }
void setControlSchemeParameters(bool absoluteRotation, bool addYawToAbsRot, bool addPitchToAbsRot);

View file

@ -349,7 +349,6 @@ bool GameProcessCameraQuery(CameraQuery *query)
// Provide some default values
query->projectionOffset = Point2F::Zero;
query->eyeOffset = Point3F::Zero;
F32 cameraFov = 0.0f;
bool fovSet = false;
@ -358,14 +357,14 @@ bool GameProcessCameraQuery(CameraQuery *query)
// is not open
if(!gEditingMission && connection->hasDisplayDevice())
{
const IDisplayDevice* display = connection->getDisplayDevice();
IDisplayDevice* display = connection->getDisplayDevice();
// Note: all eye values are invalid until this is called
display->setDrawCanvas(query->drawCanvas);
// The connection's display device may want to set the FOV
if(display->providesYFOV())
{
cameraFov = mRadToDeg(display->getYFOV());
fovSet = true;
}
display->setCurrentConnection(connection);
// Display may activate AFTER so we need to call this again just in case
display->onStartFrame();
// The connection's display device may want to set the projection offset
if(display->providesProjectionOffset())
@ -374,14 +373,27 @@ bool GameProcessCameraQuery(CameraQuery *query)
}
// The connection's display device may want to set the eye offset
if(display->providesEyeOffset())
if(display->providesEyeOffsets())
{
query->eyeOffset = display->getEyeOffset();
display->getEyeOffsets(query->eyeOffset);
}
// Grab field of view for both eyes
if (display->providesFovPorts())
{
display->getFovPorts(query->fovPort);
fovSet = true;
}
// Grab the latest overriding render view transforms
connection->getControlCameraEyeTransforms(display, query->eyeTransforms);
display->getStereoViewports(query->stereoViewports);
display->getStereoTargets(query->stereoTargets);
}
// Use the connection's FOV settings if requried
if(!fovSet && !connection->getControlCameraFov(&cameraFov))
if(!connection->getControlCameraFov(&cameraFov))
{
return false;
}

View file

@ -1650,6 +1650,7 @@ Player::Player()
mLastAbsoluteYaw = 0.0f;
mLastAbsolutePitch = 0.0f;
mLastAbsoluteRoll = 0.0f;
}
Player::~Player()
@ -2608,6 +2609,7 @@ void Player::updateMove(const Move* move)
}
mLastAbsoluteYaw = emove->rotZ[emoveIndex];
mLastAbsolutePitch = emove->rotX[emoveIndex];
mLastAbsoluteRoll = emove->rotY[emoveIndex];
// Head bank
mHead.y = emove->rotY[emoveIndex];
@ -5584,6 +5586,57 @@ void Player::getMuzzleTransform(U32 imageSlot,MatrixF* mat)
*mat = nmat;
}
DisplayPose Player::calcCameraDeltaPose(GameConnection *con, DisplayPose inPose)
{
// NOTE: this is intended to be similar to updateMove
DisplayPose outPose;
outPose.orientation = getRenderTransform().toEuler();
outPose.position = inPose.position;
if (con && con->getControlSchemeAbsoluteRotation())
{
// Pitch
outPose.orientation.x = (inPose.orientation.x - mLastAbsolutePitch);
// Constrain the range of mRot.x
while (outPose.orientation.x < -M_PI_F)
outPose.orientation.x += M_2PI_F;
while (outPose.orientation.x > M_PI_F)
outPose.orientation.x -= M_2PI_F;
// Yaw
// Rotate (heading) head or body?
if ((isMounted() && getMountNode() == 0) || (con && !con->isFirstPerson()))
{
// Rotate head
outPose.orientation.z = (inPose.orientation.z - mLastAbsoluteYaw);
}
else
{
// Rotate body
outPose.orientation.z = (inPose.orientation.z - mLastAbsoluteYaw);
}
// Constrain the range of mRot.z
while (outPose.orientation.z < 0.0f)
outPose.orientation.z += M_2PI_F;
while (outPose.orientation.z > M_2PI_F)
outPose.orientation.z -= M_2PI_F;
// Bank
if (mDataBlock->cameraCanBank)
{
outPose.orientation.y = (inPose.orientation.y - mLastAbsoluteRoll);
}
// Constrain the range of mRot.y
while (outPose.orientation.y > M_PI_F)
outPose.orientation.y -= M_2PI_F;
}
return outPose;
}
void Player::getRenderMuzzleTransform(U32 imageSlot,MatrixF* mat)
{

View file

@ -439,6 +439,7 @@ protected:
F32 mLastAbsoluteYaw; ///< Stores that last absolute yaw value as passed in by ExtendedMove
F32 mLastAbsolutePitch; ///< Stores that last absolute pitch value as passed in by ExtendedMove
F32 mLastAbsoluteRoll; ///< Stores that last absolute roll value as passed in by ExtendedMove
S32 mMountPending; ///< mMountPending suppresses tickDelay countdown so players will sit until
///< their mount, or another animation, comes through (or 13 seconds elapses).
@ -683,6 +684,7 @@ public:
void getEyeBaseTransform(MatrixF* mat, bool includeBank);
void getRenderEyeTransform(MatrixF* mat);
void getRenderEyeBaseTransform(MatrixF* mat, bool includeBank);
virtual DisplayPose calcCameraDeltaPose(GameConnection *con, DisplayPose inPose);
void getCameraParameters(F32 *min, F32 *max, Point3F *offset, MatrixF *rot);
void getMuzzleTransform(U32 imageSlot,MatrixF* mat);
void getRenderMuzzleTransform(U32 imageSlot,MatrixF* mat);

View file

@ -1969,6 +1969,75 @@ void ShapeBase::getCameraTransform(F32* pos,MatrixF* mat)
mat->mul( gCamFXMgr.getTrans() );
}
void ShapeBase::getEyeCameraTransform(IDisplayDevice *displayDevice, U32 eyeId, MatrixF *outMat)
{
MatrixF temp(1);
Point3F eyePos;
Point3F rotEyePos;
DisplayPose inPose;
displayDevice->getFrameEyePose(&inPose, eyeId);
DisplayPose newPose = calcCameraDeltaPose(displayDevice->getCurrentConnection(), inPose);
// Ok, basically we just need to add on newPose to the camera transform
// NOTE: currently we dont support third-person camera in this mode
MatrixF cameraTransform(1);
F32 fakePos = 0;
getCameraTransform(&fakePos, &cameraTransform);
QuatF baserot = cameraTransform;
QuatF qrot = QuatF(newPose.orientation);
QuatF concatRot;
concatRot.mul(baserot, qrot);
concatRot.setMatrix(&temp);
temp.setPosition(cameraTransform.getPosition() + concatRot.mulP(newPose.position, &rotEyePos));
*outMat = temp;
}
DisplayPose ShapeBase::calcCameraDeltaPose(GameConnection *con, DisplayPose inPose)
{
// NOTE: this is intended to be similar to updateMove
// WARNING: does not take into account any move values
DisplayPose outPose;
outPose.orientation = getRenderTransform().toEuler();
outPose.position = inPose.position;
if (con && con->getControlSchemeAbsoluteRotation())
{
// Pitch
outPose.orientation.x = inPose.orientation.x;
// Constrain the range of mRot.x
while (outPose.orientation.x < -M_PI_F)
outPose.orientation.x += M_2PI_F;
while (outPose.orientation.x > M_PI_F)
outPose.orientation.x -= M_2PI_F;
// Yaw
outPose.orientation.z = inPose.orientation.z;
// Constrain the range of mRot.z
while (outPose.orientation.z < -M_PI_F)
outPose.orientation.z += M_2PI_F;
while (outPose.orientation.z > M_PI_F)
outPose.orientation.z -= M_2PI_F;
// Bank
if (mDataBlock->cameraCanBank)
{
outPose.orientation.y = inPose.orientation.y;
}
// Constrain the range of mRot.y
while (outPose.orientation.y > M_PI_F)
outPose.orientation.y -= M_2PI_F;
}
return outPose;
}
void ShapeBase::getCameraParameters(F32 *min,F32* max,Point3F* off,MatrixF* rot)
{
*min = mDataBlock->cameraMinDist;
@ -1977,7 +2046,6 @@ void ShapeBase::getCameraParameters(F32 *min,F32* max,Point3F* off,MatrixF* rot)
rot->identity();
}
//----------------------------------------------------------------------------
F32 ShapeBase::getDamageFlash() const
{

View file

@ -63,7 +63,6 @@
#include "console/dynamicTypes.h"
#endif
class GFXCubemap;
class TSShapeInstance;
class SceneRenderState;
@ -1583,6 +1582,13 @@ public:
/// @param mat Camera transform (out)
virtual void getCameraTransform(F32* pos,MatrixF* mat);
/// Gets the view transform for a particular eye, taking into account the current absolute
/// orient and position values of the display device.
virtual void getEyeCameraTransform( IDisplayDevice *display, U32 eyeId, MatrixF *outMat );
/// Calculates a delta camera angle and view position based on inPose
virtual DisplayPose calcCameraDeltaPose(GameConnection *con, DisplayPose inPose);
/// Gets the index of a node inside a mounted image given the name
/// @param imageSlot Image slot
/// @param nodeName Node name