# Matrices in a scene

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

## Recommended Posts

I'm working my way through a arcade flight sim and my objects are going to have sub-objects. I can get the sub-objects onto the screen. But in order to do collision detection and possibly culling, I need to get their world position. Up until now to display them, I just glPushMatrix() and glPopMatrix(). Do I need to set aside a world transformation matrix of the sub-object or can I just extract it for the current Matrix?

##### Share on other sites
You can get the current transformation matrix with the following code:
float modelview_matrix[16];glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);

This way the objects' positions can be transformed into world-space by multiplying them by that matrix.

##### Share on other sites
Hmmmm... i am in a similar situation, and im not sure how well this method will work. Currently, at each frame, i first update the objects based on their properties (velocity, etc.), check for collisions and reposition the objects that are colliding, and then draw all of them. The problem is that the OpenGL matrices for each object is calculated as i draw them. However, i need them for collision detection, which occurs *before* i draw. So if i grab the matrices from OpenGL, they will all be one frame behind.

Im sure many other ppl have had this problem too. What were your solutions?

##### Share on other sites
Implement your own matrix system (possibly trasnposed-GL-compatible :).
Not so hard ...google for Matrix and Quaternion FAQ

##### Share on other sites
Thanks for the discussion on the scenegraph. I was more focused on the subobjects. As the inputs will be by keystroke where I purposely change the main orientation of the plane and by AI functions, I'm going to have to do my own system of tracking the Matrices of the sub-objects.
I'll probably have pointers to parent matrices and maybe Identify the level of graph where the subobject is located.
Going to have to review my math library for this stuff.
Been useful.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634123
• Total Posts
3015658
×