Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. public float? Intersects(Rectangle rectangle, Ray ray)
  2. {
  3. float num = 0f;
  4. float maxValue = float.MaxValue;
  5. if (Math.Abs(ray.Direction.X) < 1E-06f)
  6. {
  7. if ((ray.Position.X < rectangle.Left) || (ray.Position.X > rectangle.Right))
  8. {
  9. return null;
  10. }
  11. }
  12. else
  13. {
  14. float num11 = 1f / ray.Direction.X;
  15. float num8 = (rectangle.Left - ray.Position.X) * num11;
  16. float num7 = (rectangle.Right - ray.Position.X) * num11;
  17. if (num8 > num7)
  18. {
  19. float num14 = num8;
  20. num8 = num7;
  21. num7 = num14;
  22. }
  23. num = MathHelper.Max(num8, num);
  24. maxValue = MathHelper.Min(num7, maxValue);
  25. if (num > maxValue)
  26. {
  27. return null;
  28. }
  29. }
  30. if (Math.Abs(ray.Direction.Y) < 1E-06f)
  31. {
  32. if ((ray.Position.Y < rectangle.Top) || (ray.Position.Y > rectangle.Bottom))
  33. {
  34. return null;
  35. }
  36. }
  37. else
  38. {
  39. float num10 = 1f / ray.Direction.Y;
  40. float num6 = (rectangle.Top - ray.Position.Y) * num10;
  41. float num5 = (rectangle.Bottom - ray.Position.Y) * num10;
  42. if (num6 > num5)
  43. {
  44. float num13 = num6;
  45. num6 = num5;
  46. num5 = num13;
  47. }
  48. num = MathHelper.Max(num6, num);
  49. maxValue = MathHelper.Min(num5, maxValue);
  50. if (num > maxValue)
  51. {
  52. return null;
  53. }
  54. }
  55.  
  56. return new float?(num);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement