Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RECT rect{};
- auto collideable = ent->GetCollideable();
- if (!collideable)
- return rect;
- auto min = collideable->OBBMins();
- auto max = collideable->OBBMaxs();
- const matrix3x4_t& trans = ent->m_rgflCoordinateFrame();
- Vector points[] = {
- Vector(min.x, min.y, min.z),
- Vector(min.x, max.y, min.z),
- Vector(max.x, max.y, min.z),
- Vector(max.x, min.y, min.z),
- Vector(max.x, max.y, max.z),
- Vector(min.x, max.y, max.z),
- Vector(min.x, min.y, max.z),
- Vector(max.x, min.y, max.z)
- };
- Vector pointsTransformed[8];
- for (int i = 0; i < 8; i++) {
- Math::VectorTransform(points[i], trans, pointsTransformed[i]);
- }
- Vector screen_points[8] = {};
- for (int i = 0; i < 8; i++) {
- if (!Math::WorldToScreen(pointsTransformed[i], screen_points[i]))
- return rect;
- }
- auto left = screen_points[0].x;
- auto top = screen_points[0].y;
- auto right = screen_points[0].x;
- auto bottom = screen_points[0].y;
- for (int i = 1; i < 8; i++) {
- if (left > screen_points[i].x)
- left = screen_points[i].x;
- if (top < screen_points[i].y)
- top = screen_points[i].y;
- if (right < screen_points[i].x)
- right = screen_points[i].x;
- if (bottom > screen_points[i].y)
- bottom = screen_points[i].y;
- }
- return RECT{ (long)left, (long)top, (long)right, (long)bottom };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement