简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM