Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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 
122  // We can return result if we're within a threshold
123  vector delta = (alignTarget - currentAngles);
124  const float DELTA_EPSILON = 0.01;
125 
126  float deltaMagnitude = delta.LengthSq();
127  if (deltaMagnitude <= DELTA_EPSILON)
128  {
129  newAngles = alignTarget;
130  return true;
131  }
132 
133  // From quaternion
134  vector fromMat[3];
135  Math3D.AnglesToMatrix(currentAngles, fromMat);
136  float fromQuat[4];
137  Math3D.MatrixToQuat(fromMat, fromQuat);
138 
139  // To quaternion
140  vector toMat[3];
141  Math3D.AnglesToMatrix(alignTarget, toMat);
142  float toQuat[4];
143  Math3D.MatrixToQuat(toMat, toQuat);
144 
145  // Interpolate
146  float resQuat[4];
147  Math3D.QuatLerp(resQuat, fromQuat, toQuat, timeSlice * m_fInterpolateSpeed);
148 
149  newAngles = Math3D.QuatToAngles(resQuat);
150  return true;
151  }
152  else
153  {
154  // Keep incrementing the timer
155  m_fTimer += timeSlice;
156  }
157 
158  // Return original angles
159  return false;
160  }
161 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fDelay
protected float m_fDelay
Definition: SCR_TooltipManagerEditorUIComponent.c:8
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VehicleCameraAlignment
Definition: SCR_VehicleCameraAlignment.c:10
METERS_PER_SEC_TO_KILOMETERS_PER_HOUR
const float METERS_PER_SEC_TO_KILOMETERS_PER_HOUR
Contains various global constants.
Definition: Constants.c:5
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468