Skip to content

Commit f77f6b7

Browse files
committed
Aircraft control update
1 parent 227685c commit f77f6b7

File tree

3 files changed

+42
-53
lines changed

3 files changed

+42
-53
lines changed

Source/DSAdvance/DSAdvance.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
877877

878878
int main(int argc, char **argv)
879879
{
880-
SetConsoleTitle("DSAdvance 1.4");
880+
SetConsoleTitle("DSAdvance 1.5");
881881
WindowToCenter();
882882

883883
// if (false)
@@ -928,13 +928,14 @@ int main(int argc, char **argv)
928928
AppStatus.ChangeModesWithClick = IniFile.ReadBoolean("Gamepad", "ChangeModesWithClick", true);
929929
AppStatus.ChangeModesWithoutAreas = IniFile.ReadBoolean("Gamepad", "ChangeModesWithoutAreas", false);
930930

931-
AppStatus.AimMode = IniFile.ReadBoolean("Motion", "AimMode", AimMouseMode);
931+
AppStatus.AimMode = IniFile.ReadBoolean("Motion", "AimingMode", AimMouseMode);
932932
AppStatus.AimingWithL2 = IniFile.ReadBoolean("Motion", "AimingWithL2", true);
933933

934-
PrimaryGamepad.Motion.WheelAngle = IniFile.ReadFloat("Motion", "WheelAngle", 150) / 2.0f;
935-
PrimaryGamepad.Motion.WheelPitch = IniFile.ReadBoolean("Motion", "WheelPitch", false);
936-
PrimaryGamepad.Motion.WheelRoll = IniFile.ReadBoolean("Motion", "WheelRoll", true);
937-
PrimaryGamepad.Motion.WheelInvertPitch = IniFile.ReadBoolean("Motion", "WheelInvertPitch", false) ? 1 : -1;
934+
PrimaryGamepad.Motion.SteeringWheelAngle = IniFile.ReadFloat("Motion", "SteeringWheelAngle", 150) / 2.0f;
935+
PrimaryGamepad.Motion.AircraftEnabled = IniFile.ReadBoolean("Motion", "AircraftEnabled", false);
936+
PrimaryGamepad.Motion.AircraftPitchAngle = IniFile.ReadFloat("Motion", "AircraftPitchAngle", 45) / 2.0f;
937+
PrimaryGamepad.Motion.AircraftPitchInverted = IniFile.ReadBoolean("Motion", "AircraftPitchInverted", false) ? -1 : 1;
938+
PrimaryGamepad.Motion.AircraftRollSens = IniFile.ReadFloat("Motion", "AircraftRollSens", 100) * 0.11875f;
938939
PrimaryGamepad.Motion.SensX = IniFile.ReadFloat("Motion", "MouseSensX", 100) * 0.005f; // Calibration with Crysis 2, old 0.01
939940
PrimaryGamepad.Motion.SensY = IniFile.ReadFloat("Motion", "MouseSensY", 90) * 0.005f;
940941
PrimaryGamepad.Motion.SensAvg = (PrimaryGamepad.Motion.SensX + PrimaryGamepad.Motion.SensY) * 0.5f; // Sens Average
@@ -1043,7 +1044,6 @@ int main(int argc, char **argv)
10431044
GamepadSetState(GamepadOutState);
10441045

10451046
int SkipPollCount = 0;
1046-
EulerAngles MotionAngles, AnglesOffset;
10471047

10481048
AppStatus.ControllerCount = JslConnectDevices();
10491049
JslGetConnectedDeviceHandles(GamepadsID, AppStatus.ControllerCount);
@@ -1138,8 +1138,9 @@ int main(int argc, char **argv)
11381138
SecondaryGamepad.InputState = JslGetSimpleState(GamepadsID[SecondaryGamepad.DeviceIndex]);
11391139
//MotionState = JslGetMotionState(GamepadsID[SecondaryGamepad.DeviceIndex]);
11401140
//JslGetAndFlushAccumulatedGyro(GamepadsID[SecondaryGamepad.DeviceIndex], velocityX, velocityY, velocityZ);
1141-
}
1142-
else { // Split contoller (Joycons)
1141+
1142+
// Split contoller (Joycons)
1143+
} else {
11431144
SecondaryGamepad.InputState = JslGetSimpleState(GamepadsID[SecondaryGamepad.DeviceIndex]);
11441145
JOY_SHOCK_STATE tempState = JslGetSimpleState(GamepadsID[SecondaryGamepad.DeviceIndex2]);
11451146
//MotionState = JslGetMotionState(GamepadsID[SecondaryGamepad.DeviceIndex2]);
@@ -1149,8 +1150,6 @@ int main(int argc, char **argv)
11491150
SecondaryGamepad.InputState.buttons |= tempState.buttons;
11501151
//JslGetAndFlushAccumulatedGyro(GamepadsID[SecondaryGamepad.DeviceIndex2], velocityX, velocityY, velocityZ);
11511152
}
1152-
1153-
MotionAngles = QuaternionToEulerAngle(MotionState.quatW, MotionState.quatZ, MotionState.quatX, MotionState.quatY);
11541153

