Skip to content

Commit

Permalink
Fixed|VR|Client: Applying head tracking, fixed VR settings dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 21, 2014
1 parent f37d3aa commit a3df8b2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
13 changes: 9 additions & 4 deletions doomsday/client/src/render/rend_main.cpp
Expand Up @@ -512,6 +512,8 @@ Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
{
viewdata_t const *viewData = R_ViewData(consoleNum);

float bodyAngle = viewData->current.angleWithoutHeadTracking() / (float) ANGLE_MAX * 360 - 90;

vOrigin = viewData->current.origin.xzy();
vang = viewData->current.angle() / (float) ANGLE_MAX * 360 - 90; // head tracking included
vpitch = viewData->current.pitch * 85.0 / 110.0;
Expand All @@ -532,19 +534,22 @@ Matrix4f Rend_GetModelViewMatrix(int consoleNum, bool useAngles)
* these values and is syncing with them independently (however, game has more
* latency).
*/
if((vrCfg().mode() == VRConfig::OculusRift) && vrCfg().oculusRift().isReady())
OculusRift &ovr = vrCfg().oculusRift();

if((vrCfg().mode() == VRConfig::OculusRift) && ovr.isReady())
{
Vector3f const pry = vrCfg().oculusRift().headOrientation();
Vector3f const pry = ovr.headOrientation();

// Use angles directly from the Rift for best response.
roll = -radianToDegree(pry[1]);
pitch = radianToDegree(pry[0]);

}

modelView = Matrix4f::rotate(roll, Vector3f(0, 0, 1)) *
Matrix4f::rotate(pitch, Vector3f(1, 0, 0)) *
Matrix4f::rotate(yaw, Vector3f(0, 1, 0));
Matrix4f::rotate(yaw, Vector3f(0, 1, 0)) *
Matrix4f::translate(Matrix4f::rotate(radianToDegree(bodyAngle), Vector3f(0, 1, 0)) *
(ovr.headPosition() * vrCfg().mapUnitsPerMeter()));
}

return (modelView *
Expand Down
19 changes: 9 additions & 10 deletions doomsday/client/src/render/vr.cpp
Expand Up @@ -88,16 +88,6 @@ static void vrModeChanged()
win.updateCanvasFormat(); // possibly changes pixel format
}

// Make sure Oculus Rift rendering is (de)initialized as needed.
if(vrCfg().mode() == VRConfig::OculusRift)
{
vrCfg().oculusRift().init();
}
else
{
vrCfg().oculusRift().deinit();
}

/*
// Update FOV cvar accordingly.
if(vrMode == VRConfig::OculusRift)
Expand Down Expand Up @@ -140,6 +130,14 @@ D_CMD(LoadRiftParams)
return VR_LoadRiftParameters();
}*/

D_CMD(ResetRiftPose)
{
DENG2_UNUSED3(src, argc, argv);
vrCfg().oculusRift().resetTracking();
LOG_INPUT_MSG("Reset Oculus Rift position tracking");
return true;
}

void VR_ConsoleRegister()
{
// Get the built-in defaults.
Expand Down Expand Up @@ -170,6 +168,7 @@ void VR_ConsoleRegister()
C_VAR_BYTE2 ("rend-vr-swap-eyes", &vrSwapEyes, 0, 0, 1, vrConfigVariableChanged);

//C_CMD("loadriftparams", NULL, LoadRiftParams);
C_CMD("resetriftpose", NULL, ResetRiftPose);
}

#if 0
Expand Down
13 changes: 8 additions & 5 deletions doomsday/client/src/ui/clientwindow.cpp
Expand Up @@ -642,14 +642,16 @@ DENG2_PIMPL(ClientWindow)

Vector3f const pry = vrCfg().oculusRift().headOrientation();


