1
\$\begingroup\$

I'm able to rotate any model with any angle I want, where I can not rotate my model around a given point.

e.g: My model rotates from the origin assigned in its .fpx file. I want it to rotate related to a point of its bottom plane, so that it is animated as falling

\$\endgroup\$

2 Answers 2

8
\$\begingroup\$

Here is a way to rotate a Matrix (model) around a specific point :

Vector3 pointToRotateAround = modelWorldTransform.Translation +
                              modelWorldTransform.Down * modelHalfHeight; // modelHalfHeight is meant to represent distance from fbx origin to feet plane

modelWorldTransform.Translation -= pointToRotateAbout;
modelWorldTransform *= Matrix.CreateFromAxisAngle(axis, angle);//angle is the angle to rotate just this frame only
modelWorldTransforms.Translation += pointToRotateAround;

pointToRotateAround can be any Vector3 representing a point in 3d space. Make certain that the axis in the Create Method is unit length or your matrix will distort.

\$\endgroup\$
1
  • \$\begingroup\$ thanks, i've logined to write the answer (i'm quiting to home back), where i see the answer :) same logic works for a single point, too. \$\endgroup\$
    – icaptan
    Commented Nov 22, 2011 at 15:43
0
\$\begingroup\$

You can use CreateFromAxisAngle method from Matrix class. This method will create a rotation matrix about a specific axis for a given angle.

http://msdn.microsoft.com/en-us/library/bb195606(v=XNAGameStudio.40).aspx

\$\endgroup\$
3
  • \$\begingroup\$ I could not use it, i've tried and still trying to handle it, but it does not work. is there any sample using that ? it rotates already from its origin does not matter around a point or axis. \$\endgroup\$
    – icaptan
    Commented Nov 22, 2011 at 9:41
  • \$\begingroup\$ Finally CreateFromAxisAngle isn't the solution to your problem, I responded too quickly. If you want to rotate around a specific point p, first translate the view matrix of your model to -p, do the rotation and then translate to p. \$\endgroup\$ Commented Nov 22, 2011 at 12:02
  • \$\begingroup\$ Thanks Takumi :) It helped me already, i've learned CreateFromAxisAngle and after all i've solved it same with the Steve H's answer. \$\endgroup\$
    – icaptan
    Commented Nov 22, 2011 at 15:42

You must log in to answer this question.

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