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:
glPushMatrix(); glTranslatef(_position.X, _position.Y, 0); glRotatef(_angle, 0.0f, 0.0f, 1.0f); glScalef(_scale.X, _scale.Y, 0); Draw(); for (size_t e = 0; e < _entities.size(); e++) _entities[e]->Update(); glPopMatrix();
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?