11551154
// Stick dead zones
11561155
if (SkipPollCount == 0 && IsKeyPressed(VK_MENU) && IsKeyPressed(VK_F9) != 0)
@@ -1334,8 +1333,7 @@ int main(int argc, char **argv)
13341333
// [O--] - Driving mode
13351334
if (TouchState.t0X > 0 && TouchState.t0X <= TOUCHPAD_LEFT_AREA && PrimaryGamepad.GamepadActionMode != TouchpadSticksMode) {
13361335
PrimaryGamepad.GamepadActionMode = MotionDrivingMode;
1337-
AnglesOffset = MotionAngles;
1338-
1336+
13391337
PrimaryGamepad.Motion.OffsetAxisX = atan2f(MotionState.gravX, MotionState.gravZ);
13401338
PrimaryGamepad.Motion.OffsetAxisY = atan2f(MotionState.gravY, MotionState.gravZ);
13411339

@@ -1601,7 +1599,8 @@ int main(int argc, char **argv)
16011599
if (SkipPollCount == 0 && ( (PrimaryGamepad.InputState.buttons & JSMASK_CAPTURE) || (IsKeyPressed(VK_MENU) && IsKeyPressed('1')) ) ) {
16021600
if (PrimaryGamepad.GamepadActionMode == 1)
16031601
PrimaryGamepad.GamepadActionMode = GamepadDefaultMode;
1604-
else { PrimaryGamepad.GamepadActionMode = MotionDrivingMode; AnglesOffset = MotionAngles; }
1602+
else
1603+
PrimaryGamepad.GamepadActionMode = MotionDrivingMode;
16051604
SkipPollCount = SkipPollTimeOut;
16061605
}
16071606

@@ -1702,14 +1701,23 @@ int main(int argc, char **argv)
17021701
// Gamepad modes
17031702
// Motion racing [O--]
17041703
if (PrimaryGamepad.GamepadActionMode == MotionDrivingMode) {
1705-
if (PrimaryGamepad.Motion.WheelRoll)
1706-
report.sThumbLX = CalcMotionStick(MotionState.gravX, MotionState.gravZ, PrimaryGamepad.Motion.WheelAngle, PrimaryGamepad.Motion.OffsetAxisX);
1707-
else
1708-
report.sThumbLX = ToLeftStick(OffsetYPR(RadToDeg(MotionAngles.Yaw), RadToDeg(AnglesOffset.Yaw)) * -1, PrimaryGamepad.Motion.WheelAngle); // Not tested, axes swap roles
17091704

1710-
if (PrimaryGamepad.Motion.WheelPitch)
1711-
report.sThumbLY = ToLeftStick(OffsetYPR(RadToDeg(MotionAngles.Pitch), RadToDeg(AnglesOffset.Pitch)) * PrimaryGamepad.Motion.WheelInvertPitch, PrimaryGamepad.Motion.WheelAngle); // Not tested, axes swap roles
1712-
1705+
// Steering wheel
1706+
if (!PrimaryGamepad.Motion.AircraftEnabled) {
1707+
report.sThumbLX = CalcMotionStick(MotionState.gravX, MotionState.gravZ, PrimaryGamepad.Motion.SteeringWheelAngle, PrimaryGamepad.Motion.OffsetAxisX);
1708+
1709+
// Aircraft
1710+
} else {
1711+
const float InputSize = sqrtf(velocityX * velocityX + velocityY * velocityY + velocityZ * velocityZ);
1712+
float TightenedSensitivity = PrimaryGamepad.Motion.AircraftRollSens;
1713+
if (InputSize < Tightening && Tightening > 0)
1714+
TightenedSensitivity *= InputSize / Tightening;
1715+
1716+
report.sThumbLX = std::clamp((int)(ClampFloat(-(velocityY * TightenedSensitivity * FrameTime * PrimaryGamepad.Motion.JoySensX * PrimaryGamepad.Motion.CustomMulSens), -1, 1) * 32767 + report.sThumbLX), -32767, 32767);
1717+
report.sThumbLY = CalcMotionStick(MotionState.gravY, MotionState.gravZ, PrimaryGamepad.Motion.AircraftPitchAngle, PrimaryGamepad.Motion.OffsetAxisY) * PrimaryGamepad.Motion.AircraftPitchInverted;
1718+
}
1719+
1720+
17131721
// Motion aiming [--X}]
17141722
} else if (PrimaryGamepad.GamepadActionMode == MotionAimingMode || (PrimaryGamepad.GamepadActionMode == MotionAimingModeOnlyPressed &&
17151723
(AppStatus.AimingWithL2 && DeadZoneAxis(PrimaryGamepad.InputState.lTrigger, PrimaryGamepad.Triggers.DeadZoneLeft) > 0) || // Classic L2 aiming

Source/DSAdvance/DSAdvance.h

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,11 @@ struct AdvancedGamepad {
226226
float JoySensX = 0;
227227
float JoySensY = 0;
228228
float JoySensAvg = 0;
229-
float WheelAngle = 0;
230-
bool WheelPitch = false;
231-
bool WheelRoll = false;
232-
int WheelInvertPitch = 0;
229+
float SteeringWheelAngle = 0;
230+
bool AircraftEnabled = false;
231+
float AircraftPitchAngle = 0;
232+
int AircraftPitchInverted = 0;
233+
float AircraftRollSens = 0;
233234
float CustomMulSens = 1.0f;
234235
};
235236
_Motion Motion;
@@ -926,29 +927,6 @@ unsigned int WebColorToRGB(const std::string& webColor) {
926927
return (red << 16) | (green << 8) | blue;
927928
}
928929

929-
EulerAngles QuaternionToEulerAngle(double qW, double qX, double qY, double qZ) // https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
930-
{
931-
EulerAngles resAngles;
932-
// roll (x-axis rotation)
933-
double sinr = +2.0 * (qW * qX + qY * qZ);
934-
double cosr = +1.0 - 2.0 * (qX * qX + qY * qY);
935-
resAngles.Roll = atan2(sinr, cosr);
936-
937-
// pitch (y-axis rotation)
938-
double sinp = +2.0 * (qW * qY - qZ * qX);
939-
if (fabs(sinp) >= 1)
940-
resAngles.Pitch = copysign(3.14159265358979323846 / 2, sinp); // use 90 degrees if out of range
941-
else
942-
resAngles.Pitch = asin(sinp);
943-
944-
// yaw (z-axis rotation)
945-
double siny = +2.0 * (qW * qZ + qX * qY);
946-
double cosy = +1.0 - 2.0 * (qY * qY + qZ * qZ);
947-
resAngles.Yaw = atan2(siny, cosy);
948-
949-
return resAngles;
950-
}
951-
952930
float ClampFloat(float Value, float Min, float Max)
953931
{
954932
if (Value > Max)
@@ -972,10 +950,10 @@ float DeadZoneAxis(float StickAxis, float DeadZoneValue) // Possibly wrong
972950
return StickAxis * 1 / (1.0f - DeadZoneValue); // 1 - max value of stick
973951
}
974952

975-
double RadToDeg(double Rad)
953+
/*double RadToDeg(double Rad)
976954
{
977955
return Rad / 3.14159265358979323846 * 180.0;
978-
}
956+
}*/
979957

980958
double OffsetYPR(double Angle1, double Angle2) // CalcMotionStick
981959
{
@@ -987,15 +965,15 @@ double OffsetYPR(double Angle1, double Angle2) // CalcMotionStick
987965
return Angle1;
988966
}
989967

990-
SHORT ToLeftStick(double Value, float WheelAngle)
968+
/*SHORT ToLeftStick(double Value, float WheelAngle)
991969
{
992970
int LeftAxisX = trunc((32767 / WheelAngle) * Value);
993971
if (LeftAxisX < -32767)
994972
LeftAxisX = -32767;
995973
else if (LeftAxisX > 32767)
996974
LeftAxisX = 32767;
997975
return LeftAxisX;
998-
}
976+
}*/
999977

1000978
SHORT CalcMotionStick(float gravA, float gravB, float wheelAngle, float offsetAxis) {
1001979
float angleRadians = wheelAngle * (3.14159f / 180.0f); // To radians
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
JoyShockLibrary 3.0
1+
Fork JoyShockLibrary 3.0.1
2+
https://github.com/r57zone/JoyShockLibrary
3+
4+
Original JoyShockLibrary 3.0
25
https://github.com/JibbSmart/JoyShockLibrary/

0 commit comments

Comments
 (0)