Jump to content
  • Advertisement
Sign in to follow this  
ElPeque2

OpenGL On spatial transforms, OpenGL and the game's 3d logic.

This topic is 4006 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just for the hell of it (to learn), im writting my own code to represent the "scene". This implies a parent/child treeish relationship in which every object has a local transformation that represents its location and rotation relative to its parent's base (coordinate system). So the rendering in opengl would go something like... each object in turn (parent first, and then all its children) push their transformations to the transformation stack (so each object's final transformation is the combination of the tranformations of all its ancestors, in the right order), then draws itself and then pops the transformation after its last child is done. All that would be done at the time i want to do a "render". The problem is that i also need to have all that spatial representation for other things, like collition detection, mouse pointer picking, ai, etc. Maybe all this is calculated many times before any render occurs. For example, at some moment during the "update(elapsedtime);" of an object, it needs to know it's world coordinates, not just the local ones. So what should be done? Am i supposed to make all those matrix multiplications for each object myself, keep a copy of the whole transformation stack up to that point, use them for whatever game logic i need, and then just load them into OpenGL (without using the stack, it would mean calculating twise, right?) for drawing? What does everyone else do? I'd appreciate any suggestions or ideas. If i didn't explain my doubt enough, please tell me and i'll try harder to explain myself. please help :) Thanks a lot in advance.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by ElPeque2
The problem is that i also need to have all that spatial representation for other things, like collition detection, mouse pointer picking, ai, etc. Maybe all this is calculated many times before any render occurs.

For example, at some moment during the "update(elapsedtime);" of an object, it needs to know it's world coordinates, not just the local ones.

So what should be done? Am i supposed to make all those matrix multiplications for each object myself, keep a copy of the whole transformation stack up to that point, use them for whatever game logic i need, and then just load them into OpenGL (without using the stack, it would mean calculating twise, right?) for drawing?

What does everyone else do?

Yes, a few transforms are definetly needed.
Static data is obviously pre-transformed once while for dynamic working on low-detail model usually suffices.

Don't even think at transforming the vertices yourself and then fetch to GL. Besides the fact this would generate a ton of dynamic data (better to re-compute everything on the GPU again) you stand no chance of beating vertex transform performance (let alone the vertex shader issues)!

Share this post


Link to post
Share on other sites
Quote:
Original post by ElPeque2
So what should be done? Am i supposed to make all those matrix multiplications for each object myself, keep a copy of the whole transformation stack up to that point, use them for whatever game logic i need, and then just load them into OpenGL (without using the stack, it would mean calculating twise, right?) for drawing?

What does everyone else do?



Note: I'm assuming you are doing this per object, not per vertex (unlike the previous response).

I think the best option is to compute the transforms yourself and then upload the matrices directly instead of building them using the matrix stack during rendering. As you have noticed, there are many places where you need this data outside of OGL. Most implementations of OGL don't use hardware to calculate the matrix math anyway (and support for this is probably being dropped in 3.0) so you are potentially going to be just as fast doing the math outside the driver, and this way you can even cache the results if the matrix isn't changing from frame to frame.

Obviously you don't usually want to do this per vertex as hardware is used to do the vertex transforms and you wouldn't be able to use hardware VBOs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!