# Some questions about positioning/matricis/rotations

This topic is 2487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys...

Can someone please explain to me how the 'world matrix' relates to objects, I understand that a matrix is a equation/formula for translating/rotating/scaling operations. However, a model does not have a 'rotation' vector as far as I can see, so what is the matrix acting/translating on? Wouldeach object/model have it's own world matrix?

When you have a model you would like to rotate, should one keep a 'rotationX/Y/Z' variable in radion/degrees? How is the rotation 'state' stored?

Second question, I've encountred times when positioning my camera that if I have say the camera position vector3 set as (0, 5, 0), It won't display anytihng on screen. However if I add just a tiny increment to the x/z component the models will show on screen? Why does this happen?

Thank you!

##### Share on other sites
a "world matrix" moves an objects vertices from their local/object space (the space you "modeled" the program in, using a 3d modeling program for example) to "world space". All objects have their own world matrix, which translates, rotates, and scales the object relative to all the other objects in the scene. Don't forget that the order in which you multiply your transformation matrices together DOES matter, since each transformation matrix does the transformation around the point (0,0,0). for example, if you do this:

objectWorldMatrix = Rotation * Translation;

The the object will rotate (spin) around the point (0,0,0) (assuming you modeled the object around the point 0,0,0 in the modeling program), then it will move the object to another location in the world. but if you did:

objectWorldMatrix = Translation * Rotation;

Then the object will be moved to another location in the world, and then the rotation is applied and the object is again rotated around (0,0,0), which will now create an "orbiting" effect, instead of just spinning on it's own axis.

The way you store rotations depends on how you do them really. There are a couple different functions to get a rotation matrix, something like rotate only around the x axis, rotate only around the y axis, or rotate around all axes. usually they take the rotation in degrees radians. So if you are going to rotate your object every frame, you will want to keep track of the degrees that it has rotated, and add to the degrees every frame. You'll want to check to make sure if the degrees are greater than 3.14 and change it back to 0, and if they are smaller than 0, change them to 3.14. You will be creating a fresh rotation matrix each frame, so its the degrees that you want to keep track of. There are other ways to rotate objects too like using quaternions for example.

##### Share on other sites

"All objects have their own world matrix, which translates, rotates, and scales the object relative to all the other objects in the scene."
So I need to create a matrix for each model?

Where is the monkey's matrix in this example? Is it creating a matrix automatically?
In which case if I were to add a second object/model, how would I modify the below?
Matrix[] transforms = new Matrix[monkey.Bones.Count]; float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; monkey.CopyAbsoluteBoneTransformsTo(transforms); Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); Matrix view = Matrix.CreateLookAt(cameraPosition, cameraView, Vector3.Up); foreach (ModelMesh mesh in monkey.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.View = view; effect.Projection = projection; effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(monkeyPosition); } mesh.Draw(); }

##### Share on other sites
If i am reading correctly,

Matrix.CreateTranslation(monkeyPosition)

That is the monkeys matrix.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633709
• Total Posts
3013481
×