Northern
Northern

Reputation: 189

How i can calculate 2d bounding box with 3d transformation

I'm working on opengl project. I set up perspective projection and render a transformed rectangle (rotated, scaled)

How i can calculate rectangle's bounding box (rectangle position,size)

Thank you

Upvotes: 1

Views: 2644

Answers (1)

Kieren Johnstone
Kieren Johnstone

Reputation: 41993

You'd run the rectangle through the same matrices that OpenGL does to transform the 3D points into 2D screen-space ones. Get your input vectors, multiply them by any that you want to apply to the object, ModelView matrix, Projection matrix, then you have screen-space coords. Then check whether the resulting coordinates are on-screen, then you can calculate the minimum/maximum X and Y coordinates, and you have your bounding rectangle.

See also here (9.100), if you've got the GLU utility library functions available:

http://www.opengl.org/resources/faq/technical/transformations.htm

Hope that helps.

Upvotes: 1

Related Questions