Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define M_PI 3.141592653f
- #define M_PI_ON_2 (M_PI / 2.f)
- #define M_PI_ON_4 (M_PI / 4.f)
- #define M_FLT_EPSILON FLT_MIN
- // Assuming you've adjusted pos to be relative to the origin of the radar and its values are float integers (cause pixels)
- void SquareRadarClamp(float Length, Vector2D &pos)
- {
- float LenSqr = pos.LengthSqr();
- if (LenSqr <= (Length * Length * 0.5f))
- return;
- float angle = atan2(pos.y, pos.x);
- float radius = cos(M_PI_ON_4) / cos(fmodf(angle + M_PI_ON_4, M_PI_ON_2) - M_PI_ON_4);
- if (LenSqr <= (radius * radius))
- return;
- pos *= (Length * 0.5f) / (radius + M_FLT_EPSILON);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement