Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_2DOpticsComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Weapon/Sights", description: "", color: "0 0 255 255")]
3 {
4 }
5 
6 void OnSightsADSChanged(bool inADS, float fov);
8 
9 //------------------------------------------------------------------------------------------------
12 class SCR_2DOpticsComponent : ScriptedSightsComponent
13 {
14  // Action names
15  const string ACTION_WHEEL = "WeaponChangeMagnification";
16  const string ACTION_ILLUMINATION = "WeaponToggleSightsIllumination";
17 
18  const float REFERENCE_FOV = 38;
19  const float OPACITY_INITIAL = 0.75;
20 
21  const float NEAR_PLANE_DEFAULT = 0.05;
22  const float NEAR_PLANE_ZOOMED = 0.05;
23 
24  // Optics setup
25  [Attribute("", UIWidgets.ResourcePickerThumbnail, "Layout used for 2D sights HUD\n[OBSOLETE]", params: "layout", category: "Resources")]
26  protected ResourceName m_sLayoutResource;
27 
28  [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of reticle\n", params: "edds imageset", category: "Resources")]
29  protected ResourceName m_sReticleTexture;
30 
31  [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of reticle under glow\n", params: "edds imageset", category: "Resources")]
32  protected ResourceName m_sReticleGlowTexture;
33 
34  [Attribute("0", category: "Resources")]
35  protected bool m_bHasIllumination;
36 
37  [Attribute("0 0 0 1", UIWidgets.ColorPicker, category: "Resources")]
38  protected ref Color m_ReticleColor;
39 
40  [Attribute("1 1 1 1", UIWidgets.ColorPicker, category: "Resources")]
41  protected ref Color m_ReticleOutlineColor;
42 
43  [Attribute("1 0 0 1", UIWidgets.ColorPicker, category: "Resources")]
44  protected ref Color m_cReticleTextureIllumination;
45 
46  [Attribute("0.05", UIWidgets.Slider, desc: "Reticle glow texture alpha\n[ % ]", params: "0 1 0.001", category: "Resources", precision: 3)]
47  protected float m_fReticleTextureGlowAlpha;
48 
49  [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of lens filter\n", params: "edds imageset", category: "Resources")]
50  protected ResourceName m_sFilterTexture;
51 
52  [Attribute("10", UIWidgets.EditBox, desc: "Optic magnification\n[ x ]", params: "0.1 200 0.001", category: "Sights", precision: 3)]
53  protected float m_fMagnification;
54 
55  [Attribute("0", UIWidgets.Slider, "Angular size of reticle\n[ ° ]", params: "0 60 0.001", category: "Sights", precision: 3)]
56  protected float m_fReticleAngularSize;
57 
58  [Attribute("1", UIWidgets.Slider, "Portion of reticle with specified angular size\n[ % ]", params: "0 10 0.00001", category: "Sights", precision: 5)]
59  protected float m_fReticlePortion;
60 
61  [Attribute("0", UIWidgets.Slider, "POSITIVE:\n Rear focal plane - magnification at which reticle markings are valid\n\nZERO:\n Front focal plane reticle scaling with magnification.\n\nNEGATIVE:\n Enforced base FOV in degrees\n", params: "-60 200 0.001", category: "Sights", precision: 5)]
62  protected float m_fReticleBaseZoom;
63 
64  [Attribute("0", UIWidgets.CheckBox, "Check if the optic is attached to a turret\n", category: "Sights")]
65  protected bool m_bIsTurretOptic;
66 
67  [Attribute("10", UIWidgets.EditBox, desc: "Field of view of the objective\n[ ° ]", params: "0.001 60 0.001", category: "2DSights", precision: 3)]
68  protected float m_fObjectiveFov;
69 
70  [Attribute("1", UIWidgets.EditBox, desc: "Ocular texture scale\n", params: "0.001 10 0.001", category: "2DSights", precision: 3)]
71  protected float m_fObjectiveScale;
72 
73  [Attribute("1.1", UIWidgets.EditBox, desc: "Vignette texture scale\n", params: "0.001 10 0.001", category: "2DSights", precision: 3)]
74  protected float m_fVignetteScale;
75 
76  [Attribute("1", UIWidgets.CheckBox, "Should hide parent object when using 2D sights\n", category: "2DSights")]
77  protected bool m_bShouldHideParentObject;
78 
79  [Attribute("0", UIWidgets.CheckBox, "Should hide parent character when using 2D sights\n", category: "2DSights")]
80  protected bool m_bShouldHideParentCharacter;
81 
82  // Animation attributes
83  [Attribute("0", UIWidgets.Slider, "Time before entering animation starts", params: "0 2000 1", category: "Animations")]
84  protected int m_iAnimationActivationDelay;
85 
86  [Attribute("0", UIWidgets.Slider, "Animation time for canceling optic.", params: "0 2000 1", category: "Animations")]
87  protected int m_iAnimationDeactivationDelay;
88 
89  [Attribute("0", UIWidgets.Slider, "Animation time for optic animation", params: "0 5 0.01", category: "Animations")]
90  protected float m_fAnimationEnterTime;
91 
92  [Attribute("2", UIWidgets.Slider, "Speed of blur fade out on optic entering", params: "0.01 5 0.01", category: "Animations")]
93  protected float m_fAnimationSpeedBlur;
94 
95  // Effect attributes
96  [Attribute("0", UIWidgets.EditBox, desc: "Optic misalignment damping speed - intended for binoculars, the higher, the faster the misalignment gets zeroed", params: "0 60 0.1", category: "Effects")]
97  protected float m_fMisalignmentDampingSpeed;
98 
99  [Attribute("0.1", UIWidgets.EditBox, desc: "Rotation effect scaling", params: "-100 100 0.01", category: "Effects")]
100  protected float m_fRotationScale;
101 
102  [Attribute("4", UIWidgets.EditBox, desc: "Rotation damping speed - the higher, the faster the rotation speed gets zeroed", params: "0 60 0.1", category: "Effects")]
103  protected float m_fRotationDampingSpeed;
104 
105  [Attribute("0.01", UIWidgets.EditBox, desc: "Movement effect scaling", params: "-100 100 0.01", category: "Effects")]
106  protected float m_fMovementScale;
107 
108  [Attribute("2", UIWidgets.EditBox, desc: "Movement damping speed - the higher, the faster the movement speed gets zeroed", params: "0 60 0.1", category: "Effects")]
109  protected float m_fMovementDampingSpeed;
110 
111  [Attribute("1", UIWidgets.EditBox, desc: "Roll effect scaling", params: "-100 100 0.01", category: "Effects")]
112  protected float m_fRollScale;
113 
114  [Attribute("0", UIWidgets.EditBox, desc: "Roll damping speed - the higher, the faster the optic gets uprighted", params: "0 60 0.1", category: "Effects")]
115  protected float m_fRollDampingSpeed;
116 
117  [Attribute("1", UIWidgets.EditBox, desc: "Optic misalignment scale - for turrets and binoculars", params: "-60 60 0.1", category: "Effects")]
118  protected float m_fMisalignmentScale;
119 
120  [Attribute("1", UIWidgets.EditBox, desc: "Vignette adjustment speed - the faster, the less inertia there is", params: "0 60 0.1", category: "Effects")]
121  protected float m_fVignetteMoveSpeed;
122 
123  [Attribute("1", UIWidgets.EditBox, desc: "Motion blur effect scaling", params: "0 100", category: "Effects")]
124  protected float m_fMotionBlurScale;
125 
126  [Attribute("0.1", UIWidgets.EditBox, desc: "Max level of motion blur intensity", params: "0 1 0.01", category: "Effects")]
127  protected float m_fMotionBlurMax;
128 
129  // 0 = immediately when entering ADS camera, 1.0 = only after full blend
130  [Attribute("1", UIWidgets.Slider, "Percentage of camera transition at which sights activate.", params: "0.0 1.0 0.01", category: "Sights")]
131  protected float m_fADSActivationPercentage;
132 
133  // 0 = immediately when leaving ADS camera, 1.0 = only after full blend
134  [Attribute("0", UIWidgets.Slider, "Percentage of camera transition at which sights deactivate.", params: "0.0 1.0 0.01", category: "Sights")]
135  protected float m_fADSDeactivationPercentage;
136 
137  [Attribute("0", UIWidgets.ComboBox, "Type of zeroing for this sights.", "", ParamEnumArray.FromEnum(SCR_EPIPZeroingType), category: "Sights")]
138  protected SCR_EPIPZeroingType m_eZeroingType;
139 
140  [Attribute("0", UIWidgets.Slider, "Reticle Offset of scope center in X", params: "-1 1 0.0001", precision: 5, category: "Sights")]
141  protected float m_fReticleOffsetX;
142 
143  [Attribute("0", UIWidgets.Slider, "Reticle Offset of scope center in Y", params: "-1 1 0.0001", precision: 5, category: "Sights")]
144  protected float m_fReticleOffsetY;
145 
146  [Attribute("25", UIWidgets.Slider, "Interpolation speed for zeroing interpolation", params: "1 100.0 0.1", category: "Sights")]
147  protected float m_fReticleOffsetInterpSpeed;
148 
149  [Attribute("0 0 0", UIWidgets.EditBox, "Camera offset when looking through scope", category: "Sights", params: "inf inf 0 purpose=coords space=entity coordsVar=m_vCameraPoint")]
150  protected vector m_vCameraOffset;
151 
152  [Attribute("0 0 0", UIWidgets.EditBox, "Camera angles when looking through scope", category: "Sights", params: "inf inf 0 purpose=angles space=entity anglesVar=m_vCameraAngles")]
153  protected vector m_vCameraAngles;
154 
155  [Attribute("1 1 1", UIWidgets.EditBox, "Camera misalignment scale for 2D optics", category: "Sights")]
156  protected vector m_vCameraMisalignmentScale;
157 
158  protected float m_fCurrentReticleOffsetY;
159  protected float m_fCurrentCameraPitch;
160 
161  //------------------------------------------------------------------------------------------------
162  override float GetADSActivationPercentageScript()
163  {
164  return m_fADSActivationPercentage;
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  override float GetADSDeactivationPercentageScript()
169  {
170  return m_fADSDeactivationPercentage;
171  }
172 
173  //------------------------------------------------------------------------------------------------
174  // Getters for attributes
175  float GetReticleOffsetX()
176  {
177  return m_fReticleOffsetX;
178  }
179 
180  void GetReticleTextures(out ResourceName reticleTexture, out ResourceName reticleTextureGlow, out ResourceName filterTexture)
181  {
182  reticleTexture = m_sReticleTexture;
183  reticleTextureGlow = m_sReticleGlowTexture;
184  filterTexture = m_sFilterTexture;
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  void GetReticleData(out float reticleAngularSize, out float reticlePortion, out float reticleBaseZoom)
189  {
190  reticleAngularSize = m_fReticleAngularSize;
191  reticlePortion = m_fReticlePortion;
192  reticleBaseZoom = m_fReticleBaseZoom;
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  float GetObjectiveFov()
197  {
198  return m_fObjectiveFov;
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  float GetObjectiveScale()
203  {
204  return m_fObjectiveScale;
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  float GetVignetteScale()
209  {
210  return m_fVignetteScale;
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  float GetMisalignmentDampingSpeed()
215  {
216  return m_fMisalignmentDampingSpeed;
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  float GetRotationScale()
221  {
222  return m_fRotationScale;
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  float GetRotationDampingSpeed()
227  {
228  return m_fRotationDampingSpeed;
229  }
230 
231  //------------------------------------------------------------------------------------------------
232  float GetMovementScale()
233  {
234  return m_fMovementScale;
235  }
236 
237  //------------------------------------------------------------------------------------------------
238  float GetMovementDampingSpeed()
239  {
240  return m_fMovementDampingSpeed;
241  }
242 
243  //------------------------------------------------------------------------------------------------
244  float GetRollScale()
245  {
246  return m_fRollScale;
247  }
248 
249  //------------------------------------------------------------------------------------------------
250  float GetRollDampingSpeed()
251  {
252  return m_fRollDampingSpeed;
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  float GetMisalignmentScale()
257  {
258  return m_fMisalignmentScale;
259  }
260 
261  //------------------------------------------------------------------------------------------------
262  float GetVignetteMoveSpeed()
263  {
264  return m_fVignetteMoveSpeed;
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  float GetMotionBlurScale()
269  {
270  return m_fMotionBlurScale;
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  float GetMotionBlurMax()
275  {
276  return m_fMotionBlurMax;
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  // Needed for zeroing
281  SCR_EPIPZeroingType GetZeroType()
282  {
283  return m_eZeroingType;
284  }
285 
286  //------------------------------------------------------------------------------------------------
287  float GetMagnification()
288  {
289  return m_fMagnification;
290  }
291 
292  //------------------------------------------------------------------------------------------------
293  bool GetIsOpticsHidden()
294  {
295  return m_bIsOpticsHidden;
296  }
297 
298  //------------------------------------------------------------------------------------------------
299  bool GetIsZoomed()
300  {
301  return m_bZoomed;
302  }
303 
304  protected ref array<float> m_aReticleSizes = {};
305  protected int m_iSelectedZoomLevel = 0;
306 
307  // Overall movement
308  protected float m_fScratchesRoll;
309 
310  // FOVs
311  protected float m_fFovZoomed;
312  protected float m_fDefaultSize;
313  protected float m_fCurrentReticleSize;
314  protected float m_fNearPlaneCurrent;
315 
316  // Movement check
317  protected bool m_bIsMoving;
318  protected bool m_bIsRotating;
319  protected bool m_bZoomed = false;
320  protected bool m_bWasEntityHidden = false;
321  protected int m_iHeadBoneId = -1;
322 
323  protected bool m_bIsOpticsHidden;
324  protected bool m_bIsIlluminationOn;
325 
326  // Owner and character references
327  protected ChimeraCharacter m_ParentCharacter = null;
328 
329  static ref ScriptInvokerBase<OnSightsADSChanged> s_OnSightsADSChanged = new ScriptInvokerBase<OnSightsADSChanged>();
330  static ref ScriptInvokerBase<On2DOpticsADSChange> s_On2DOpticADSChanged = new ScriptInvokerBase<On2DOpticsADSChange>();
331  protected ref ScriptInvokerVoid s_OnSetupOpticImage = new ScriptInvokerVoid();
332  protected ref ScriptInvokerBase<On2DOpticsIlluminationChange> s_OnIlluminationChange = new ScriptInvokerBase<On2DOpticsIlluminationChange>();
333 
334  //------------------------------------------------------------------------------------------------
335  ScriptInvokerVoid OnSetupOpticImage()
336  {
337  return s_OnSetupOpticImage;
338  }
339 
340  //------------------------------------------------------------------------------------------------
341  ScriptInvokerBase<On2DOpticsIlluminationChange> OnIlluminationChange()
342  {
343  return s_OnIlluminationChange;
344  }
345 
346  //------------------------------------------------------------------------------------------------
348  float GetFovZoomed()
349  {
350  // m_fMagnification value may change during gameplay
351  // But player camera may not exist at the moment, so at first we store magnification to compute it from and then compute it on first use
352  if (m_fFovZoomed < 0)
353  m_fFovZoomed = CalculateZoomFOV(-m_fFovZoomed);
354 
355  return m_fFovZoomed;
356  }
357 
358  //------------------------------------------------------------------------------------------------
360  void SetFovZoomed(float value)
361  {
362  m_fFovZoomed = value;
363  }
364 
365  //------------------------------------------------------------------------------------------------
366  float GetNearPlane()
367  {
368  return m_fNearPlaneCurrent;
369  }
370 
371  //------------------------------------------------------------------------------------------------
372  int GetAnimationActivationDelay()
373  {
374  return m_iAnimationActivationDelay;
375  }
376 
377  //------------------------------------------------------------------------------------------------
378  int GetAnimationDeactivationDelay()
379  {
380  return m_iAnimationDeactivationDelay;
381  }
382 
383  //------------------------------------------------------------------------------------------------
384  float GetAnimationEnterTime()
385  {
386  return m_fAnimationEnterTime;
387  }
388 
389  //------------------------------------------------------------------------------------------------
390  float GetAnimationSpeedBlur()
391  {
392  return m_fAnimationSpeedBlur;
393  }
394 
395  //------------------------------------------------------------------------------------------------
396  bool GetIsMoving()
397  {
398  return m_bIsMoving;
399  }
400 
401  //------------------------------------------------------------------------------------------------
402  bool GetIsRotating()
403  {
404  return m_bIsRotating;
405  }
406 
407  //------------------------------------------------------------------------------------------------
408  float GetScratchesRoll()
409  {
410  return m_fScratchesRoll;
411  }
412 
413  //------------------------------------------------------------------------------------------------
418  override void OnInit(IEntity owner)
419  {
420  m_fScratchesRoll = Math.RandomFloat(0, 360);
421 
422  // m_fMagnification value may change during gameplay
423  // But player camera may not exist at the moment, so at first we store magnification to compute it from and then compute it on first use
424  m_fFovZoomed = -m_fMagnification;
425  }
426 
427  //------------------------------------------------------------------------------------------------
428  override void OnSightADSActivated()
429  {
430  m_ParentCharacter = ChimeraCharacter.Cast(GetOwner().GetParent());
431 
432  super.OnSightADSActivated();
433 
434  s_On2DOpticADSChanged.Invoke(this, true);
435  s_OnSightsADSChanged.Invoke(true, GetFovZoomed());
436 
437  // Play cover fade in animaiton
438  m_fNearPlaneCurrent = NEAR_PLANE_DEFAULT;
439  GetGame().GetCallqueue().CallLater(HideObjects, m_iAnimationActivationDelay, false);
440 
441  m_bZoomed = true;
442 
443  m_bIsOpticsHidden = false;
444 
445  // Setup illumination
446  EnableReticleIllumination(m_bIsIlluminationOn);
447  }
448 
449  //------------------------------------------------------------------------------------------------
450  override void OnSightADSDeactivated()
451  {
452  super.OnSightADSDeactivated();
453  s_On2DOpticADSChanged.Invoke(this, false);
454  s_OnSightsADSChanged.Invoke(false, 0);
455 
456  // Initialize to current zero value
457  m_fCurrentReticleOffsetY = GetReticleOffsetYTarget();
458 
459  if (m_bWasEntityHidden)
460  {
461  IEntity owner = GetOwner();
462  if (owner)
463  owner.SetFlags(EntityFlags.VISIBLE, false);
464 
465  if (m_ParentCharacter)
466  m_ParentCharacter.SetFlags(EntityFlags.VISIBLE, false);
467 
468  m_bWasEntityHidden = false;
469  }
470 
471  GetGame().GetCallqueue().Remove(HideObjects); // in case this is called quickly after OnSightADSActivated, HideObjects needs to be cleared to prevent conflict
472 
473  // Leaving animation
474  m_fNearPlaneCurrent = NEAR_PLANE_DEFAULT;
475 
476  m_bZoomed = false;
477  m_bIsOpticsHidden = true;
478 
479  // Clean up reticle illumination
480  EnableReticleIllumination(false);
481  }
482 
483  //------------------------------------------------------------------------------------------------
484  protected override void OnSightADSPostFrame(IEntity owner, float timeSlice)
485  {
486  float interp = Math.Min(1, timeSlice * m_fReticleOffsetInterpSpeed);
487  // Interpolate zeroing values
488  float reticleTarget = GetReticleOffsetYTarget();
489  m_fCurrentReticleOffsetY = Math.Lerp(m_fCurrentReticleOffsetY, reticleTarget, interp);
490  float pitchTarget = GetCameraPitchTarget();
491  m_fCurrentCameraPitch = Math.Lerp(m_fCurrentCameraPitch, pitchTarget, interp);
492  }
493 
494  //------------------------------------------------------------------------------------------------
496  protected void HideObjects()
497  {
498  // Near plane
499  m_fNearPlaneCurrent = NEAR_PLANE_ZOOMED;
500 
501  // Hide rendering
502  if (m_bShouldHideParentObject)
503  {
504  IEntity owner = GetOwner();
505  if (owner)
506  owner.ClearFlags(EntityFlags.VISIBLE, false);
507 
508  // Set flag as otherwise we can make visible something that we didn't make invisible
509  m_bWasEntityHidden = true;
510  }
511 
512  // Hide parent character
513  if (m_bShouldHideParentCharacter)
514  {
515  if (m_ParentCharacter)
516  m_ParentCharacter.ClearFlags(EntityFlags.VISIBLE, false);
517 
518  // Set flag as otherwise we can make visible something that we didn't make invisible
519  m_bWasEntityHidden = true;
520  }
521  }
522 
523  //------------------------------------------------------------------------------------------------
525  static float CalculateZoomFOV(float magnification)
526  {
527  CameraManager cameraManager = GetGame().GetCameraManager();
528  if (!cameraManager)
529  return 74;
530 
531  float referenceFOV;
532  PlayerCamera camera = PlayerCamera.Cast(cameraManager.CurrentCamera());
533  if (camera)
534  referenceFOV = camera.GetFocusFOV();
535  else
536  referenceFOV = cameraManager.GetFirstPersonFOV();
537 
538  float referenceTan = Math.Tan(Math.DEG2RAD * (referenceFOV * 0.5));
539  return Math.RAD2DEG * 2 * Math.Atan2(referenceTan, magnification);
540  }
541 
542  //------------------------------------------------------------------------------------------------
544  bool IsMoveCloseToLimit(vector move, float limitMin)
545  {
546  float x = move[0];
547  float y = move[1];
548 
549  return (float.AlmostEqual(x, 0, limitMin) && float.AlmostEqual(y, 0, limitMin));
550  }
551 
552  //------------------------------------------------------------------------------------------------
556 
557  vector GetMisalignmentAngles(notnull CameraBase camera)
558  {
559 
560  // Get camera parent to sight matrix
561  vector parentToSightMat[4];
562  GetParentToLocalTransform(parentToSightMat, camera.GetParent());
563 
564  // Camera in parent space
565  vector cameraMat[4];
566  camera.GetLocalTransform(cameraMat);
567 
568  // Sight camera angles offset
569  vector sightMat[3];
570  vector sightAngles = {-m_vCameraAngles[1], - m_vCameraAngles[0] - m_fCurrentCameraPitch, 0};
571  Math3D.AnglesToMatrix(sightAngles, sightMat);
572 
573  // Sight camera angles mat in parent space
574  Math3D.MatrixMultiply3(sightMat, parentToSightMat, sightMat);
575 
576  // Sight and camera in parent space
577  Math3D.MatrixMultiply3(sightMat, cameraMat, sightMat);
578 
579  // Sight transform which is important for turrets
580  vector turretMat[3];
581  GetSightsTransform(turretMat, true);
582  Math3D.MatrixInvMultiply3(sightMat, turretMat, sightMat);
583 
584  // Sight angles as seen by camera
585  vector angles = Math3D.MatrixToAngles(sightMat);
586 
587  // Account for additional optic camera roll
588  angles[2] = angles[2] + m_vCameraAngles[2];
589 
590  // Scale misalignment for off-axis scopes
591  angles[0] = angles[0] * m_vCameraMisalignmentScale[0];
592  angles[1] = angles[1] * m_vCameraMisalignmentScale[1];
593  angles[2] = angles[2] * m_vCameraMisalignmentScale[2];
594 
595  // Misalignment should not exceed 180 degrees
596  angles[0] = fixAngle_180_180(angles[0]);
597  angles[1] = fixAngle_180_180(angles[1]);
598 
599  return angles;
600  }
601 
602  //------------------------------------------------------------------------------------------------
603  vector GetRotation(out vector previousDir, float timeSlice)
604  {
605  if (timeSlice <= 0)
606  return vector.Zero;
607 
608  CameraManager cameraManager = GetGame().GetCameraManager();
609  if (!cameraManager)
610  return vector.Zero;
611 
612  CameraBase camera = cameraManager.CurrentCamera();
613  if (!camera)
614  return vector.Zero;
615 
616  vector currentDir = camera.GetWorldTransformAxis(2);
617 
618  bool rotated = !float.AlmostEqual(previousDir[0], currentDir[0]);
619  rotated |= !float.AlmostEqual(previousDir[1], currentDir[1]);
620 
621  if (rotated)
622  {
623  m_bIsRotating = true;
624  vector rotation = (currentDir - previousDir) / timeSlice;
625  previousDir = currentDir;
626  return camera.VectorToLocal(rotation);
627  }
628 
629  m_bIsRotating = false;
630 
631  return vector.Zero;
632  }
633 
634  //------------------------------------------------------------------------------------------------
635  vector GetMovement(out vector previousPos, float timeSlice)
636  {
637  if (timeSlice <= 0)
638  return vector.Zero;
639 
640  CameraManager cameraManager = GetGame().GetCameraManager();
641  if (!cameraManager)
642  return vector.Zero;
643 
644  CameraBase camera = cameraManager.CurrentCamera();
645  if (!camera)
646  return vector.Zero;
647 
648  vector currentPos = camera.GetWorldTransformAxis(3);
649 
650  bool moved = !float.AlmostEqual(previousPos[0], currentPos[0]);
651  moved &= !float.AlmostEqual(previousPos[1], currentPos[1]);
652  moved &= !float.AlmostEqual(previousPos[2], currentPos[2]);
653 
654  if (moved)
655  {
656  m_bIsMoving = true;
657  vector movement = (currentPos - previousPos) / timeSlice;
658  previousPos = currentPos;
659  return camera.VectorToLocal(movement);
660  }
661 
662  m_bIsMoving = false;
663  return vector.Zero;
664  }
665 
666  //------------------------------------------------------------------------------------------------
667  protected vector GetSightsRelPosition()
668  {
669  IEntity owner = GetOwner();
670  if (m_ParentCharacter && owner)
671  return m_ParentCharacter.CoordToLocal(owner.GetOrigin());
672 
673  return vector.Zero;
674  }
675 
676  //------------------------------------------------------------------------------------------------
677  bool HasIllumination()
678  {
679  return m_bHasIllumination;
680  }
681 
682  //------------------------------------------------------------------------------------------------
683  Color GetReticleColor()
684  {
685  return Color.FromInt(m_ReticleColor.PackToInt());
686  }
687 
688  //------------------------------------------------------------------------------------------------
689  Color GetReticleOutlineColor()
690  {
691  return Color.FromInt(m_ReticleOutlineColor.PackToInt());
692  }
693 
694  //------------------------------------------------------------------------------------------------
695  Color GetReticleIlluminationColor()
696  {
697  return Color.FromInt(m_cReticleTextureIllumination.PackToInt());
698  }
699 
700  //------------------------------------------------------------------------------------------------
702  protected void EnableReticleIllumination(bool enable)
703  {
704  Color reticleTint;
705  Color glowTint;
706 
707  if (m_bHasIllumination && enable)
708  {
709  reticleTint = GetReticleIlluminationColor();
710  glowTint = GetReticleIlluminationColor();
711  }
712  else
713  {
714  reticleTint = GetReticleColor();
715  glowTint = GetReticleOutlineColor();
716  }
717 
718  glowTint.SetA(m_fReticleTextureGlowAlpha * glowTint.A());
719  s_OnIlluminationChange.Invoke(reticleTint, glowTint);
720  }
721 
722  //------------------------------------------------------------------------------------------------
723  protected float GetReticleOffsetYTarget()
724  {
725  return 0.0;
726  }
727 
728  //------------------------------------------------------------------------------------------------
729  float GetCurrentReticleOffsetY()
730  {
731  return m_fCurrentReticleOffsetY;
732  }
733 
734  //------------------------------------------------------------------------------------------------
735  protected float GetCameraPitchTarget()
736  {
737  if (m_eZeroingType == SCR_EPIPZeroingType.EPZ_CAMERA_TURN)
738  return -GetCurrentSightsRange()[0];
739 
740  return 0.0;
741  }
742 
743  //------------------------------------------------------------------------------------------------
744  float GetCurrentCameraPitchOffset()
745  {
746  return m_fCurrentCameraPitch;
747  }
748 
749  //------------------------------------------------------------------------------------------------
750  vector GetCameraOffset()
751  {
752  return m_vCameraOffset;
753  }
754 
755  //------------------------------------------------------------------------------------------------
756  vector GetCameraAngles()
757  {
758  return m_vCameraAngles;
759  }
760 
761  //------------------------------------------------------------------------------------------------
767  IEntity GetParentToLocalTransform(out vector result[4], IEntity parent = null)
768  {
769  vector temp[4];
770  Math3D.MatrixIdentity4(temp);
771 
772  IEntity lastNode = GetOwner();
773 
774  while (lastNode)
775  {
776  // Stop on defined parent entity, that is final node
777  if (parent == lastNode)
778  break;
779 
780  vector localTransform[4];
781  lastNode.GetLocalTransform(localTransform);
782 
783  // If using a pivot, we need to apply the pivot transformation
784  TNodeId pivotIndex = lastNode.GetPivot();
785  if (pivotIndex != -1)
786  {
787  // Multiply pivot * local TM = model TM
788  IEntity parentNode = lastNode.GetParent();
789  if (parentNode)
790  {
791  vector pivotTM[4];
792  parentNode.GetAnimation().GetBoneMatrix(pivotIndex, pivotTM);
793 
794  // This should not be happening - there should
795  // rather be no pivot, yet it triggers at times.
796  // ??? TODO@AS: See if we can have better API for pivoting like this
797  if (!SCR_Math3D.IsMatrixEmpty(pivotTM))
798  Math3D.MatrixMultiply4(pivotTM, localTransform, localTransform);
799  }
800  }
801 
802  Math3D.MatrixMultiply4(localTransform, temp, result);
803  Math3D.MatrixCopy(result, temp);
804 
805  lastNode = lastNode.GetParent();
806  }
807 
808  Math3D.MatrixGetInverse4(temp, result);
809 
810  return lastNode;
811  }
812 
813  //------------------------------------------------------------------------------------------------
819  IEntity GetCameraLocalTransform(out vector matrix[4])
820  {
821  // Apply offset and angles as configured against front sight position
822  vector position = m_vCameraOffset + GetSightsFrontPosition(true);
823  vector yawPitchRoll = Vector(m_vCameraAngles[1], m_vCameraAngles[0] + m_fCurrentCameraPitch, m_vCameraAngles[2]);
824 
825  // Construct the local matrix in relation to original parent
826  Math3D.AnglesToMatrix(yawPitchRoll, matrix);
827  matrix[3] = position;
828 
829  // Now additionally we will browse the hierarchy until we hit our weapon
830  vector temp[4];
831  Math3D.MatrixCopy(matrix, temp);
832 
833  IEntity parent = GetOwner();
834  IEntity lastNode = parent;
835 
836  BaseWeaponComponent weaponRoot;
837  while (lastNode)
838  {
839  // Stop on weapon, that is final node
840  weaponRoot = BaseWeaponComponent.Cast(lastNode.FindComponent(BaseWeaponComponent));
841  if (weaponRoot)
842  break;
843 
846  vector localTransform[4];
847  lastNode.GetLocalTransform(localTransform);
848 
849  // If using a pivot, we need to apply the pivot transformation
850  TNodeId pivotIndex = lastNode.GetPivot();
851  if (pivotIndex != -1)
852  {
853  // Multiply pivot * local TM = model TM
854  IEntity parentNode = lastNode.GetParent();
855  if (parentNode)
856  {
857  vector pivotTM[4];
858  parentNode.GetAnimation().GetBoneMatrix(pivotIndex, pivotTM);
859 
860  // This should not be happening - there should
861  // rather be no pivot, yet it triggers at times.
862  // ??? TODO@AS: See if we can have better API for pivoting like this
863  if (!SCR_Math3D.IsMatrixEmpty(pivotTM))
864  Math3D.MatrixMultiply4(pivotTM, localTransform, localTransform);
865  }
866  }
867  Math3D.MatrixMultiply4(temp, localTransform, temp);
868  lastNode = lastNode.GetParent();
869  }
870 
871  // Only use calculated matrix+parent if its valid
872  if (weaponRoot)
873  {
874  Math3D.MatrixCopy(temp, matrix);
875  parent = lastNode;
876  }
877 
878  return parent;
879  }
880 
881  //------------------------------------------------------------------------------------------------
882  void SetObjectiveFov(float objectiveFov)
883  {
884  m_fObjectiveFov = objectiveFov;
885  }
886 
887  //------------------------------------------------------------------------------------------------
888  void SetObjectiveScale(float objectiveScale)
889  {
890  m_fObjectiveScale = objectiveScale;
891  }
892 
893  //------------------------------------------------------------------------------------------------
894  void SetReticleBaseZoom(float reticleBaseZoom)
895  {
896  m_fReticleBaseZoom = reticleBaseZoom;
897  }
898 
899  //------------------------------------------------------------------------------------------------
900  void SetReticleAngularSize(float reticleAngularSize)
901  {
902  m_fReticleAngularSize = reticleAngularSize;
903  }
904 
905  //------------------------------------------------------------------------------------------------
906  void SetReticlePortion(float reticlePortion)
907  {
908  m_fReticlePortion = reticlePortion;
909  }
910 
911  //------------------------------------------------------------------------------------------------
912  void SetReticleOffsetX(float reticleOffsetX)
913  {
914  m_fReticleOffsetX = reticleOffsetX;
915  }
916 
917  //------------------------------------------------------------------------------------------------
918  void SetReticleOffsetY(float reticleOffsetY)
919  {
920  m_fReticleOffsetY = reticleOffsetY;
921  }
922 }
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ScriptedSightsComponentClass
Definition: ScriptedSightsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetSightsFrontPosition
proto external vector GetSightsFrontPosition(bool localSpace=false)
GetSightsTransform
proto external bool GetSightsTransform(out vector transform[4], bool localSpace=false)
SCR_2DOpticsComponentClass
Definition: SCR_2DOpticsComponent.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_Math3D
Contains various scripted 3D math functions.
Definition: SCR_Math3D.c:2
SCR_2DOpticsComponent
Definition: SCR_2DOpticsComponent.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
OnSightsADSChanged
func OnSightsADSChanged
Definition: SCR_2DOpticsComponent.c:7
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
GetCurrentSightsRange
proto external vector GetCurrentSightsRange()
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
fixAngle_180_180
float fixAngle_180_180(float pAngle)
Definition: CharacterCameraBase.c:14
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180