Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCamera1stPersonTurret.c
Go to the documentation of this file.
1 // *************************************************************************************
2 // ! CharacterCamera1stPersonVehicle - 1st person camera when character is in vehicle
3 // *************************************************************************************
4 class CharacterCamera1stPersonTurret extends CharacterCamera1stPerson
5 {
6 
7  protected TurretControllerComponent m_pTurretController;
8  protected TurretComponent m_pControlledTurret;
9  protected TurretCompartmentSlot m_pCompartment;
10  protected vector m_vVertAimLimits;
11  protected vector m_vHorAimLimits;
12  protected float m_fLRAngleAdd;
13  protected vector m_vPrevEyePosition;
14  protected IEntity m_OwnerVehicle;
15 
16  protected vector m_vLastCameraAngles; //< Does not update in freelook
17 
18  //-----------------------------------------------------------------------------
19  void CharacterCamera1stPersonTurret(CameraHandlerComponent pCameraHandler)
20  {
21  m_ApplyHeadBob = false;
22  m_vPrevEyePosition = m_OwnerCharacter.EyePositionModel();
23  m_OffsetLS = "0.0 0.1 0.0";
24  m_bLRAngleNoLimit = true;
25  }
26 
27  //-----------------------------------------------------------------------------
28  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
29  {
30  super.OnActivate(pPrevCamera, pPrevCameraResult);
31 
32  if (m_pCompartmentAccess && m_pCompartmentAccess.IsInCompartment())
33  {
34  BaseCompartmentSlot compartment = m_pCompartmentAccess.GetCompartment();
35  if (compartment)
36  {
37  m_OwnerVehicle = compartment.GetVehicle();
38 
39  SCR_VehicleCameraDataComponent vehicleCamData = SCR_VehicleCameraDataComponent.Cast(m_OwnerVehicle.FindComponent(SCR_VehicleCameraDataComponent));
40  if (vehicleCamData)
41  {
42  m_fRollFactor = vehicleCamData.m_fRollFactor;
43  m_fPitchFactor = vehicleCamData.m_fPitchFactor;
44  }
45 
46  m_pTurretController = TurretControllerComponent.Cast(compartment.GetController());
47  if (!m_pTurretController)
48  return;
49 
50  // If we'll have multiple turrets, don't cache turret
51  m_pControlledTurret = m_pTurretController.GetTurretComponent();
52  if (!m_pControlledTurret)
53  return;
54 
55  m_pControlledTurret.GetAimingLimits(m_vHorAimLimits, m_vVertAimLimits);
56  m_pCompartment = TurretCompartmentSlot.Cast(compartment);
57  }
58  }
59 
60  m_fLRAngleAdd = 0;
61 
62  m_CharacterHeadAimingComponent.SetPitchLimitReductionMultiplier(1.25); // Pitch reduction to avoid neckhole
63  }
64  //-----------------------------------------------------------------------------
65  static float UpdateAngleWithTarget(out float pAngle, out float pAngleAdd, out float addVelocity, vector limits, float pDt, float target, float change, bool freeLook)
66  {
68  pAngle = target;
69  pAngle = Math.Clamp(pAngle, limits[0], limits[1]);
70  // remove freelook when switched back to controlled state
71  pAngleAdd = Math.SmoothCD(pAngleAdd, 0, addVelocity, 0.14, 1000, pDt);
72 
73  return Math.Clamp(pAngle + pAngleAdd, limits[0], limits[1]);
74  }
75  //-----------------------------------------------------------------------------
76  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
77  {
78  // no super for now, will calculate angle based on turret aiming (HeadAngles not supported when turret compartment attachment)
79  if (!m_pControlledTurret)
80  return;
81 
82  pOutResult.m_pWSAttachmentReference = null;
83  pOutResult.m_pOwner = m_OwnerCharacter;
84  pOutResult.m_fPositionModelSpace = 1.0;
85  pOutResult.m_fFOV = m_fFOV;
86  pOutResult.m_fNearPlane = 0.04;
87  pOutResult.m_bAllowInterpolation = true;
88  pOutResult.m_bUpdateWhenBlendOut = true;
89  pOutResult.m_fUseHeading = 0.0;
90  pOutResult.m_iDirectBoneMode = EDirectBoneMode.None;
91  pOutResult.m_iDirectBone = -1;
92 
93  vector offset = m_OffsetLS;
94  if (m_pCompartment && m_pCompartment.IsDirectAimMode() && m_pTurretController.GetCanAimOnlyInADS())
95  {
96  offset = "0 0 0";
97  }
98 
99  CharacterControllerComponent charController = m_OwnerCharacter.GetCharacterController();
100 
102  m_vLastCameraAngles = m_pControlledTurret.GetAimingDirectionWorld().VectorToAngles();
103  if (charController.IsFreeLookEnabled() || m_pTurretController.GetCanAimOnlyInADS())
104  {
105  // Override angle limits based on turret aiming angles
106  float turretPitch = m_pControlledTurret.GetAimingRotation()[1];
107  float downLimit = -40.0;
108  if (turretPitch < 0.0)
109  downLimit -= turretPitch;
110  float upLimit = 89.9;
111  if (turretPitch > 0.0)
112  upLimit -= turretPitch;
113 
114  float turretYaw = m_pControlledTurret.GetAimingRotation()[0];
115  float leftLimit = -160.0;
116  if (turretYaw < 0.0)
117  leftLimit -= turretYaw;
118  float rightLimit = 160.0;
119  if (turretYaw > 0.0)
120  rightLimit -= turretYaw;
121 
122  m_CharacterHeadAimingComponent.SetLimitAnglesOverride(downLimit, upLimit, leftLimit, rightLimit);
123 
124  vector lookAnglesOverriden = m_CharacterHeadAimingComponent.GetLookAngles();
125  m_vLastCameraAngles += lookAnglesOverriden;
126 
127  m_CharacterHeadAimingComponent.ResetLimitAnglesOverride();
128  }
129 
130  // character matrix
131  vector charMat[4];
132  m_OwnerCharacter.GetWorldTransform(charMat);
133  vector charAngles = Math3D.MatrixToAngles(charMat);
134 
135  Math3D.AnglesToMatrix(m_vLastCameraAngles - charAngles, pOutResult.m_CameraTM);
136 
138  m_vPrevEyePosition = vector.Lerp(m_vPrevEyePosition, m_OwnerCharacter.EyePositionModel(), 0.25);
139  pOutResult.m_CameraTM[3] = m_vPrevEyePosition + offset;
140 
141  // Apply shake
142  if (m_CharacterCameraHandler)
143  m_CharacterCameraHandler.AddShakeToToTransform(pOutResult.m_CameraTM, pOutResult.m_fFOV);
144  }
145 
146  //-----------------------------------------------------------------------------
147  override void OnAfterCameraUpdate(float pDt, bool pIsKeyframe, inout vector transformMS[4])
148  {
149  AddVehiclePitchRoll(m_OwnerVehicle, pDt, transformMS);
150  }
151 
152  //-----------------------------------------------------------------------------
153  override float GetBaseFOV()
154  {
155  CameraManager cameraManager = GetGame().GetCameraManager();
156  if (!cameraManager)
157  return 0;
158 
159  return cameraManager.GetVehicleFOV();
160  }
161 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnUpdate
override void OnUpdate(BaseWorld world, float timeslice)
Definition: game.c:910
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandLoiter.c:23
TurretCompartmentSlot
Definition: TurretCompartmentSlot.c:12
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
CharacterCamera1stPerson
Definition: CharacterCamera1stPerson.c:106
SCR_VehicleCameraDataComponent
Definition: SCR_VehicleCameraDataComponent.c:7