Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCamera3rdPersonTurret.c
Go to the documentation of this file.
1 // *************************************************************************************
2 // ! CharacterCamera3rdPersonTurret - 3rd person camera when character is controlling turret
3 // *************************************************************************************
4 class CharacterCamera3rdPersonTurret extends CharacterCameraBase
5 {
6 
7  static const float CONST_UD_MIN = -45.0;
8  static const float CONST_UD_MAX = 30.0;
9  static const float CONST_UD_CAMERA_ANGLE_OFFSET = -10.0;
10 
11  protected TurretControllerComponent m_pTurretController;
12  protected TurretComponent m_pControlledTurret;
13  protected vector m_vVertAimLimits;
14  protected vector m_vHorAimLimits;
15  protected vector m_vCameraCenter;
16  protected float m_fLRAngleAdd;
17  protected float m_fHeight;
18  protected float m_fDist_Min;
19  protected IEntity m_OwnerVehicle;
20 
21  protected vector m_vLastCameraAngles; //< Does not update in freelook
22  //-----------------------------------------------------------------------------
23  void CharacterCamera3rdPersonTurret(CameraHandlerComponent pCameraHandler)
24  {
25  m_bLRAngleNoLimit = true;
26  }
27 
28  //-----------------------------------------------------------------------------
29  void InitCameraData()
30  {
31  CompartmentAccessComponent compartmentAccess = m_OwnerCharacter.GetCompartmentAccessComponent();
32  if (compartmentAccess && compartmentAccess.IsInCompartment())
33  {
34  auto compartment = compartmentAccess.GetCompartment();
35  m_OwnerVehicle = compartment.GetVehicle();
36  IEntity turret = compartment.GetOwner();
37  if (turret)
38  {
39  vector mins, maxs;
40  turret.GetBounds(mins, maxs);
41  m_vCameraCenter = (maxs - mins) * 0.5 + mins;
42 
44  if (vehicleCamData)
45  {
46  m_fHeight = vehicleCamData.m_fHeight;
47  m_fDist_Min = vehicleCamData.m_fDist_Min;
48  m_fFOV = vehicleCamData.m_fFOV;
49  m_vCameraCenter[1] = m_vCameraCenter[1] + m_fHeight;
50  m_vCameraCenter[2] = m_vCameraCenter[2] - m_fDist_Min;
51  m_fRollFactor = vehicleCamData.m_fRollFactor;
52  m_fPitchFactor = vehicleCamData.m_fPitchFactor;
53  }
54 
55  // If we'll have multiple turrets, don't cache turret
56  m_pTurretController = TurretControllerComponent.Cast(compartment.GetController());
57  if (!m_pTurretController)
58  return;
59 
60  m_pControlledTurret = m_pTurretController.GetTurretComponent();
61  if (!m_pControlledTurret)
62  return;
63 
64  m_pControlledTurret.GetAimingLimits(m_vHorAimLimits, m_vVertAimLimits);
65  m_vVertAimLimits[0] = CONST_UD_MIN;
66  m_vVertAimLimits[1] = CONST_UD_MAX;
67  }
68  }
69  }
70 
71  //-----------------------------------------------------------------------------
72  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
73  {
74  super.OnActivate(pPrevCamera, pPrevCameraResult);
75 
76  InitCameraData();
77  }
78  //-----------------------------------------------------------------------------
79  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
80  {
81  CompartmentAccessComponent compartmentAccess = m_OwnerCharacter.GetCompartmentAccessComponent();
82  if (compartmentAccess && compartmentAccess.IsInCompartment() )
83  {
84  auto compartment = compartmentAccess.GetCompartment();
85  if (m_OwnerVehicle != compartment.GetVehicle())
86  {
87  InitCameraData();
88  }
89  }
90 
91  if (!m_pControlledTurret || !m_pTurretController)
92  return;
93 
94  // character matrix
95  vector charMat[4];
96  m_OwnerCharacter.GetWorldTransform(charMat);
97 
98  // parent transform
99  vector turretMat[4];
100  IEntity parentEntity = m_OwnerCharacter.GetParent();
101  if (!parentEntity)
102  parentEntity = m_OwnerCharacter;
103 
104  parentEntity.GetWorldTransform(turretMat);
105 
106  vector charAngles = Math3D.MatrixToAngles(charMat);
107  vector lookAngles = m_CharacterHeadAimingComponent.GetLookAngles();
108 
109  CharacterControllerComponent charController = m_OwnerCharacter.GetCharacterController();
110 
112  m_vLastCameraAngles = m_pControlledTurret.GetAimingDirectionWorld().VectorToAngles();
113  if (charController.IsFreeLookEnabled() || m_pTurretController.GetCanAimOnlyInADS())
114  {
115  m_vLastCameraAngles += lookAngles;
116  }
117  Math3D.AnglesToMatrix(m_vLastCameraAngles - charAngles, pOutResult.m_CameraTM);
118 
119  // position
120  vector cameraPositionLS = turretMat[3].InvMultiply4(turretMat) + Vector(0, m_vCameraCenter[1], 0);
121 
122  CompartmentAccessComponent cac = m_OwnerCharacter.GetCompartmentAccessComponent();
123  if (!(cac && (cac.IsGettingOut() || cac.IsGettingIn())))
124  {
125  // Offset by character height, height is not the same when entities are rotated, this is why we revert position without any rotation. Then we can do the height diff.
126  float charHeight = (charMat[3] - turretMat[3]).InvMultiply3(turretMat)[1];
127  cameraPositionLS[1] = cameraPositionLS[1] - charHeight;
128  }
129 
130  // This is our pivot point
131  pOutResult.m_CameraTM[3] = cameraPositionLS;
132 
133  const float camDist = 2.0;
134 
135  // other parameters
136  pOutResult.m_fUseHeading = 0.0;
137  pOutResult.m_fFOV = m_fFOV;
138  pOutResult.m_fDistance = camDist;
139  pOutResult.m_bAllowInterpolation = true;
140  pOutResult.m_pWSAttachmentReference = null;
141  pOutResult.m_pOwner = m_OwnerCharacter;
142  pOutResult.m_bUpdateWhenBlendOut = false;
143 
144  // Apply shake
145  if (m_CharacterCameraHandler)
146  m_CharacterCameraHandler.AddShakeToToTransform(pOutResult.m_CameraTM, pOutResult.m_fFOV);
147  }
148 
149  //-----------------------------------------------------------------------------
150  override void OnAfterCameraUpdate(float pDt, bool pIsKeyframe, inout vector transformMS[4])
151  {
152  AddVehiclePitchRoll(m_OwnerVehicle, pDt, transformMS);
153  }
154 };
m_fHeight
protected float m_fHeight
Definition: SCR_BaseAreaMeshComponent.c:15
OnUpdate
override void OnUpdate(BaseWorld world, float timeslice)
Definition: game.c:910
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandLoiter.c:23
CharacterCameraBase
Definition: CharacterCameraADS.c:4
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
TurretControllerComponent
Definition: TurretControllerComponent.c:12
SCR_VehicleCameraDataComponent
Definition: SCR_VehicleCameraDataComponent.c:7