Sign in to follow this  
Regal

Rotation matrices

Recommended Posts

Hi All, I am trying to smoothly rotate and translate a 3D object from one position to other.for that I have : 3 Transformation matrices. Original transform where the object residing initially. Current transform - to where I rotate or translate the object Desired Transform - to where I want to place the object finally.. Now I can smoothly move to the desired position from the current position using some translation path calculations. I calculate the middle position(say mid) of current and desired again the middle position of current and mid,mid and desired and so on... this gives me a set of translation path between those two transforms, and can translate some what smoothly from current to desired. Like that I want a smooth rotation from the current to desired. How can I find the correct rotation matrices between the current and desired positions? Is there any way to find the transformation matrices between these two transforms instead of calculating the translation and rotation matrices separatly? Please help me.. Thanks in Advance.. Regal

Share this post


Link to post
Share on other sites

// convert matrices to quats and position vectors
Quat qDesired = Desired.ToQuat();
Quat qOriginal = Original.ToQuat();
Vec3 vDesired = Vec3(Desired.m30,Desired.m31,Desired.m32);
Vec3 vOriginal = Vec3(Original.m30,Original.m31,Original.m32);

// vary between 0 and 1 to between the original and desired Transforms
float tControl = 0;

// lerp between the start and end
Quat qCurrent = Slerp(qOriginal,qDesired,tControl);
Vec3 vCurrent = Lerp(vOriginal,vDesired,tControl);

// convert Quat and Vec3 back to matrix
Mat Current = qCurrent.ToMatrix();
Current.m30 = vCurrent.x;
Current.m31 = vCurrent.y;
Current.m32 = vCurrent.z;




Share this post


Link to post
Share on other sites
Hi Rob.. Thanks a lot... thats working..
But again a problem.. The rotation is not around the object center..
I have to correct that.. Any Suggestions??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this