• What is your GameDev Story?

Archived

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

how do I achieve this type of transformation?

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

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 on other sites
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 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 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;
}

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• Forum Statistics

• Total Topics
634151
• Total Posts
3015819
×