Skip to content

Commit

Permalink
Fix weapon when not in VR, and add independent aiming.
Browse files Browse the repository at this point in the history
New in_independentAim cvar controls independent aiming when not in VR.
Known issue: Independent aim outside VR doesn't currently work with GUIs.
Note that the flashlight is still glitchy when not in VR.
  • Loading branch information
CarlKenner committed May 23, 2019
1 parent dbf55b4 commit 76d5550
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
13 changes: 12 additions & 1 deletion neo/d3xp/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ idAngles pdaAngle2( 0, 0, 76.5);
idAngles pdaAngle3( 0, 0, 0);

extern idCVar g_useWeaponDepthHack;
extern idCVar in_independentAim;


/*
Expand Down Expand Up @@ -16954,7 +16955,17 @@ void idPlayer::CalculateViewWeaponPosVR( int hand, idVec3 &origin, idMat3 &axis
angQuat = idAngles( commonVr->independentWeaponPitch, commonVr->independentWeaponYaw, 0 ).ToQuat();

idQuat gunAxis = angQuat;
gunAxis *= bodyAxis.ToQuat();
if( game->isVR || in_independentAim.GetInteger() )
{
gunAxis *= bodyAxis.ToQuat();
}
else
{
idMat3 headAxis = idAngles( viewAngles.pitch, viewAngles.yaw, 0.0f ).ToMat3();
gunAxis *= headAxis.ToQuat();
commonVr->independentWeaponPitch = 0;
commonVr->independentWeaponYaw = 0;
}
newAx = gunAxis.ToMat3();

int flip = vr_weaponHand.GetInteger() == 0 ? 1 : -1;
Expand Down
5 changes: 4 additions & 1 deletion neo/d3xp/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ idCVar g_useWeaponDepthHack( "g_useWeaponDepthHack", "0", CVAR_BOOL | CVAR_GAME
idCVar g_weaponShadows( "g_weaponShadows", "1", CVAR_BOOL | CVAR_GAME | CVAR_ARCHIVE, "Cast shadows from weapons" ); // Koz

extern idCVar cg_predictedSpawn_debug;
extern idCVar in_independentAim;

/***********************************************************************
Expand Down Expand Up @@ -4848,7 +4849,8 @@ idWeapon::GetProjectileLaunchOriginAndAxis
void idWeapon::GetProjectileLaunchOriginAndAxis( idVec3& origin, idMat3& axis )
{
assert( owner != NULL );
if ( game->isVR )
// Carl: in VR, or when using independent aim, we fire from the weapon model itself
if( game->isVR || in_independentAim.GetInteger() )
{
static weapon_t curWeap = WEAPON_NONE;

Expand Down Expand Up @@ -4886,6 +4888,7 @@ void idWeapon::GetProjectileLaunchOriginAndAxis( idVec3& origin, idMat3& axis )
return;
}

// Carl: When not in VR, we usually fire from our eyes (the centre of the screen)
// calculate the muzzle position
if( barrelJointView != INVALID_JOINT && projectileDict.GetBool( "launchFromBarrel" ) )
{
Expand Down
24 changes: 19 additions & 5 deletions neo/framework/UsercmdGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ idCVar vr_joyCurves( "vr_joyCurves", "0", CVAR_ARCHIVE | CVAR_INTEGER, "Joy powe
idCVar vr_joyCurveSensitivity( "vr_joyCurveSensitivity", "9", CVAR_ARCHIVE | CVAR_FLOAT, "Sensitivity val 0 - 9\n" );
idCVar vr_joyCurveLin( "vr_joyCurveLin", "4", CVAR_ARCHIVE | CVAR_FLOAT, "Linear point for joyCurves\n sens < lin = power curve\n, sens = lin = linear\n, sens > lin = frac power curve.\n" );

// Carl: Non-VR-mode independent weapon control
idCVar in_independentAim( "in_independentAim", "0", CVAR_ARCHIVE | CVAR_INTEGER, "Independent weapon aim. 0 = normal look/aim, 1 = mouse aims weapon, 2 = keys aim weapon, 3 = both aim weapon", 0, 3 );


/*
Expand Down Expand Up @@ -477,11 +479,23 @@ void idUsercmdGenLocal::AdjustAngles()

if ( !game->isVR )
{
viewangles[YAW] -= speed * in_yawSpeed.GetFloat() * ButtonState( UB_LOOKRIGHT );
viewangles[YAW] += speed * in_yawSpeed.GetFloat() * ButtonState( UB_LOOKLEFT );
if( in_independentAim.GetInteger() & 2 )
{
float yawdelta, pitchdelta;
yawdelta = speed * in_yawSpeed.GetFloat() * ( ButtonState( UB_LOOKLEFT ) - ButtonState( UB_LOOKRIGHT ) );
pitchdelta = speed * in_pitchSpeed.GetFloat() * ( ButtonState( UB_LOOKDOWN ) - ButtonState( UB_LOOKUP ) );
commonVr->CalcAimMove( yawdelta, pitchdelta ); // update the independent weapon angles and return any movement changes.
viewangles[YAW] += yawdelta;
viewangles[PITCH] += pitchdelta;
}
else
{
viewangles[YAW] -= speed * in_yawSpeed.GetFloat() * ButtonState( UB_LOOKRIGHT );
viewangles[YAW] += speed * in_yawSpeed.GetFloat() * ButtonState( UB_LOOKLEFT );

viewangles[PITCH] -= speed * in_pitchSpeed.GetFloat() * ButtonState( UB_LOOKUP );
viewangles[PITCH] += speed * in_pitchSpeed.GetFloat() * ButtonState( UB_LOOKDOWN );
viewangles[PITCH] -= speed * in_pitchSpeed.GetFloat() * ButtonState( UB_LOOKUP );
viewangles[PITCH] += speed * in_pitchSpeed.GetFloat() * ButtonState( UB_LOOKDOWN );
}
}
else // Koz add independent weapon aiming
{
Expand Down Expand Up @@ -603,7 +617,7 @@ void idUsercmdGenLocal::MouseMove()
pitchdelta = m_pitch.GetFloat() * in_mouseSpeed.GetFloat() * (in_mouseInvertLook.GetBool() ? -my : my);

// Koz begin add mouse control here
if( commonVr->hasHMD && vr_enable.GetBool() )
if( ( commonVr->hasHMD && vr_enable.GetBool() ) || in_independentAim.GetInteger() & 1 )
{
// update the independent weapon angles and return any view changes based on current aim mode
commonVr->CalcAimMove( yawdelta, pitchdelta );
Expand Down
6 changes: 3 additions & 3 deletions neo/vr/Vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ idCVar vr_forward_keyhole( "vr_forward_keyhole", "11.25", CVAR_FLOAT | CVAR_ARCH

idCVar vr_PDAfixLocation( "vr_PDAfixLocation", "0", CVAR_BOOL | CVAR_ARCHIVE | CVAR_GAME, "Fix PDA position in space in front of player\n instead of holding in hand." );

idCVar vr_weaponPivotOffsetForward( "vr_weaponPivotOffsetForward", "3", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotOffsetHorizontal( "vr_weaponPivotOffsetHorizontal", "0", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotOffsetVertical( "vr_weaponPivotOffsetVertical", "0", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotOffsetForward( "vr_weaponPivotOffsetForward", "4", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotOffsetHorizontal( "vr_weaponPivotOffsetHorizontal", "-4", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotOffsetVertical( "vr_weaponPivotOffsetVertical", "-12", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );
idCVar vr_weaponPivotForearmLength( "vr_weaponPivotForearmLength", "16", CVAR_GAME | CVAR_ARCHIVE | CVAR_FLOAT, "" );

idCVar vr_guiScale( "vr_guiScale", "1", CVAR_FLOAT | CVAR_RENDERER | CVAR_ARCHIVE, "scale reduction factor for full screen menu/pda scale in VR", 0.0001f, 1.0f ); // Koz allow scaling of full screen guis/pda
Expand Down

0 comments on commit 76d5550

Please sign in to comment.