mirror of
https://github.com/DrBeef/RTCWQuest.git
synced 2025-03-03 23:51:20 +00:00
More virtual stock stuff
This commit is contained in:
parent
f0d839b38f
commit
62eef448fc
10 changed files with 88 additions and 33 deletions
|
@ -1340,8 +1340,8 @@ void RTCWVR_Init()
|
|||
vr.backpackitemactive = 0;
|
||||
vr.visible_hud = qtrue;
|
||||
vr.dualwield = qfalse;
|
||||
vr.vstock_weapon = qfalse;
|
||||
vr.vstock_engaged = qfalse;
|
||||
vr.ironsight_lock_weapon = qfalse;
|
||||
vr.ironsight_lock_engaged = qfalse;
|
||||
|
||||
//Clear teleport stuff
|
||||
vr.teleportexecute = qfalse;
|
||||
|
|
|
@ -44,9 +44,10 @@ typedef struct {
|
|||
qboolean detachablescope; // Scope can be detached from weapon
|
||||
|
||||
//Virtual Stock stuff
|
||||
qboolean vstock_weapon; // Weapon has a stock that can be used "vitually"
|
||||
qboolean vstock_engaged; // Virtual Stock is engaged
|
||||
vec3_t vstock_weapon_offset; // The offset of the fixed primary hand when Virtual Stock is engaged (set by cgame Weapon code)
|
||||
qboolean ironsight_lock_weapon; // Weapon can be used with ironsight lock mode
|
||||
qboolean ironsight_lock_engaged; // Ironsight Lock is engaged
|
||||
vec3_t ironsight_lock_offset; // The weapon offset location when iron sight lock is engaged (set by cgame Weapon code)
|
||||
vec3_t vstock_shoulder; // The pivot point (shoulder) when classic virtual stock is used (instead of the dominant controller)
|
||||
|
||||
qboolean hasbinoculars;
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ void HandleInput_WeaponAlign( ovrInputStateTrackedRemote *pDominantTrackedRemote
|
|||
int domButton1, int domButton2, int offButton1, int offButton2 );
|
||||
|
||||
|
||||
|
||||
void CalculateShoulderPosition();
|
||||
void updateScopeAngles();
|
||||
|
||||
#endif //vrinput_h
|
|
@ -122,6 +122,20 @@ void acquireTrackedRemotesData(const ovrMobile *Ovr, double displayTime) {//The
|
|||
}
|
||||
}
|
||||
|
||||
void CalculateShoulderPosition()
|
||||
{
|
||||
VectorCopy(vr.hmdposition, vr.vstock_shoulder);
|
||||
//Adjust to shoulder location for when vstock was engaged
|
||||
vr.vstock_shoulder[1] -= 0.25f;
|
||||
|
||||
//This bit might be overkill
|
||||
/*
|
||||
vec2_t xy;
|
||||
rotateAboutOrigin(0.25f, 0.0f, - vr.hmdorientation[YAW], xy);
|
||||
vr.vstock_shoulder[0] += xy[0];
|
||||
vr.vstock_shoulder[1] += xy[1];
|
||||
*/
|
||||
}
|
||||
|
||||
//YAW: Left increase, Right decrease
|
||||
void updateScopeAngles()
|
||||
|
@ -129,14 +143,14 @@ void updateScopeAngles()
|
|||
//Bit of a hack, but use weapon orientation / position for view when scope is engaged
|
||||
static vec3_t currentScopeAngles;
|
||||
static vec3_t lastScopeAngles;
|
||||
if (vr.scopeengaged || vr.vstock_engaged)
|
||||
if (vr.scopeengaged || vr.ironsight_lock_engaged)
|
||||
{
|
||||
if (vr.vstock_engaged)
|
||||
if (vr.ironsight_lock_engaged)
|
||||
{
|
||||
//Copy weapon offset X
|
||||
vr.calculated_weaponoffset[0] = vr.vstock_weapon_offset[1];
|
||||
vr.calculated_weaponoffset[1] = vr.vstock_weapon_offset[2];
|
||||
vr.calculated_weaponoffset[2] = vr.vstock_weapon_offset[0];
|
||||
vr.calculated_weaponoffset[0] = vr.ironsight_lock_offset[1];
|
||||
vr.calculated_weaponoffset[1] = vr.ironsight_lock_offset[2];
|
||||
vr.calculated_weaponoffset[2] = vr.ironsight_lock_offset[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -173,12 +173,26 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
if (distance < (STABILISATION_DISTANCE / 2.0f))
|
||||
{
|
||||
stabilised = qtrue;
|
||||
if (vr.weapon_stabilised != stabilised) {
|
||||
// blip to let user know they are stabilised
|
||||
RTCWVR_Vibrate(100, 0, 0.4);
|
||||
RTCWVR_Vibrate(100, 1, 0.4);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((pOffTrackedRemoteNew->Buttons & ovrButton_GripTrigger) && (distance < STABILISATION_DISTANCE))
|
||||
{
|
||||
stabilised = qtrue;
|
||||
}
|
||||
|
||||
//Recalculate shoulder position if required
|
||||
if (vr.weapon_stabilised != stabilised &&
|
||||
vr_virtual_stock->integer == 1 &&
|
||||
(pOffTrackedRemoteNew->Buttons & ovrButton_GripTrigger))
|
||||
{
|
||||
CalculateShoulderPosition();
|
||||
}
|
||||
|
||||
vr.weapon_stabilised = stabilised;
|
||||
|
||||
//Engage scope / virtual stock if conditions are right
|
||||
|
@ -198,11 +212,11 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
}
|
||||
}
|
||||
|
||||
//Engage scope / virtual stock if conditions are right
|
||||
//Engage scope / virtual stock (iron sight lock) if conditions are right
|
||||
qboolean vstockReady = vr.weapon_stabilised && (distanceToHMD < VSTOCK_ENGAGE_DISTANCE) &&
|
||||
(vr.vstock_weapon && vr_virtual_stock->integer > 0);
|
||||
if (vstockReady != vr.vstock_engaged) {
|
||||
vr.vstock_engaged = vstockReady;
|
||||
(vr.ironsight_lock_weapon && vr_virtual_stock->integer >= 2);
|
||||
if (vstockReady != vr.ironsight_lock_engaged) {
|
||||
vr.ironsight_lock_engaged = vstockReady;
|
||||
|
||||
//Resync on either transition
|
||||
RTCWVR_ResyncClientYawWithGameYaw();
|
||||
|
@ -247,8 +261,14 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
vr.current_weaponoffset[2] = pWeapon->HeadPose.Pose.Position.z - vr.hmdposition[2];
|
||||
vr.current_weaponoffset_timestamp = Sys_Milliseconds( );
|
||||
|
||||
//Lerp (stabilises pistol) - Won't have any effect on any other weapons
|
||||
VectorLerp(vr.weaponoffset_history[1], (vr.pistol && vr.weapon_stabilised) ? 0.25f : 1.0f, vr.current_weaponoffset, vr.calculated_weaponoffset);
|
||||
//Lerp (stabilises pistol)
|
||||
if (vr.pistol && vr.weapon_stabilised)
|
||||
{
|
||||
//First update current weapon offset with average of the two controller positions
|
||||
VectorLerp(vr.offhandoffset, 0.5f, vr.current_weaponoffset, vr.current_weaponoffset);
|
||||
//Now lerp with previous position to smooth it out
|
||||
VectorLerp(vr.weaponoffset_history[0], 0.5f, vr.current_weaponoffset, vr.calculated_weaponoffset);
|
||||
}
|
||||
|
||||
//Does weapon velocity trigger attack (knife) and is it fast enough
|
||||
static qboolean velocityTriggeredAttack = false;
|
||||
|
@ -278,7 +298,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
//Don't do this for pistols
|
||||
if (!vr.pistol && (vr.weapon_stabilised || vr.dualwield))
|
||||
{
|
||||
if (vr.scopeengaged || vr.vstock_engaged)
|
||||
if (vr.scopeengaged || vr.ironsight_lock_engaged)
|
||||
{
|
||||
float x = pOff->HeadPose.Pose.Position.x - vr.hmdposition[0];
|
||||
float y = pOff->HeadPose.Pose.Position.y - (vr.hmdposition[1] - 0.1f); // Use a point lower
|
||||
|
@ -289,7 +309,21 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)),
|
||||
-degrees(atan2f(x, -z)), 0);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else if (vr_virtual_stock->integer == 1) // Classic Virtual Stock
|
||||
{
|
||||
float x = pOff->HeadPose.Pose.Position.x - vr.vstock_shoulder[0];
|
||||
float y = pOff->HeadPose.Pose.Position.y - vr.vstock_shoulder[1];
|
||||
float z = pOff->HeadPose.Pose.Position.z - vr.vstock_shoulder[2];
|
||||
float zxDist = length(x, z);
|
||||
|
||||
if (zxDist != 0.0f && z != 0.0f) {
|
||||
VectorSet(vr.weaponangles, -degrees(atanf(y / zxDist)),
|
||||
-degrees(atan2f(x, -z)), 0); // No roll on virtual stock
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float x = pOff->HeadPose.Pose.Position.x - pWeapon->HeadPose.Pose.Position.x;
|
||||
float y = pOff->HeadPose.Pose.Position.y - pWeapon->HeadPose.Pose.Position.y;
|
||||
float z = pOff->HeadPose.Pose.Position.z - pWeapon->HeadPose.Pose.Position.z;
|
||||
|
@ -659,6 +693,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
}
|
||||
|
||||
RTCWVR_ResyncClientYawWithGameYaw();
|
||||
CalculateShoulderPosition();
|
||||
}
|
||||
} else if (pPrimaryJoystick->x < 0.3f) {
|
||||
increaseSnap = true;
|
||||
|
@ -681,6 +716,7 @@ void HandleInput_Default( ovrInputStateTrackedRemote *pDominantTrackedRemoteNew,
|
|||
}
|
||||
|
||||
RTCWVR_ResyncClientYawWithGameYaw();
|
||||
CalculateShoulderPosition();
|
||||
}
|
||||
} else if (pPrimaryJoystick->x > -0.3f) {
|
||||
decreaseSnap = true;
|
||||
|
|
|
@ -3685,7 +3685,8 @@ void CG_DrawActive( int stereoView ) {
|
|||
int vr_cinematic_stereo = trap_Cvar_VariableIntegerValue( "vr_cinematic_stereo");
|
||||
if ( !cgVR->scopeengaged &&
|
||||
(!cg.cameraMode || (cg.cameraMode && vr_cinematic_stereo)) &&
|
||||
!cgVR->vstock_engaged) {
|
||||
!(cgVR->ironsight_lock_engaged && vStock == 2))
|
||||
{
|
||||
VectorMA( cg.refdef.vieworg, -separation, cg.refdef.viewaxis[1], cg.refdef.vieworg );
|
||||
}
|
||||
|
||||
|
|
|
@ -2091,7 +2091,7 @@ static float CG_CalculateWeaponPositionAndScale( playerState_t *ps, vec3_t origi
|
|||
&(adjust[PITCH]), &(adjust[YAW]), &(adjust[ROLL]));
|
||||
VectorScale(temp_offset, scale, offset);
|
||||
|
||||
if (cgVR->vstock_engaged) {
|
||||
if (cgVR->ironsight_lock_engaged) {
|
||||
adjust[YAW] += virtualStockOffsets[ps->weapon][0];
|
||||
}
|
||||
|
||||
|
@ -3666,14 +3666,14 @@ void CG_AddViewWeapon( playerState_t *ps ) {
|
|||
case WP_KNIFE:
|
||||
cgVR->velocitytriggered = qtrue;
|
||||
cgVR->scopedweapon = qfalse;
|
||||
cgVR->vstock_weapon = qfalse;
|
||||
cgVR->ironsight_lock_weapon = qfalse;
|
||||
break;
|
||||
case WP_LUGER:
|
||||
case WP_SILENCER:
|
||||
case WP_COLT:
|
||||
cgVR->velocitytriggered = qfalse;
|
||||
cgVR->scopedweapon = qfalse;
|
||||
cgVR->vstock_weapon = qfalse;
|
||||
cgVR->ironsight_lock_weapon = qfalse;
|
||||
cgVR->pistol = qtrue;
|
||||
break;
|
||||
case WP_FG42:
|
||||
|
@ -3681,13 +3681,14 @@ void CG_AddViewWeapon( playerState_t *ps ) {
|
|||
cgVR->velocitytriggered = qfalse;
|
||||
cgVR->scopedweapon = qtrue;
|
||||
cgVR->detachablescope = qtrue;
|
||||
cgVR->vstock_weapon = cgVR->scopedetached; // only available when not scoped
|
||||
cgVR->ironsight_lock_weapon = cgVR->scopedetached; // only available when not scoped
|
||||
break;
|
||||
case WP_THOMPSON:
|
||||
case WP_STEN:
|
||||
case WP_MP40:
|
||||
cgVR->velocitytriggered = qfalse;
|
||||
cgVR->scopedweapon = qfalse;
|
||||
cgVR->vstock_weapon = qtrue; // only available when not scoped
|
||||
cgVR->ironsight_lock_weapon = qtrue; // only available when not scoped
|
||||
break;
|
||||
case WP_GARAND:
|
||||
case WP_SNOOPERSCOPE:
|
||||
|
@ -3697,18 +3698,19 @@ void CG_AddViewWeapon( playerState_t *ps ) {
|
|||
cgVR->scopedweapon = qtrue;
|
||||
cgVR->scopedetached = qfalse;
|
||||
cgVR->detachablescope = qfalse;
|
||||
cgVR->vstock_weapon = qfalse;
|
||||
cgVR->ironsight_lock_weapon = qfalse;
|
||||
break;
|
||||
default:
|
||||
cgVR->velocitytriggered = qfalse;
|
||||
cgVR->scopedweapon = qfalse;
|
||||
cgVR->vstock_weapon = qfalse;
|
||||
cgVR->ironsight_lock_weapon = qfalse;
|
||||
break;
|
||||
}
|
||||
|
||||
int controlScheme = trap_Cvar_VariableIntegerValue("vr_control_scheme");
|
||||
int vStock = trap_Cvar_VariableIntegerValue("vr_virtual_stock");
|
||||
if (vStock) {
|
||||
float multiplier = (vStock == 1 ? -1.0f : 1.0f);
|
||||
if (vStock >= 2) {
|
||||
float multiplier = (controlScheme == 0 ? -1.0f : 1.0f);
|
||||
|
||||
vec3_t offset;
|
||||
VectorClear(offset);
|
||||
|
@ -3720,11 +3722,12 @@ void CG_AddViewWeapon( playerState_t *ps ) {
|
|||
|
||||
vec3_t forward, right, up;
|
||||
AngleVectors(orientation, forward, right, up);
|
||||
//VectorMA(offset, (cg_stereoSeparation.value / 2.0f) * multiplier, right, offset);
|
||||
if (vStock == 3)
|
||||
VectorMA(offset, (cg_stereoSeparation.value / 2.0f) * multiplier, right, offset);
|
||||
VectorMA(offset, virtualStockOffsets[ps->weapon][1], up, offset);
|
||||
VectorMA(offset, virtualStockOffsets[ps->weapon][2], forward, offset);
|
||||
|
||||
VectorCopy(offset, cgVR->vstock_weapon_offset);
|
||||
VectorCopy(offset, cgVR->ironsight_lock_offset);
|
||||
}
|
||||
|
||||
// add everything onto the hand
|
||||
|
|
|
@ -280,7 +280,7 @@ itemDef
|
|||
text "Virtual Stock:"
|
||||
type ITEM_TYPE_MULTI
|
||||
cvar "vr_virtual_stock"
|
||||
cvarFloatList {"Off" 0 "Enabled (Right Eye)" 1 "Enabled (Left Eye)" 2 }
|
||||
cvarFloatList {"Off" 0 "Classic" 1 "Ironsight Lock (Mono)" 2 "Ironsight Lock (Stereo)" 3 }
|
||||
rect 82 165 290 12
|
||||
textalign ITEM_ALIGN_RIGHT
|
||||
textalignx 142
|
||||
|
|
|
@ -253,7 +253,7 @@ itemDef
|
|||
text "Virtual Stock:"
|
||||
type ITEM_TYPE_MULTI
|
||||
cvar "vr_virtual_stock"
|
||||
cvarFloatList {"Off" 0 "Enabled (Right Eye)" 1 "Enabled (Left Eye)" 2 }
|
||||
cvarFloatList {"Off" 0 "Classic" 1 "Ironsight Lock (Mono)" 2 "Ironsight Lock (Stereo)" 3 }
|
||||
rect 82 165 290 12
|
||||
textalign ITEM_ALIGN_RIGHT
|
||||
textalignx 142
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue