Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CharacterCamera3rdPersonBase.c
Go to the documentation of this file.
1 // *************************************************************************************
2 // ! CharacterCamera3rdPersonBase - base 3rd person camera
3 // *************************************************************************************
5 {
6  //-----------------------------------------------------------------------------
7  static const float CONST_UD_MIN = -89.0;
8  static const float CONST_UD_MAX = 89.0;
9 
10  static const float CONST_LR_MIN = -160.0;
11  static const float CONST_LR_MAX = 160.0;
12 
13  //-----------------------------------------------------------------------------
14  void CharacterCamera3rdPersonBase(CameraHandlerComponent pCameraHandler)
15  {
16  m_fFOVFilterVel = 0;
17  }
18 
19  //-----------------------------------------------------------------------------
20  override void OnActivate(ScriptedCameraItem pPrevCamera, ScriptedCameraItemResult pPrevCameraResult)
21  {
22  super.OnActivate(pPrevCamera, pPrevCameraResult);
23  if (pPrevCamera)
24  {
25  // Use last shoulder state
26  m_fShoulderLRPrefered = GetShoulderLastActive();
27  }
28  m_fFOVFilter = pPrevCameraResult.m_fFOV;
29  }
30 
31  //-----------------------------------------------------------------------------
32  override void OnUpdate(float pDt, out ScriptedCameraItemResult pOutResult)
33  {
34  pOutResult.m_vBaseAngles = GetBaseAngles();
35 
37  m_fFOV = GetBaseFOV();
38 
40  vector lookAngles = m_CharacterHeadAimingComponent.GetLookAngles();
41 
42  if (!m_bIgnoreCharacterPitch)
43  lookAngles[1] = lookAngles[1] + m_OwnerCharacter.GetLocalYawPitchRoll()[1];
44 
46  Math3D.AnglesToMatrix(lookAngles, pOutResult.m_CameraTM);
47 
49  if (m_iBoneIndex != -1)
50  {
51  vector boneMatrix[4];
52  m_OwnerCharacter.GetAnimation().GetBoneMatrix(m_iBoneIndex, boneMatrix);
53  pOutResult.m_CameraTM[3] = boneMatrix[3];
54  }
55  else
56  {
57  pOutResult.m_CameraTM[3] = "0 0 0";
58  }
59 
61  float leaning = m_ControllerComponent.GetLeaning();
62  if( leaning < -0.1 )
63  m_fShoulderLRPrefered = -1;
64  else if( leaning > 0.1 )
65  m_fShoulderLRPrefered = 1;
66 
67  m_fShoulderLROffset = Math.SmoothCD(m_fShoulderLROffset, m_fShoulderLRPrefered, m_fCameraLRShoulderVel, 0.14, 1000, pDt);
68 
69  m_fLeaningOffset = m_ControllerComponent.GetCurrentLeanAmount();
70  float shoulderDist = GetShoulderDistance();
71 
73  vector msOffset = m_CameraOffsetMS;
74  vector lsOffset = m_CameraOffsetLS;
75  if (m_bShoulderInLS)
76  {
77  lsOffset[0] = lsOffset[0] + shoulderDist;
78  }
79  else
80  {
81  msOffset[0] = msOffset[0] + shoulderDist;
82  }
83 
84  // character matrix
85  vector charMat[4];
86  m_OwnerCharacter.GetTransform(charMat);
87 
89  vector velocity = m_ControllerComponent.GetVelocity();
90  velocity = velocity.InvMultiply3(charMat);
91  for (int i = 0; i < 3; i++)
92  {
93  velocity[i] = Math.Clamp(velocity[i], -m_vMaxVelocity[i], m_vMaxVelocity[i]);
94  }
95  m_v3rd_VelocityAdd += (velocity - m_v3rd_VelocityAdd) * pDt * 2;
96 
97  msOffset = msOffset + m_v3rd_VelocityAdd * -0.05;
98  // ls offset + ms offset + shoulder width
99  pOutResult.m_CameraTM[3] = pOutResult.m_CameraTM[3] + pOutResult.m_CameraTM[0] * lsOffset[0] + pOutResult.m_CameraTM[1] * lsOffset[1] + pOutResult.m_CameraTM[2] * lsOffset[2] + msOffset;
100 
101  float currY = pOutResult.m_CameraTM[3][1];
102  if (m_fYoffsetPrevFrame == 0)
103  {
104  m_fYoffsetPrevFrame = currY;
105  }
106  m_fYoffsetPrevFrame = Math.Lerp(m_fYoffsetPrevFrame, currY, 0.01);
107  float yDelta = 1;
108  if (m_fYoffsetPrevFrame != 0)
109  {
110  yDelta = Math.Pow(currY/m_fYoffsetPrevFrame, 2); // easing
111  }
112 
113  pOutResult.m_CameraTM[3][1] = m_fYoffsetPrevFrame * yDelta;
114 
115  m_fBobScale = m_CharacterCameraHandler.AddViewBobToTransform(pOutResult.m_CameraTM, 1, true);
116 
118  pOutResult.m_fDistance = m_fDistance;
119  pOutResult.m_iDirectBoneMode = EDirectBoneMode.None;
120  pOutResult.m_fUseHeading = 1.0;
121  pOutResult.m_fShoulderDist = m_fShoulderLROffset;
122  pOutResult.m_fNearPlane = 0.04;
123  pOutResult.m_fPositionModelSpace = 1.0;
124  pOutResult.m_pWSAttachmentReference = null;
125  pOutResult.m_pOwner = m_OwnerCharacter;
126 
127  m_fFOVFilter = Math.SmoothCD(m_fFOVFilter, pOutResult.m_fFOV, m_fFOVFilterVel, 0.2, 1000, pDt);
128  pOutResult.m_fFOV = m_fFOVFilter;
129  }
130 
131  //-----------------------------------------------------------------------------
132  override float GetBaseFOV()
133  {
134  CameraManager cameraManager = GetGame().GetCameraManager();
135  if (!cameraManager)
136  return 0;
137 
138  return cameraManager.GetThirdPersonFOV();
139  }
140 
141  //-----------------------------------------------------------------------------
144  int GetActiveShoulder()
145  {
146  return m_fShoulderLRPrefered;
147  }
148 
149  //-----------------------------------------------------------------------------
150  override float GetShoulderDistance()
151  {
152  return m_fShoulderLROffset * m_fShoulderWidth + m_fLeanDistance * m_fLeaningOffset;
153  }
154  //-----------------------------------------------------------------------------
156  protected int m_iBoneIndex = -1;
157  protected vector m_CameraOffsetMS;
158  protected vector m_CameraOffsetLS;
159  protected float m_fDistance;
160  protected float m_fShoulderWidth;
161  protected bool m_bShoulderInLS;
162  protected float m_fLeanDistance;
163  protected vector m_vMaxVelocity = "2 2 2";
164 
165  protected float m_fBobScale;
166 
167  protected int m_fShoulderLRPrefered = 1;
168  protected float m_fShoulderLROffset;
169  protected float m_fLeaningOffset;
170  protected float m_fCameraLRShoulderVel;
171  protected float m_fLeaningOffsetVel;
172  protected vector m_v3rd_VelocityAdd = vector.Zero;
173  protected float m_fYoffsetPrevFrame = 0.0;
174 };
m_fDistance
float m_fDistance
Definition: SCR_AIGroupTargetCluster.c:38
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnActivate
override void OnActivate()
Definition: SCR_CharacterCommandLoiter.c:23
CharacterCameraBase
Definition: CharacterCameraADS.c:4
CharacterCamera3rdPersonBase
Definition: CharacterCamera3rdPersonCrouch.c:4
m_OwnerCharacter
private SCR_ChimeraCharacter m_OwnerCharacter
Definition: CharacterCameraHandlerComponent.c:984
m_ControllerComponent
private SCR_CharacterControllerComponent m_ControllerComponent
Definition: CharacterCameraHandlerComponent.c:985