Skip to content

Commit

Permalink
Add vr_floor_offset CVAR to help with seated play.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmbruns committed Jun 27, 2017
1 parent f1a777c commit c24b0bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
15 changes: 7 additions & 8 deletions src/gl/stereo3d/gl_openvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ S_API uint32_t VR_GetInitToken();

#endif

// For conversion between real-world and doom units
#define VERTICAL_DOOM_UNITS_PER_METER 27.0f

EXTERN_CVAR(Int, screenblocks);
EXTERN_CVAR(Float, movebob);
EXTERN_CVAR(Bool, gl_billboard_faces_camera);
EXTERN_CVAR(Int, gl_multisample);
EXTERN_CVAR(Float, vr_vunits_per_meter)
EXTERN_CVAR(Float, vr_floor_offset)

bool IsOpenVRPresent()
{
Expand Down Expand Up @@ -299,7 +298,7 @@ void OpenVREyePose::GetViewShift(FLOATTYPE yaw, FLOATTYPE outViewShift[3]) const
0, 1, 0, 0, // Y-up in OpenVR -> Z-up in Doom
0, 0, 0, 1};
doomInOpenVR.multMatrix(permute);
doomInOpenVR.scale(VERTICAL_DOOM_UNITS_PER_METER, VERTICAL_DOOM_UNITS_PER_METER, VERTICAL_DOOM_UNITS_PER_METER); // Doom units are not meters
doomInOpenVR.scale(vr_vunits_per_meter, vr_vunits_per_meter, vr_vunits_per_meter); // Doom units are not meters
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
doomInOpenVR.scale(pixelstretch, pixelstretch, 1.0); // Doom universe is scaled by 1990s pixel aspect ratio
doomInOpenVR.rotate(deltaYawDegrees, 0, 0, 1);
Expand All @@ -312,7 +311,7 @@ void OpenVREyePose::GetViewShift(FLOATTYPE yaw, FLOATTYPE outViewShift[3]) const
// We want to align those two heights here
const player_t & player = players[consoleplayer];
double vh = player.viewheight; // Doom thinks this is where you are
double hh = openvr_X_hmd[1][3] * VERTICAL_DOOM_UNITS_PER_METER; // HMD is actually here
double hh = (openvr_X_hmd[1][3] - vr_floor_offset) * vr_vunits_per_meter; // HMD is actually here
doom_EyeOffset[2] += hh - vh;
// TODO: optionally allow player to jump and crouch by actually jumping and crouching
}
Expand Down Expand Up @@ -443,9 +442,9 @@ VSMatrix OpenVREyePose::getQuadInWorld(

// doom_units from meters
new_projection.scale(
-VERTICAL_DOOM_UNITS_PER_METER,
VERTICAL_DOOM_UNITS_PER_METER,
-VERTICAL_DOOM_UNITS_PER_METER);
-vr_vunits_per_meter,
vr_vunits_per_meter,
-vr_vunits_per_meter);
double pixelstretch = level.info ? level.info->pixelstretch : 1.2;
new_projection.scale(pixelstretch, pixelstretch, 1.0); // Doom universe is scaled by 1990s pixel aspect ratio

Expand Down
4 changes: 3 additions & 1 deletion src/gl/stereo3d/gl_stereo_cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ CVAR(Float, vr_ipd, 0.062f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // METERS
CVAR(Float, vr_screendist, 0.80f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS

// default conversion between (vertical) DOOM units and meters
CVAR(Float, vr_hunits_per_meter, 41.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS
CVAR(Float, vr_vunits_per_meter, 27.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS

CVAR(Float, vr_floor_offset, 0.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS

// Manage changing of 3D modes:
namespace s3d {
Expand Down
8 changes: 5 additions & 3 deletions src/gl/stereo3d/gl_stereo_leftright.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
#include "gl/renderer/gl_renderstate.h"
#include "gl/renderer/gl_renderer.h"
#include "gl/renderer/gl_renderbuffers.h"
#include "g_levellocals.h" // pixelstretch
#include <cmath>

EXTERN_CVAR(Float, vr_screendist)
EXTERN_CVAR(Float, vr_hunits_per_meter)
EXTERN_CVAR(Float, vr_vunits_per_meter)
EXTERN_CVAR(Bool, vr_swap_eyes)

namespace s3d {
Expand Down Expand Up @@ -69,8 +70,9 @@ VSMatrix ShiftedEyePose::GetProjection(float fov, float aspectRatio, float fovRa
/* virtual */
void ShiftedEyePose::GetViewShift(float yaw, float outViewShift[3]) const
{
float dx = -cos(DEG2RAD(yaw)) * vr_hunits_per_meter * getShift();
float dy = sin(DEG2RAD(yaw)) * vr_hunits_per_meter * getShift();
double pixelstretch = level.info ? level.info->pixelstretch : 1.20;
float dx = -cos(DEG2RAD(yaw)) * vr_vunits_per_meter * pixelstretch * getShift();
float dy = sin(DEG2RAD(yaw)) * vr_vunits_per_meter * pixelstretch * getShift();
outViewShift[0] = dx;
outViewShift[1] = dy;
outViewShift[2] = 0;
Expand Down

0 comments on commit c24b0bf

Please sign in to comment.