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'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

share|improve this question
add comment

2 Answers

up vote 8 down vote accepted

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.

share|improve this answer
    
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. –  icaptan Nov 22 '11 at 15:43
add comment

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

share|improve this answer
    
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. –  icaptan Nov 22 '11 at 9:41
    
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. –  Takumi Nov 22 '11 at 12:02
    
Thanks Takumi :) It helped me already, i've learned CreateFromAxisAngle and after all i've solved it same with the Steve H's answer. –  icaptan Nov 22 '11 at 15:42
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.