I'm trying to implement a basic scene graph in DirectX using C++. I am using a left child-right sibling binary tree to do this. I'm having trouble updating each node's world transformation relative to its parent (and its parent's parent etc.). I'm struggling to get it to work recursively, though I can get it to work like this:

for(int i = 0; i < NUM_OBJECTS; i++)
    // Initialize to identity matrix.

    int k = i;
    while( k != -1 )
        mObject[i].toWorldXForm *= mObject[k].toParentXForm;
        k = mObject[k].parent;

toWorldXForm is the object's world transform and toParentXForm is the object's transform relative to the parent. I want to do this using a method within my object class (the code above is in my main class). This is what I've tried but it doesn't work (only works with nodes 1 generation away from the root)

if (this->sibling != NULL)
this->toWorldXForm *= this->toParentXForm;
this->toWorldXForm *= toParentXForm;    
toParentXForm *= this->toParentXForm;
if (this->child != NULL)

Sorry if I've not been clear, please tell me if there's anything else you need to know. I've no doubt it's merely a silly mistake on my part, hopefully an outside view will be able to spot the problem.

  • \$\begingroup\$ Search for skeletal animation, they solve similar problem of propagating transformations. \$\endgroup\$
    – user712092
    Commented Aug 10, 2011 at 18:03

1 Answer 1


I believe what you are trying to do is simply stack the matrix of each child to generate the toWorldMatrix from a set of toParentMatrices?


class Object

   void GenerateWorldMats();

   cMatrix toWorld;
   cMatrix toParent;

   Object* mParent;
   Object** mChildren;
   uint32 mNumChildren;

You can...

void Object::GenerateWorldMats()  
   if(mParent == NULL)
      toWorld = mParent.toWorld * toParent;  //Or Swapped order depending on pre or post mult

   for(int i = 0; i < mNumChildren; ++i)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .