# Rotate 3D Model from a custom position

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?

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);


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

• By point you mean the world coordinate? can u post some sample code Commented Nov 23, 2011 at 11:13
• 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. Commented Nov 23, 2011 at 11:26

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);