Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TeleportToCursorManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  protected static const float SETTLE_THRESHOLD = 0.01;
8 
9  [Attribute("")]
10  private string m_sActionTeleportToCursor;
11 
12  [Attribute("")]
13  private string m_sActionTeleportToPlayer;
14 
15  [Attribute("5", UIWidgets.Auto, "")]
16  private float m_fMinDistance;
17 
18  [Attribute("30", UIWidgets.Auto, "")]
19  private float m_fMaxDistance;
20 
21  [Attribute(desc: "How far from the target position is camera teleported before it plays settle-in animation.", defvalue: "5")]
22  private float m_fSettleInDistance;
23 
24  [Attribute(defvalue: "275", desc: "When further than this limit, teleport the camera instantly, otherwise start transition from its current position.")]
25  private float m_fTeleportDistance;
26 
27  [Attribute(defvalue: "0.12")]
28  private float m_fTransitionStrength;
29 
30  [Attribute("15", UIWidgets.Auto, "")]
31  private float m_fMinAngle;
32 
33  [Attribute("-30", UIWidgets.Slider, params: "-89 89 0.1")]
34  private float m_fDefaultAngle;
35 
36  [Attribute()]
37  private string m_sSoundEvent;
38 
39  private bool m_bIsSettling;
40  private bool m_bIsTeleportInit;
41  private bool m_bIsDefaultDistance;
42  private bool m_bIsDefaultAngle;
43  private bool m_bIsStartAtCurrentPos;
44  private bool m_bDisableInterruption;
45  private vector m_vInitPos;
46  private vector m_vTargetPos;
47  private vector m_vTargetRot;
48  private float m_fDistance;
49  private float m_fDistancePrev;
50 
51  //------------------------------------------------------------------------------------------------
61  bool TeleportCamera(vector position, bool forceDefaultDistance = false, bool forceDefaultAngle = false, bool forceStartAtCurrentPos = false, bool disableInterruption = false, float distance = -1, bool noSound = false)
62  {
63  if (position == vector.Zero)
64  return false;
65 
67 
69  m_bIsTeleportInit = true;
70  m_bIsDefaultDistance = forceDefaultDistance;
71  m_bIsDefaultAngle = forceDefaultAngle;
72  m_bIsStartAtCurrentPos = forceStartAtCurrentPos;
73  m_bDisableInterruption = disableInterruption;
74  if (distance < 0)
75  distance = m_fMaxDistance;
76 
78 
79  //--- Force default angle when the target position is off-screen
80  ArmaReforgerScripted game = GetGame();
81  if (game && !m_bIsDefaultAngle)
82  {
83  WorkspaceWidget workspace = game.GetWorkspace();
84  if (workspace)
85  {
86  vector screenPos = workspace.ProjWorldToScreen(m_vTargetPos, game.GetWorld());
87  float screenW, screenH;
88  workspace.GetScreenSize(screenW, screenH);
89  screenW = workspace.DPIUnscale(screenW);
90  screenH = workspace.DPIUnscale(screenH);
91  if (screenPos[0] < 0 || screenPos[1] < 0 || screenPos[0] > screenW || screenPos[1] > screenH)
92  {
93  m_bIsDefaultAngle = true;
94  }
95  }
96  }
97 
98  if (!noSound && !m_sSoundEvent.IsEmpty())
99  SCR_UISoundEntity.SoundEvent(m_sSoundEvent);
100 
101  return true;
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  override void EOnCameraFrame(SCR_ManualCameraParam param)
106  {
107  if (param.isManualInputEnabled)
108  {
109  if (m_sActionTeleportToCursor && GetInputManager().GetActionValue(m_sActionTeleportToCursor))
110  {
111  //--- Teleport under cursor
112  vector pos;
113  if (!param.GetCursorWorldPos(pos))
114  return;
115 
116  if (!TeleportCamera(pos))
117  return;
118  }
119  if (m_sActionTeleportToPlayer && GetInputManager().GetActionValue(m_sActionTeleportToPlayer))
120  {
121  //--- Teleport to player (or on initial camera position if player is not present)
122  vector pos = m_vInitPos;
123  IEntity player = SCR_PlayerController.GetLocalMainEntity();
124  if (player)
125  pos = player.GetOrigin();
126 
127  if (!TeleportCamera(pos, false, true))
128  return;
129  }
130  }
131 
132  //--- Start teleporting
133  if (m_bIsTeleportInit)
134  {
135  //--- Calculate target rotation
136  vector angles = param.transform[2].VectorToAngles().MapAngles();
137  if (m_bIsDefaultAngle)
138  {
139  angles[1] = m_fDefaultAngle;
140  }
141  else if (angles[1] > -m_fMinAngle)
142  {
143  angles[1] = -m_fMinAngle; //--- Never look up
144  }
145  m_vTargetRot = angles.AnglesToVector();
146 
147  //--- Calculate target position. Don't make it further away than current distance from camera.
148  float dis = m_fDistance;
149  if (!m_bIsDefaultDistance)
150  {
151  dis = Math.Min(dis, vector.Distance(m_vTargetPos, param.transform[3]));
152 
153  //--- When closer than limit, factor in camera height as well
154  if (dis < m_fDistance)
155  {
156  vector pos = param.transform[3];
157  float height = pos[1] - param.world.GetSurfaceY(pos[0], pos[2]);
158  dis = Math.Min(dis, height);
159  }
160  dis = Math.Max(dis, m_fMinDistance);
161  }
162  m_vTargetPos = m_vTargetPos - m_vTargetRot * dis;
163  param.isManualInput = false; //--- Cancel manual input, it prevents inertia from catapulting camera far away
164 
165  //--- When further than given limit, teleport the camera nearby, otherwise start transition from the current position.
166  if (!m_bIsStartAtCurrentPos && vector.Distance(m_vTargetPos, param.transform[3]) > m_fTeleportDistance)
167  {
168  //--- Modify original values, because normal ones get overridden later (see MatrixCopy)
169  param.transformOriginal[2] = m_vTargetRot;
170  vector dirTo = (m_vTargetPos - param.transformOriginal[3]).Normalized();
171  param.transformOriginal[3] = m_vTargetPos - dirTo * m_fSettleInDistance;
172  }
173 
174  m_bIsSettling = true;
175  m_bIsTeleportInit = false;
176  }
177 
178  if (param.isManualInput && !m_bDisableInterruption)
179  {
180  //--- Some other system moved the camera, terminate
181  m_bIsSettling = false;
182  }
183  else if (m_bIsSettling)
184  {
185  //--- Erase previous changes (e.g., inertia)
186  Math3D.MatrixCopy(param.transformOriginal, param.transform);
187 
188  //--- Settled at target position or cannot move further for some reason, terminate
189  float dis = vector.Distance(param.transform[3], m_vTargetPos);
190  if (vector.Distance(param.transform[3], m_vTargetPos) < SETTLE_THRESHOLD || Math.AbsFloat(dis - m_fDistancePrev) < SETTLE_THRESHOLD)
191  {
192  m_bIsSettling = false;
193  return;
194  }
195  m_fDistancePrev = dis;
196 
197  //--- Play transition animation
198  float progress = Math.Min(param.timeSlice / m_fTransitionStrength, 1);
199  param.transform[2] = vector.Lerp(param.transform[2], m_vTargetRot, progress);
200  param.transform[3] = vector.Lerp(param.transform[3], m_vTargetPos, progress);
201  param.rotDelta = vector.Zero;
202  param.isDirty = true;
203  }
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  override bool EOnCameraInit()
208  {
209  m_vInitPos = GetCameraEntity().GetOrigin();
210  return true;
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  override void EOnCameraParentChange(bool attached, IEntity parent)
215  {
216  if (attached)
217  m_vTargetPos = parent.CoordToLocal(m_vTargetPos);
218  else
219  m_vTargetPos = parent.CoordToParent(m_vTargetPos);
220  }
221 }
m_fDistance
float m_fDistance
Definition: SCR_AIGroupTargetCluster.c:38
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
CoordToCamera
protected vector CoordToCamera(vector pos)
Definition: SCR_BaseManualCameraComponent.c:71
Attribute
typedef Attribute
Post-process effect of scripted camera.
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
GetCameraEntity
protected SCR_ManualCamera GetCameraEntity()
Definition: SCR_BaseManualCameraComponent.c:59
SCR_ManualCameraParam
Parameter for carrying information between individual camera components.
Definition: SCR_ManualCameraParam.c:5
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_TeleportToCursorManualCameraComponent
Teleport the camera to the cursor's world position.
Definition: SCR_TeleportToCursorManualCameraComponent.c:5
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
m_vTargetPos
vector m_vTargetPos
Definition: SCR_AICombatMoveRequest.c:77
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468