From 862c8d2c4cf006964ea7a6000d28240858a6ca26 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 31 Jan 2023 22:13:11 +0000 Subject: [PATCH] Dynamically select world scale based on game --- .../rendering/hwrenderer/data/hw_vrmodes.cpp | 45 ++++++++++++------- source/core/gameinput.cpp | 4 +- source/core/rendering/hw_entrypoint.cpp | 8 ++-- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp b/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp index 2ed7b21c5..f70882ee7 100644 --- a/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp +++ b/source/common/rendering/hwrenderer/data/hw_vrmodes.cpp @@ -64,8 +64,6 @@ CVAR(Float, vr_ipd, 0.062f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) // METERS // distance between viewer and the display screen CVAR(Float, vr_screendist, 0.80f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS -CVAR(Float, vr_hunits_per_meter, 24.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS - CVAR(Float, vr_height_adjust, 0.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // METERS CVAR(Int, vr_control_scheme, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) CVAR(Bool, vr_move_use_offhand, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) @@ -93,16 +91,33 @@ CVAR(Bool, vr_hud_fixed_roll, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) int playerHeight = 0; +extern int g_gameType; +#define GAMEFLAG_DUKE 0x00000001 +inline bool isDuke() +{ + return g_gameType & (GAMEFLAG_DUKE); +} + +float vr_hunits_per_meter() +{ + if (isDuke()) + { + return 24.0f; + } + + return 41.0f; +} + float getHmdAdjustedHeightInMapUnit() { if (playerHeight != 0) { - return ((hmdPosition[1] + vr_height_adjust) * vr_hunits_per_meter) - + return ((hmdPosition[1] + vr_height_adjust) * vr_hunits_per_meter()) - playerHeight; } //Just use offset from origin - return ((hmdPosition[1] - hmdOrigin[1]) * vr_hunits_per_meter); + return ((hmdPosition[1] - hmdOrigin[1]) * vr_hunits_per_meter()); } #define isqrt2 0.7071067812f @@ -191,14 +206,14 @@ VSMatrix VREyeInfo::GetHUDProjection(int width, int height) const VSMatrix new_projection; new_projection.loadIdentity(); - float stereo_separation = (vr_ipd * 0.5) * vr_hunits_per_meter * vr_hud_stereo * (getEye() == 1 ? 1.0 : -1.0); + float stereo_separation = (vr_ipd * 0.5) * vr_hunits_per_meter() * vr_hud_stereo * (getEye() == 1 ? 1.0 : -1.0); new_projection.translate(stereo_separation, 0, 0); // doom_units from meters new_projection.scale( - -vr_hunits_per_meter, - vr_hunits_per_meter, - -vr_hunits_per_meter); + -vr_hunits_per_meter(), + vr_hunits_per_meter(), + -vr_hunits_per_meter()); if (vr_hud_fixed_roll) { @@ -250,14 +265,14 @@ VSMatrix VREyeInfo::GetPlayerSpriteProjection(int width, int height) const new_projection.loadIdentity(); float weapon_stereo_effect = 2.8f; - float stereo_separation = (vr_ipd * 0.5) * vr_hunits_per_meter * weapon_stereo_effect * (getEye() == 1 ? -1.0 : 1.0); + float stereo_separation = (vr_ipd * 0.5) * vr_hunits_per_meter() * weapon_stereo_effect * (getEye() == 1 ? -1.0 : 1.0); new_projection.translate(stereo_separation, 0, 0); // doom_units from meters new_projection.scale( - -vr_hunits_per_meter, - vr_hunits_per_meter, - -vr_hunits_per_meter); + -vr_hunits_per_meter(), + vr_hunits_per_meter(), + -vr_hunits_per_meter()); new_projection.rotate(-hmdorientation[ROLL], 0, 0, 1); @@ -285,7 +300,7 @@ VSMatrix VREyeInfo::GetPlayerSpriteProjection(int width, int height) const float VREyeInfo::getShift() const { - return mShiftFactor * vr_ipd * vr_hunits_per_meter; + return mShiftFactor * vr_ipd * vr_hunits_per_meter(); } int VREyeInfo::getEye() const @@ -361,8 +376,8 @@ DVector3 VREyeInfo::GetViewShift(FRotator viewAngles) const if (vr_positional_tracking) { - eyeOffset[1] += -posforward * vr_hunits_per_meter; - eyeOffset[0] += posside * vr_hunits_per_meter; + eyeOffset[1] += -posforward * vr_hunits_per_meter(); + eyeOffset[0] += posside * vr_hunits_per_meter(); eyeOffset[2] += getHmdAdjustedHeightInMapUnit(); } diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp index 5aeae8c30..ceadcfa8c 100644 --- a/source/core/gameinput.cpp +++ b/source/core/gameinput.cpp @@ -106,7 +106,7 @@ void resetTurnHeldAmt() void VR_GetMove(float *joy_forward, float *joy_side, float *hmd_forward, float *hmd_side, float *up, float *yaw, float *pitch, float *roll); -extern int resetGameYaw; +extern int resyncVRYawWithGame; //--------------------------------------------------------------------------- // @@ -310,7 +310,7 @@ void PlayerAngles::doViewYaw(const ESyncBits actions) if (ViewAngles.Yaw.Degrees() != 0.0f || ViewAngles.Roll.Degrees() != 0.0f) { - resetGameYaw = 1; + resyncVRYawWithGame = 1; } // Process angle return to zeros. diff --git a/source/core/rendering/hw_entrypoint.cpp b/source/core/rendering/hw_entrypoint.cpp index 35cff4c71..26c48f807 100644 --- a/source/core/rendering/hw_entrypoint.cpp +++ b/source/core/rendering/hw_entrypoint.cpp @@ -56,7 +56,7 @@ EXTERN_CVAR(Bool, cl_capfps) -extern int resetGameYaw; +extern int resyncVRYawWithGame; extern float gameYaw; PalEntry GlobalMapFog; @@ -227,12 +227,12 @@ FRenderViewpoint SetupViewpoint(DCoreActor* cam, const DVector3& position, int s gameYaw -= hmdYawDeltaDegrees; } - if (gamestate == GS_LEVEL && resetGameYaw) + if (gamestate == GS_LEVEL && resyncVRYawWithGame) { - if (resetGameYaw > 0) + if (resyncVRYawWithGame > 0) gameYaw = (float) (-90.f + angles.Yaw.Degrees()); - resetGameYaw--; + resyncVRYawWithGame--; } }