Advertisement
Guest User

Untitled

a guest
Jul 19th, 2016
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #define M_PI 3.141592653f
  2. #define M_PI_ON_2 (M_PI / 2.f)
  3. #define M_PI_ON_4 (M_PI / 4.f)
  4. #define M_FLT_EPSILON FLT_MIN
  5.  
  6. // Assuming you've adjusted pos to be relative to the origin of the radar and its values are float integers (cause pixels)
  7. void SquareRadarClamp(float Length, Vector2D &pos)
  8. {
  9. float LenSqr = pos.LengthSqr();
  10.  
  11. if (LenSqr <= (Length * Length * 0.5f))
  12. return;
  13.  
  14. float angle = atan2(pos.y, pos.x);
  15.  
  16. float radius = cos(M_PI_ON_4) / cos(fmodf(angle + M_PI_ON_4, M_PI_ON_2) - M_PI_ON_4);
  17.  
  18. if (LenSqr <= (radius * radius))
  19. return;
  20.  
  21. pos *= (Length * 0.5f) / (radius + M_FLT_EPSILON);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement