7 static const float CONST_UD_MIN = -89.0;
8 static const float CONST_UD_MAX = 89.0;
10 static const float CONST_LR_MIN = -180.0;
11 static const float CONST_LR_MAX = 180.0;
13 static const float STEERING_DEGREES = 5;
14 static const float ANGULAR_INERTIA = 5;
15 protected float m_fSteeringAngle;
16 protected float m_fInertiaAngle;
20 protected float m_fDist_Desired;
21 protected float m_fDist_Min;
22 protected float m_fDist_Max;
23 protected float m_fFOV_SpeedAdjustMax;
24 protected float m_fBobScale;
25 protected float m_fShakeScale;
26 protected float m_fSpeedMax;
28 protected IEntity m_OwnerVehicle;
29 protected BaseCompartmentSlot m_pCompartment;
31 protected vector m_vCenter;
33 protected vector m_vLastVel;
34 protected vector m_vLastAngVel;
35 protected vector m_vAcceleration;
37 protected float m_f3rd_TraceClipPct;
38 protected float m_fBob_FastUp;
39 protected float m_fBob_FastRight;
40 protected float m_fBob_SlowUp;
41 protected float m_fBob_SlowRight;
44 protected float m_fBob_Acceleration;
47 protected float m_fAngleThirdPerson;
52 bool m_bCharacterWasJustEjected =
false;
55 void CharacterCamera3rdPersonVehicle(CameraHandlerComponent pCameraHandler)
57 m_fFOV = GetBaseFOV();
58 m_bLRAngleNoLimit =
true;
64 CompartmentAccessComponent compartmentAccess =
m_OwnerCharacter.GetCompartmentAccessComponent();
65 if (compartmentAccess && compartmentAccess.IsInCompartment())
67 m_pCompartment = compartmentAccess.GetCompartment();
68 IEntity vehicle = m_pCompartment.GetOwner().GetRootParent();
71 m_OwnerVehicle = vehicle;
77 if (ownerCamData && ownerCamData.m_bOverrideVehicleSettings)
78 vehicleCamData = ownerCamData;
83 m_fDist_Desired = vehicleCamData.m_fDist_Desired;
84 m_fDist_Min = vehicleCamData.m_fDist_Min;
85 m_fDist_Max = vehicleCamData.m_fDist_Max;
87 m_fFOV_SpeedAdjustMax = vehicleCamData.m_fFOV_SpeedAdjustMax;
88 m_fBobScale = vehicleCamData.m_fBobScale;
89 m_fShakeScale = vehicleCamData.m_fShakeScale;
90 m_fSpeedMax = vehicleCamData.m_fSpeedMax;
91 m_pCameraAimpointData = vehicleCamData.m_pCameraAimpointData;
92 m_pCameraAlignData = vehicleCamData.m_pCameraAlignData;
93 m_fRollFactor = vehicleCamData.m_fRollFactor;
94 m_fPitchFactor = vehicleCamData.m_fPitchFactor;
95 m_fAngleThirdPerson = vehicleCamData.m_fAngleThirdPerson * Math.DEG2RAD;
98 Physics physics = vehicle.GetPhysics();
101 m_vCenter = physics.GetCenterOfMass();
106 vehicle.GetBounds(mins, maxs);
107 m_vCenter = (maxs - mins) * 0.5 + mins;
114 override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
116 super.OnActivate(pPrevCamera, pPrevCameraResult);
120 vector f = pPrevCamera.GetBaseAngles();
121 m_fUpDownAngle = f[0];
122 m_fLeftRightAngle = f[1];
126 if (characterCamera1stPersonVehicle)
128 m_fRollSmooth = characterCamera1stPersonVehicle.m_fRollSmooth;
129 m_fRollSmoothVel = characterCamera1stPersonVehicle.m_fRollSmoothVel;
130 m_fPitchSmooth = characterCamera1stPersonVehicle.m_fPitchSmooth;
131 m_fPitchSmoothVel = characterCamera1stPersonVehicle.m_fPitchSmoothVel;
137 override void OnBlendOut()
139 CompartmentAccessComponent compartmentAccess =
m_OwnerCharacter.GetCompartmentAccessComponent();
140 if (compartmentAccess && compartmentAccess.IsInCompartment())
141 m_bCharacterWasJustEjected = compartmentAccess.WasLastGettingOutTeleportation();
145 override void OnUpdate(
float pDt, out ScriptedCameraItemResult pOutResult)
147 CompartmentAccessComponent compartmentAccess =
m_OwnerCharacter.GetCompartmentAccessComponent();
148 if (compartmentAccess && compartmentAccess.IsInCompartment())
150 m_pCompartment = compartmentAccess.GetCompartment();
151 IEntity vehicle = m_pCompartment.GetOwner().GetRootParent();
152 if (vehicle && vehicle != m_OwnerVehicle)
159 float udAngle = UpdateUDAngle(m_fUpDownAngle, CONST_UD_MIN, CONST_UD_MAX, pDt);
160 m_fLeftRightAngle = UpdateLRAngle(m_fLeftRightAngle, CONST_LR_MIN, CONST_LR_MAX, pDt);
162 pOutResult.m_vBaseAngles = GetBaseAngles();
165 m_fFOV = GetBaseFOV();
168 vector characterOffset = vector.Zero;
169 vector localVelocity = vector.Zero;
170 vector localAngVelocity = vector.Zero;
173 bool bCharacterAttached =
true;
178 m_OwnerVehicle.GetTransform(vehMat);
180 vector vehToCharLocalMat[4];
181 if (!m_bCharacterWasJustEjected &&
m_OwnerCharacter.GetAncestorToLocalTransform(m_OwnerVehicle, vehToCharLocalMat))
182 characterOffset = m_vCenter.Multiply4(vehToCharLocalMat);
186 if (m_bCharacterWasJustEjected && compartmentAccess)
188 compartmentAccess.GetTeleportTarget(charMat);
192 characterOffset = m_vCenter.Multiply4(vehMat).InvMultiply4(charMat);
193 bCharacterAttached =
false;
196 Physics physics = m_OwnerVehicle.GetPhysics();
199 localVelocity = physics.GetVelocity().InvMultiply3(vehMat);
200 localAngVelocity = physics.GetAngularVelocity().InvMultiply3(vehMat);
206 VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(m_OwnerVehicle.FindComponent(VehicleWheeledSimulation));
208 steeringAngle = simulation.GetSteering();
213 Math3D.MatrixIdentity4(vehMat);
217 vector smoothVelocity = vector.Lerp(m_vLastVel, localVelocity, pDt);
218 m_fInertiaAngle = Math.Lerp(m_fInertiaAngle, localAngVelocity[1] * ANGULAR_INERTIA, pDt);
219 m_fSteeringAngle = Math.Lerp(m_fSteeringAngle, steeringAngle * STEERING_DEGREES, pDt);
222 m_vLastVel = localVelocity;
223 m_vLastAngVel = localAngVelocity;
225 vector yawPitchRoll = Math3D.MatrixToAngles(vehMat);
229 lookAngles[0] = m_fLeftRightAngle + m_fInertiaAngle + m_fSteeringAngle;
230 lookAngles[1] = udAngle - yawPitchRoll[1] * m_fPitchFactor;
234 Math3D.AnglesToMatrix(lookAngles, pOutResult.m_CameraTM);
237 if (bCharacterAttached)
240 vector orientation[3];
241 Math3D.AnglesToMatrix(Vector(0, 0, -yawPitchRoll[2]), orientation);
242 Math3D.MatrixMultiply3(orientation, pOutResult.m_CameraTM, pOutResult.m_CameraTM);
245 float angle = yawPitchRoll[2] * m_fRollFactor * Math.DEG2RAD * pOutResult.m_CameraTM[2][2];
247 float rollMask = Math.Max(0, vehMat[1][1]);
248 SCR_Math3D.RotateAround(pOutResult.m_CameraTM, vector.Zero, pOutResult.m_CameraTM[2], -angle * rollMask, pOutResult.m_CameraTM);
251 float heightSign = vehMat[1][1];
252 pOutResult.m_CameraTM[3] = characterOffset + Vector(0, heightSign *
m_fHeight, 0);
256 pOutResult.m_CameraTM[3] = characterOffset + Vector(0,
m_fHeight, 0);
263 float speed = localVelocity.Length();
265 float camDist = Math.Clamp((m_fDist_Max - m_fDist_Min) * speedScale + m_fDist_Desired, m_fDist_Min, m_fDist_Max);
284 if (m_pCameraAimpointData)
288 pOutResult.m_CameraTM[3] = pOutResult.m_CameraTM[3] + translation;
293 bool applyCharAngle =
true;
294 if (sm_TagLyingCamera != -1)
296 CharacterAnimationComponent characterAnimationComponent =
m_OwnerCharacter.GetAnimationComponent();
297 if (characterAnimationComponent && characterAnimationComponent.IsPrimaryTag(sm_TagLyingCamera))
298 applyCharAngle =
false;
301 SCR_Math3D.RotateAround(pOutResult.m_CameraTM, pOutResult.m_CameraTM[3], pOutResult.m_CameraTM[0], m_fAngleThirdPerson, pOutResult.m_CameraTM);
303 SCR_Math3D.RotateAround(pOutResult.m_CameraTM, pOutResult.m_CameraTM[3], pOutResult.m_CameraTM[0], 0, pOutResult.m_CameraTM);
307 pOutResult.m_fUseHeading = 0.0;
308 pOutResult.m_fFOV = m_fFOV + speedScale * m_fFOV_SpeedAdjustMax;
309 pOutResult.m_fDistance = camDist;
310 pOutResult.m_pWSAttachmentReference =
null;
312 pOutResult.m_bAllowCollisionSolver = bCharacterAttached;
314 pOutResult.m_bAllowInterpolation = !m_bCharacterWasJustEjected;
315 m_bCharacterWasJustEjected =
false;
318 if (m_CharacterCameraHandler)
319 m_CharacterCameraHandler.AddShakeToToTransform(pOutResult.m_CameraTM, pOutResult.m_fFOV);
323 override void OnAfterCameraUpdate(
float pDt,
bool pIsKeyframe, inout vector transformMS[4])
329 private void UpdateViewBob(
float pDt, vector localVelocity, vector localAngularVelocity)
334 vector velDiff = localVelocity - m_vLastVel;
335 vector angVelDiff = localAngularVelocity - m_vLastAngVel;
336 float speed = localVelocity.Length();
337 float accel = velDiff.Length() * (1 / pDt) + angVelDiff.Length() * (1 / pDt);
339 if (accel > m_fBob_Acceleration)
340 m_fBob_Acceleration += (accel - m_fBob_Acceleration) * Math.Clamp(pDt * 12, 0, 1);
342 m_fBob_Acceleration += (accel - m_fBob_Acceleration) * Math.Clamp(pDt * 7, 0, 1);
347 m_fBob_SlowUp += Math.Clamp(slowTimeSlice, 0, 1);
348 if (m_fBob_SlowUp >= 1)
350 m_fBob_SlowRight += Math.Clamp(slowTimeSlice * 0.75, 0, 1);
351 if (m_fBob_SlowRight >= 1)
352 m_fBob_SlowRight -= 1;
359 m_fBob_FastUp *= 1 - pDt;
360 m_fBob_FastRight *= 1 - pDt;
364 m_fBob_FastUp += Math.Clamp(fastTimeSlice, 0, 1);
365 if (m_fBob_FastUp >= 1)
367 m_fBob_FastRight += Math.Clamp(fastTimeSlice * 1.4, 0, 1);
368 if (m_fBob_FastRight >= 1)
369 m_fBob_FastRight -= 1;
379 float bobFw = Math.Sin(m_fBob_FastUp * 360 * Math.DEG2RAD) * -0.05 * bobFastScale;
380 float bobUp = Math.Sin(m_fBob_FastUp * 360 * Math.DEG2RAD) * 0.05 * bobFastScale;
381 float bobRt = Math.Sin(m_fBob_FastRight * 360 * Math.DEG2RAD) * 0.05 * bobFastScale;
382 float bobYaw = Math.Sin(m_fBob_FastRight * 360 * Math.DEG2RAD) * 0.3 * bobFastScale;
383 float bobPitch = Math.Sin(m_fBob_FastUp * 360 * Math.DEG2RAD) * 0.3 * bobFastScale;
384 float bobRoll = Math.Sin(m_fBob_FastRight * 360 * Math.DEG2RAD) * 0.4 * bobFastScale;
385 bobFw += Math.Sin(m_fBob_SlowUp * 360 * Math.DEG2RAD) * -0.025 * bobSlowScale;
386 bobUp += Math.Sin(m_fBob_SlowUp * 360 * Math.DEG2RAD) * 0.05 * bobSlowScale;
387 bobRt += Math.Sin(m_fBob_SlowRight * 360 * Math.DEG2RAD) * 0.05 * bobSlowScale;
388 bobYaw += Math.Sin(m_fBob_SlowRight * 360 * Math.DEG2RAD) * 0.2 * bobSlowScale;
389 bobPitch += Math.Sin(m_fBob_SlowUp * 360 * Math.DEG2RAD) * 0.2 * bobSlowScale;
390 bobRoll += Math.Sin(m_fBob_SlowRight * 360 * Math.DEG2RAD) * 0.45 * bobSlowScale;
392 vector angBobMat[3], endBobmat[3];
393 Math3D.AnglesToMatrix(Vector(bobPitch, bobYaw, bobRoll), angBobMat);
394 Math3D.MatrixMultiply3(outTransform, angBobMat, endBobmat);
395 outTransform[0] = endBobmat[0];
396 outTransform[1] = endBobmat[1];
397 outTransform[2] = endBobmat[2];
398 outTransform[3] = Vector(bobRt, bobUp, bobFw).Multiply3(outTransform) + outTransform[3];
402 override float GetBaseFOV()
404 CameraManager cameraManager =
GetGame().GetCameraManager();
408 return cameraManager.GetVehicleFOV();