Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VehicleCameraAlignment.c
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
11{
15 [Attribute("1.1", UIWidgets.Slider, "Delay in seconds before auto-alignment is triggered", params: "0 60 0.001")]
16 private float m_fDelay;
17
18 /*
19 The speed of the camera when interpolating to default.
20 */
21 [Attribute("1.2", UIWidgets.Slider, "The speed of the camera when interpolating to default. Lower values mean smoother, slower transition.", params: "0 10 0.001")]
22 private float m_fInterpolateSpeed;
23
24 /*
25 Align angles (in degrees) as yaw, pitch, roll in local space.
26 */
27 [Attribute("0 -9 0", UIWidgets.Slider, "Align angles as yaw, pitch, roll in local space.")]
28 private vector m_vAlignYawPitchRoll;
29
30 /*
31 Align angles (in degrees) as yaw, pitch, roll in local space when reversing.
32 */
33 [Attribute("180 -18 0", UIWidgets.Slider, "Align angles as yaw, pitch, roll in local space when reversing.")]
34 private vector m_vAlignYawPitchRollReverse;
35
36 /*
37 If checked (true), auto-alignment will be enabled even when in "focus mode".
38 If unchecked, auto-alignment will be disabled when in "focus mode".
39 */
40 [Attribute("0", UIWidgets.CheckBox, "If checked (true), auto-alignment will be enabled even when in 'focus mode'. If unchecked, auto-alignment will be disabled when in 'focus mode'.")]
41 private bool m_bEnableInFocusMode;
42
43 /*
44 The speed in kph going backwards needed for the camera to transition into opposite direction.
45 */
46 [Attribute("3", UIWidgets.Slider, "The speed in kph going backwards needed for the camera to transition into opposite direction.", params: "0 10 0.001")]
47 private float m_fReverseSpeedTrigger;
48
49 /*
50 The speed in kph going forward needed for the camera to start aligning.
51 */
52 [Attribute("5", UIWidgets.Slider, "The speed in kph going forward needed for the camera to automatically start aligning to direction.", params: "0 10 0.001")]
53 private float m_fForwardSpeedTrigger;
54
58 private float m_fTimer;
59
60
61 /*
62 Should auto align be enabled on gamepad?
63 */
64 [Attribute("1", UIWidgets.CheckBox, "Enabled on gamepad?")]
65 private bool m_bEnableGamepad;
66
67 /*
68 Should auto align be enabled on keyboard and mouse?
69 */
70 [Attribute("0", UIWidgets.CheckBox, "Enabled on keyboard and mouse?")]
71 private bool m_bEnableKeyboard;
72
73 //-----------------------------------------------------------------------------
82 bool Update(vector aimChange, vector currentAngles, vector localVelocity, bool isFocus, float timeSlice, out vector newAngles)
83 {
84 EInputDeviceType lastDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
85 if ((lastDevice != EInputDeviceType.GAMEPAD) && !m_bEnableKeyboard)
86 return false;
87 else if ((lastDevice == EInputDeviceType.GAMEPAD) && !m_bEnableGamepad)
88 return false;
89
90
91 // Input changed, return original.
92 if (aimChange != vector.Zero)
93 {
94 m_fTimer = 0.0;
95 return false;
96 }
97
98 // Focus mode not enabled
99 if (!m_bEnableInFocusMode && isFocus)
100 {
101 m_fTimer = 0.0;
102 return false;
103 }
104
105 // Do not align until fast enough
106 float speed = localVelocity[2] * METERS_PER_SEC_TO_KILOMETERS_PER_HOUR;
107 if (speed > -m_fReverseSpeedTrigger && speed < m_fForwardSpeedTrigger)
108 {
109 m_fTimer = 0.0;
110 return false;
111 }
112
113 // Timer has reached its peak, perform auto aligning..
114 if (m_fTimer > m_fDelay)
115 {
116 // Check fwd/backwards speed to find out if we're reversing
117 bool isReverse = speed <= -m_fReverseSpeedTrigger;
118 vector alignTarget = m_vAlignYawPitchRoll;
119 if (isReverse)
120 alignTarget = m_vAlignYawPitchRollReverse;
121 alignTarget[1] = 0.0; // Hack: Ignore pitch for now. This is independently controlled by CharacterCamera3rdPersonVehicle.c
122
123 // We can return result if we're within a threshold
124 vector delta = (alignTarget - currentAngles);
125 const float DELTA_EPSILON = 0.01;
126
127 float deltaMagnitude = delta.LengthSq();
128 if (deltaMagnitude <= DELTA_EPSILON)
129 {
130 newAngles = alignTarget;
131 return true;
132 }
133
134 // From quaternion
135 vector fromMat[3];
136 Math3D.AnglesToMatrix(currentAngles, fromMat);
137 float fromQuat[4];
138 Math3D.MatrixToQuat(fromMat, fromQuat);
139
140 // To quaternion
141 vector toMat[3];
142 Math3D.AnglesToMatrix(alignTarget, toMat);
143 float toQuat[4];
144 Math3D.MatrixToQuat(toMat, toQuat);
145
146 // Interpolate
147 float resQuat[4];
148 Math3D.QuatLerp(resQuat, fromQuat, toQuat, timeSlice * m_fInterpolateSpeed);
149
150 newAngles = Math3D.QuatToAngles(resQuat);
151 return true;
152 }
153 else
154 {
155 // Keep incrementing the timer
156 m_fTimer += timeSlice;
157 }
158
159 // Return original angles
160 return false;
161 }
162};
const float METERS_PER_SEC_TO_KILOMETERS_PER_HOUR
Contains various global constants.
Definition Constants.c:5
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_FieldOfViewSettings Attribute