Jump to content
  • Advertisement
Sign in to follow this  
Regal

Rotation matrices

This topic is 3562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

// 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
Wrap the rotation by 2 translations: First translate the object so that the desired center is moved to zero, then rotate, then translate the object back.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!