Skip to content

Commit b1f4d27

Browse files
committed
Add option to switch between head- and controller-oriented movement
1 parent cecb715 commit b1f4d27

File tree

7 files changed

+52
-9
lines changed

7 files changed

+52
-9
lines changed

Code/GameCVars.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ void SCVars::InitVRCVars(IConsole* pConsole)
880880
pConsole->Register("vr_weapon_hand", &vr_weapon_hand, 1, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Which hand holds and controls weapon: 0 (left) or 1 (right)");
881881
pConsole->Register("vr_movement_hand", &vr_movement_hand, 0, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Which hand controls player movement: 0 (left) or 1 (right)");
882882
pConsole->Register("vr_suit_hand", &vr_suit_hand, 1, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Which hand controls the suit menu: 0 (left) or 1 (right)");
883+
pConsole->Register("vr_movement_mode", &vr_movement_mode, 0, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Controls the orientation of player movement. 0 - head, 1 - controller");
883884
pConsole->Register("vr_weapon_pitch_offset", &vr_weapon_pitch_offset, 0, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Adjust weapon vertical holding angle");
884885
pConsole->Register("vr_weapon_yaw_offset", &vr_weapon_yaw_offset, 0, VF_RESTRICTEDMODE|VF_DUMPTODISK, "Adjust weapon horizontal holding angle");
885886
pConsole->Register("vr_weapon_crosshair", &vr_weapon_crosshair, 0, VF_RESTRICTEDMODE|VF_DUMPTODISK, "If enabled, displays a simple crosshair for player weapons to assist with aiming in VR");

Code/GameCVars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ struct SCVars
443443
int vr_weapon_hand;
444444
int vr_movement_hand;
445445
int vr_suit_hand;
446+
int vr_movement_mode;
446447
float vr_weapon_pitch_offset;
447448
float vr_weapon_yaw_offset;
448449
int vr_weapon_crosshair;

Code/PlayerMovement.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static Vec3 ProjectPointToLine(const Vec3 &point,const Vec3 &lineStart,const Vec
160160
//-----------------------------------------------------------------------------------------------
161161
void CPlayerMovement::ProcessFlyMode()
162162
{
163-
Quat viewQuat = m_baseQuat * gVR->GetHMDQuat();
163+
Quat viewQuat = GetFlyQuat();
164164
Vec3 move = viewQuat * m_movement.desiredVelocity;
165165

166166
float zMove(0.0f);
@@ -192,8 +192,9 @@ void CPlayerMovement::ProcessFlyingZeroG()
192192
{
193193
bool debug = false;
194194
Vec3 entityPos = m_player.GetEntity()->GetWorldPos();
195-
Vec3 vRight(m_baseQuat.GetColumn0());
196-
Vec3 vFwd(m_baseQuat.GetColumn1());
195+
Quat baseQuat = GetMoveQuat();
196+
Vec3 vRight(baseQuat.GetColumn0());
197+
Vec3 vFwd(baseQuat.GetColumn1());
197198

198199
bool trail = (g_pGameCVars->pl_zeroGParticleTrail != 0);
199200
if (trail)
@@ -295,7 +296,7 @@ void CPlayerMovement::ProcessFlyingZeroG()
295296
desiredLocalVelocity.z = desiredLocalNormalizedVelocity.z * maxSpeed;
296297

297298
// The desired movement is applied in viewspace, not in entityspace, since entity does not nessecarily pitch while swimming.
298-
Quat viewQuat = m_baseQuat * gVR->GetHMDQuat();
299+
Quat viewQuat = GetFlyQuat();
299300
desiredWorldVelocity += viewQuat.GetColumn0() * desiredLocalVelocity.x;
300301
desiredWorldVelocity += viewQuat.GetColumn1() * desiredLocalVelocity.y;
301302
desiredWorldVelocity += viewQuat.GetColumn2() * desiredLocalVelocity.z;
@@ -653,7 +654,8 @@ void CPlayerMovement::ProcessSwimming()
653654
{
654655
bool debug = (g_pGameCVars->cl_debugSwimming != 0);
655656
Vec3 entityPos = m_player.GetEntity()->GetWorldPos();
656-
Vec3 vRight(m_baseQuat.GetColumn0());
657+
Quat baseQuat = GetMoveQuat();
658+
Vec3 vRight(baseQuat.GetColumn0());
657659

658660
// Don't enable sticky surface directly when entering water.
659661
if (m_stats.inWaterTimer < 0.5f)
@@ -781,7 +783,7 @@ void CPlayerMovement::ProcessSwimming()
781783
desiredLocalNormalizedVelocity.x = m_movement.desiredVelocity.x * g_pGameCVars->pl_swimSideSpeedMul;
782784
desiredLocalNormalizedVelocity.y = m_movement.desiredVelocity.y * backwardMultiplier;
783785

784-
Quat viewQuat = m_baseQuat * gVR->GetHMDQuat();
786+
Quat viewQuat = GetFlyQuat();
785787

786788
// AI can set a custom sprint value, so don't cap the movement vector
787789
float sprintMultiplier = 1.0f;
@@ -938,7 +940,8 @@ void CPlayerMovement::ProcessParachute()
938940
m_request.type = eCMT_Impulse;//eCMT_Fly;
939941
m_request.velocity = (Vec3(0,0,desiredZ)-m_stats.velocity) * m_stats.mass/* * m_frameTime*/;//desiredVelocity;
940942

941-
Vec3 forwardComp(m_baseQuat.GetColumn1() * 10.0f);
943+
Quat baseQuat = GetMoveQuat();
944+
Vec3 forwardComp(baseQuat.GetColumn1() * 10.0f);
942945
forwardComp.z = 0.0f;
943946

944947
m_request.velocity += forwardComp * m_stats.mass;// * m_frameTime;//desiredVelocity;
@@ -987,8 +990,9 @@ void CPlayerMovement::ProcessOnGroundOrJumping(CPlayer& player)
987990
NETINPUT_TRACE(m_player.GetEntityId(), backwardMul);
988991
NETINPUT_TRACE(m_player.GetEntityId(), strafeMul);
989992

990-
move += m_baseQuat.GetColumn0() * desiredVelocityClamped.x * strafeMul * backwardMul;
991-
move += m_baseQuat.GetColumn1() * desiredVelocityClamped.y * backwardMul;
993+
Quat baseQuat = GetMoveQuat();
994+
move += baseQuat.GetColumn0() * desiredVelocityClamped.x * strafeMul * backwardMul;
995+
move += baseQuat.GetColumn1() * desiredVelocityClamped.y * backwardMul;
992996
}
993997

994998
float sprintMult = 1.0f;
@@ -1706,3 +1710,23 @@ void CPlayerMovement::AdjustPlayerPositionOnLadder(CPlayer &player)
17061710
}
17071711
}
17081712
}
1713+
1714+
Quat CPlayerMovement::GetMoveQuat()
1715+
{
1716+
if (g_pGameCVars->vr_movement_mode == 0)
1717+
return m_baseQuat;
1718+
else
1719+
{
1720+
Vec3 fwd = gVR->GetMovementControllerQuat().GetColumn1();
1721+
fwd.z = 0;
1722+
return Quat::CreateRotationVDir(fwd.GetNormalizedSafe());
1723+
}
1724+
}
1725+
1726+
Quat CPlayerMovement::GetFlyQuat()
1727+
{
1728+
if (g_pGameCVars->vr_movement_mode == 0)
1729+
return m_baseQuat * gVR->GetHMDQuat();
1730+
else
1731+
return gVR->GetMovementControllerQuat();
1732+
}

Code/PlayerMovement.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class CPlayerMovement
4242
void AdjustMovementForEnvironment( Vec3& movement, bool sprinting );
4343
void AdjustPlayerPositionOnLadder(CPlayer &player);
4444

45+
Quat GetMoveQuat();
46+
Quat GetFlyQuat();
47+
4548
SCharacterMoveRequest m_request; // our primary output... how to move!
4649
bool m_detachLadder; // do we want to detach from a ladder?
4750
Vec3 m_velocity; // from CPlayer... gets updated here and committed

Code/VR/VRGui.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ void VRGui::DrawSettingsMenu()
203203
bool invertVehicleY = g_pGameCVars->vr_vehicle_invert_y;
204204
ImGui::Checkbox("Invert look Y-axis for vehicles and mounted guns", &invertVehicleY);
205205
g_pGameCVars->vr_vehicle_invert_y = invertVehicleY;
206+
207+
ImGui::Text("Movement relative to");
208+
ImGui::SetItemTooltip("Choose if movement direction is relative to head or controller");
209+
ImGui::SameLine(0.2f * windowSize.x);
210+
ImGui::RadioButton("Head", &g_pGameCVars->vr_movement_mode, 0);
211+
ImGui::SameLine();
212+
ImGui::RadioButton("Controller", &g_pGameCVars->vr_movement_mode, 1);
206213
}
207214

208215
if (ImGui::CollapsingHeader("Weapons"))

Code/VR/VRManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ Matrix34 VRManager::GetWorldControllerWeaponTransform(int side)
515515
return view * controllerTransform;
516516
}
517517

518+
Quat VRManager::GetMovementControllerQuat()
519+
{
520+
Matrix34 controllerTransform = GetWorldControllerTransform(g_pGameCVars->vr_movement_hand);
521+
return Quat(controllerTransform);
522+
}
523+
518524
Vec3 VRManager::GetControllerVelocity(int side)
519525
{
520526
Vec3 controllerVelocity = gXR->GetInput()->GetControllerVelocity(side);

Code/VR/VRManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class VRManager
5151
Matrix34 GetControllerWeaponTransform(int side);
5252
Matrix34 GetTwoHandWeaponTransform();
5353
Matrix34 GetWorldControllerWeaponTransform(int side);
54+
Quat GetMovementControllerQuat();
5455
Vec3 GetControllerVelocity(int side);
5556
Vec3 GetControllerWorldVelocity(int side);
5657
void ModifyPlayerEye(CPlayer* pPlayer, Vec3& eyePosition, Vec3& eyeDirection);

0 commit comments

Comments
 (0)