AMFP Enhanced
C++ reference: the code this unofficial fork added
Loading...
Searching...
No Matches
LuxPadLook.h
Go to the documentation of this file.
1/*
2 * AMFP-2026: gamepad look response (Input tab: dead zone, look acceleration, separate X / Y
3 * speed). Pure math, unit tested in tests/cpp/test_pad_look.cpp.
4 */
5#ifndef LUX_PAD_LOOK_H
6#define LUX_PAD_LOOK_H
7
8#include <cmath>
9
10static const float kLuxLookCurveStock = 1.5f; // the original: v * sqrt(|v|)
11static const float kLuxLookCurveAccel = 2.2f; // finer aim near the centre
12static const float kLuxLookBoostDelay = 0.25f; // full tilt held this long before turning faster
13static const float kLuxLookBoostRamp = 0.4f;
14static const float kLuxLookBoostMax = 1.8f;
15static const float kLuxLookBoostTilt = 0.92f;
16
17/** One stick axis after the dead zone (rescaled so it starts from 0) and the response curve. */
18inline float LuxPadLookAxis(float afValue, float afDeadZone, bool abAccel)
19{
20 float fAbs = std::fabs(afValue);
21 if(fAbs <= afDeadZone || afDeadZone >= 1.0f) return 0;
22 float fT = (fAbs - afDeadZone) / (1.0f - afDeadZone);
23 if(fT > 1.0f) fT = 1.0f;
24 float fOut = std::pow(fT, abAccel ? kLuxLookCurveAccel : kLuxLookCurveStock);
25 return afValue < 0 ? -fOut : fOut;
26}
27
28/** Turning speed boost while the stick is held at full tilt (acceleration only). */
30{
31public:
32 cLuxPadLookBoost() : mfHeld(0) {}
33 void Update(float afTimeStep, float afTilt)
34 {
35 if(std::fabs(afTilt) >= kLuxLookBoostTilt) mfHeld += afTimeStep > 0 ? afTimeStep : 0;
36 else mfHeld = 0;
37 }
38 float Multiplier() const
39 {
40 float fT = (mfHeld - kLuxLookBoostDelay) / kLuxLookBoostRamp;
41 if(fT <= 0) return 1.0f;
42 if(fT > 1) fT = 1;
43 return 1.0f + (kLuxLookBoostMax - 1.0f) * fT;
44 }
45private:
46 float mfHeld;
47};
48
49#endif
float LuxPadLookAxis(float afValue, float afDeadZone, bool abAccel)
One stick axis after the dead zone (rescaled so it starts from 0) and the response curve.
Definition LuxPadLook.h:18
static const float kLuxLookBoostRamp
Definition LuxPadLook.h:13
static const float kLuxLookBoostMax
Definition LuxPadLook.h:14
static const float kLuxLookBoostDelay
Definition LuxPadLook.h:12
static const float kLuxLookCurveStock
Definition LuxPadLook.h:10
static const float kLuxLookCurveAccel
Definition LuxPadLook.h:11
static const float kLuxLookBoostTilt
Definition LuxPadLook.h:15
float Multiplier() const
Definition LuxPadLook.h:38
void Update(float afTimeStep, float afTilt)
Definition LuxPadLook.h:33