# in XNA 4.0, How to get the matrix or Vector3 of a model?

I'm trying, for many days, to get the Matrix or the Vector3 of my 3D model, I don't want to use the World matrix because I need first to idenfy the axes of my object for animation (= rotation of a second object around my first object).

If you have an idea or a tutorial for this ?

Many thanks,

Jeangil

• I'm not sure what you are asking. Are you asking how to get the vertices of your 3D model? Jul 4 '11 at 14:29
• Do you have the orientation and the position of your model? Now you want to put that in a 4x4 matrix? Jul 4 '11 at 14:40
• Please elaborate on the problem you are trying to solve. Jul 4 '11 at 15:48
• Sorry to be not very clear, but it's not very clear in my mind.I want to know the orientation, the axis(= means the UP, Right and Forward vector) of my model at any time. Is it possible with Matrix and vector3 ? Thank you in advance Jeangil Jul 4 '11 at 18:06

The "matrix" of an object in model space with no transformations applied is simply:

Matrix.Identity


Similarly the position would simply be:

Vector3.Zero


The "world" matrix is responsible for transforming an object that is in model space into world space.

To make object A orbit object B you could do this with object B's world matrix. Simply apply an appropriate orbit matrix (translation then rotation), followed by object B's world matrix, to object A. This will then be object A's world matrix.

Alternately: you could take object B's world matrix and use the appropriate Matrix properties: Translation to get the position and Forward, Left, Up, etc (MSDN), to get the appropriate axes for constructing the series of transformations to orbit object B.

• Thank you, Andrew I am going to read and try what you have sent to me. Jeangil Jul 4 '11 at 18:11

It sounds like you may be looking for the bone transforms, which define transforms for each mesh in a model relative to the model's coordinate system. This lets you, say, rotate a car wheel about its own axis, and keep it correctly positioned relative to the car chassis.

var model = Content.Load<Model>(@"mymodel")


You can easily get to the bone transforms with

model.CopyAbsoluteBoneTransformsTo(transforms)


This XNA App Hub sample demonstrates loading a tank model, and having its wheels and turret move relative to the model.

The basic idea is that different meshes (in this case, the wheels and tank) are connected via "bones." Bones represent a hierarchical relationship between model elements (despite the name, they are not exclusive to animal or human models).

In your 3D modeling app of choice, you define bones connecting child meshes (wheels) to parent meshes (the tank chassis), and define transforms in the child mesh's space that transform the mesh relative to its parent.

By using the .CopyAbsoluteBoneTransforms() method, you can quickly concatenate the child's transforms with the parent. This has the effect of putting the child mesh in the parent's coordinate space, so that you'll get a valid result when you multiply the result by the view and projection matrices.