Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

1 Answer

up vote 5 down vote accepted

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)
share|improve this answer
    
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
1  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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