Skip to content

Commit

Permalink
User-configurable mouse aiming sensitivity
Browse files Browse the repository at this point in the history
- Loaded from config file, no UI available to configure it in-game yet
  • Loading branch information
sturnclaw committed Jan 27, 2023
1 parent 657e967 commit 8f3097d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ship/PlayerShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ PlayerShipController::PlayerShipController() :
m_joystickDeadzone = Clamp(deadzone, 0.01f, 1.0f); // do not use (deadzone * deadzone) as values are 0<>1 range, aka: 0.1 * 0.1 = 0.01 or 1% deadzone!!! Not what player asked for!
m_fovY = Pi::config->Float("FOVVertical");
m_lowThrustPower = Pi::config->Float("DefaultLowThrustPower");
m_aimingSens = Pi::config->Float("AimSensitivity", 1.0f);

InputBindings.RegisterBindings();
Pi::input->AddInputFrame(&InputBindings);
Expand Down Expand Up @@ -659,17 +660,19 @@ void PlayerShipController::PollControls(const float timeStep, int *mouseMotion,

vector3d objDir = m_mouseDir * rot;

// TODO: this FOV value can be out-of-sync with the value used to render the frame
// PlayerShipController likely needs to know about the camera being rendered through
const double radiansPerPixel = 0.00002 * m_fovY;
const int maxMotion = std::max(abs(mouseMotion[0]), abs(mouseMotion[1]));
const double accel = Clamp(maxMotion / 4.0, 0.0, 90.0 / m_fovY);

m_mouseX += mouseMotion[0] * accel * radiansPerPixel;
m_mouseX += mouseMotion[0] * accel * radiansPerPixel * m_aimingSens;
double modx = clipmouse(objDir.x, m_mouseX);
m_mouseX -= modx;

const bool invertY = (Pi::input->IsMouseYInvert() ? !m_invertMouse : m_invertMouse);

m_mouseY += mouseMotion[1] * accel * radiansPerPixel * (invertY ? -1 : 1);
m_mouseY += mouseMotion[1] * accel * radiansPerPixel * (invertY ? -1 : 1) * m_aimingSens;
double mody = clipmouse(objDir.y, m_mouseY);
m_mouseY -= mody;

Expand Down
1 change: 1 addition & 0 deletions src/ship/PlayerShipController.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class PlayerShipController : public ShipController {
float m_fovY; //for mouse acceleration adjustment
float m_joystickDeadzone;
float m_lowThrustPower;
float m_aimingSens;
int m_combatTargetIndex; //for PostLoadFixUp
int m_navTargetIndex;
int m_followTargetIndex;
Expand Down

0 comments on commit 8f3097d

Please sign in to comment.