/// @todo Adjustable compositor depth?
compositor->setCompositeProjection(
GL_GetProjectionMatrix()
* Matrix4f::rotate(radianToDegree(pry[1]), Vector3f(0, 0, -1))
* Matrix4f::rotate(radianToDegree(pry[0]), Vector3f(1, 0, 0))
* Matrix4f::rotate(radianToDegree(pry[2]), Vector3f(0, 1, 0))
* Matrix4f::translate(swizzle(vrCfg().oculusRift().headOrientation(),
AxisNegX, AxisNegY, AxisZ))
* Matrix4f::scale(Vector3f(1.f, -1.f / vrCfg().oculusRift().aspect(), 1.f))
* Matrix4f::translate(Vector3f(-.5f, -.5f, -uiDistance)));
* Matrix4f::scale(Vector3f(uiSize, -uiSize / vrCfg().oculusRift().aspect(), 1.f))
* Matrix4f::translate(Vector3f(-.5f, -.5f, uiDistance)));
}
else
{
Expand Down Expand Up @@ -809,6 +811,8 @@ void ClientWindow::canvasGLInit(Canvas &)

void ClientWindow::preDraw()
{
// NOTE: This occurs during the Canvas paintGL event.

ClientApp::app().preFrame(); /// @todo what about multiwindow?

DENG_ASSERT_IN_MAIN_THREAD();
Expand All @@ -821,14 +825,13 @@ void ClientWindow::preDraw()
{
d->updateRootSize();
}
d->updateCompositor();

// NOTE: This occurs during the Canvas paintGL event.
BaseWindow::preDraw();
}

void ClientWindow::drawWindowContent()
{
d->updateCompositor();
root().draw();
LIBGUI_ASSERT_GL_OK();
}
Expand Down
24 changes: 14 additions & 10 deletions doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp
Expand Up @@ -25,6 +25,7 @@
#include <doomsday/console/exec.h>

#include <de/SignalAction>
#include "CommandAction"

using namespace de;
using namespace ui;
Expand All @@ -37,13 +38,13 @@ DENG_GUI_PIMPL(VRSettingsDialog)
CVarSliderWidget *humanHeight;
CVarSliderWidget *ipd;
CVarSliderWidget *riftSamples;
CVarSliderWidget *riftPredictionLatency;
ButtonWidget *riftReset;
ButtonWidget *riftSetup;
ButtonWidget *desktopSetup;

Instance(Public *i)
: Base(i)
, riftPredictionLatency(0)
, riftReset(0)
, riftSetup(0)
{
ScrollAreaWidget &area = self.area();
Expand Down Expand Up @@ -72,8 +73,9 @@ DENG_GUI_PIMPL(VRSettingsDialog)

if(vrCfg().oculusRift().isReady())
{
area.add(riftPredictionLatency = new CVarSliderWidget("rend-vr-rift-latency"));
riftPredictionLatency->setDisplayFactor(1000);
area.add(riftReset = new ButtonWidget);
riftReset->setText(tr("Recenter Tracking"));
riftReset->setAction(new CommandAction("resetriftpose"));

area.add(riftSetup = new ButtonWidget);
riftSetup->setText(tr("Apply Rift Settings"));
Expand Down Expand Up @@ -127,14 +129,16 @@ VRSettingsDialog::VRSettingsDialog(String const &name)
layout.setCellAlignment(Vector2i(0, 5), ui::AlignLeft);
layout.append(*ovrLabel, 2) << *sampleLabel << *d->riftSamples;

LabelWidget *utilLabel = LabelWidget::newWithText(tr("Utilities:"), &area());
if(vrCfg().oculusRift().isReady())
{
LabelWidget *latencyLabel = LabelWidget::newWithText(tr("Prediction Latency:"), &area());
LabelWidget *utilLabel = LabelWidget::newWithText(tr("Utilities:"), &area());

layout << *latencyLabel << *d->riftPredictionLatency
<< *utilLabel << *d->riftSetup
<< Const(0) << *d->desktopSetup;
layout << *utilLabel << *d->riftReset
<< Const(0) << *d->riftSetup
<< Const(0) << *d->desktopSetup;
}
else
{
layout << *utilLabel << *d->desktopSetup;
}

area().setContentSize(layout.width(), layout.height());
Expand Down

0 comments on commit a3df8b2

Please sign in to comment.