IRL crouch

This commit is contained in:
Petr Bartos 2023-10-12 20:58:59 +02:00
parent ce6d680ba9
commit 1d6418330b
7 changed files with 106 additions and 0 deletions

View file

@ -1504,6 +1504,8 @@ void RTCWVR_Init()
vr_gesture_triggered_use = Cvar_Get ("vr_gesture_triggered_use", "1", CVAR_ARCHIVE);
vr_use_gesture_boundary = Cvar_Get ("vr_use_gesture_boundary", "0.35", CVAR_ARCHIVE);
vr_draw_hud = Cvar_Get ("vr_draw_hud", "1", CVAR_ARCHIVE);
vr_irl_crouch_enabled = Cvar_Get ("vr_irl_crouch_enabled", "0", CVAR_ARCHIVE);
vr_irl_crouch_to_stand_ratio = Cvar_Get ("vr_irl_crouch_to_stand_ratio", "0.65", CVAR_ARCHIVE);
//Defaults
vr_control_scheme = Cvar_Get( "vr_control_scheme", "0", CVAR_ARCHIVE);
@ -1857,6 +1859,13 @@ void RTCWVR_getHMDOrientation() {//Get orientation
updateHMDOrientation();
// Max-height is set only once on start, or after re-calibration
// (ignore too low value which is sometimes provided on start)
if (!vr.maxHeight || vr.maxHeight < 1.0) {
vr.maxHeight = positionHmd.y;
}
vr.curHeight = positionHmd.y;
ALOGV(" HMD-Position: %f, %f, %f", positionHmd.x, positionHmd.y, positionHmd.z);
}

View file

@ -81,6 +81,10 @@ typedef struct {
qboolean toggleMainMenu;
int akimboTriggerState;
qboolean akimboFire;
qboolean vrIrlCrouchEnabled;
float vrIrlCrouchToStandRatio;
float maxHeight;
float curHeight;
//////////////////////////////////////
// Test stuff for weapon alignment

View file

@ -16,3 +16,5 @@ cvar_t *vr_screen_dist;
cvar_t *vr_gesture_triggered_use;
cvar_t *vr_use_gesture_boundary;
cvar_t *vr_draw_hud;
cvar_t *vr_irl_crouch_enabled;
cvar_t *vr_irl_crouch_to_stand_ratio;

View file

@ -44,6 +44,8 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG
vr.teleportenabled = vr_teleport->integer != 0;
vr.visible_hud = vr_draw_hud->integer;
vr.vrIrlCrouchEnabled = vr_irl_crouch_enabled->integer != 0;
vr.vrIrlCrouchToStandRatio = vr_irl_crouch_to_stand_ratio->value;
static qboolean dominantGripPushed = false;
static float dominantGripPushTime = 0.0f;
@ -595,6 +597,8 @@ void HandleInput_Default( ovrInputStateGamepad *pFootTrackingNew, ovrInputStateG
(primaryButtonsOld & primaryButton1)) {
sendButtonAction("+movedown", (primaryButtonsNew & primaryButton1));
// Reset max height for IRL crouch
vr.maxHeight = 0;
}
//Weapon Chooser

View file

@ -1635,6 +1635,60 @@ static void PM_CheckDuck( void ) {
return;
}
// IRL Crouch
vr_client_info_t* vr;
#ifdef CGAMEDLL
vr = cgVR;
#endif
#ifdef GAMEDLL
vr = gVR;
#endif
if (vr && !pm->ps->clientNum && vr->vrIrlCrouchEnabled) {
int standheight = pm->ps->maxs[2];
int crouchheight = pm->ps->crouchMaxZ;
// In-game view height always matches full stand height
// (we are crouching IRL, no need to artificially lower view)
pm->ps->viewheight = standheight - 8;
// Compute in-game height based on HMD height above floor
// (adjust height only when crouching, ignore IRL jumps)
int computedHeight = pm->ps->standViewHeight;
if (crouchheight < standheight && vr->curHeight < vr->maxHeight) {
// Count minimum IRL crouch height based on maximum IRL height
//trap_Cvar_VariableValue("vr_irl_crouch_to_stand_ratio", &vrIrlCrouchToStandRatio);
float minHeight = vr->maxHeight * vr->vrIrlCrouchToStandRatio;
if (vr->curHeight < minHeight) { // Do not allow to crawl (set min height)
computedHeight = crouchheight;
} else {
float heightRatio = (vr->curHeight - minHeight) / (vr->maxHeight - minHeight);
computedHeight = pm->ps->crouchViewHeight + (int)(heightRatio * (standheight - crouchheight));
}
}
// Adjust height based on where are you standing
// (cannot stand up if there is no place, find nearest possible height)
for (int i = computedHeight; i > 0; i--) {
pm->maxs[2] = i;
pm->trace( &trace, pm->ps->origin, pm->mins, pm->maxs, pm->ps->origin, pm->ps->clientNum, pm->tracemask );
if ( !trace.allsolid ) {
break;
} else {
// Lower view height to not see through ceiling
// (in case you stand up IRL in tight place)
pm->ps->viewheight--;
}
}
// Toggle duck flag based on in-game height (need to be at least half-way crouched)
if (pm->maxs[2] < crouchheight + (standheight - crouchheight)/2) {
pm->ps->pm_flags |= PMF_DUCKED;
} else {
pm->ps->pm_flags &= ~PMF_DUCKED;
}
return;
}
if ( pm->cmd.upmove < 0 ) { // duck
pm->ps->pm_flags |= PMF_DUCKED;
} else

View file

@ -413,6 +413,23 @@ itemDef
visible 1
}
itemDef {
name vr
group grpControls
type ITEM_TYPE_YESNO
text "IRL Crouch:"
cvar "vr_irl_crouch_enabled"
rect 82 285 290 12
textalign ITEM_ALIGN_RIGHT
textalignx 142
textaligny 10
textscale .23
style WINDOW_STYLE_FILLED
backcolor 1 1 1 .07
forecolor 1 1 1 1
visible 1
}
// TOOLS MESSAGE //
itemDef

View file

@ -386,6 +386,22 @@ itemDef
visible 1
}
itemDef {
name ingame_vr
group grpControls
type ITEM_TYPE_YESNO
text "IRL Crouch:"
cvar "vr_irl_crouch_enabled"
rect 82 285 290 12
textalign ITEM_ALIGN_RIGHT
textalignx 142
textaligny 10
textscale .23
style WINDOW_STYLE_FILLED
backcolor 1 1 1 .07
forecolor 1 1 1 1
visible 1
}
itemDef {
name yesno_message