Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCamera1stPersonVehicle.c
Go to the documentation of this file.
1 
2 // *************************************************************************************
3 // ! CharacterCamera1stPersonVehicle - 1st person camera when character is in vehicle
4 // *************************************************************************************
6 {
7  protected IEntity m_OwnerVehicle;
8  protected float m_fAngleFirstPerson;
9  protected float m_fAngleFirstPersonScale;
10 
11  //-----------------------------------------------------------------------------
12  void CharacterCamera1stPersonVehicle(CameraHandlerComponent pCameraHandler)
13  {
14  m_ApplyHeadBob = false;
15  }
16 
17  //-----------------------------------------------------------------------------
18  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
19  {
20  super.OnActivate(pPrevCamera, pPrevCameraResult);
21 
22  CharacterCamera3rdPersonVehicle characterCamera3rdPersonVehicle = CharacterCamera3rdPersonVehicle.Cast(pPrevCamera);
23  if (characterCamera3rdPersonVehicle)
24  {
25  m_fRollSmooth = characterCamera3rdPersonVehicle.m_fRollSmooth;
26  m_fRollSmoothVel = characterCamera3rdPersonVehicle.m_fRollSmoothVel;
27  m_fPitchSmooth = characterCamera3rdPersonVehicle.m_fPitchSmooth;
28  m_fPitchSmoothVel = characterCamera3rdPersonVehicle.m_fPitchSmoothVel;
29  }
30 
31  if (m_pCompartmentAccess)
32  {
33  BaseCompartmentSlot compartment = m_pCompartmentAccess.GetCompartment();
34  if (compartment)
35  {
36  m_OwnerVehicle = compartment.GetOwner();
37 
38  if (m_OwnerVehicle)
39  {
40  SCR_VehicleCameraDataComponent vehicleCamData = SCR_VehicleCameraDataComponent.Cast(m_OwnerVehicle.FindComponent(SCR_VehicleCameraDataComponent));
41  if( vehicleCamData )
42  {
43  m_fRollFactor = vehicleCamData.m_fRollFactor;
44  m_fPitchFactor = vehicleCamData.m_fPitchFactor;
45  m_fAngleFirstPerson = vehicleCamData.m_fAngleFirstPerson * Math.DEG2RAD;
46  }
47 
48  if (m_ControllerComponent && m_ControllerComponent.IsGadgetInHands())
49  m_fAngleFirstPersonScale = 0;
50  else
51  m_fAngleFirstPersonScale = 1;
52  }
53  }
54  }
55 
56  m_bCameraTransition = false;
57  }
58 
59  //-----------------------------------------------------------------------------
60 
61  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
62  {
63  if (!m_bCameraTransition)
64  {
65  m_UseLookPositionOverrideLS = true;
66 
67  // Prevent camera from moving behind the character as it orbits around the head.
68  float yawOffset = -0.5 * m_CharacterHeadAimingComponent.GetLookAngles()[0];
69  vector additiveYaw = { yawOffset, 0.0, 0.0 };
70 
71  // Camera moves forward as the player looks sideways (providing better view off the shoulders when pitching down).
72  const float OneBy90 = 1.0 / 90.0;
73  float zOffset = -0.07 - 0.13 * Math.Clamp(Math.AbsFloat(additiveYaw[0] * OneBy90), 0.0, 1.0);
74  vector offsetLS = { m_OffsetLS[0], m_OffsetLS[1], zOffset };
75 
76  vector resultTM[4];
77  m_CharacterHeadAimingComponent.GetLookTransformationLS(GetCameraBoneIndex(), EDirectBoneMode.RelativePosition, offsetLS, additiveYaw, resultTM);
78  m_LookPositionOverrideLS = resultTM[3];
79 
80  m_CharacterHeadAimingComponent.SetPitchLimitReductionMultiplier(0.5); // Less aggressive pitch reduction.
81  }
82 
83  super.OnUpdate(pDt, pOutResult);
84  pOutResult.m_fUseHeading = 0.0;
85  AddVehiclePitchRoll(m_OwnerVehicle, pDt, pOutResult.m_CameraTM);
86 
87  // Specific case for character lying down, where assumption for world-up fails
88  // If we want to allow such cases on a 'daily basis', reconsider how seating
89  // and vehicle cameras work in first person :)
90  if (sm_TagLyingCamera != -1 && sm_TagItemUpdateCols != -1)
91  {
92  CharacterAnimationComponent characterAnimationComponent = m_OwnerCharacter.GetAnimationComponent();
93  if (characterAnimationComponent && characterAnimationComponent.IsPrimaryTag(sm_TagLyingCamera))
94  {
95  // The character has very odd orientation in this case, the entity transformation retains its world up relation,
96  // but the character body is not lying flat, just chilling, so let's deploy some quick magic here:
97  pOutResult.m_vBaseAngles = m_CharacterHeadAimingComponent.GetAimingRotation();
98  pOutResult.m_fUseHeading = 0.0;
99  pOutResult.m_iDirectBoneMode = EDirectBoneMode.RelativePosition;
100  pOutResult.m_iDirectBone = GetCameraBoneIndex();
101  pOutResult.m_bAllowInterpolation = true;
102 
103  vector additiveRotation = "0 0 0";
104  vector offset = m_OffsetLS;
105  m_CharacterHeadAimingComponent.GetLookTransformationLS(pOutResult.m_iDirectBone, pOutResult.m_iDirectBoneMode, offset, additiveRotation, pOutResult.m_CameraTM);
106  if( m_ApplyHeadBob )
107  m_CharacterCameraHandler.AddViewBobToTransform(pOutResult.m_CameraTM, 1, false);
108 
109  vector rotMat[3];
110  if (!characterAnimationComponent.IsPrimaryTag(sm_TagItemUpdateCols))
111  Math3D.AnglesToMatrix(Vector(0, 90, 0), rotMat); // Already laying
112  else
113  {
114  vector camMatrix[4]; // Entering, exiting
115  m_OwnerCharacter.GetAnimation().GetBoneMatrix(m_OwnerCharacter.GetAnimation().GetBoneIndex("Head"), camMatrix);
116  vector camAngles = Math3D.MatrixToAngles(camMatrix);
117  Math3D.AnglesToMatrix(Vector(0, -camAngles[1], 0), rotMat);
118  }
119 
120  //Math3D.AnglesToMatrix(Vector(0, -camAngles[1], 0), rotMat);
121  Math3D.MatrixMultiply3(rotMat, pOutResult.m_CameraTM, pOutResult.m_CameraTM);
122  return;
123  }
124  }
125 
126  // Rotate camera if not having gadget in hands
127  if (float.AlmostEqual(m_fAngleFirstPerson, 0))
128  return;
129 
130  // First person camera angle offset only for pilot
131  Vehicle vehicle = Vehicle.Cast(m_OwnerVehicle);
132  if (!vehicle || vehicle.GetPilot() != m_OwnerCharacter)
133  return;
134 
135  if (m_ControllerComponent && m_ControllerComponent.IsGadgetInHands())
136  m_fAngleFirstPersonScale -= pDt * 3;
137  else
138  m_fAngleFirstPersonScale += pDt * 3;
139 
140  m_fAngleFirstPersonScale = Math.Clamp(m_fAngleFirstPersonScale, 0, 1);
141 
142  SCR_Math3D.RotateAround(pOutResult.m_CameraTM, pOutResult.m_CameraTM[3], pOutResult.m_CameraTM[0], m_fAngleFirstPerson * m_fAngleFirstPersonScale, pOutResult.m_CameraTM);
143  }
144 
145  //-----------------------------------------------------------------------------
146  override void OnAfterCameraUpdate(float pDt, bool pIsKeyframe, inout vector transformMS[4])
147  {
148  }
149 
150  //-----------------------------------------------------------------------------
151  override float GetBaseFOV()
152  {
153  CameraManager cameraManager = GetGame().GetCameraManager();
154  if (!cameraManager)
155  return 0;
156 
157  return cameraManager.GetVehicleFOV();
158  }
159 };
160 // *************************************************************************************
161 // ! CharacterCamera1stPersonVehicleTransition - 1st person camera when character is getting in/out vehicle
162 // ************************************************************************************
163 class CharacterCamera1stPersonVehicleTransition extends CharacterCamera1stPersonVehicle
164 {
165  private bool m_isExiting = false;
166 
167  //-----------------------------------------------------------------------------
168  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
169  {
170  super.OnActivate(pPrevCamera, pPrevCameraResult);
171  m_bCameraTransition = true;
172  m_isExiting = false;
173  }
174 
175  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
176  {
177  super.OnUpdate(pDt, pOutResult);
178  if (m_pCompartmentAccess)
179  {
180  if (m_pCompartmentAccess.IsGettingOut())
181  m_isExiting = true;
182 
183  if (!m_pCompartmentAccess.IsInCompartment() && m_isExiting)
184  {
185  pOutResult.m_bAllowInterpolation = false;
186  pOutResult.m_fUseHeading = 1.0;
187  }
188  }
189  }
190 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
CharacterCamera1stPersonVehicle
Definition: CharacterCamera1stPersonVehicle.c:163
OnUpdate
override void OnUpdate(BaseWorld world, float timeslice)
Definition: game.c:910
SCR_Math3D
Contains various scripted 3D math functions.
Definition: SCR_Math3D.c:2
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandLoiter.c:23
m_OwnerCharacter
private SCR_ChimeraCharacter m_OwnerCharacter
Definition: CharacterCameraHandlerComponent.c:984
OnAfterCameraUpdate
override void OnAfterCameraUpdate(float pDt, bool pIsKeyframe, inout vector transformMS[4], inout vector transformWS[4])
after camera update
Definition: CharacterCameraHandlerComponent.c:535
m_ControllerComponent
private SCR_CharacterControllerComponent m_ControllerComponent
Definition: CharacterCameraHandlerComponent.c:985
CharacterCamera1stPerson
Definition: CharacterCamera1stPerson.c:106
SCR_VehicleCameraDataComponent
Definition: SCR_VehicleCameraDataComponent.c:7