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.

enter image description here

I have a 3D Model like above in which i want to rotate it from a given location(pointed in red) but I can only rotate it from the middle. How can I rotate it from a custom point.

Edit:

I successfully able to rotate the model from the below position by getting the radius of the model and applying it to the world matrix

        Vector3 point = new Vector3(-radius, 0, 0);
        world = Matrix.CreateTranslation(-radius, 0, 0);

But now I cannot change the position of the object and it always centered in middle of the screen. I think that's because i applied the above code. How can I place it anywhere I want?

share|improve this question
2  
I think that it's similar to this: gamedev.stackexchange.com/questions/20056/… –  zacharmarz Nov 23 '11 at 11:04
add comment

3 Answers 3

up vote 2 down vote accepted

Finally i was able to do that,

    Matrix rotation = Matrix.Identity; 

Inside the constructor get the radius and make it minus. because originally it was set to Matrix.Identity

    rotation = Matrix.CreateTranslation(-radius, 0, 0);
share|improve this answer
add comment

You have to bring the point you want to rotate to the (0,0,0) position and then apply the rotation.

share|improve this answer
    
By point you mean the world coordinate? can u post some sample code –  Nips Nov 23 '11 at 11:13
1  
Yes, I mean translate the world coordinates of the point you wish to be your center of rotation to the origin ( 0,0,0 ). The sample code would be exactly what Dan answered. What you have to do (the concept is much more important than the code) is realize that the center of your object is in the (0,0,0) (that's why it rotates on it's own axis, because it is standing in the axis of rotation). Then to bring one corner of it to the origin you have to translate HALF of the object towards it. Ok my english is bad, I hope you understand what I'm trying to tell you. –  mikidelux Nov 23 '11 at 11:26
add comment

You have to translate your custom point to the (0,0,0) and then rotate it from there. If your box is 2 x 5 x 2 and you wanted to rotate it over de the X axis, if were using OpenGL you could do something like this

glTranslatef(-1.0f,-2.5f,-1.0f);
glRotatef(rot, 1.0, 0.0, 0.0);
share|improve this answer
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.