Jump to content
  • Advertisement
Sign in to follow this  

Getting absolute position/rotation/scale in a 2D scene graph

This topic is 2086 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

I have a simple scene graph system. Entities can have child entities, and every update on an entity pushes a matrix, applies the transforms, draws that entity and then updates the child entities, before popping the matrix again. Here's the code using OpenGL:

        glTranslatef(_position.X, _position.Y, 0);
        glRotatef(_angle, 0.0f, 0.0f, 1.0f);
        glScalef(_scale.X, _scale.Y, 0);

        for (size_t e = 0; e < _entities.size(); e++)

Now I want to be able to access an entity's absolute transformations. The caveat here is that I need to be able to do it outside the push/pop statements, so the matrices will no longer be correct. Entities have access to their parent so you can access those, but that means that every time I want to check an absolute value, I'd have to recursively go up the parents.


Does anyone have any solutions to this?

Share this post

Link to post
Share on other sites

1) Store the absolute transform with the entity

2) Use the fact that matrix multiplication of transforms e.g. (ABCD)-1 = D-1C-1B-1A-1 where X-1 is the inverse transform for X (which is trivial for scale, rotations and translations). This works for any number of composite matrix multiplications (EDIT: accuracy may be a problem though), I just used 4 as an example. Option 1 is probably best.

Edited by Paradigm Shifter

Share this post

Link to post
Share on other sites

In case you need it:


float matrix[16]


glMultMatrixf(   matrix) - apply your own transformation to the current matrix

glLoadMatrixf(  matrix) - set the current matrix for OpenGL

glGetFloatv(     GL_MODELVIEW_MATRIX, matrix) - get the current matrix from OpenGL


So you dont have to go through the push-pops if you have your matrices saved.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!