Skip to content

Commit

Permalink
Refactor|Client: Moved VRConfig to libappfw
Browse files Browse the repository at this point in the history
Also, removed some of the public member variables of VRConfig.
  • Loading branch information
skyjake committed Jan 30, 2014
1 parent 9d981f3 commit 0f09aa8
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 187 deletions.
87 changes: 4 additions & 83 deletions doomsday/client/include/render/vr.h
Expand Up @@ -21,95 +21,16 @@
#define CLIENT_RENDER_VR_H

#include "dd_types.h"

#include <de/OculusRift>

namespace de {

/**
* Virtual reality configuration settings.
*/
class VRConfig
{
public:
/**
* Stereoscopic 3D rendering mode. This enumeration determines the integer value in
* the console variable.
*/
enum StereoMode
{
Mono, // 0
GreenMagenta,
RedCyan,
LeftOnly,
RightOnly,
TopBottom, // 5
SideBySide,
Parallel,
CrossEye,
OculusRift,
RowInterleaved, // 10 // NOT IMPLEMENTED YET
ColumnInterleaved, // NOT IMPLEMENTED YET
Checkerboard, // NOT IMPLEMENTED YET
QuadBuffered,
NUM_STEREO_MODES
};

public:
VRConfig();

de::OculusRift &oculusRift();
de::OculusRift const &oculusRift() const;

/// Currently active stereo rendering mode.
StereoMode mode() const;

static bool modeNeedsStereoGLFormat(StereoMode mode);

/// @param eye: -1 means left eye, +1 means right eye
/// @return viewpoint eye shift in map units
float getEyeShift(float eye) const;

void setEyeHeightInMapUnits(float eyeHeightInMapUnits);

private:
DENG2_PRIVATE(d)

public:
int vrMode;
float ipd; ///< Interpupillary distance in meters
float playerHeight; ///< Human player's real world height in meters
float dominantEye; ///< Kludge for aim-down-weapon-sight modes
bool swapEyes; ///< When true, inverts stereoscopic effect

// Unlike most 3D modes, Oculus Rift typically uses no frustum shift.
// (or if we did, it would be different and complicated)
bool applyFrustumShift;

// local viewpoint relative eye position in map units,
// VR::eyeShift is ordinarily set from VR::getEyeShift()
float eyeShift;

float hudDistance; // Distance from player character to screen, in map units (not used in Rift mode, because it's used by frustum shift)
float weaponDistance; // (UNUSED) Distance from player character to weapon sprite, in map units

int riftFramebufferSamples; // Multisampling used in unwarped Rift framebuffer
};

} // namespace de
#include <de/VRConfig>

extern de::VRConfig vrCfg;

namespace VR {

// Register console variables
void consoleRegister();
void VR_ConsoleRegister();

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

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

} // namespace VR
bool VR_LoadRiftParameters();

#endif // CLIENT_RENDER_VR_H
8 changes: 4 additions & 4 deletions doomsday/client/src/gl/gl_main.cpp
Expand Up @@ -192,7 +192,7 @@ void GL_DoUpdate()

// Blit screen to video.
ClientWindow::main().swapBuffers(
VRConfig::modeNeedsStereoGLFormat(vrCfg.mode())? gl::SwapStereoBuffers : gl::SwapMonoBuffer);
vrCfg.needsStereoGLFormat()? gl::SwapStereoBuffers : gl::SwapMonoBuffer);

// We will arrive here always at the same time in relation to the displayed
// frame: it is a good time to update the mouse state.
Expand Down Expand Up @@ -586,15 +586,15 @@ Matrix4f GL_GetProjectionMatrix()
* applies the viewpoint shift.
*/
float frustumShift = 0;
if (vrCfg.applyFrustumShift)
if (vrCfg.frustumShift())
{
frustumShift = vrCfg.eyeShift * glNearClip / vrCfg.hudDistance;
frustumShift = vrCfg.eyeShift() * glNearClip / vrCfg.hudDistance;
}

return Matrix4f::frustum(-fW - frustumShift, fW - frustumShift,
-fH, fH,
glNearClip, glFarClip) *
Matrix4f::translate(Vector3f(-vrCfg.eyeShift, 0, 0)) *
Matrix4f::translate(Vector3f(-vrCfg.eyeShift(), 0, 0)) *
Matrix4f::scale(Vector3f(1, 1, -1));
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/rend_main.cpp
Expand Up @@ -429,7 +429,7 @@ void Rend_Register()
LensFx_Register();
fx::Vignette::consoleRegister();
fx::LensFlares::consoleRegister();
VR::consoleRegister();
VR_ConsoleRegister();
}

