View Full Version : How do I determinate bounding box???
11-20-2001, 05:12 AM
Could some OpenGL guru answer me the following question:
I have defined some points in display list (f.e. using glVertex). How do I determinate the bounding box of these points? f.e. in Win32 API there is the following function GetRgnBox() which returns bounding box of defined region. Is there something like this in OpenGL? What is the common way to do this task??
Thanks a lot in advance,
11-20-2001, 06:03 AM
If by bounding box youm mean you want the smallest box whic will hold all the point then it easy eonugh.
Scan through them all and keep track of the biggest and smallest (b * s) x, y & z coords you come across.
The top cornaer ob the box is then (sX,sY,sZ)and the opposite is (bX,bY,bZ)
11-20-2001, 10:47 PM
Imagine that you have a set of objects and you insert them with different attitudes in the drawing. i.e. before insert each item glTranslate and glRotate is applied. To calc the bounding box I have to do the same transformations which OpenGL already has done. Why to do the same work twice?
11-21-2001, 03:21 AM
Because OpenGL is for drawing 3D-graphics and not for calculating antything a 3D-engine needs
11-21-2001, 06:59 AM
You could try using the OpenGL feedback mechanism to read the transformed vertices.
11-21-2001, 10:44 AM
It would be faster if he calculated the bb without using OpenGL. Use the algorithm that Zadkiel provided. If you need to rotate it and translate it then you should keep track of your modelview matrix so you don't need to get it from OpenGL. A good rule of thumb is to minimize any use of glGet, and if you can, eliminate it altogether.
11-21-2001, 11:04 PM
Zadkiel suggested straightforward but not elegant way to perform this task. Obviously I can scan all vertices but I also may use some glu primitives, and all of them may be rotated, scaled and transformed. I mean that indeed OpenGL knows bounding box since it performs all transformations. Again, in Win32 it is only one call to GetRgnBox() to get 2d axes aligned bounding box.
Rob The Bloke
11-23-2001, 10:07 AM
it is the best way to do it. you need to do some maths here, openGL is not a scene hierarchy and has no actual `knowledge` of what it has drawn in terms of spatial relationship between vertices & polygons. OpenGL's sole purpose is to draw primitives on screen, nothing more. Any functionality you want on top of that must be coded by yourself....
If you are using glu primitives presumably YOU know what the size is initially, and then YOU must keep track of what YOU are doing to it. OpenGL wont do anything unless you tell it to, therefore it is up to you to determine the bounding box. Sorry but there is no other way. http://www.opengl.org/discussion_boards/ubb/frown.gif
[This message has been edited by Rob The Bloke (edited 11-23-2001).]
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.