Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

nhatkthanh

how do I achieve this type of transformation?

This topic is 5241 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

suppose I have an arbitrary axis (a vector) and i have an object that is 5 units away from the axis ^ /|\ | | Object | | and I want to rotate that object, how can I achieve that effect? because when I use rotateAxis the object will just rotate about its center. thanks, Thanh.

Share this post


Link to post
Share on other sites
Advertisement
I''m not quite sure I get what you''re say here so I''ll give you both ways.

1. If you want to rotate the around its own center make sure you rotate it before you apply the translation to it.

2. If you want to rotate it about the world center (like in an orbit) apply the rotation after the translation.

Share this post


Link to post
Share on other sites
yep the second one, like an orbit. So first I''ll create a translation matrix then the rotation matrix around an axis then multiply them both then apply that to the object will that work?

thanks again.

Share this post


Link to post
Share on other sites
Here is some code to set up a rotation around an arbitrary axis

//=======================================================================================//
// ---===( Create Arbitrary Axis Rotation Matrix )===--- //
//=======================================================================================//
Matrix4x4 &Matrix4x4::SetToRotation( Vector3D v, float r )
{
r = -r;
float x = v.x, y = v.y, z = v.z;
float c = Cos(r), s = Sin(r);
float t = 1-c;
_00 = t*x*x + c ; _01 = t*x*y + s*z; _02 = t*x*z - s*y; _03 = 0;
_10 = t*x*y - s*z; _11 = t*y*y + c; _12 = t*y*z + s*x; _13 = 0;
_20 = t*x*z + s*y; _21 = t*y*z - s*x; _22 = t*z*z + c ; _23 = 0;
_30 = 0; _31 = 0; _32 = 0; _33 = 1;

return *this;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!