| 63 | } |
| 64 | |
| 65 | void CrosshairData::Update(const Vector3& targetPos, bool isActive, bool doPulse) |
| 66 | { |
| 67 | constexpr auto ROT = ANGLE(2.0f); |
| 68 | constexpr auto ALIGN_ANGLE_STEP = ANGLE(360.0f / SEGMENT_COUNT); |
| 69 | constexpr auto SCALE_PRIMARY = 1.0f; |
| 70 | constexpr auto SCALE_PERIPHERAL = 0.8f; |
| 71 | constexpr auto RADIUS_SCALE_PRIMARY = 0.5f; |
| 72 | constexpr auto RADIUS_SCALE_PERIPHERAL = 0.25f; |
| 73 | constexpr auto PULSE_SCALE_MAX = 1.3f; |
| 74 | constexpr auto MORPH_LERP_ALPHA = 0.3f; |
| 75 | constexpr auto ORIENT_LERP_ALPHA = 0.1f; |
| 76 | constexpr auto RADIUS_LERP_ALPHA = 0.2f; |
| 77 | |
| 78 | if (Position.has_value()) |
| 79 | StoreInterpolationData(); |
| 80 | |
| 81 | // Update active status. |
| 82 | IsActive = isActive; |
| 83 | |
| 84 | // Update position. |
| 85 | Position = g_Renderer.Get2DPosition(targetPos); |
| 86 | |
| 87 | // Update orientation. |
| 88 | if (IsPrimary) |
| 89 | { |
| 90 | Orientation += IsActive ? ROT : (ROT * 2); |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | short closestAlignAngle = round(Orientation / ALIGN_ANGLE_STEP) * ALIGN_ANGLE_STEP; |
| 95 | Orientation = (short)round(Lerp(Orientation, closestAlignAngle, ORIENT_LERP_ALPHA)); |
| 96 | } |
| 97 | |
| 98 | // Update scale. |
| 99 | if (IsActive) |
| 100 | { |
| 101 | float cameraDist = Vector3::Distance(Camera.pos.ToVector3(), targetPos); |
| 102 | float scaleTarget = GetScale(cameraDist) * (IsPrimary ? SCALE_PRIMARY : SCALE_PERIPHERAL); |
| 103 | |
| 104 | Scale = Lerp(Scale, scaleTarget, MORPH_LERP_ALPHA); |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | Scale = Lerp(Scale, 0.0f, MORPH_LERP_ALPHA / 4); |
| 109 | } |
| 110 | |
| 111 | // Update color. |
| 112 | if (!IsActive) |
| 113 | { |
| 114 | ColorTarget = CrosshairData::COLOR_GRAY; |
| 115 | ColorTarget.w = 0.0f; |
| 116 | } |
| 117 | Color = Vector4::Lerp(Color, ColorTarget, MORPH_LERP_ALPHA); |
| 118 | |
| 119 | float radiusScaleTarget = IsPrimary ? RADIUS_SCALE_PRIMARY : RADIUS_SCALE_PERIPHERAL; |
| 120 | if (!IsActive) |
| 121 | radiusScaleTarget = RADIUS_SCALE_PERIPHERAL; |
| 122 |
nothing calls this directly
no test coverage detected