4
\$\begingroup\$

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. enter image description here

And i need this: enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ The order of your matrix multiplications matters. Translate first. \$\endgroup\$
    – MichaelHouse
    Feb 19 '13 at 16:40
  • \$\begingroup\$ I tried but it is not better damage... \$\endgroup\$ Feb 19 '13 at 17:12
  • \$\begingroup\$ 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. \$\endgroup\$ Feb 19 '13 at 17:19
5
\$\begingroup\$

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)
\$\endgroup\$
2
  • \$\begingroup\$ 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.. \$\endgroup\$ Feb 19 '13 at 21:58
  • 1
    \$\begingroup\$ Try this -> Matrix.CreateTranslation(-rotationCenter) * Matrix.CreateScale(scale) * Matrix.CreateRotationY(rotationLoot) * Matrix.CreateTranslation(translation) \$\endgroup\$
    – Blau
    Feb 20 '13 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.