OpenGL API Specifications
Documents and Learning ResourcesSupport Libraries and FrameworksFunction Libraries and GeneratorsThis list contains some basic resources for getting started with, and developing for, OpenGL 3.0 and onwards. Contact your forum moderator if you want to contribute to the list or have any comments.Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 07 March 2012 - 09:09 AM
Posted 07 March 2012 - 10:40 AM
Posted 07 March 2012 - 10:56 AM
He's not.Why are you using OpenGL functions to transform a bounding box?
Follow my RTS game ICBM
https://twitter.com/dpadam450
http://www.gamedev.net/blog/2202-dpadam450s-journal/
Posted 07 March 2012 - 11:15 AM
...
Is there a way to calculate coordinates in world space, based on the current modelview matrix? ...
Please notice that using the MODELVIEW matrix means that the bbox is transformed into view space but not into world space. There is nothing wrong with this in general, because collision detection can be done in any space as long as all participating bounding volumes (or whatever is used) are given in the same space. However, bounding volumes of static objects are usually given in world space, and transforming them into view space may be needless effort.Right after setting up your transforms, you can call glGetDoublev(GL_MODELVIEW_MATRIX, double[16] array). With that matrix you will have to manually loop through your Box vertices and do matrix multiplication.
Posted 07 March 2012 - 01:06 PM
The way I generally approach it is to give the box its own coordinates, and apply transformations to those manually using vectors, Matrices and quaternions.
Right after setting up your transforms, you can call glGetDoublev(GL_MODELVIEW_MATRIX, double[16] array). With that matrix you will have to manually loop through your Box vertices and do matrix multiplication.
Posted 07 March 2012 - 01:24 PM
Besides the fact that using the MODELVIEW matrix is wrong if you want to go to world space (see my post above) ... it depends on which kind of bbox you want. A so-called axis aligned bounding box (AABB) is, as the name says, axis aligned, usually with the world axes. This kind of bbox undergoes no rotation. Instead it has to be recomputed by finding the maxima and minima after scaling and rotation has been done to the model. On the other hand, the object bounding box (OBB) will be scaled and rotated like the model. Both are ways are valid.The way I generally approach it is to give the box its own coordinates, and apply transformations to those manually using vectors, Matrices and quaternions.
Right after setting up your transforms, you can call glGetDoublev(GL_MODELVIEW_MATRIX, double[16] array). With that matrix you will have to manually loop through your Box vertices and do matrix multiplication.
I had considered this, but if I were to generate the bbox, and then apply the transformation/rotation/scale to it manually, a rotated model, would result in a rotated bbox. I was under the impression that this was bad practice. Unless I am mistaken.
Alternatively, I could use the apply the matrix to the points in the model, and then calculate a bounding box, but since applying rotation requires trig, and it would be run on every single vertex on every model, each frame, I imagined it would absorb ridiculous resources. Again though, I could be mistaken here as well.
Posted 07 March 2012 - 02:06 PM
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.
Posted 07 March 2012 - 03:18 PM
Depends on how you build it. Either use AABBs like haegarr mentioned, or if you want rotated bounding boxes (probably mostly used in hitboxes) I would simply have a class that contains the model and its orientation, location and scale, and use that to set the state of both the GL objects and the Bounding box. That way you have logically seperated the two very different types of functionality, and you ensure that you're always running your calculations in the correct space.I had considered this, but if I were to generate the bbox, and then apply the transformation/rotation/scale to it manually, a rotated model, would result in a rotated bbox. I was under the impression that this was bad practice. Unless I am mistaken.
Alternatively, I could use the apply the matrix to the points in the model, and then calculate a bounding box, but since applying rotation requires trig, and it would be run on every single vertex on every model, each frame, I imagined it would absorb ridiculous resources. Again though, I could be mistaken here as well.
A sensible approach, and it'll help simplify collision detection as checking for intersection with a sphere is trivial.A bounding sphere may be an option for you here. It will certainly be easier to calculate - just position it's center at the object's position and calculate the radius from the object size and largest scale factor, done - no need to bother with rotations. They're also faster to test against the frustum, but the tradeoff is that a sphere may not be an optimal shape for all objects.
Posted 07 March 2012 - 03:57 PM
Posted 07 March 2012 - 06:46 PM
Right, what exactly do you want? If you don't want a rotated box then what else would you want? You could take your AABB and simply translate it instead of rotate it, but if your AABB is rectangular, then you cant just translate it. It really depends what you want the AABB for. Physics or Frustum culling?would result in a rotated bbox
Follow my RTS game ICBM
https://twitter.com/dpadam450
http://www.gamedev.net/blog/2202-dpadam450s-journal/
Posted 08 March 2012 - 01:28 PM
Posted 10 March 2012 - 06:00 PM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.