Tuesday, March 5, 2019

XNA advanced rotation 3D


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



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...