# Drawing & transforming matrices upwards

I'm drawing a hierarchy of 3D objects in C# XNA where each objects has a transform that holds position, rotation and scale.

I get my expected results If I draw my objects from my root node in this fashion:

public void Draw(Matrix world, Matrix view, Matrix proj)
{
foreach (var item in Children)
item.Draw(world * item.Transform, view, proj);
}


However, I want to draw my objects by starting with a child node, drawing upwards, and achieving drawing from a child-object relative space. How would I do this?

I've tried a number of ways or drawing the parent nodes with inverted transform, but I'm not getting the correct results, I'm guessing I need to take care of the multiplication order, but I don't know what that is if I'm going up instead of down.

• I guess the parent would be drawn with the childs inverted matrix. Have you tried that? – Stefan Agartsson Nov 3 '16 at 13:52
• Yeah I tried that, it sort of works, but the objects spin around like crazy, so it seems the multiplication order is screwed up, I've tried lots of different variations but can't seem to find the right one. – jsmars Nov 3 '16 at 15:50
• This seems like an XY problem (you try to achieve X, so you do Y, but it doesn't work), what do you want to achieve with it – Bálint Mar 20 '17 at 9:54

Having done a system exactly like this. It's basically am ordering issue as you seem to have most of the pieces in place. The part you need to do though is understand their is another multiplication you need to do and that's the attachment point.

Will do this as a basic step process for now.

1. Create a world transform for model x. Scale rotate translate.
2. In local model space. Create a matrix translation for your attachment point for your child object. Multiply this with your x transform to get where your child would be in world space.
3. Create a scale rotate transform for the model in ITS local space. Should be the identity matrix most likely. But if its a tank turret then its the rotarion matrix.
4. Multiply child model matrix by the attachment matrix.
5. Repeat 3 and 4 for every subsequent child.

The use of this technique is not limited to the model rendering but also for things such as particle attachment points and barrel ejection points on guns etc.

A big part of that is the Model.CopyAbsoluteBoneTransformsTo() method