Implement virtual gun stock

This commit is contained in:
Petr Bartos 2022-10-19 22:20:39 +02:00
parent a235a57205
commit 61faf0a731
4 changed files with 47 additions and 16 deletions

View File

@ -65,7 +65,7 @@ typedef struct {
menuradiobutton_s autoswitch;
menuradiobutton_s scope;
menuradiobutton_s twohanded;
menulist_s twohanded;
menulist_s directionmode;
menulist_s snapturn;
menuradiobutton_s uturn;
@ -84,7 +84,7 @@ static controls3_t s_controls3;
static void Controls3_SetMenuItems( void ) {
s_controls3.autoswitch.curvalue = trap_Cvar_VariableValue( "cg_autoswitch" ) != 0;
s_controls3.scope.curvalue = trap_Cvar_VariableValue( "vr_weaponScope" ) != 0;
s_controls3.twohanded.curvalue = trap_Cvar_VariableValue( "vr_twoHandedWeapons" ) != 0;
s_controls3.twohanded.curvalue = trap_Cvar_VariableValue( "vr_twoHandedWeapons" );
s_controls3.directionmode.curvalue = (int)trap_Cvar_VariableValue( "vr_directionMode" ) % NUM_DIRECTIONMODE;
s_controls3.snapturn.curvalue = (int)trap_Cvar_VariableValue( "vr_snapturn" ) / 45;
s_controls3.uturn.curvalue = trap_Cvar_VariableValue( "vr_uturn" ) != 0;
@ -268,6 +268,14 @@ static void Controls3_MenuInit( void ) {
NULL
};
static const char *s_twohandedmode[] =
{
"Disabled",
"Enabled (Basic)",
"Enabled (VR Gun Stock)",
NULL
};
memset( &s_controls3, 0 ,sizeof(controls3_t) );
Controls3_Cache();
@ -317,13 +325,15 @@ static void Controls3_MenuInit( void ) {
s_controls3.scope.generic.y = y;
y += BIGCHAR_HEIGHT+2;
s_controls3.twohanded.generic.type = MTYPE_RADIOBUTTON;
s_controls3.twohanded.generic.type = MTYPE_SPINCONTROL;
s_controls3.twohanded.generic.name = "Two-Handed Weapons:";
s_controls3.twohanded.generic.flags = QMF_PULSEIFFOCUS|QMF_SMALLFONT;
s_controls3.twohanded.generic.callback = Controls3_MenuEvent;
s_controls3.twohanded.generic.id = ID_TWOHANDED;
s_controls3.twohanded.generic.x = VR_X_POS;
s_controls3.twohanded.generic.y = y;
s_controls3.twohanded.itemnames = s_twohandedmode;
s_controls3.twohanded.numitems = 3;
y += BIGCHAR_HEIGHT+2;
s_controls3.directionmode.generic.type = MTYPE_SPINCONTROL;

View File

@ -889,20 +889,39 @@ static void IN_VRController( qboolean isRightController, XrPosef pose )
if (vr_twoHandedWeapons->integer && vr.weapon_stabilised)
{
//Apply smoothing to the weapon hand
vec3_t smooth_weaponoffset;
VectorAdd(vr.weaponoffset, vr.weaponoffset_last[0], smooth_weaponoffset);
VectorAdd(smooth_weaponoffset, vr.weaponoffset_last[1],smooth_weaponoffset);
VectorScale(smooth_weaponoffset, 1.0f/3.0f, smooth_weaponoffset);
if (vr_twoHandedWeapons->integer == 2) // Virtual gun stock
{
// Offset to the appropriate eye a little bit
vec2_t xy;
rotateAboutOrigin(Cvar_VariableValue("cg_stereoSeparation") / 2.0f, 0.0f, -vr.hmdorientation[YAW], xy);
float x = vr.offhandposition[0] - (vr.hmdposition[0] + xy[0]);
float y = vr.offhandposition[1] - (vr.hmdposition[1] - 0.1f) + vr_heightAdjust->value; // Use a point lower
float z = vr.offhandposition[2] - (vr.hmdposition[2] + xy[1]);
vec3_t vec;
VectorSubtract(vr.offhandoffset, smooth_weaponoffset, vec);
float zxDist = length(x, z);
float zxDist = length(vec[0], vec[2]);
if (zxDist != 0.0f && z != 0.0f) {
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)),
-degrees(atan2f(x, -z)), 0);
}
}
else // Basic two-handed
{
// Apply smoothing to the weapon hand
vec3_t smooth_weaponoffset;
VectorAdd(vr.weaponoffset, vr.weaponoffset_last[0], smooth_weaponoffset);
VectorAdd(smooth_weaponoffset, vr.weaponoffset_last[1],smooth_weaponoffset);
VectorScale(smooth_weaponoffset, 1.0f/3.0f, smooth_weaponoffset);
if (zxDist != 0.0f && vec[2] != 0.0f) {
VectorSet(vr.weaponangles, -degrees(atanf(vec[1] / zxDist)),
-degrees(atan2f(vec[0], -vec[2])), vr.weaponangles[ROLL] / 2.0f); //Dampen roll on stabilised weapon
vec3_t vec;
VectorSubtract(vr.offhandoffset, smooth_weaponoffset, vec);
float zxDist = length(vec[0], vec[2]);
if (zxDist != 0.0f && vec[2] != 0.0f) {
VectorSet(vr.weaponangles, -degrees(atanf(vec[1] / zxDist)),
-degrees(atan2f(vec[0], -vec[2])), vr.weaponangles[ROLL] / 2.0f); // Dampen roll on stabilised weapon
}
}
}
}

View File

@ -69,9 +69,10 @@ itemDef {
itemDef {
name controls3
group grpControls3
type ITEM_TYPE_YESNO
type ITEM_TYPE_MULTI
text "Two-Handed Weapons:"
cvar "vr_twoHandedWeapons"
cvarFloatList { "Disabled" 0 "Enabled (Basic)" 1 "Enabled (VR Gun Stock)" 2}
rect 99 125 256 20
textalign ITEM_ALIGN_RIGHT
textalignx 128

View File

@ -191,9 +191,10 @@ itemDef {
itemDef {
name controls
group grpControls
type ITEM_TYPE_YESNO
type ITEM_TYPE_MULTI
text "Two-Handed Weapons:"
cvar "vr_twoHandedWeapons"
cvarFloatList { "Disabled" 0 "Enabled (Basic)" 1 "Enabled (VR Gun Stock)" 2}
rect 30 56 200 20
textalign ITEM_ALIGN_RIGHT
textalignx 143