static void reportWallSectionDrawn(Line &line)
Expand Down
78 changes: 5 additions & 73 deletions doomsday/client/src/render/vr.cpp
@@ -1,7 +1,7 @@
/** @file render/vr.cpp Stereoscopic rendering and Oculus Rift support.
*
* @authors Copyright (c) 2013-2014 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright (c) 2013 Christopher Bruns <cmbruns@rotatingpenguin.com>
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand All @@ -20,82 +20,14 @@
#include "de_console.h"
#include "render/vr.h"

#include <de/OculusRift>

namespace de {

DENG2_PIMPL(VRConfig)
{
de::OculusRift ovr;
float eyeHeightInMapUnits;

Instance(Public *i)
: Base(i)
, eyeHeightInMapUnits(41)
{}
};

VRConfig::VRConfig()
: d(new Instance(this))
, vrMode(Mono)
, ipd(.064f) // average male IPD
, playerHeight(1.75f)
, dominantEye(0.0f)
, swapEyes(0)
, applyFrustumShift(true)
, eyeShift(0)
, hudDistance(20.0f)
, weaponDistance(10)
, riftFramebufferSamples(2)
{}

OculusRift &VRConfig::oculusRift()
{
return d->ovr;
}

OculusRift const &VRConfig::oculusRift() const
{
return d->ovr;
}

VRConfig::StereoMode VRConfig::mode() const
{
return (StereoMode) vrMode;
}

bool VRConfig::modeNeedsStereoGLFormat(StereoMode mode)
{
return mode == QuadBuffered;
}

void VRConfig::setEyeHeightInMapUnits(float eyeHeightInMapUnits)
{
d->eyeHeightInMapUnits = eyeHeightInMapUnits;
}

float VRConfig::getEyeShift(float eye) const
{
// 0.95 because eyes are not at top of head
float mapUnitsPerMeter = d->eyeHeightInMapUnits / (0.95 * playerHeight);
float result = mapUnitsPerMeter * (eye - dominantEye) * 0.5 * ipd;
if(swapEyes)
{
result *= -1;
}
return result;
}

} // namespace de

de::VRConfig vrCfg; // global

static float vrRiftFovX = 114.8f;
static float vrNonRiftFovX = 95.f;
static float riftLatency = .030f;
static byte autoLoadRiftParams = 1;

float VR::riftFovX()
float VR_RiftFovX()
{
return vrRiftFovX;
}
Expand Down Expand Up @@ -151,10 +83,10 @@ static void vrNonRiftFovXChanged()

D_CMD(LoadRiftParams)
{
return VR::loadRiftParameters();
return VR_LoadRiftParameters();
}

void VR::consoleRegister()
void VR_ConsoleRegister()
{
C_VAR_BYTE ("rend-vr-autoload-rift-params", &autoLoadRiftParams, 0, 0, 1);
C_VAR_FLOAT2("rend-vr-nonrift-fovx", &vrNonRiftFovX, 0, 5.0f, 270.0f, vrNonRiftFovXChanged);
Expand All @@ -176,7 +108,7 @@ void VR::consoleRegister()

/// @todo warping

bool VR::loadRiftParameters()
bool VR_LoadRiftParameters()
{
de::OculusRift &ovr = vrCfg.oculusRift();

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -742,7 +742,7 @@ void ClientWindow::canvasGLReady(Canvas &canvas)

PersistentCanvasWindow::canvasGLReady(canvas);

if(VRConfig::modeNeedsStereoGLFormat(vrCfg.mode()) && !canvas.format().stereo())
if(vrCfg.needsStereoGLFormat() && !canvas.format().stereo())
{
LOG_GL_WARNING("Current VR mode needs a stereo buffer, but it isn't supported");
}
Expand Down Expand Up @@ -825,7 +825,7 @@ bool ClientWindow::setDefaultGLFormat() // static
//fmt.setStencilBufferSize(8);
fmt.setDoubleBuffer(true);

if(VRConfig::modeNeedsStereoGLFormat(vrCfg.mode()))
if(vrCfg.needsStereoGLFormat())
{
// Only use a stereo format for modes that require it.
LOG_GL_MSG("Using a stereoscopic frame buffer format");
Expand Down

0 comments on commit 0f09aa8

Please sign in to comment.