Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_2DOpticsComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Weapon/Sights", description: "", color: "0 0 255 255")]
3{
4 // Optics setup
5 [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of reticle\n", params: "edds imageset", category: "Resources")]
7
8 [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of reticle under glow\n", params: "edds imageset", category: "Resources")]
10
11 [Attribute("0", category: "Resources")]
12 protected bool m_bHasIllumination;
13
14 [Attribute("0 0 0 1", UIWidgets.ColorPicker, category: "Resources")]
15 protected ref Color m_ReticleColor;
16
17 [Attribute("1 1 1 1", UIWidgets.ColorPicker, category: "Resources")]
20 [Attribute("1 0 0 1", UIWidgets.ColorPicker, category: "Resources")]
22
23 [Attribute("0.05", UIWidgets.Slider, desc: "Reticle glow texture alpha\n[ % ]", params: "0 1 0.001", category: "Resources", precision: 3)]
24 protected float m_fReticleTextureGlowAlpha;
25
26 [Attribute("", UIWidgets.ResourceNamePicker, desc: "Texture of lens filter\n", params: "edds imageset", category: "Resources")]
28
29 [Attribute("1.1", UIWidgets.EditBox, desc: "Vignette texture scale\n", params: "0.001 10 0.001", category: "2DSights", precision: 3)]
30 protected float m_fVignetteScale;
31
32 [Attribute("1", UIWidgets.CheckBox, "Should hide parent object when using 2D sights\n", category: "2DSights")]
34
35 [Attribute("0", UIWidgets.CheckBox, "Should hide parent character when using 2D sights\n", category: "2DSights")]
37
38 // Animation attributes
39 [Attribute("0", UIWidgets.Slider, "Time before entering animation starts", params: "0 2000 1", category: "Animations")]
41
42 [Attribute("0", UIWidgets.Slider, "Animation time for canceling optic.", params: "0 2000 1", category: "Animations")]
44
45 [Attribute("0", UIWidgets.Slider, "Animation time for optic animation", params: "0 5 0.01", category: "Animations")]
46 protected float m_fAnimationEnterTime;
47
48 [Attribute("2", UIWidgets.Slider, "Speed of blur fade out on optic entering", params: "0.01 5 0.01", category: "Animations")]
49 protected float m_fAnimationSpeedBlur;
50
51 // Effect attributes
52 [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")]
54
55 [Attribute("0.1", UIWidgets.EditBox, desc: "Rotation effect scaling", params: "-100 100 0.01", category: "Effects")]
56 protected float m_fRotationScale;
57
58 [Attribute("4", UIWidgets.EditBox, desc: "Rotation damping speed - the higher, the faster the rotation speed gets zeroed", params: "0 60 0.1", category: "Effects")]
59 protected float m_fRotationDampingSpeed;
60
61 [Attribute("0.2", UIWidgets.EditBox, desc: "Movement effect scaling", params: "-100 100 0.01", category: "Effects")]
62 protected float m_fMovementScale;
63
64 [Attribute("2", UIWidgets.EditBox, desc: "Movement damping speed - the higher, the faster the movement speed gets zeroed", params: "0 60 0.1", category: "Effects")]
65 protected float m_fMovementDampingSpeed;
66
67 [Attribute("1", UIWidgets.EditBox, desc: "Roll effect scaling", params: "-100 100 0.01", category: "Effects")]
68 protected float m_fRollScale;
69
70 [Attribute("0", UIWidgets.EditBox, desc: "Roll damping speed - the higher, the faster the optic gets uprighted", params: "0 60 0.1", category: "Effects")]
71 protected float m_fRollDampingSpeed;
72
73 [Attribute("1", UIWidgets.EditBox, desc: "Optic misalignment scale - for turrets and binoculars", params: "-60 60 0.1", category: "Effects")]
74 protected float m_fMisalignmentScale;
75
76 [Attribute("1", UIWidgets.EditBox, desc: "Vignette adjustment speed - the faster, the less inertia there is", params: "0 60 0.1", category: "Effects")]
77 protected float m_fVignetteMoveSpeed;
78
79 [Attribute("1", UIWidgets.EditBox, desc: "Motion blur effect scaling", params: "0 100", category: "Effects")]
80 protected float m_fMotionBlurScale;
81
82 [Attribute("0.1", UIWidgets.EditBox, desc: "Max level of motion blur intensity", params: "0 1 0.01", category: "Effects")]
83 protected float m_fMotionBlurMax;
84
85 // 0 = immediately when entering ADS camera, 1.0 = only after full blend
86 [Attribute("1", UIWidgets.Slider, "Percentage of camera transition at which sights activate.", params: "0.0 1.0 0.01", category: "Sights")]
88
89 // 0 = immediately when leaving ADS camera, 1.0 = only after full blend
90 [Attribute("0", UIWidgets.Slider, "Percentage of camera transition at which sights deactivate.", params: "0.0 1.0 0.01", category: "Sights")]
92
93 [Attribute("0", UIWidgets.ComboBox, "Type of zeroing for this sights.", "", ParamEnumArray.FromEnum(SCR_EPIPZeroingType), category: "Sights")]
94 protected SCR_EPIPZeroingType m_eZeroingType;
95
96 [Attribute("25", UIWidgets.Slider, "Interpolation speed for zeroing interpolation", params: "1 100.0 0.1", category: "Sights")]
98
99 [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")]
101
102 [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")]
104
105 //------------------------------------------------------------------------------------------------
106 // Needed for zeroing
107 SCR_EPIPZeroingType GetZeroType()
109 return m_eZeroingType;
110 }
111
115 }
116
118 {
120 }
121
122 //------------------------------------------------------------------------------------------------
124 {
126 }
127
128 //------------------------------------------------------------------------------------------------
130 {
131 return Color.FromInt(m_ReticleColor.PackToInt());
132 }
133
134 //------------------------------------------------------------------------------------------------
136 {
137 return Color.FromInt(m_ReticleOutlineColor.PackToInt());
138 }
139
140 //------------------------------------------------------------------------------------------------
142 {
143 return Color.FromInt(m_cReticleTextureIllumination.PackToInt());
144 }
145
146 //------------------------------------------------------------------------------------------------
148 {
149 return m_fReticleTextureGlowAlpha;
150 }
151
152 //------------------------------------------------------------------------------------------------
154 {
156 }
157
158 //------------------------------------------------------------------------------------------------
160 {
162 }
163
164 //------------------------------------------------------------------------------------------------
166 {
168 }
169
170 //------------------------------------------------------------------------------------------------
172 {
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
180 }
181
182 //------------------------------------------------------------------------------------------------
184 {
186 }
187
188 //------------------------------------------------------------------------------------------------
190 {
192 }
193
194 //------------------------------------------------------------------------------------------------
196 {
198 }
199
200 //------------------------------------------------------------------------------------------------
202 {
204 }
205
206 //------------------------------------------------------------------------------------------------
208 {
210 }
211
212 //------------------------------------------------------------------------------------------------
214 {
216 }
217
218 //------------------------------------------------------------------------------------------------
220 {
222 }
223
224 //------------------------------------------------------------------------------------------------
226 {
228 }
229
230 //------------------------------------------------------------------------------------------------
232 {
234 }
235
236 //------------------------------------------------------------------------------------------------
238 {
240 }
241
242 //------------------------------------------------------------------------------------------------
244 {
246 }
247
248 //------------------------------------------------------------------------------------------------
250 {
252 }
253
254 //------------------------------------------------------------------------------------------------
255 void GetReticleTextures(out ResourceName reticleTexture, out ResourceName reticleTextureGlow, out ResourceName filterTexture)
256 {
257 reticleTexture = m_sReticleTexture;
258 reticleTextureGlow = m_sReticleGlowTexture;
259 filterTexture = m_sFilterTexture;
260 }
261
262 //------------------------------------------------------------------------------------------------
264 {
266 }
267
268 //------------------------------------------------------------------------------------------------
270 {
272 }
273
274 //------------------------------------------------------------------------------------------------
276 {
278 }
279
280 //------------------------------------------------------------------------------------------------
282 {
284 }
285}
286
287void OnSightsADSChanged(bool inADS, float fov);
289
290//------------------------------------------------------------------------------------------------
293class SCR_2DOpticsComponent : ScriptedSightsComponent
294{
295 [Attribute("0", UIWidgets.Slider, "Reticle Offset of scope center in X", params: "-1 1 0.0001", precision: 5, category: "Sights")]
296 protected float m_fReticleOffsetX;
297
298 [Attribute("0", UIWidgets.Slider, "Reticle Offset of scope center in Y", params: "-1 1 0.0001", precision: 5, category: "Sights")]
299 protected float m_fReticleOffsetY;
300
301 [Attribute("10", UIWidgets.EditBox, desc: "Field of view of the objective\n[ ° ]", params: "0.001 60 0.001", category: "2DSights", precision: 3)]
302 protected float m_fObjectiveFov;
303
304 [Attribute("1", UIWidgets.EditBox, desc: "Ocular texture scale\n", params: "0.001 10 0.001", category: "2DSights", precision: 3)]
305 protected float m_fObjectiveScale;
306
307 [Attribute("0", UIWidgets.Slider, "Angular size of reticle\n[ ° ]", params: "0 60 0.001", category: "Sights", precision: 3)]
308 protected float m_fReticleAngularSize;
309
310 [Attribute("1", UIWidgets.Slider, "Portion of reticle with specified angular size\n[ % ]", params: "0 10 0.00001", category: "Sights", precision: 5)]
311 protected float m_fReticlePortion;
312
313 [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)]
314 protected float m_fReticleBaseZoom;
315
316 [Attribute("10", UIWidgets.EditBox, desc: "Optic magnification\n[ x ]", params: "0.1 200 0.001", category: "Sights", precision: 3)]
317 protected float m_fMagnification;
318
319 // Action names
320 const string ACTION_ZOOM_IN = "WeaponOpticsZoomIn";
321 const string ACTION_ZOOM_OUT = "WeaponOpticsZoomOut";
322 const string ACTION_ILLUMINATION = "WeaponToggleSightsIllumination";
323
324 const float REFERENCE_FOV = 28;
325 const float OPACITY_INITIAL = 0.75;
326
327 const float NEAR_PLANE_DEFAULT = 0.05;
328 const float NEAR_PLANE_ZOOMED = 0.05;
329
331 protected float m_fCurrentCameraPitch;
332
333 //------------------------------------------------------------------------------------------------
334 // Getters for attributes
336 {
337 return m_fReticleOffsetX;
338 }
339
340 //------------------------------------------------------------------------------------------------
341 void GetReticleData(out float reticleAngularSize, out float reticlePortion, out float reticleBaseZoom)
342 {
343 reticleAngularSize = m_fReticleAngularSize;
344 reticlePortion = m_fReticlePortion;
345 reticleBaseZoom = m_fReticleBaseZoom;
346 }
347
348 //------------------------------------------------------------------------------------------------
350 {
351 return m_fObjectiveFov;
352 }
353
354 //------------------------------------------------------------------------------------------------
356 {
357 return m_fObjectiveScale;
358 }
359
360 //------------------------------------------------------------------------------------------------
362 {
363 return m_bIsOpticsHidden;
364 }
365
366 //------------------------------------------------------------------------------------------------
368 {
369 return m_fMagnification;
370 }
371
372 //------------------------------------------------------------------------------------------------
374 {
376 if (!data)
377 return 0;
378
379 return data.GetAnimationSpeedBlur();
380 }
381
382 //------------------------------------------------------------------------------------------------
384 {
386 if (!data)
387 return 1;
388
389 return data.GetADSActivationPercentage();
390 }
391
392 //------------------------------------------------------------------------------------------------
394 {
396 if (!data)
397 return 0;
398
399 return data.GetADSDeactivationPercentage();
400 }
401
402 protected int m_iSelectedZoomLevel;
403
404 // Overall movement
405 protected float m_fScratchesRoll;
406
407 // FOVs
408 protected float m_fFovZoomed;
409 protected float m_fDefaultSize;
410 protected float m_fNearPlaneCurrent;
411
412 // Movement check
413 protected bool m_bIsMoving;
414 protected bool m_bIsRotating;
415 protected bool m_bWasEntityHidden;
416 protected int m_iHeadBoneId = -1;
417
418 protected bool m_bIsOpticsHidden;
419 protected bool m_bIsIlluminationOn;
420
421 // Owner and character references
423
424 static ref ScriptInvokerBase<OnSightsADSChanged> s_OnSightsADSChanged = new ScriptInvokerBase<OnSightsADSChanged>();
425 static ref ScriptInvokerBase<On2DOpticsADSChange> s_On2DOpticADSChanged = new ScriptInvokerBase<On2DOpticsADSChange>();
427 protected ref ScriptInvokerBase<On2DOpticsIlluminationChange> s_OnIlluminationChange = new ScriptInvokerBase<On2DOpticsIlluminationChange>();
428
429 //------------------------------------------------------------------------------------------------
434
435 //------------------------------------------------------------------------------------------------
436 ScriptInvokerBase<On2DOpticsIlluminationChange> OnIlluminationChange()
437 {
439 }
440
441 //------------------------------------------------------------------------------------------------
444 {
445 // m_fMagnification value may change during gameplay
446 // 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
447 if (m_fFovZoomed < 0)
449
450 return m_fFovZoomed;
451 }
452
453 //------------------------------------------------------------------------------------------------
455 void SetFovZoomed(float value)
456 {
457 m_fFovZoomed = value;
458 }
459
460 //------------------------------------------------------------------------------------------------
462 {
463 return m_fNearPlaneCurrent;
464 }
465
466 //------------------------------------------------------------------------------------------------
468 {
469 return m_bIsMoving;
470 }
471
472 //------------------------------------------------------------------------------------------------
474 {
475 return m_bIsRotating;
476 }
477
478 //------------------------------------------------------------------------------------------------
480 {
481 return m_fScratchesRoll;
482 }
483
484 //------------------------------------------------------------------------------------------------
489 override void OnInit(IEntity owner)
490 {
491 m_fScratchesRoll = Math.RandomFloat(0, 360);
492
493 // m_fMagnification value may change during gameplay
494 // 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
495 m_fFovZoomed = -m_fMagnification;
496 }
497
498 //------------------------------------------------------------------------------------------------
499 protected void HandleSightActivation()
500 {
501 IEntity owner = GetOwner();
503
504 s_On2DOpticADSChanged.Invoke(this, true);
505 s_OnSightsADSChanged.Invoke(true, GetFovZoomed());
506
507 // Play cover fade in animaiton
510 if (data)
511 GetGame().GetCallqueue().CallLater(HideObjects, data.GetAnimationActivationDelay(), false);
512
513 m_bIsOpticsHidden = false;
514
515 // Setup illumination
517 }
518
519 //------------------------------------------------------------------------------------------------
520 protected void HandleSightDeactivation()
521 {
522 s_On2DOpticADSChanged.Invoke(this, false);
523 s_OnSightsADSChanged.Invoke(false, 0);
524
525 // Initialize to current zero value
527
529 {
530 IEntity owner = GetOwner();
531 if (owner && !owner.IsDeleted())
532 owner.SetFlags(EntityFlags.VISIBLE, false);
533
534 if (m_ParentCharacter && !m_ParentCharacter.IsDeleted())
535 m_ParentCharacter.SetFlags(EntityFlags.VISIBLE, false);
536
537 m_bWasEntityHidden = false;
538 }
539
540 GetGame().GetCallqueue().Remove(HideObjects); // in case this is called quickly after OnSightADSActivated, HideObjects needs to be cleared to prevent conflict
541
542 // Leaving animation
544
545 m_bIsOpticsHidden = true;
546 }
547
548 //------------------------------------------------------------------------------------------------
549 override void OnSightADSActivated()
550 {
551 super.OnSightADSActivated();
552
554 }
555
556 //------------------------------------------------------------------------------------------------
557 override void OnSightADSDeactivated()
558 {
559 super.OnSightADSDeactivated();
560
562 }
563
564 //------------------------------------------------------------------------------------------------
565 protected override void OnSightADSPostFrame(IEntity owner, float timeSlice)
566 {
568 if (!data)
569 return;
570
571 float interp = Math.Min(1, timeSlice * data.GetReticleOffsetInterpSpeed());
572 // Interpolate zeroing values
573 float reticleTarget = GetReticleOffsetYTarget();
574 m_fCurrentReticleOffsetY = Math.Lerp(m_fCurrentReticleOffsetY, reticleTarget, interp);
575 float pitchTarget = GetCameraPitchTarget();
576 m_fCurrentCameraPitch = Math.Lerp(m_fCurrentCameraPitch, pitchTarget, interp);
577 }
578
579 //------------------------------------------------------------------------------------------------
581 protected void HideObjects()
582 {
583 // Near plane
585
586 IEntity owner = GetOwner();
588 if (!data)
589 return;
590
591 // Hide rendering
592 if (data.ShouldHideParentObject())
593 {
594 if (owner)
595 owner.ClearFlags(EntityFlags.VISIBLE, false);
596
597 // Set flag as otherwise we can make visible something that we didn't make invisible
598 m_bWasEntityHidden = true;
599 }
600
601 // Hide parent character
602 if (data.ShouldHideParentCharacter())
603 {
605 m_ParentCharacter.ClearFlags(EntityFlags.VISIBLE, false);
606
607 // Set flag as otherwise we can make visible something that we didn't make invisible
608 m_bWasEntityHidden = true;
609 }
610 }
611
612 //------------------------------------------------------------------------------------------------
614 static float CalculateZoomFOV(float magnification)
615 {
616 CameraManager cameraManager = GetGame().GetCameraManager();
617 if (!cameraManager)
618 return REFERENCE_FOV;
619
620 float referenceFOV;
621 PlayerCamera camera = PlayerCamera.Cast(cameraManager.CurrentCamera());
622 if (camera)
623 referenceFOV = camera.GetFocusFOV();
624 else
625 referenceFOV = cameraManager.GetFirstPersonFOV();
626
627 float referenceTan = Math.Tan(Math.DEG2RAD * (referenceFOV * 0.5));
628 return Math.RAD2DEG * 2 * Math.Atan2(referenceTan, magnification);
629 }
630
631 //------------------------------------------------------------------------------------------------
633 bool IsMoveCloseToLimit(vector move, float limitMin)
634 {
635 float x = move[0];
636 float y = move[1];
637
638 return (float.AlmostEqual(x, 0, limitMin) && float.AlmostEqual(y, 0, limitMin));
639 }
640
641 //------------------------------------------------------------------------------------------------
645 */
646 vector GetMisalignmentAngles(notnull CameraBase camera)
647 {
649 if (!data)
650 return vector.Zero;
651
652 // Get camera to sight matrix
653 vector cameraToSightMat[4];
654 SCR_EntityHelper.GetRelativeLocalTransform(GetOwner(), camera, cameraToSightMat);
655
656 vector cameraAngles = data.GetCameraAngles();
657 // Sight camera angles offset
658 vector sightMat[3];
659 vector sightAngles = {-cameraAngles[1], - cameraAngles[0] - m_fCurrentCameraPitch, 0};
660 Math3D.AnglesToMatrix(sightAngles, sightMat);
661
662 // Sight camera angles mat in sight space
663 Math3D.MatrixMultiply3(sightMat, cameraToSightMat, sightMat);
664
665 // Sight transform which is important for turrets
666 vector turretMat[4];
667 GetSightsTransform(turretMat, true);
668 Math3D.MatrixInvMultiply3(sightMat, turretMat, sightMat);
669
670 // Sight angles as seen by camera
671 vector angles = Math3D.MatrixToAngles(sightMat);
672
673 // Account for additional optic camera roll
674 angles[2] = angles[2] + cameraAngles[2];
675
676 // Misalignment should not exceed 180 degrees
677 angles = SCR_Math3D.FixEulerVector180(angles);
678
679 return angles;
680 }
681
682 //------------------------------------------------------------------------------------------------
683 vector GetRotation(out vector previousDir, float timeSlice)
684 {
685 if (timeSlice <= 0)
686 return vector.Zero;
687
688 CameraManager cameraManager = GetGame().GetCameraManager();
689 if (!cameraManager)
690 return vector.Zero;
691
692 CameraBase camera = cameraManager.CurrentCamera();
693 if (!camera)
694 return vector.Zero;
695
696 vector currentDir = camera.GetWorldTransformAxis(2);
697
698 bool rotated = !float.AlmostEqual(previousDir[0], currentDir[0]);
699 rotated |= !float.AlmostEqual(previousDir[1], currentDir[1]);
700
701 if (rotated)
702 {
703 m_bIsRotating = true;
704 vector rotation = (currentDir - previousDir) / timeSlice;
705 previousDir = currentDir;
706 return camera.VectorToLocal(rotation);
707 }
708
709 m_bIsRotating = false;
710
711 return vector.Zero;
712 }
713
714 //------------------------------------------------------------------------------------------------
715 vector GetMovement(out vector previousPos, float timeSlice)
716 {
717 if (timeSlice <= 0)
718 return vector.Zero;
719
720 CameraManager cameraManager = GetGame().GetCameraManager();
721 if (!cameraManager)
722 return vector.Zero;
723
724 CameraBase camera = cameraManager.CurrentCamera();
725 if (!camera)
726 return vector.Zero;
727
728 vector currentPos = camera.GetWorldTransformAxis(3);
729
730 const float threshold = 0.0001;
731 float distance = vector.Distance(currentPos, previousPos);
732
733 if (distance > threshold)
734 {
735 m_bIsMoving = true;
736 float scale = (distance - threshold) / distance;
737 vector movement = (currentPos - previousPos) * (scale / timeSlice);
738 previousPos = currentPos;
739 return camera.VectorToLocal(movement);
740 }
741
742 m_bIsMoving = false;
743 return vector.Zero;
744 }
745
746 //------------------------------------------------------------------------------------------------
748 {
749 IEntity owner = GetOwner();
750 if (m_ParentCharacter && owner)
751 return m_ParentCharacter.CoordToLocal(owner.GetOrigin());
752
753 return vector.Zero;
754 }
755
756 //------------------------------------------------------------------------------------------------
758 protected void EnableReticleIllumination(bool enable)
759 {
760 Color reticleTint;
761 Color glowTint;
762
764 if (!data)
765 return;
766
767 if (data.HasIllumination() && enable)
768 {
769 reticleTint = data.GetReticleIlluminationColor();
770 glowTint = data.GetReticleIlluminationColor();
771 }
772 else
773 {
774 reticleTint = data.GetReticleColor();
775 glowTint = data.GetReticleOutlineColor();
776 }
777
778 glowTint.SetA(data.GetReticleTextureGlowAlpha() * glowTint.A());
779 s_OnIlluminationChange.Invoke(reticleTint, glowTint);
780 }
781
782 //------------------------------------------------------------------------------------------------
783 protected float GetReticleOffsetYTarget()
784 {
785 return 0.0;
786 }
787
788 //------------------------------------------------------------------------------------------------
790 {
792 }
793
794 //------------------------------------------------------------------------------------------------
795 protected float GetCameraPitchTarget()
796 {
798 if (!data)
799 return 0;
800
801 if (data.GetZeroType() == SCR_EPIPZeroingType.EPZ_CAMERA_TURN)
802 return -GetCurrentSightsRange()[0];
803
804 return 0;
805 }
806
807 //------------------------------------------------------------------------------------------------
809 {
811 }
812
813 //------------------------------------------------------------------------------------------------
820 {
821 IEntity parent = GetOwner();
823 if (!data)
824 return parent;
825
826 // Apply offset and angles as configured against front sight position
827 vector position = data.GetCameraOffset() + GetSightsFrontPosition(true);
828 vector cameraAngles = data.GetCameraAngles();
829 vector yawPitchRoll = Vector(cameraAngles[1], cameraAngles[0] + m_fCurrentCameraPitch, cameraAngles[2]);
830
831 // Construct the local matrix in relation to original parent
832 Math3D.AnglesToMatrix(yawPitchRoll, matrix);
833 matrix[3] = position;
834
835 // Now additionally we will browse the hierarchy until we hit our weapon
836 vector temp[4];
837 Math3D.MatrixCopy(matrix, temp);
838
839 IEntity lastNode = parent;
840
841 BaseWeaponComponent weaponRoot;
842 while (lastNode)
843 {
844 // Stop on weapon, that is final node
845 weaponRoot = BaseWeaponComponent.Cast(lastNode.FindComponent(BaseWeaponComponent));
846 if (weaponRoot)
847 break;
848
851 vector localTransform[4];
852 lastNode.GetLocalTransform(localTransform);
853
854 // If using a pivot, we need to apply the pivot transformation
855 TNodeId pivotIndex = lastNode.GetPivot();
856 if (pivotIndex != -1)
857 {
858 // Multiply pivot * local TM = model TM
859 IEntity parentNode = lastNode.GetParent();
860 if (parentNode)
861 {
862 vector pivotTM[4];
863 parentNode.GetAnimation().GetBoneMatrix(pivotIndex, pivotTM);
864
865 // This should not be happening - there should
866 // rather be no pivot, yet it triggers at times.
867 // ??? TODO@AS: See if we can have better API for pivoting like this
868 if (!SCR_Math3D.IsMatrixEmpty(pivotTM))
869 Math3D.MatrixMultiply4(pivotTM, localTransform, localTransform);
870 }
871 }
872 Math3D.MatrixMultiply4(temp, localTransform, temp);
873 lastNode = lastNode.GetParent();
874 }
875
876 // Only use calculated matrix+parent if its valid
877 if (weaponRoot)
878 {
879 Math3D.MatrixCopy(temp, matrix);
880 parent = lastNode;
881 }
882
883 return parent;
884 }
885
886 //------------------------------------------------------------------------------------------------
887 void SetObjectiveFov(float objectiveFov)
888 {
889 m_fObjectiveFov = objectiveFov;
890 }
891
892 //------------------------------------------------------------------------------------------------
893 void SetObjectiveScale(float objectiveScale)
894 {
895 m_fObjectiveScale = objectiveScale;
896 }
897
898 //------------------------------------------------------------------------------------------------
899 void SetReticleBaseZoom(float reticleBaseZoom)
900 {
901 m_fReticleBaseZoom = reticleBaseZoom;
902 }
903
904 //------------------------------------------------------------------------------------------------
905 void SetReticleAngularSize(float reticleAngularSize)
906 {
907 m_fReticleAngularSize = reticleAngularSize;
908 }
909
910 //------------------------------------------------------------------------------------------------
911 void SetReticlePortion(float reticlePortion)
912 {
913 m_fReticlePortion = reticlePortion;
914 }
915
916 //------------------------------------------------------------------------------------------------
917 void SetReticleOffsetX(float reticleOffsetX)
918 {
919 m_fReticleOffsetX = reticleOffsetX;
920 }
921
922 //------------------------------------------------------------------------------------------------
923 void SetReticleOffsetY(float reticleOffsetY)
924 {
925 m_fReticleOffsetY = reticleOffsetY;
926 }
927}
vector scale
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref array< string > angles
float m_fRollScale
float m_fMotionBlurScale
ref Color m_ReticleColor
params precision
ResourceName m_sFilterTexture
vector m_vCameraOffset
bool m_bHasIllumination
float m_fVignetteMoveSpeed
float m_fMisalignmentDampingSpeed
float m_fMovementDampingSpeed
func OnSightsADSChanged
float m_fReticleOffsetInterpSpeed
vector m_vCameraAngles
SCR_EPIPZeroingType m_eZeroingType
float m_fMotionBlurMax
float m_fMisalignmentScale
float m_fRotationScale
float m_fMovementScale
float m_fAnimationEnterTime
float m_fRollDampingSpeed
float m_fRotationDampingSpeed
int m_iAnimationDeactivationDelay
ref Color m_ReticleOutlineColor
float m_fVignetteScale
int m_iAnimationActivationDelay
ref Color m_cReticleTextureIllumination
float m_fADSDeactivationPercentage
bool m_bShouldHideParentObject
bool m_bShouldHideParentCharacter
float m_fADSActivationPercentage
SCR_CharacterSoundComponentClass GetComponentData()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
float distance
vector position
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition Color.c:13
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external Animation GetAnimation()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external IEntity GetParent()
proto external TNodeId GetPivot()
Returns pivot ID from hierarchy component.
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
proto external bool IsDeleted()
proto external void GetLocalTransform(out vector mat[])
See IEntity::GetTransform.
Definition Math.c:13
void GetReticleTextures(out ResourceName reticleTexture, out ResourceName reticleTextureGlow, out ResourceName filterTexture)
SCR_EPIPZeroingType GetZeroType()
bool IsMoveCloseToLimit(vector move, float limitMin)
Return true if move X a Y is below limit.
override float GetADSDeactivationPercentageScript()
vector GetMovement(out vector previousPos, float timeSlice)
void SetReticleOffsetY(float reticleOffsetY)
ScriptInvokerBase< On2DOpticsIlluminationChange > OnIlluminationChange()
override void OnSightADSActivated()
override void OnInit(IEntity owner)
static ref ScriptInvokerBase< On2DOpticsADSChange > s_On2DOpticADSChanged
ScriptInvokerVoid OnSetupOpticImage()
void SetReticlePortion(float reticlePortion)
float GetFovZoomed()
Get base FOV of the optic, used to determine maximum FOV.
void SetReticleAngularSize(float reticleAngularSize)
void SetReticleOffsetX(float reticleOffsetX)
ChimeraCharacter m_ParentCharacter
void SetObjectiveFov(float objectiveFov)
void HideObjects()
Hides objects to prevent clipping when entering ADS.
ref ScriptInvokerVoid s_OnSetupOpticImage
override void OnSightADSDeactivated()
vector GetRotation(out vector previousDir, float timeSlice)
void SetObjectiveScale(float objectiveScale)
override void OnSightADSPostFrame(IEntity owner, float timeSlice)
void SetReticleBaseZoom(float reticleBaseZoom)
override float GetADSActivationPercentageScript()
void GetReticleData(out float reticleAngularSize, out float reticlePortion, out float reticleBaseZoom)
static ref ScriptInvokerBase< OnSightsADSChanged > s_OnSightsADSChanged
vector GetMisalignmentAngles(notnull CameraBase camera)
static float CalculateZoomFOV(float magnification)
Return camera FOV for given magnification. Focus FOV is used as reference 1x magnification.
IEntity GetCameraLocalTransform(out vector matrix[4])
void EnableReticleIllumination(bool enable)
Toggle between illumination modes.
void SetFovZoomed(float value)
Set base FOV of the optic. Negative value means magnification to compute new m_fFovZoomed with.
ref ScriptInvokerBase< On2DOpticsIlluminationChange > s_OnIlluminationChange
static bool GetRelativeLocalTransform(notnull IEntity owner, notnull IEntity member, out vector relativeTransform[4])
Contains various scripted 3D math functions.
Definition SCR_Math3D.c:3
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
int TNodeId
Node global id is a hash of name of the node.
Definition EnEntity.c:18
RespawnSystemComponentClass GameComponentClass vector vector rotation
proto native vector Vector(float x, float y, float z)