# 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.

Link to example ->

You can reference the game here. There is a tank that has articulated turrets, Anti aircraft battery that rotates on its base, and planes with articulated propellers. The bullet ejection points are accurate and as depicted in screenshot below.

• Isn't what you described still drawing from a parent object to a child object and figuring out the world position for the child relative the parent? What I want to achieve is (for the example), starting off by drawing a machinegun at say 0,0,0, and then call drawing for it's parent wing, which will be transformed according to the attachment position of the machinegun, and also include rotation and scale. and keep going up. – jsmars Feb 28 '18 at 15:05
• In that case you could reverse the entire process starting with the identity matrix Or a local space matrix for the position scale rotation. You would need to invert the attachment matrix to Get the parent to be placed in your local space in the orientation you want. – ErnieDingo Feb 28 '18 at 19:34

The "simple Animation Sample" that MS offered in their educational site for XNA demonstrates how that is done. http://xbox.create.msdn.com/en-US/education/catalog/sample/simple_animation

It uses a tank model but basically the tank's hatch and gun barrel are children of the turret which is a child of the tank body and it shows how to move the children while moving or not moving the parents.

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

• This isn't really what I'm looking for. All Model.CopyAbsoluteBoneTransformsTo() does is copy the mesh components transforms, which they then alter and draw separately. What I'd like to do, taking this sample, would be to draw one of the components, say the animated wheel, see it stand completely still, and see the rest of the tank spinning around the wheel. As if I where standing on the wheel, and I don't want to do this by altering the camera matrix to match the wheel. – jsmars Nov 4 '16 at 7:08