Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
CharacterCamera1stPersonUnconscious.c
Go to the documentation of this file.
1// *************************************************************************************
2// ! CharacterCamera1stPersonUnconscious - first person only unconscious
3// *************************************************************************************
4class CharacterCamera1stPersonUnconscious extends CharacterCamera1stPerson
5{
6 void CharacterCamera1stPersonUnconscious(CameraHandlerComponent pCameraHandler)
7 {
8 }
9
10 void PrintMatrix(string Name, const vector InMatrix[4])
11 {
12
13 Print(string.Format("%1 %2 %3 %4 %5", Name, InMatrix[0], InMatrix[1], InMatrix[2], InMatrix[3]), LogLevel.ERROR);
14 }
15
16 override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
17 {
18 // Note: The transformation is discarded (overwritten) later on
19 super.OnUpdate(pDt, pOutResult);
20
21 pOutResult.m_vBaseAngles = "0 0 0";
22 pOutResult.m_fUseHeading = 0.0;
23 pOutResult.m_iDirectBoneMode = EDirectBoneMode.RelativeTransform;
24
25 // TODO@AS: For now always use the camera bone. If transition is animated,
26 // it is safe to revert to using GetCameraBoneIndex(), assuming sm_TagFPCamera is set.
27 pOutResult.m_iDirectBone = sm_iCameraBoneIndex;
28
29 vector animationBoneWorldTM [4];
30 int headBoneIndex = m_OwnerCharacter.GetAnimation().GetBoneIndex("Head");
31 m_OwnerCharacter.GetAnimation().GetBoneMatrix(headBoneIndex, animationBoneWorldTM);
32
33 vector charMat[4];
34 m_OwnerCharacter.GetWorldTransform(charMat);
35
36 Math3D.MatrixMultiply4(charMat, animationBoneWorldTM, animationBoneWorldTM);
37
38 // Head bone in model space is rotated 180 around its yaw axis,
39 // so we simply undo this rotation
40 vector lookAngles = m_CharacterHeadAimingComponent.GetLookAngles();
41 float y = lookAngles[0] - 180.0;
42
43 while (y < -180)
44 y += 360;
45 while (y > 180)
46 y -= 360;
47
48 lookAngles[0] = y;
49
50 if (m_OwnerCharacter.GetAnimationComponent().IsRagdollActive())
51 {
52 // Apply lookat angles.
53 Math3D.AnglesToMatrix(lookAngles, pOutResult.m_CameraTM);
54
55 //NOTE: 2 is head bone
56 m_OwnerCharacter.GetAnimation().GetBoneMatrix(headBoneIndex, m_ragdollHeadWorldTR);
57
58 Math3D.MatrixMultiply3(m_ragdollHeadWorldTR, pOutResult.m_CameraTM, m_ragdollHeadWorldTR);
59
60 //apply offset translation
61 pOutResult.m_CameraTM[3] = "0 0 0";
62
63 Math3D.MatrixMultiply4(charMat, m_ragdollHeadWorldTR, m_ragdollHeadWorldTR);
64 Math3D.MatrixToQuat(m_ragdollHeadWorldTR, m_ragdollHeadQuatWS);
65
66 m_fCurrentEaseOutRagdollSmoothTime = m_fEaseOutRagdollSmoothTime;
67 }
68 else if (m_fCurrentEaseOutRagdollSmoothTime > 0.0 && m_ragdollHeadWorldTR[0] != vector.Zero && m_ragdollHeadWorldTR[1] != vector.Zero && m_ragdollHeadWorldTR[2] != vector.Zero)
69 {
70 Math3D.AnglesToMatrix(lookAngles, pOutResult.m_CameraTM);
71
72 //calculate the lerp step
73 m_fCurrentEaseOutRagdollSmoothTime -= pDt;
74 float step = 1.0 - (m_fCurrentEaseOutRagdollSmoothTime / m_fEaseOutRagdollSmoothTime);
75 step = Math.Clamp(step, 0.0, 1.0);
76
77 //transform pOutResult.m_CameraTM to world space
78 vector cameraWorldTM[4];
79 Math3D.MatrixMultiply4(animationBoneWorldTM, pOutResult.m_CameraTM, cameraWorldTM);
80
81 //to quat, lerp, to TM
82 float targetQuatWS[4];
83 Math3D.MatrixToQuat(cameraWorldTM, targetQuatWS);
84 Math3D.QuatLerp(targetQuatWS, m_ragdollHeadQuatWS, targetQuatWS, step);
85 Math3D.QuatNorm(targetQuatWS);
86 Math3D.QuatToMatrix(targetQuatWS, pOutResult.m_CameraTM);
87 pOutResult.m_CameraTM[3] = cameraWorldTM[3];
88
89 //go back to bone space
90 vector invertedAnimationBoneWorldTM[4];
91 Math3D.MatrixGetInverse4(animationBoneWorldTM, invertedAnimationBoneWorldTM);
92 Math3D.MatrixMultiply4(invertedAnimationBoneWorldTM, pOutResult.m_CameraTM, pOutResult.m_CameraTM);
93
94 //apply offset translation
95 pOutResult.m_CameraTM[3] = m_OffsetLS;
96 }
97 else
98 {
99 Math3D.AnglesToMatrix(lookAngles, pOutResult.m_CameraTM);
100 pOutResult.m_CameraTM[3] = m_OffsetLS;
101 }
102
103 // Apply camera shake if there is shake to be applied
104 if (m_CharacterCameraHandler)
105 m_CharacterCameraHandler.AddShakeToToTransform(pOutResult.m_CameraTM, pOutResult.m_fFOV);
106 }
107
108 protected float m_fEaseOutRagdollSmoothTime = 0.5;
110 protected float m_ragdollHeadQuatWS[4] = {0, 0, 0, 1};
112};
override void OnUpdate()
EDirectBoneMode
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14