7 enum SCR_EPIPZeroingType
15 class SCR_2DPIPSightsComponent : SCR_2DSightsComponent
19 protected bool m_b2DIsEnabled;
22 [
Attribute(
"{EF091399D840192D}UI/layouts/Sights/PictureInPictureSightsLayout.layout", UIWidgets.ResourcePickerThumbnail,
"The layout used for the PIP component",
params:
"layout",
category:
"PiPSights")]
23 protected ResourceName m_sPIPLayoutResource;
25 [
Attribute(
"RTTexture0", UIWidgets.EditBox,
"Name of RTTexture widget within provided layout\n",
category:
"PiPSights")]
26 protected string m_sRTTextureWidgetName;
28 [
Attribute(
"RenderTarget0", UIWidgets.EditBox,
"Name of RenderTarget widget within provided layout\n",
category:
"PiPSights")]
29 protected string m_sRTargetWidgetName;
31 [
Attribute(
"8", UIWidgets.Slider,
"Camera index used for this PIP component\n",
params:
"0 31 1",
category:
"PiPSights")]
32 protected int m_iCameraIndex;
34 [
Attribute(
"2", UIWidgets.Slider,
"GUI widget index for this PIP component\n",
category:
"PiPSights")]
35 protected int m_iGuiIndex;
37 [
Attribute(
"21", UIWidgets.Slider,
"Camera field of view used by this PIP component. Determines LOD used. Set to 0 to use Focus FOV.\n[°]",
params:
"0 89.99 0.01",
category:
"PiPSights")]
38 protected float m_fMainCameraFOV;
40 [
Attribute(
"0.2", UIWidgets.Slider,
"Camera near clipping plane\n[m]",
params:
"0 1000 0.01",
category:
"PiPSights")]
41 protected float m_fNearPlane;
43 [
Attribute(
"0", UIWidgets.Slider,
"Camera far clipping plane. Set to zero to match maximum view distance\n[m]",
params:
"0 10000 1",
category:
"PiPSights")]
44 protected float m_fFarPlane;
47 [
Attribute(
"1.0", UIWidgets.Slider,
"Scale of resolution used by the PIP\n[x]",
params:
"0.1 1 0.1",
category:
"PiPSights")]
48 protected float m_fResolutionScale;
50 [
Attribute(
"{972DF18CB9BFCBD4}Common/Postprocess/HDR_ScopePiP.emat", UIWidgets.EditBox,
"HDR material resource\n",
params:
"emat",
category:
"PiPSights")]
51 protected ResourceName m_rScopeHDRMatrial;
54 [
Attribute(
"0.25", UIWidgets.Slider,
"Percentage of camera transition at which sights activate\n[%]",
params:
"0.0 1.0 0.01",
category:
"PiPSights")]
55 protected float m_fADSActivationPercentagePIP;
58 [
Attribute(
"0.75", UIWidgets.Slider,
"Percentage of camera transition at which sights deactivate\n[%]",
params:
"0.0 1.0 0.01",
category:
"PiPSights")]
59 protected float m_fADSDeactivationPercentagePIP;
61 [
Attribute(
"40", UIWidgets.Slider,
"Vignette parallax angle scale, divided by objective FOV.\n[x]",
params:
"-100 100 0.1",
category:
"PiPSights-Parallax")]
62 protected float m_fVignetteParallaxScale;
64 [
Attribute(
"0.014", UIWidgets.Slider,
"Optimal distance from scope, where no parallax distant effect is present\n[m]",
params:
"-0.2 0.2 0.001",
category:
"PiPSights-Parallax")]
65 protected float m_fCenterDistance;
67 [
Attribute(
"0.8", UIWidgets.Slider,
"How the parallax is affected when the eye moves closer to scope\n[x]",
params:
"0 1 0.001",
category:
"PiPSights-Parallax")]
68 protected float m_fDistanceMoveNear;
70 [
Attribute(
"0.4", UIWidgets.Slider,
"How the parallax is affected when the eye moves farther from scope\n[x]",
params:
"0 1 0.001",
category:
"PiPSights-Parallax")]
71 protected float m_fDistanceMoveFar;
73 [
Attribute(
"0.5", UIWidgets.Slider,
"Basic value for simulating parallax effect\n",
params:
"0 2 0.001",
category:
"PiPSights-Parallax")]
74 protected float m_fBasicParallax;
76 [
Attribute(
"1.75", UIWidgets.Slider,
"Max parallax value for simulating parallax effect\nShould be bigger than BasicParallax\n",
params:
"0 2 0.001",
category:
"PiPSights-Parallax")]
77 protected float m_fMaxParallax;
79 [
Attribute(
"0.0", UIWidgets.Slider,
"Parallax axis offset in X\n[°]",
params:
"-90 90 0.001",
category:
"PiPSights-Parallax")]
80 protected float m_fCenterOffsetX;
82 [
Attribute(
"0.0", UIWidgets.Slider,
"Parallax axis offset in Y\n[°]",
params:
"-90 90 0.001",
category:
"PiPSights-Parallax")]
83 protected float m_fCenterOffsetY;
85 [
Attribute(
"0.01", UIWidgets.Slider,
"Radius of PIP scope ocular\n[m]",
params:
"0.001 1 0.0001",
category:
"PiPSights", precision: 5)]
86 protected float m_fScopeRadius;
88 [
Attribute(
"1.05", UIWidgets.Slider,
"PIP reticle additional scale to compensate discrepancy between camera and reticle\n[x]",
params:
"0.01 10 0.00001",
category:
"PiPSights", precision: 5)]
89 protected float m_fReticlePIPScale;
91 [
Attribute(
"1.0", UIWidgets.Slider,
"PIP objective inner edge. Should be lower than max\n[x]",
params:
"0.001 10 0.00001",
category:
"PiPSights-Parallax", precision: 5)]
92 protected float m_fObjectivePIPEdgeMin;
94 [
Attribute(
"1.05", UIWidgets.Slider,
"PIP objective outer edge\[x]",
params:
"0.001 10 0.00001",
category:
"PiPSights-Parallax", precision: 5)]
95 protected float m_fObjectivePIPEdgeMax;
97 [
Attribute(
"{5366CEDE2A151631}Terrains/Common/Water/UnderWater/oceanUnderwater.emat", UIWidgets.ResourcePickerThumbnail,
"Underwater postprocess material\n",
params:
"emat",
category:
"PiPSights")]
98 protected ResourceName m_sUnderwaterPPMaterial;
100 protected int m_iLastProjectionFrame = -1;
101 protected vector m_vScreenScopeCenter;
102 protected float m_fScreenScopeRadiusSq;
103 protected float m_fReticleScale;
104 protected float m_fEdgeScale = 1;
105 protected float m_fParallaxX;
106 protected float m_fParallaxY;
108 protected IEntity m_CurrentPlayable;
111 protected ref Color m_cReticleColor = m_ReticleColor;
118 bool IsScreenPositionInSights(vector screenPosition)
123 BaseWorld world =
GetGame().GetWorld();
124 int index = world.GetFrameNumber();
127 if (m_iLastProjectionFrame !=
index)
129 WorkspaceWidget workspaceWidget =
GetGame().GetWorkspace();
132 m_vScreenScopeCenter = workspaceWidget.ProjWorldToScreen(sightsRear, world);
133 m_vScreenScopeCenter[2] = 0.0;
135 vector extent = workspaceWidget.ProjWorldToScreen(sightsRear +
GetOwner().GetWorldTransformAxis(0) * m_fScopeRadius, world);
138 const float invSqrt2 = 0.70710678118;
139 m_fScreenScopeRadiusSq = invSqrt2 * vector.DistanceSq(extent, m_vScreenScopeCenter);
140 m_iLastProjectionFrame =
index;
143 float screenDistanceSq = vector.DistanceSq(screenPosition, m_vScreenScopeCenter);
144 return screenDistanceSq < m_fScreenScopeRadiusSq;
147 protected int m_iDisableVignetteFrames;
150 protected ref Widget m_wPIPRoot;
153 protected bool m_bPIPIsEnabled;
154 protected static int s_bIsPIPActive;
157 protected RTTextureWidget m_wRenderTargetTextureWidget;
160 protected RenderTargetWidget m_wRenderTargetWidget;
165 Material m_pMaterial;
166 int m_iVignetteCenterXIndex = -1;
167 int m_iVignetteCenterYIndex = -1;
168 int m_iVignettePowerIndex = -1;
169 int m_iLensDistortIndex = -1;
170 int m_iReticleOffsetXIndex = -1;
171 int m_iReticleOffsetYIndex = -1;
172 int m_iReticleColorIndex = -1;
173 int m_iReticleScaleIndex = -1;
174 int m_iEdgeMinIndex = -1;
175 int m_iEdgeMaxIndex = -1;
176 int m_iEdgeCenterXIndex = -1;
177 int m_iEdgeCenterYIndex = -1;
192 int GetPIPCameraIndex()
194 return m_iCameraIndex;
201 return super.GetADSActivationPercentageScript();
203 return m_fADSActivationPercentagePIP;
210 return super.GetADSDeactivationPercentageScript();
212 return m_fADSDeactivationPercentagePIP;
218 return m_bPIPIsEnabled;
225 static bool IsPIPActive()
227 return s_bIsPIPActive;
231 float GetMainCameraFOV()
236 if (m_fMainCameraFOV > 0)
237 return m_fMainCameraFOV;
239 m_fMainCameraFOV = CalculateZoomFOV(1);
240 return m_fMainCameraFOV;
244 private bool IsLocalControlledEntity(IEntity pEntity,
bool checkHierarchy =
true)
254 auto pPlayerController = pGame.GetPlayerController();
255 if (!pPlayerController)
258 auto pControlledEntity = pPlayerController.GetControlledEntity();
259 if (!pControlledEntity)
263 if (pControlledEntity == pEntity)
271 m_CurrentPlayable = pEntity.GetParent();
273 while (m_CurrentPlayable)
275 if (pControlledEntity == m_CurrentPlayable)
278 m_CurrentPlayable = m_CurrentPlayable.GetParent();
291 protected CameraBase CreateCamera(IEntity parent, vector
position, vector angles,
int cameraIndex,
float fov,
float nearPlane,
float farPlane)
294 BaseWorld baseWorld = parent.GetWorld();
297 EntitySpawnParams
params =
new EntitySpawnParams();
298 parent.GetWorldTransform(
params.Transform);
302 parent = GetCameraLocalTransform(mat);
304 pipCamera.SetCameraIndex(m_iCameraIndex);
305 pipCamera.SetVerticalFOV(fov);
306 pipCamera.SetNearPlane(nearPlane);
307 pipCamera.SetFarPlane(farPlane);
308 pipCamera.ApplyProps(m_iCameraIndex);
309 baseWorld.SetCameraLensFlareSet(cameraIndex, CameraLensFlareSetType.FirstPerson,
string.Empty);
312 parent.AddChild(pipCamera, -1, EAddChildFlags.AUTO_TRANSFORM);
313 pipCamera.SetLocalTransform(mat);
314 pipCamera.UpdatePIPCamera(1.0);
319 protected Widget CreateUI(
string layout,
string rtTextureName,
string rtName, out RTTextureWidget RTTexture, out RenderTargetWidget RTWidget)
322 if (
layout ==
string.Empty)
326 Widget root =
GetGame().GetWorkspace().CreateWidgets(
layout);
333 RTTexture = RTTextureWidget.Cast(root.FindAnyWidget(rtTextureName));
334 RTWidget = RenderTargetWidget.Cast(root.FindAnyWidget(rtName));
335 if (!RTTexture || !RTWidget)
337 root.RemoveFromHierarchy();
345 void SetPIPEnabled(
bool enabled)
349 if (enabled && !m_bPIPIsEnabled)
351 m_iDisableVignetteFrames = 5;
356 if (!m_wPIPRoot || !m_wRenderTargetTextureWidget || !m_wRenderTargetWidget)
357 m_wPIPRoot = CreateUI(m_sPIPLayoutResource, m_sRTTextureWidgetName, m_sRTargetWidgetName, m_wRenderTargetTextureWidget, m_wRenderTargetWidget);
361 Print(
"Could not create PIP layouts!", LogLevel.ERROR);
371 float viewDistance =
GetGame().GetViewDistance();
373 viewDistance = Math.Min(viewDistance, m_fFarPlane);
380 Print(
"Could not create PIP camera!", LogLevel.ERROR);
385 BaseWorld baseWorld = owner.GetWorld();
386 m_wRenderTargetWidget.SetWorld(baseWorld, m_iCameraIndex);
389 m_wRenderTargetWidget.SetResolutionScale(m_fResolutionScale, m_fResolutionScale);
391 if (!owner.IsDeleted())
392 m_wRenderTargetTextureWidget.SetGUIWidget(owner, m_iGuiIndex);
396 GetGame().GetWorld().SetCameraPostProcessEffect(m_iCameraIndex, 10, PostProcessEffectType.HDR, m_rScopeHDRMatrial);
399 if (m_sUnderwaterPPMaterial !=
string.Empty)
400 GetGame().GetWorld().SetCameraPostProcessEffect(m_iCameraIndex, 2, PostProcessEffectType.UnderWater, m_sUnderwaterPPMaterial);
402 s_bIsPIPActive =
true;
403 m_bPIPIsEnabled =
true;
408 if (!enabled && m_bPIPIsEnabled)
411 s_bIsPIPActive =
false;
412 m_bPIPIsEnabled =
false;
418 protected void DestroyCamera(CameraBase camera)
422 IEntity cameraParent = camera.GetParent();
424 cameraParent.RemoveChild(camera);
426 camera.GetWorld().SetCameraPostProcessEffect(m_iCameraIndex, 10, PostProcessEffectType.HDR,
string.Empty);
427 camera.GetWorld().SetCameraPostProcessEffect(m_iCameraIndex, 2, PostProcessEffectType.UnderWater,
string.Empty);
428 camera.GetWorld().SetCameraLensFlareSet(m_iCameraIndex, CameraLensFlareSetType.None,
string.Empty);
439 if (m_wRenderTargetTextureWidget && owner && !owner.IsDeleted())
440 m_wRenderTargetTextureWidget.SetGUIWidget(owner, -1);
444 m_wPIPRoot.RemoveFromHierarchy();
448 DestroyCamera(m_PIPCamera);
453 protected override void EnableReticleIllumination(
bool enable)
455 super.EnableReticleIllumination(enable);
457 if (m_bHasIllumination && enable)
458 m_cReticleColor = GetReticleIlluminationColor();
460 m_cReticleColor = GetReticleColor();
472 if (!IsLocalControlledEntity(owner))
488 m_iDisableVignetteFrames = 15;
492 UpdateScopeMaterial();
499 if (m_bHasIllumination)
502 EnableReticleIllumination(m_bIsIlluminationOn);
506 s_OnSightsADSChanged.Invoke(
true, m_fMainCameraFOV);
512 SetPIPEnabled(
false);
515 m_b2DIsEnabled =
true;
516 super.OnSightADSActivated();
518 else if (!scope2d && m_b2DIsEnabled)
520 m_b2DIsEnabled =
false;
521 super.OnSightADSDeactivated();
533 if (!m_CurrentPlayable)
540 auto camMgr =
GetGame().GetCameraManager();
541 if (camMgr && camMgr.GetOverlayCamera() == m_PIPCamera)
542 camMgr.SetOverlayCamera(
null);
545 SetPIPEnabled(
false);
551 s_OnSightsADSChanged.Invoke(
false, 0);
556 super.OnSightADSDeactivated();
557 m_b2DIsEnabled =
false;
561 SetPIPEnabled(
false);
571 void UpdateCamera(
float timeSlice)
576 if (m_fScopeRadius <= 0)
580 CameraManager cameraManager =
GetGame().GetCameraManager();
584 CameraBase mainCamera = cameraManager.CurrentCamera();
589 mainCamera.GetLocalTransform(cameraMat);
590 vector localCameraPosition = cameraMat[3];
592 vector parentToLocalMat[4];
593 GetParentToLocalTransform(parentToLocalMat, mainCamera.GetParent());
594 localCameraPosition = localCameraPosition.Multiply4(parentToLocalMat);
597 float distance = vector.Distance(pipSurfaceCenter, localCameraPosition);
606 fov = fovInfo.GetFOV();
607 SCR_CharacterCameraHandlerComponent.SetOverlayCameraFOV(fov);
611 fov = mainCamera.GetVerticalFOV();
615 float scopeSize = Math.Atan2(m_fScopeRadius * 2,
distance) * Math.RAD2DEG;
616 float screenPortion = scopeSize / mainCamera.GetVerticalFOV();
617 float currentFOV = m_PIPCamera.GetVerticalFOV();
618 bool fovChanged = !
float.AlmostEqual(fov * screenPortion, currentFOV, currentFOV * 0.005);
622 if (variableSights && !fovChanged)
623 fovChanged = variableSights.IsAdjusting();
627 m_PIPCamera.SetVerticalFOV(fov * screenPortion);
631 m_fEdgeScale = fov / variableSights.GetBaseFOV();
634 if (fovChanged && m_fReticleAngularSize != 0)
637 if (m_fReticleBaseZoom > 0)
638 m_fReticleBaseZoom = -CalculateZoomFOV(m_fReticleBaseZoom);
641 if (m_fReticleBaseZoom == 0)
643 else if (m_fReticleBaseZoom < 0)
644 fovReticle = -m_fReticleBaseZoom;
647 m_fReticleScale = fovReticle * screenPortion * m_fReticlePortion / m_fReticleAngularSize;
652 GetCameraLocalTransform(mat);
656 vector sightsTransform[4];
659 vector parallaxPoint = sightsTransform[3] + sightsTransform[2] *
distance;
660 vector parallaxDirection = (parallaxPoint - localCameraPosition).Normalized();
661 vector angles =
SCR_Math3D.FixEulerVector180(parallaxDirection.VectorToAngles());
664 angles += Vector(m_fCenterOffsetX, m_fCenterOffsetY, 0);
667 angles *= fov / mainCamera.GetVerticalFOV();
670 m_fParallaxX = -angles[0];
671 m_fParallaxY = angles[1];
675 Math3D.AnglesToMatrix(angles, parallax);
676 Math3D.MatrixMultiply3(mat, parallax, mat);
679 m_PIPCamera.SetLocalTransform(mat);
682 m_PIPCamera.UpdatePIPCamera(timeSlice);
688 int mainCameraIndex = 0;
689 CameraManager manager =
GetGame().GetCameraManager();
692 CameraBase cam = manager.CurrentCamera();
694 mainCameraIndex = cam.GetCameraIndex();
697 BaseWorld world =
GetOwner().GetWorld();
698 float hdrBrightness = world.GetCameraHDRBrightness(mainCameraIndex);
699 world.SetCameraHDRBrightness(m_iCameraIndex, hdrBrightness);
703 void UpdateScopeMaterial()
705 if (m_iDisableVignetteFrames > 0)
707 m_pMaterial.SetParamByIndex(m_iVignetteCenterXIndex, 0);
708 m_pMaterial.SetParamByIndex(m_iVignetteCenterYIndex, 0);
709 m_pMaterial.SetParamByIndex(m_iVignettePowerIndex, 2);
711 m_iDisableVignetteFrames--;
719 CharacterControllerComponent controller = character.GetCharacterController();
723 BaseWeaponManagerComponent weaponManager = controller.GetWeaponManagerComponent();
727 CameraManager cameraManager =
GetGame().GetCameraManager();
731 CameraBase mainCamera = cameraManager.CurrentCamera();
737 mainCamera.GetLocalTransform(mainCam);
740 vector sightsLSCam[4];
742 weaponManager.GetCurrentSightsCameraTransform(sightsLSCam, fov);
745 vector scopePosCam = sightsLSCam[3] - mainCam[3];
748 vector scopeFwd = sightsLSCam[2];
749 vector camFwd = mainCam[2];
758 float ns = vector.Dot(camFwd, scopeFwd);
759 float nP = vector.Dot(scopePosCam, scopeFwd);
762 vector projP = camFwd*t;
764 vector locPos = scopePosCam - projP;
772 float distance = Math.AbsFloat(t) - m_fCenterDistance;
775 float vignettePower = 0;
783 distancePower = m_fDistanceMoveFar;
788 distancePower = m_fDistanceMoveNear;
793 float fc = 1 - 1 /(Math.Log2(distancePower*Math.AbsFloat(
distance) + 2));
796 vignettePower = Math.Clamp(fc* 100, m_fBasicParallax, m_fMaxParallax);
815 float pipFOV = m_PIPCamera.GetVerticalFOV();
818 float vignetteParallaxScale;
819 if (m_fObjectiveFov > 0)
820 vignetteParallaxScale = m_fVignetteParallaxScale / (m_fObjectiveFov * m_fObjectiveScale);
822 m_pMaterial.SetParamByIndex(m_iVignetteCenterXIndex, -m_fParallaxX * vignetteParallaxScale / pipFOV);
823 m_pMaterial.SetParamByIndex(m_iVignetteCenterYIndex, -m_fParallaxY * vignetteParallaxScale / pipFOV);
824 m_pMaterial.SetParamByIndex(m_iVignettePowerIndex, vignettePower);
827 m_pMaterial.SetParamByIndex(m_iEdgeCenterXIndex, m_fParallaxX * m_fReticlePIPScale / pipFOV);
828 m_pMaterial.SetParamByIndex(m_iEdgeCenterYIndex, m_fParallaxY * m_fReticlePIPScale / pipFOV);
829 float edgeSize = m_fObjectiveFov * m_fObjectiveScale * m_fEdgeScale / pipFOV;
830 m_pMaterial.SetParamByIndex(m_iEdgeMinIndex, 0.5 * m_fReticlePIPScale * edgeSize * edgeSize * m_fObjectivePIPEdgeMin);
831 m_pMaterial.SetParamByIndex(m_iEdgeMaxIndex, 0.5 * m_fReticlePIPScale * edgeSize * edgeSize * m_fObjectivePIPEdgeMax);
834 m_pMaterial.SetParamByIndex(m_iReticleScaleIndex, m_fReticleScale / m_fReticlePIPScale);
835 m_pMaterial.SetParamByIndex(m_iReticleOffsetXIndex, m_fReticleScale * (m_fParallaxX + m_fReticleOffsetX) / pipFOV);
836 m_pMaterial.SetParamByIndex(m_iReticleOffsetYIndex, m_fReticleScale * (m_fParallaxY + m_fCurrentReticleOffsetY) / pipFOV);
839 float reticleRGBA[4] = {m_cReticleColor.R(), m_cReticleColor.G(), m_cReticleColor.B(), m_cReticleColor.A()};
840 m_pMaterial.SetParamByIndex(m_iReticleColorIndex, reticleRGBA);
849 super.OnSightADSPostFrame(owner, timeSlice);
854 if ((m_bPIPIsEnabled && use2D) || (!m_bPIPIsEnabled && !use2D))
863 UpdateCamera(timeSlice);
866 if (m_pMaterial && m_PIPCamera)
867 UpdateScopeMaterial();
877 protected override void OnInit(IEntity owner)
881 if (m_rScopeHDRMatrial.IsEmpty())
882 Print(
"Scope HDR material is empty!", LogLevel.WARNING);
884 ResourceName mat = m_rScopeHDRMatrial;
885 m_pMaterial = Material.GetOrLoadMaterial(mat, 0);
889 m_iVignetteCenterXIndex = m_pMaterial.GetParamIndex(
"VignetteCenterX");
890 m_iVignetteCenterYIndex = m_pMaterial.GetParamIndex(
"VignetteCenterY");
891 m_iVignettePowerIndex = m_pMaterial.GetParamIndex(
"Vignette");
892 m_iLensDistortIndex = m_pMaterial.GetParamIndex(
"LensDistort");
893 m_iReticleOffsetXIndex = m_pMaterial.GetParamIndex(
"ReticleOffsetX");
894 m_iReticleOffsetYIndex = m_pMaterial.GetParamIndex(
"ReticleOffsetY");
895 m_iReticleColorIndex = m_pMaterial.GetParamIndex(
"ReticleColor");
896 m_iReticleScaleIndex = m_pMaterial.GetParamIndex(
"ReticleScale");
897 m_iEdgeMinIndex = m_pMaterial.GetParamIndex(
"EdgeMin");
898 m_iEdgeMaxIndex = m_pMaterial.GetParamIndex(
"EdgeMax");
899 m_iEdgeCenterXIndex = m_pMaterial.GetParamIndex(
"EdgeCenterX");
900 m_iEdgeCenterYIndex = m_pMaterial.GetParamIndex(
"EdgeCenterY");
904 Print(
"Cannot initialize PiP HDR PP !", LogLevel.ERROR);
910 protected override void ApplyRecoilToCamera(inout vector pOutCameraTransform[4], vector aimModAngles)
915 vector weaponAnglesMat[3];
916 Math3D.AnglesToMatrix(aimModAngles, weaponAnglesMat);
917 Math3D.MatrixMultiply3(pOutCameraTransform, weaponAnglesMat, pOutCameraTransform);
926 return super.CanFreelook();
931 protected override void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
933 const ShapeFlags shapeFlags = ShapeFlags.ONCE | ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOOUTLINE;
934 const float axisLength = 0.1;
936 vector ownerTransform[4];
937 owner.GetWorldTransform(ownerTransform);
939 vector objectiveTransform[4];
940 Math3D.AnglesToMatrix(m_vCameraAngles, objectiveTransform);
941 Math3D.MatrixMultiply3(objectiveTransform, ownerTransform, objectiveTransform);
944 vector objectiveSide = objectiveTransform[0];
945 vector objectiveUp = objectiveTransform[1];
946 vector objectiveForward = objectiveTransform[2];
947 vector objectiveCenter = objectiveTransform[3];
949 Shape rightArrow = Shape.CreateArrow(objectiveCenter, objectiveCenter + objectiveSide * axisLength, 0.01, Color.DARK_RED, shapeFlags);
950 Shape upArrow = Shape.CreateArrow(objectiveCenter, objectiveCenter + objectiveUp * axisLength, 0.01, Color.DARK_GREEN, shapeFlags);
951 Shape fwdArrow = Shape.CreateArrow(objectiveCenter, objectiveCenter + objectiveForward * axisLength, 0.01, Color.DARK_BLUE, shapeFlags);
954 objectiveTransform[1] = objectiveForward;
955 objectiveTransform[2] = objectiveUp;
956 objectiveTransform[3] = objectiveCenter;
957 SCR_Shape.DrawCircle(objectiveTransform, m_fScopeRadius, Color.DARK_RED, COLOR_YELLOW_A, shapeFlags);
960 vector ocularTransform[4];
961 ocularTransform[0] = ownerTransform[0];
962 ocularTransform[1] = ownerTransform[2];
963 ocularTransform[2] = ownerTransform[1];
966 SCR_Shape.DrawCircle(ocularTransform, m_fScopeRadius, Color.DARK_RED, COLOR_YELLOW_A, shapeFlags);
969 vector ocularHorizontal[2];
970 vector ocularSide = ownerTransform[0] * m_fScopeRadius;
971 ocularHorizontal[0] = ocularTransform[3] + ocularSide;
972 ocularHorizontal[1] = ocularTransform[3] - ocularSide;
974 vector ocularVertical[2];
975 vector ocularUp = ownerTransform[1] * m_fScopeRadius;
976 ocularVertical[0] = ocularTransform[3] - ocularUp;
977 ocularVertical[1] = ocularTransform[3] + ocularUp;
979 Shape.CreateLines(Color.DARK_RED, shapeFlags, ocularHorizontal, 2);
980 Shape.CreateLines(Color.DARK_RED, shapeFlags, ocularVertical, 2);
983 vector eyeTransform[4]
985 Shape.CreateArrow(eyeTransform[3], ocularTransform[3], m_fScopeRadius* 0.3, Color.DARK_CYAN, shapeFlags);
986 Shape.CreateSphere(Color.DARK_CYAN, shapeFlags, eyeTransform[3], 0.001);
991 protected static bool s_PIPDiagRegistered;
994 protected void InputFloatClamped(inout
float value,
string label,
float min,
float max,
int pxWidth = 100)
996 DbgUI.InputFloat(label, value, pxWidth);
997 value = Math.Clamp(value, min, max);
1001 protected void DrawDiagWindow()
1003 DbgUI.Begin(
"2DPIPSights");
1005 InputFloatClamped(m_fCenterDistance,
"m_fCenterDistance", -0.2, 0.2);
1006 InputFloatClamped(m_fDistanceMoveNear,
"m_fDistanceMoveNear", 0.0, 1.0);
1007 InputFloatClamped(m_fDistanceMoveFar,
"m_fDistanceMoveFar", 0.0, 1.0);
1008 InputFloatClamped(m_fBasicParallax,
"m_fBasicParallax", 0.0, 2.0);
1009 InputFloatClamped(m_fMaxParallax,
"m_fMaxParallax", 0.0, 2.0);
1010 InputFloatClamped(m_fCenterOffsetX,
"m_fCenterOffsetX", -90.0, 90.0);
1011 InputFloatClamped(m_fCenterOffsetY,
"m_fCenterOffsetY", -90.0, 90.0);
1012 InputFloatClamped(m_fCurrentCameraPitch,
"m_fCurrentCameraPitch", -90.0, 90.0);
1013 InputFloatClamped(m_fScopeRadius,
"m_fScopeRadius", -90.0, 90.0);
1014 InputFloatClamped(m_fReticlePIPScale,
"m_fReticlePIPScale", 0.01, 100.0);
1015 InputFloatClamped(m_fObjectivePIPEdgeMin,
"m_fObjectivePIPEdgeMin", 0.0, 10.0);
1016 InputFloatClamped(m_fObjectivePIPEdgeMax,
"m_fObjectivePIPEdgeMax", 0.0, 10.0);
1017 InputFloatClamped(m_fVignetteParallaxScale,
"m_fVignetteParallaxScale", -100.0, 100.0);
1025 void SCR_2DPIPSightsComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
1028 if (!s_PIPDiagRegistered)
1030 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_WEAPONS_PIP_SIGHTS,
"",
"Show PIP settings diag",
"Weapons");
1031 s_PIPDiagRegistered =
true;
1038 void ~SCR_2DPIPSightsComponent()
1043 m_pMaterial.Release();
1051 SetPIPEnabled(
false);