122 if (!s_bOpticDiagRegistered)
126 s_bOpticDiagRegistered =
true;
149 s_bToggle2DOptics = !s_bToggle2DOptics;
150 SetScope2DEnabled(!
SCR_Global.IsScope2DEnabled());
189 Print(
"Scope vignette movement is not possible due to missing widget references!",
LogLevel.WARNING);
249 CameraBase camera =
GetGame().GetCameraManager().CurrentCamera();
251 fov = camera.GetVerticalFOV();
256 else if (!forceUpdate)
277 float reticleAngularSize;
363 activationDelay =
data.GetAnimationActivationDelay();
364 enterTime =
data.GetAnimationEnterTime();
384 int deactivationDelay;
387 deactivationDelay =
data.GetAnimationDeactivationDelay();
398 if (animationSpeed > 0)
440 s_bDebugOpticsReset =
true;
446 void UpdateScale(
float reticleScale,
float vignetteScale,
float objectiveScale)
451 uiScale = workspace.DPIUnscale(workspace.GetHeight());
493 CameraManager cameraManager =
GetGame().GetCameraManager();
496 CameraBase camera = cameraManager.CurrentCamera();
498 fov = camera.GetVerticalFOV();
501 float uiHeight = workspace.DPIUnscale(workspace.GetHeight());
502 float offsetX = x * uiHeight / fov;
503 float offsetY = y * uiHeight / fov;
510 float pivotX = 0.5 - (offsetX /
size[0]);
511 float pivotY = 0.5 - (offsetY /
size[1]);
517 float pivotX = 0.5 - (offsetX /
size[0]);
518 float pivotY = 0.5 - (offsetY /
size[1]);
532 float intensity =
m_wBlur.GetIntensity();
533 intensity =
Math.Lerp(intensity, 0, timeSlice * speed);
542 m_wBlur.SetIntensity(intensity);
563 CameraManager cameraManager =
GetGame().GetCameraManager();
567 CameraBase camera = cameraManager.CurrentCamera();
572 float fov = camera.GetVerticalFOV();
630 float vignetteDistance = vignetteObjectiveOffset.Length();
639 float screenW, screenH;
640 workspace.GetScreenSize(screenW, screenH);
641 screenW = workspace.DPIUnscale(screenW);
642 screenH = workspace.DPIUnscale(screenH);
644 float pixelsPerDegree = screenH / fov;
649 float frontPaddingLeft = defaultFrontLeft + objectiveX;
653 if (frontPaddingLeft > frontEdgeRight)
654 frontPaddingLeft = frontEdgeRight + (frontPaddingLeft - frontEdgeRight) * 2;
661 float frontPaddingTop = defaultFrontTop - objectiveY;
665 if (frontPaddingTop > frontEdgeBottom)
666 frontPaddingTop = frontEdgeBottom + (frontPaddingTop - frontEdgeBottom) * 2;
673 float rearPaddingLeft = defaultRearLeft + vignetteX;
677 if (rearPaddingLeft > rearEdgeLeft)
678 rearPaddingLeft = rearEdgeLeft + (rearPaddingLeft - rearEdgeLeft) * 2;
685 float rearPaddingTop = defaultRearTop - vignetteY;
689 if (rearPaddingTop > rearEdgeBottom)
690 rearPaddingTop = rearEdgeBottom + (rearPaddingTop - rearEdgeBottom) * 2;
730 float intensity =
Math.AbsFloat(posX);
731 if (intensity >
Math.AbsFloat(posY))
732 intensity =
Math.AbsFloat(posY);
735 intensity = intensity *
data.GetMotionBlurScale();
736 if (intensity >
data.GetMotionBlurMax())
737 intensity =
data.GetMotionBlurMax();
739 m_wBlur.SetIntensity(intensity);
745 return (screenSize - layerSize) * 0.5;
749 protected static bool s_bOpticDiagRegistered;
750 protected static bool s_bToggle2DOptics;
751 protected static bool s_bDebugOptics;
752 protected static bool s_bDebugOpticsReset;
753 protected static bool s_bDebug2DOptics;
754 protected static bool s_bDebug2DOpticsReset;
755 protected static bool s_bDebugDrawReset;
756 protected static bool s_bDebugDrawCross =
true;
757 protected static bool s_bDebugDrawNotches =
true;
758 protected static bool s_bDebugDrawFieldOfView =
true;
759 protected static bool s_bDebugDrawRandomColors;
762 protected static float s_fCrossUnit = 0.05625;
763 protected static float s_fCrossRadius = 100;
766 protected static float s_fNotchesUnit = 0.05625;
767 protected static float s_fNotchesSize = 100;
768 protected static float s_fNotchesSmallLength = 5;
769 protected static float s_fNotchesSmallSpacing = 5;
770 protected static float s_fNotchesLargeLength = 10;
771 protected static float s_fNotchesLargeSpacing = 10;
774 protected static float s_fFieldOfViewUnit = 0.05625;
775 protected static float s_fFieldOfViewAngle = 100;
778 protected static int s_iLineColor;
781 protected void InputFloatClamped(inout
float value,
string label,
float min,
float max,
int pxWidth = 100)
783 DbgUI.InputFloat(label, value, pxWidth);
784 value = Math.Clamp(value, min, max);
790 if (s_bDebugOpticsReset)
792 s_bDebugOpticsReset =
false;
794 if (!SCR_Global.IsScope2DEnabled())
796 SetScope2DEnabled(
true);
797 s_bToggle2DOptics = !DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_WEAPONS_OPTICS_USE_2D);
803 if (s_bDebugDrawReset)
805 s_bDebugDrawReset =
false;
806 s_bDebugDrawCross =
true;
807 s_bDebugDrawNotches =
true;
808 s_bDebugDrawFieldOfView =
true;
809 s_bDebugDrawRandomColors =
false;
812 s_fCrossUnit = 0.05625;
813 s_fCrossRadius = 100;
816 s_fNotchesUnit = 0.05625;
817 s_fNotchesSize = 100;
818 s_fNotchesSmallLength = 5;
819 s_fNotchesSmallSpacing = 5;
820 s_fNotchesLargeLength = 10;
821 s_fNotchesLargeSpacing = 10;
824 s_fFieldOfViewUnit = 0.05625;
825 s_fFieldOfViewAngle = 100;
834 m_Optic.GetSightsTransform(sightMat,
true);
835 sightMat[3] =
m_Optic.GetSightsFrontPosition(
true);
837 m_Optic.GetOwner().GetWorldTransform(ownerMat);
838 Math3D.MatrixMultiply4(ownerMat, sightMat, sightMat);
842 CameraBase camera =
GetGame().GetCameraManager().CurrentCamera();
846 camera.GetTransform(cameraMat);
847 sightMat[0] = cameraMat[0];
848 sightMat[1] = cameraMat[1];
851 DbgUI.Begin(
"Optics", 100, 300);
853 array<string> units = {};
858 DbgUI.Text(
"________________________________________");
859 DbgUI.Check(
"OPTICS ", s_bDebugOptics);
875 if (
m_Optic && DbgUI.Button(
"LOAD OPTICS ATTRIBUTES"))
878 if (
m_Optic && DbgUI.Button(
"SAVE OPTICS ATTRIBUTES"))
892 DbgUI.Text(
"________________________________________");
893 DbgUI.Check(
"2D OPTICS ", s_bDebug2DOptics);
897 if (s_bDebug2DOptics)
908 InputFloatClamped(
m_fRollScale,
"m_fRollScale ", -100, 100);
915 DbgUI.Text(
"________________________________________");
917 if (DbgUI.Button(
"RESET DEBUG ATTRIBUTES"))
918 s_bDebugDrawReset =
true;
920 DbgUI.Check(
"RANDOM LINE COLORS ", s_bDebugDrawRandomColors);
922 if (s_bDebugDrawRandomColors)
923 s_iLineColor = s_aRandomColors.GetRandomElement();
932 DbgUI.Text(
"________________________________________");
933 DbgUI.Check(
"CROSS ", s_bDebugDrawCross);
937 if (s_bDebugDrawCross)
940 DbgUI.Combo(
"Cross units ", s_eCrossUnit, units);
942 InputFloatClamped(s_fCrossUnit,
"Custom cross unit deg", 0, 180);
944 InputFloatClamped(s_fCrossRadius,
"Cross radius ", 0, 1000);
947 float unit = DebugAngleUnitsToDegrees(s_eCrossUnit, s_fCrossUnit);
949 DebugDrawCross(sightMat, s_fCrossRadius * unit);
954 DbgUI.Text(
"________________________________________");
955 DbgUI.Check(
"NOTCHES ", s_bDebugDrawNotches);
959 if (s_bDebugDrawNotches)
962 DbgUI.Combo(
"Notches units ", s_eNotchesUnit, units);
964 InputFloatClamped(s_fNotchesUnit,
"Custom notches unit deg", 0, 180);
966 InputFloatClamped(s_fNotchesSize,
"Size ", 0, 100);
967 InputFloatClamped(s_fNotchesSmallLength,
"Small length ", 0, 100);
968 InputFloatClamped(s_fNotchesSmallSpacing,
"Small spacing ", 0, 100);
969 InputFloatClamped(s_fNotchesLargeLength,
"Large length ", 0, 100);
970 InputFloatClamped(s_fNotchesLargeSpacing,
"Large spacing ", 0, 100);
973 float unit = DebugAngleUnitsToDegrees(s_eNotchesUnit, s_fNotchesUnit);
974 DebugDrawNotches(sightMat, s_fNotchesSmallLength * unit, s_fNotchesSmallSpacing * unit, s_fNotchesSize * unit * 0.5);
975 DebugDrawNotches(sightMat, s_fNotchesLargeLength * unit, s_fNotchesLargeSpacing * unit, s_fNotchesSize * unit * 0.5);
980 DbgUI.Text(
"________________________________________");
981 DbgUI.Check(
"FIELD OF VIEW ", s_bDebugDrawFieldOfView);
985 if (s_bDebugDrawFieldOfView)
988 DbgUI.Combo(
"Field of view units ", s_eFieldOfViewUnit, units);
990 InputFloatClamped(s_fFieldOfViewUnit,
"Custom field of view unit deg", 0, 180);
992 InputFloatClamped(s_fFieldOfViewAngle,
"Field of view angle ", 0, 1000);
995 float unit = DebugAngleUnitsToDegrees(s_eFieldOfViewUnit, s_fFieldOfViewUnit);
997 DebugDrawFieldOfView(sightMat, s_fFieldOfViewAngle * unit);
1002 if (
m_Optic && s_bDebugOptics)
1005 if (
m_Optic && s_bDebug2DOptics)
1024 return reticleAngularSize;
1034 return objectiveSize;
1047 return Math.RAD2DEG * 0.001;
1053 static void DebugDrawFieldOfView(vector sightMat[4],
float angle)
1055 if (
float.AlmostEqual(angle, 0))
1059 float targetSize = Math.Tan(Math.DEG2RAD * angle * 0.5);
1061 CameraBase currentCamera =
GetGame().GetCameraManager().CurrentCamera();
1063 range = currentCamera.GetFarPlane() * 0.5;
1066 fovMat[0] = sightMat[0];
1067 fovMat[1] = sightMat[2];
1068 fovMat[2] = sightMat[1];
1069 fovMat[3] = sightMat[3] + sightMat[2] * range;
1075 protected void DebugDrawNotches(vector sightMat[4],
float length,
float spacing,
float size)
1077 if (
float.AlmostEqual(length, 0))
1080 if (
float.AlmostEqual(spacing, 0))
1083 vector opticSide = sightMat[0];
1084 vector opticUp = sightMat[1];
1085 vector opticDir = sightMat[2];
1086 vector opticPos = sightMat[3];
1089 int count = Math.Floor(
size / spacing);
1090 float notchSpacing = Math.DEG2RAD * spacing;
1091 float notchHalf = Math.Tan(Math.DEG2RAD * length * 0.5);
1093 CameraBase currentCamera =
GetGame().GetCameraManager().CurrentCamera();
1095 range = currentCamera.GetFarPlane() * 0.5;
1097 vector zeroMat[4] = sightMat;
1098 zeroMat[3] = opticPos + opticDir * range;
1100 vector notchMat[4] = zeroMat;
1101 vector notchSide = opticSide * notchHalf * range;
1102 vector notchUp = opticUp * notchHalf * range;
1107 for (
int i; i < count; i++)
1109 SCR_Math3D.RotateAround(notchMat, opticPos, opticUp, -notchSpacing, notchMat);
1110 notch[0] = notchMat[3] + notchUp;
1111 notch[1] = notchMat[3] - notchUp;
1117 for (
int i; i < count; i++)
1119 SCR_Math3D.RotateAround(notchMat, opticPos, opticUp, notchSpacing, notchMat);
1120 notch[0] = notchMat[3] + notchUp;
1121 notch[1] = notchMat[3] - notchUp;
1127 for (
int i; i < count; i++)
1129 SCR_Math3D.RotateAround(notchMat, opticPos, opticSide, -notchSpacing, notchMat);
1130 notch[0] = notchMat[3] + notchSide;
1131 notch[1] = notchMat[3] - notchSide;
1137 for (
int i; i < count; i++)
1139 SCR_Math3D.RotateAround(notchMat, opticPos, opticSide, notchSpacing, notchMat);
1140 notch[0] = notchMat[3] + notchSide;
1141 notch[1] = notchMat[3] - notchSide;
1147 protected void DebugDrawCross(vector sightMat[4],
float radius)
1149 if (
float.AlmostEqual(radius, 0))
1152 vector opticSide = sightMat[0];
1153 vector opticUp = sightMat[1];
1154 vector opticDir = sightMat[2];
1155 vector opticPos = sightMat[3];
1158 float crossRadius = Math.Tan(Math.DEG2RAD * radius * 0.5);
1160 CameraBase currentCamera =
GetGame().GetCameraManager().CurrentCamera();
1162 range = currentCamera.GetFarPlane() * 0.5;
1164 vector crossPos = opticPos + opticDir * range;
1168 cross[0] = opticPos;
1169 cross[1] = crossPos;
1173 vector crossSide = opticSide * crossRadius * range;
1174 cross[0] = crossPos + crossSide;
1175 cross[1] = crossPos - crossSide;
1179 vector crossUp = opticUp * crossRadius * range;
1180 cross[0] = crossPos + crossUp;
1181 cross[1] = crossPos - crossUp;
1185 cross[0] = crossPos - crossUp - crossSide;
1186 cross[1] = crossPos + crossUp + crossSide;
1190 cross[0] = crossPos + crossUp - crossSide;
1191 cross[1] = crossPos - crossUp + crossSide;
1196 static void SetScope2DEnabled(
bool enabled)