0
\$\begingroup\$

I have a 3d Model that it wasn't made from the origin of the 3d program, lets say that it was built at (100, 100, 100), I know how to rotate a model, but around the model origin point, (0, 0, 0), now how can I rotate the model around its own center? In this example the (100, 100, 100) so that instead of going around the origin point (like the earth around the sun) it will rotate around its own center (like the earth rotation around its center) so I can create an effect of the earth rotating around the sun and rotating around its own center.

Here's my code:

modelTransform = (Matrix.CreateScale(3f, 3f, 3f) * Matrix.CreateRotationX(rotation) * Matrix.CreateTranslation(myModel.Position));
effect.World = transform[mesh.ParentBone.Index] * modelTransform;

with this code my earth is rotating around the sun, but I have no idea how to rotate it around its own center.

\$\endgroup\$

1 Answer 1

5
\$\begingroup\$

Translate the model back to the origin, rotate it, then translate it back. In XNA, you can do something like that with the following:

public Vector2 RotateAboutOrigin(Vector2 point, Vector2 origin, float rotation)
{
    return Vector2.Transform(point - origin, Matrix.CreateRotationZ(rotation)) + Origin;
}

Choose CreateRotationY or CreateRotationZ depending on what you're using for "up".

That will translate the object to back to the origin, rotate it, then translate it back.

\$\endgroup\$
2
  • \$\begingroup\$ What would point be? \$\endgroup\$ Dec 26, 2013 at 3:42
  • \$\begingroup\$ Since you want to move the earth back to the center of the system, the point is the position that moves the earth to the center. So, subtract the offset from the origin. If your origin is at zero, just make the offset negative, from your example, (-100, -100, -100) \$\endgroup\$
    – House
    Dec 26, 2013 at 4:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .