15 [
Attribute(
"1.1", UIWidgets.Slider,
"Delay in seconds before auto-alignment is triggered",
params:
"0 60 0.001")]
16 private float m_fDelay;
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;
27 [
Attribute(
"0 -9 0", UIWidgets.Slider,
"Align angles as yaw, pitch, roll in local space.")]
28 private vector m_vAlignYawPitchRoll;
33 [
Attribute(
"180 -18 0", UIWidgets.Slider,
"Align angles as yaw, pitch, roll in local space when reversing.")]
34 private vector m_vAlignYawPitchRollReverse;
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;
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;
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;
58 private float m_fTimer;
64 [
Attribute(
"1", UIWidgets.CheckBox,
"Enabled on gamepad?")]
65 private bool m_bEnableGamepad;
70 [
Attribute(
"0", UIWidgets.CheckBox,
"Enabled on keyboard and mouse?")]
71 private bool m_bEnableKeyboard;
82 bool Update(vector aimChange, vector currentAngles, vector localVelocity,
bool isFocus,
float timeSlice, out vector newAngles)
84 EInputDeviceType lastDevice =
GetGame().GetInputManager().GetLastUsedInputDevice();
85 if ((lastDevice != EInputDeviceType.GAMEPAD) && !m_bEnableKeyboard)
87 else if ((lastDevice == EInputDeviceType.GAMEPAD) && !m_bEnableGamepad)
92 if (aimChange != vector.Zero)
99 if (!m_bEnableInFocusMode && isFocus)
107 if (speed > -m_fReverseSpeedTrigger && speed < m_fForwardSpeedTrigger)
117 bool isReverse = speed <= -m_fReverseSpeedTrigger;
118 vector alignTarget = m_vAlignYawPitchRoll;
120 alignTarget = m_vAlignYawPitchRollReverse;
123 vector delta = (alignTarget - currentAngles);
124 const float DELTA_EPSILON = 0.01;
126 float deltaMagnitude = delta.LengthSq();
127 if (deltaMagnitude <= DELTA_EPSILON)
129 newAngles = alignTarget;
135 Math3D.AnglesToMatrix(currentAngles, fromMat);
137 Math3D.MatrixToQuat(fromMat, fromQuat);
141 Math3D.AnglesToMatrix(alignTarget, toMat);
143 Math3D.MatrixToQuat(toMat, toQuat);
147 Math3D.QuatLerp(resQuat, fromQuat, toQuat, timeSlice * m_fInterpolateSpeed);
149 newAngles = Math3D.QuatToAngles(resQuat);