# How rotate a 3D cube at its center XNA?

I try to rotate a 3D cube on itself from its center, not the edge. Here is my code used.

``````public rotatemyCube()
{
...
Matrix newTransform = Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation);
my3Dcube.Transform = newTransform;
....

public void updateRotateCube()
{
rotationLoot += 0.01f;
}
``````

My cube rotate fine, but not from the center. Here is a schematic that explains my problem.

And i need this:

-
The order of your matrix multiplications matters. Translate first. – Byte56 Feb 19 '13 at 16:40
I tried but it is not better damage... – Mehdi Bugnard Feb 19 '13 at 17:12
Is my3Dcube your own 3D model (created in an external tool)? Your vertices might be in the 0-1 range instead of -.5-.5 range. So like Byte56 said, translate your Cube so that the center is at 0,0. before your rotate. – Luis Estrada Feb 19 '13 at 17:19
ok thanks i'm going try this – Mehdi Bugnard Feb 19 '13 at 20:56

If you want to rotate an object around.Center must be at the point(0,0,0) To achieve that simply Translate the object to point(0,0,0) Rotate and Translate back

``````example:
Translate(0,0,-1)
Rotate(90)
Translate(0,0,1)
``````
-
i have try this :var rotationCenter = new Vector3(0.2f, 0.2f, 0.2f); Matrix transformation = Matrix.CreateTranslation(translation - rotationCenter) * Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation + rotationCenter) ; but not work.. – Mehdi Bugnard Feb 19 '13 at 21:58
Try this -> Matrix.CreateTranslation(-rotationCenter) * Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation) – Blau Feb 20 '13 at 0:41
thanks amigo ^^ all it's work fine now – Mehdi Bugnard Feb 20 '13 at 8:09