From a3df8b20f334535c4780de88be0245b4336b4ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Thu, 21 Aug 2014 19:48:51 +0300 Subject: [PATCH] Fixed|VR|Client: Applying head tracking, fixed VR settings dialog --- doomsday/client/src/render/rend_main.cpp | 13 ++++++---- doomsday/client/src/render/vr.cpp | 19 +++++++-------- doomsday/client/src/ui/clientwindow.cpp | 13 ++++++---- .../src/ui/dialogs/vrsettingsdialog.cpp | 24 +++++++++++-------- 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/doomsday/client/src/render/rend_main.cpp b/doomsday/client/src/render/rend_main.cpp index 0154b8f470..8780d72ece 100644 --- a/doomsday/client/src/render/rend_main.cpp +++ b/doomsday/client/src/render/rend_main.cpp @@ -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; @@ -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 * diff --git a/doomsday/client/src/render/vr.cpp b/doomsday/client/src/render/vr.cpp index e72a055c4b..7fc4c3c547 100644 --- a/doomsday/client/src/render/vr.cpp +++ b/doomsday/client/src/render/vr.cpp @@ -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) @@ -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. @@ -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 diff --git a/doomsday/client/src/ui/clientwindow.cpp b/doomsday/client/src/ui/clientwindow.cpp index c2d76d9854..7ddb6b2a6b 100644 --- a/doomsday/client/src/ui/clientwindow.cpp +++ b/doomsday/client/src/ui/clientwindow.cpp @@ -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 { @@ -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(); @@ -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(); } diff --git a/doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp b/doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp index 6ce04c0aa4..16a91cbaa6 100644 --- a/doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp +++ b/doomsday/client/src/ui/dialogs/vrsettingsdialog.cpp @@ -25,6 +25,7 @@ #include #include +#include "CommandAction" using namespace de; using namespace ui; @@ -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(); @@ -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")); @@ -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());