Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. RECT rect{};
  2. auto collideable = ent->GetCollideable();
  3.  
  4. if (!collideable)
  5. return rect;
  6.  
  7. auto min = collideable->OBBMins();
  8. auto max = collideable->OBBMaxs();
  9.  
  10. const matrix3x4_t& trans = ent->m_rgflCoordinateFrame();
  11.  
  12. Vector points[] = {
  13. Vector(min.x, min.y, min.z),
  14. Vector(min.x, max.y, min.z),
  15. Vector(max.x, max.y, min.z),
  16. Vector(max.x, min.y, min.z),
  17. Vector(max.x, max.y, max.z),
  18. Vector(min.x, max.y, max.z),
  19. Vector(min.x, min.y, max.z),
  20. Vector(max.x, min.y, max.z)
  21. };
  22.  
  23. Vector pointsTransformed[8];
  24. for (int i = 0; i < 8; i++) {
  25. Math::VectorTransform(points[i], trans, pointsTransformed[i]);
  26. }
  27.  
  28. Vector screen_points[8] = {};
  29.  
  30. for (int i = 0; i < 8; i++) {
  31. if (!Math::WorldToScreen(pointsTransformed[i], screen_points[i]))
  32. return rect;
  33. }
  34.  
  35. auto left = screen_points[0].x;
  36. auto top = screen_points[0].y;
  37. auto right = screen_points[0].x;
  38. auto bottom = screen_points[0].y;
  39.  
  40. for (int i = 1; i < 8; i++) {
  41. if (left > screen_points[i].x)
  42. left = screen_points[i].x;
  43. if (top < screen_points[i].y)
  44. top = screen_points[i].y;
  45. if (right < screen_points[i].x)
  46. right = screen_points[i].x;
  47. if (bottom > screen_points[i].y)
  48. bottom = screen_points[i].y;
  49. }
  50. return RECT{ (long)left, (long)top, (long)right, (long)bottom };
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement