Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCameraBase.c
Go to the documentation of this file.
1 // TODO: remove these global methods!!
2 
3 float fixAngle_PI_PI(float pAngle)
4 {
5  while (pAngle > Math.PI)
6  pAngle -= Math.PI2;
7 
8  while (pAngle < -Math.PI)
9  pAngle += Math.PI2;
10 
11  return pAngle;
12 }
13 
14 float fixAngle_180_180(float pAngle)
15 {
16  while (pAngle > 180)
17  pAngle -= 360;
18 
19  while (pAngle < -180)
20  pAngle += 360;
21 
22  return pAngle;
23 }
24 
25 class CharacterCameraBase : ScriptedCameraItem
26 {
27  //------------------------------------------------------------------------------------------------
29  void CharacterCameraBase(CameraHandlerComponent pCameraHandler)
30  {
31  m_fLRAngleVel = 0;
32  m_fUDAngleVel = 0;
33  m_fFOV = GetBaseFOV();
34 
35  m_CharacterCameraHandler = SCR_CharacterCameraHandlerComponent.Cast(m_CameraHandler);
36  m_OwnerCharacter = ChimeraCharacter.Cast(pCameraHandler.GetOwner());
37  m_ControllerComponent = SCR_CharacterControllerComponent.Cast(m_OwnerCharacter.FindComponent(SCR_CharacterControllerComponent));
38  m_Input = m_ControllerComponent.GetInputContext();
39  if (sm_TagFPCamera == -1)
40  {
41  sm_TagFPCamera = GameAnimationUtils.RegisterAnimationTag("TagFPCamera");
42  }
43  if (sm_TagADSTransitionIn == -1)
44  {
45  sm_TagADSTransitionIn = GameAnimationUtils.RegisterAnimationTag("TagTransitionADSIn");
46  }
47  if (sm_TagADSTransitionOut == -1)
48  {
49  sm_TagADSTransitionOut = GameAnimationUtils.RegisterAnimationTag("TagTransitionADSOut");
50  }
51  if (sm_TagLyingCamera == -1)
52  {
53  sm_TagLyingCamera = GameAnimationUtils.RegisterAnimationTag("TagLyingCamera");
54  }
55  if (sm_TagItemUpdateCols == -1)
56  {
57  sm_TagItemUpdateCols = GameAnimationUtils.RegisterAnimationTag("TagItemUpdateColliders");
58  }
59  if (sm_iCameraBoneIndex == -1)
60  {
61  Animation anim = m_OwnerCharacter.GetAnimation();
62  sm_iHeadBoneIndex = anim.GetBoneIndex("Head");
63  sm_iCameraBoneIndex = anim.GetBoneIndex("Camera");
64  }
65  m_CharacterAnimationComponent = CharacterAnimationComponent.Cast(m_OwnerCharacter.FindComponent(CharacterAnimationComponent));
66  CharacterCommandHandlerComponent cmdHandler = CharacterCommandHandlerComponent.Cast(m_CharacterAnimationComponent.FindComponent(CharacterCommandHandlerComponent));
67  m_CharacterHeadAimingComponent = CharacterHeadAimingComponent.Cast(m_OwnerCharacter.FindComponent(CharacterHeadAimingComponent));
68  m_CommandWeapons = cmdHandler.GetCommandModifier_Weapon();
69  m_CompartmentAccessComponent = m_OwnerCharacter.GetCompartmentAccessComponent();
70  m_CmdHandler = cmdHandler;
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  float UpdateUDAngle(out float pAngle, float pMin, float pMax, float pDt)
75  {
76  pAngle = Math.Clamp(m_CharacterHeadAimingComponent.GetAimingRotation()[1], pMin, pMax);
77 
78  //On Foot
79  if (m_CompartmentAccessComponent && !m_CompartmentAccessComponent.IsInCompartment())
80  pAngle += m_ControllerComponent.GetInputContext().GetAimingAngles()[1];
81 
82  return pAngle;
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  float UpdateLRAngle(float pAngle, float pMin, float pMax, float pDt)
87  {
88  bool bCompartmentForcesFreeLook = false;
89  if (m_CompartmentAccessComponent && m_CompartmentAccessComponent.IsInCompartment())
90  bCompartmentForcesFreeLook = m_CompartmentAccessComponent.GetCompartment().GetForceFreeLook();
91 
93  if (m_ControllerComponent.IsFreeLookEnabled() || m_ControllerComponent.IsTrackIREnabled() || m_bForceFreeLook || bCompartmentForcesFreeLook)
94  {
95  pAngle = m_CharacterHeadAimingComponent.GetAimingRotation()[0];
96 
97  if (!m_bLRAngleNoLimit)
98  {
99  pAngle = Math.Clamp(pAngle, pMin, pMax);
100  }
101  else
102  {
103  pAngle = fixAngle_180_180(pAngle);
104  }
105 
106  m_fLRAngleVel = 0; // reset filter
107  }
108  else
109  {
110  pAngle = Math.SmoothCD(pAngle, 0, m_fLRAngleVel, 0.14, 1000, pDt);
111  }
112 
113  return pAngle;
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult);
118 
119  //------------------------------------------------------------------------------------------------
120  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
121  {
122  // Save shoulder state if camera was 3rd person or pass on last state
123  if (pPrevCamera)
124  {
125  if ( pPrevCamera.IsInherited(CharacterCamera3rdPersonBase) )
126  {
127  m_fShoulderLastActive = CharacterCamera3rdPersonBase.Cast(pPrevCamera).GetActiveShoulder();
128  }
129  else if ( pPrevCamera.IsInherited(CharacterCameraBase) )
130  {
131  m_fShoulderLastActive = CharacterCameraBase.Cast(pPrevCamera).GetShoulderLastActive();
132  }
133  }
135  {
136  m_CameraHandler.SetLensFlareSet(CameraLensFlareSetType.ThirdPerson, "");
137  }
138  else
139  {
140  m_CameraHandler.SetLensFlareSet(CameraLensFlareSetType.FirstPerson, "");
141  }
142 
143  CharacterCameraBase prevCameraBase = CharacterCameraBase.Cast(pPrevCamera);
144  if (prevCameraBase)
145  {
146  m_fPitchSmooth = prevCameraBase.m_fPitchSmooth;
147  m_fPitchSmoothVel = prevCameraBase.m_fPitchSmoothVel;
148  m_fRollSmooth = prevCameraBase.m_fRollSmooth;
149  m_fRollSmoothVel = prevCameraBase.m_fRollSmoothVel;
150  }
151 
152  m_CharacterHeadAimingComponent.SetPitchLimitReductionMultiplier(1.0);
153  m_CharacterHeadAimingComponent.ResetLimitAnglesOverride();
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  void ForceFreelook(bool state)
158  {
159  m_bForceFreeLook = state;
160  }
161 
162  //-----------------------------------------------------------------------------
165  int GetShoulderLastActive()
166  {
167  return m_fShoulderLastActive;
168  }
169 
170  //------------------------------------------------------------------------------------------------
173  float GetShoulderDistance()
174  {
175  return 0.0;
176  }
177 
178  //------------------------------------------------------------------------------------------------
181  float GetInterpolatedUDTransformAngle(float pDt)
182  {
183  vector physTransform[4];
184  m_OwnerCharacter.GetLocalTransform(physTransform);
185  m_fTransformUDAngle = Math.SmoothCD(m_fTransformUDAngle, physTransform[2][1], m_fTransformUDAngleVel, 0.14, 1000, pDt);
186  return m_fTransformUDAngle * Math.RAD2DEG;
187  }
188 
189  //------------------------------------------------------------------------------------------------
195  void AddPitchRoll(vector yawPitchRoll, float pitchFactor, float rollFactor, inout vector transformMS[4])
196  {
197  // Get camera forward, without height
198  vector cameraForward = transformMS[2];
199  cameraForward[1] = 0.0;
200  cameraForward.Normalize();
201 
202  // Get camera right, without height
203  vector cameraAside = transformMS[0];
204  cameraAside[1] = 0;
205  cameraAside.Normalize();
206 
207  // See how much of individual components to apply
208  float rollAmount = vector.Dot(cameraForward, vector.Forward);
209  float pitchAmount = vector.Dot(cameraAside, vector.Forward);
210 
211  float pitch = yawPitchRoll[1];
212  float roll = yawPitchRoll[2];
213 
214  float newPitch = pitchFactor * (pitch * rollAmount - roll * pitchAmount);
215  float newRoll = rollFactor * (roll * rollAmount - pitch * pitchAmount);
216 
217  // Create rotation matrix
218  vector newPitchRoll = Vector(0, newPitch, newRoll);
219  vector rotMat[3];
220  Math3D.AnglesToMatrix(newPitchRoll, rotMat);
221 
222  // Apply matrix to final transformation
223  Math3D.MatrixMultiply3(transformMS, rotMat, transformMS);
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  protected void AddVehiclePitchRoll(IEntity vehicle, float pDt, inout vector transformMS[4])
228  {
229  if (!vehicle)
230  return;
231 
232  vector vehMat[4];
233  vehicle.GetTransform(vehMat);
234 
235  // Compensate for roll after camera is updated
236  vector yawPitchRoll = Math3D.MatrixToAngles(vehMat);
237  m_fPitchSmooth = Math.SmoothCD(m_fPitchSmooth, -yawPitchRoll[1], m_fPitchSmoothVel, 0.14, 1000, pDt);
238  m_fRollSmooth = Math.SmoothCD(m_fRollSmooth, -yawPitchRoll[2], m_fRollSmoothVel, 0.14, 1000, pDt);
239  yawPitchRoll[0] = 0;
240  yawPitchRoll[1] = m_fPitchSmooth;
241  yawPitchRoll[2] = m_fRollSmooth;
242 
243  float rollMask = Math.Max(0, vehMat[1][1]); // Do not apply roll factor when the vehicle is upside-down.
244  AddPitchRoll(yawPitchRoll, m_fPitchFactor, rollMask * m_fRollFactor, transformMS);
245  }
246 
248  protected float m_fUpDownAngle;
249  protected float m_fUpDownAngleAdd;
250  protected float m_fLeftRightAngle = 0.0;
251 
252  //-----------------------------------------------------------------------------
253  override void SetBaseAngles(out vector angles)
254  {
255  m_fUpDownAngle = fixAngle_180_180(angles[0]);
256  m_fLeftRightAngle = fixAngle_180_180(angles[1]);
257  }
258 
259  //-----------------------------------------------------------------------------
260  override vector GetBaseAngles()
261  {
262  return m_CharacterHeadAimingComponent.GetLookAngles();
263  }
264 
265  //------------------------------------------------------------------------------------------------
269  protected TNodeId GetCameraBoneIndex()
270  {
271  if (m_CharacterAnimationComponent.IsPrimaryTag(sm_TagFPCamera))
272  {
273  return sm_iCameraBoneIndex;
274  }
275  return sm_iHeadBoneIndex;
276  }
277 
278  protected float m_fFOV;
279 
280  protected float m_fLRAngleVel;
281  protected float m_fUDAngleVel;
282  protected float m_fTransformUDAngleVel;
283  protected float m_fTransformUDAngle;
284  protected bool m_bForceFreeLook;
285  protected bool m_bLRAngleNoLimit;
286 
287  protected bool m_bIgnoreCharacterPitch;
288 
289  protected float m_fFOVFilter;
290  protected float m_fFOVFilterVel;
291 
292  protected int m_fShoulderLastActive = 1;
293 
294  protected float m_fRollFactor;
295  protected float m_fRollSmooth;
296  protected float m_fRollSmoothVel;
297  protected float m_fPitchFactor;
298  protected float m_fPitchSmooth;
299  protected float m_fPitchSmoothVel;
300 
301  protected ChimeraCharacter m_OwnerCharacter;
302  protected SCR_CharacterControllerComponent m_ControllerComponent;
303  protected CharacterInputContext m_Input;
304  protected SCR_CharacterCameraHandlerComponent m_CharacterCameraHandler;
305  protected CharacterAnimationComponent m_CharacterAnimationComponent;
306  protected CharacterHeadAimingComponent m_CharacterHeadAimingComponent;
307  protected CharacterCommandWeapon m_CommandWeapons;
308  protected CompartmentAccessComponent m_CompartmentAccessComponent;
309  protected CharacterCommandHandlerComponent m_CmdHandler;
310  protected float m_fShakeProgress;
311  protected float m_fShakeVelocity;
312  protected static TNodeId sm_iCameraBoneIndex = -1;
313  protected static TNodeId sm_iHeadBoneIndex = -1;
314  protected static AnimationTagID sm_TagFPCamera = -1;
315  protected static AnimationTagID sm_TagLyingCamera = -1; // beware: very deceitful!
316  protected static AnimationTagID sm_TagItemUpdateCols = -1; // beware: very deceitful!
317  protected static AnimationTagID sm_TagADSTransitionOut = -1;
318  protected static AnimationTagID sm_TagADSTransitionIn = -1;
319 }
CharacterInputContext
Definition: CharacterInputContext.c:12
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
fixAngle_PI_PI
float fixAngle_PI_PI(float pAngle)
Definition: CharacterCameraBase.c:3
IsInherited
bool IsInherited(string factionKey)
Definition: SCR_Faction.c:227
CharacterCameraBase
Definition: CharacterCameraADS.c:4
CharacterCamera3rdPersonBase
Definition: CharacterCamera3rdPersonCrouch.c:4
m_CameraHandler
protected SCR_CharacterCameraHandlerComponent m_CameraHandler
Definition: SCR_InfoDisplayExtended.c:26
CharacterCommandWeapon
Definition: CharacterCommandWeapon.c:12
GameAnimationUtils
Definition: GameAnimationUtils.c:7
fixAngle_180_180
float fixAngle_180_180(float pAngle)
Definition: CharacterCameraBase.c:14