Skip to content

Commit

Permalink
Refactor|Oculus Rift: Migrated head tracking to libappfw
Browse files Browse the repository at this point in the history
de::OculusRift accesses LibOVR and provides head tracking information.
  • Loading branch information
skyjake committed Jan 30, 2014
1 parent ad9e78b commit f22b329
Show file tree
Hide file tree
Showing 28 changed files with 439 additions and 362 deletions.
1 change: 0 additions & 1 deletion doomsday/client/client.pro
Expand Up @@ -37,7 +37,6 @@ include(../dep_deng1.pri)
include(../dep_shell.pri)
include(../dep_gui.pri)
include(../dep_appfw.pri)
include(../dep_rift.pri)

# Definitions ----------------------------------------------------------------

Expand Down
59 changes: 3 additions & 56 deletions doomsday/client/include/render/vr.h
Expand Up @@ -22,7 +22,7 @@

#include "dd_types.h"

#include <de/Vector>
#include <de/OculusRift>

namespace de {

Expand Down Expand Up @@ -55,61 +55,11 @@ class VRConfig
NUM_STEREO_MODES
};

/**
* State parameters for Oculus Rift.
*/
class OculusRift {
public:
OculusRift();

bool init();

void deinit();

void setRiftLatency(float latency);

// True if Oculus Rift is enabled and can report head orientation.
bool isReady() const;

void update();

// Called to allow head orientation to change again.
void allowUpdate();

// Returns current pitch, roll, yaw angles, in radians. If no head tracking is available,
// the returned values are not valid.
Vector3f headOrientation() const;

float interpupillaryDistance() const;

// Use screen size instead of resolution in case non-square pixels?
float aspect() const { return 0.5f * _screenSize.x / _screenSize.y; }
Vector2f const &screenSize() const { return _screenSize; }
Vector4f const &chromAbParam() const { return _chromAbParam; }
float distortionScale() const;
float fovX() const; // in degrees
float fovY() const; // in degrees
Vector4f const &hmdWarpParam() const { return _hmdWarpParam; }
float lensSeparationDistance() const { return _lensSeparationDistance; }

private:
DENG2_PRIVATE(d)

Vector2f _screenSize;
float _lensSeparationDistance;
Vector4f _hmdWarpParam;
Vector4f _chromAbParam;
float _eyeToScreenDistance;

public:
float riftLatency;
};

public:
VRConfig();

OculusRift &ovr();
OculusRift const &ovr() const;
OculusRift &oculusRift();
OculusRift const &oculusRift() const;

/// Currently active stereo rendering mode.
StereoMode mode() const;
Expand Down Expand Up @@ -157,9 +107,6 @@ void consoleRegister();

float riftFovX(); ///< Horizontal field of view in Oculus Rift in degrees

// To release memory and resources when done, for tidiness.
//void deleteOculusTracker();

// Load Oculus Rift parameters via Rift SDK
bool loadRiftParameters();

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/dd_main.cpp
Expand Up @@ -2372,7 +2372,7 @@ int DD_GetInteger(int ddvalue)
return (int) GL_PrepareLSTexture(LST_DYNAMIC);

case DD_USING_HEAD_TRACKING:
return vrCfg.mode() == VRConfig::ModeOculusRift && vrCfg.ovr().isReady();
return vrCfg.mode() == VRConfig::ModeOculusRift && vrCfg.oculusRift().isReady();
#endif

case DD_NUMLUMPS:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -564,7 +564,7 @@ Matrix4f GL_GetProjectionMatrix()

if (vrCfg.mode() == VRConfig::ModeOculusRift)
{
aspect = vrCfg.ovr().aspect();
aspect = vrCfg.oculusRift().aspect();
// A little trigonometry to apply aspect ratio to angles
float x = tan(0.5 * de::degreeToRadian(Rend_FieldOfView()));
yfov = de::radianToDegree(2.0 * atan2(x/aspect, 1.0f));
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -540,9 +540,9 @@ Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
* these values and is syncing with them independently (however, game has more
* latency).
*/
if((vrCfg.mode() == VRConfig::ModeOculusRift) && vrCfg.ovr().isReady())
if((vrCfg.mode() == VRConfig::ModeOculusRift) && vrCfg.oculusRift().isReady())
{
Vector3f const pry = vrCfg.ovr().headOrientation();
Vector3f const pry = vrCfg.oculusRift().headOrientation();

// Use angles directly from the Rift for best response.
roll = -radianToDegree(pry[1]);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/render/viewports.cpp
Expand Up @@ -872,7 +872,7 @@ DENG_EXTERN_C void R_RenderPlayerView(int num)

// Latest possible time to check the real head angles. After this we'll be
// using the provided values.
vrCfg.ovr().update();
vrCfg.oculusRift().update();

R_SetupPlayerSprites();

Expand Down Expand Up @@ -1324,7 +1324,7 @@ angle_t viewer_t::angle() const
{
// Apply the actual, current yaw offset. The game has omitted the "body yaw"
// portion from the value already.
a += (fixed_t)(radianToDegree(vrCfg.ovr().headOrientation()[2]) / 180 * ANGLE_180);
a += (fixed_t)(radianToDegree(vrCfg.oculusRift().headOrientation()[2]) / 180 * ANGLE_180);
}
return a;
}

0 comments on commit f22b329

Please sign in to comment.