Jump to content
  • Advertisement
Sign in to follow this  
Muncher

basic rotation

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

G'day! I don't fully understand how to take a vector, and create a rotation matrix that i can use to orient a 3d model; nor can i find an example in any of my books, is there a link or explanation that will show me? Muncher

Share this post


Link to post
Share on other sites
Advertisement
I assume that you want to take a model with a facing vector, and then take a new vector and rotate the model so that the model's new facing vector is aligned with the given vector. One way to do that is to take the cross product of the two vectors to get an axis of rotation for the model, the magnitude of the cross product can be used to determine the angle of rotation.

Share this post


Link to post
Share on other sites
I implemented your solution, and it works ok - thanks!

But when the models facing vector is near the orientation vector, its shrinking the model! When the vectors are the same, the drawn model cannot be seen.
I guess this is because the cross of the two identical vectors is producing 0 length axis of rotation vectors?

Is there a way around this?

Cheers
Muncher

Share this post


Link to post
Share on other sites
You are correct; the magnitude of the cross product is proportional to the sine of the angle between the two vectors, so it approaches zero-length as the vectors approach positive or negative alignment.

Generally you'll want to normalize the axis of rotation before constructing a matrix from it. I think OpenGL does this for you (if you're using OpenGL), but you have to give it a vector of sufficient magnitude to work with.

If you're using sicrane's method, you've already taken the magnitude of the cross product to find the angle of rotation. Simply divide the vector by this magnitude to normalize it. If the magnitude is too small (< some epsilon), the vectors are either aligned, in which case you can just load the identity matrix, or opposite, in which case there are multiple solutions.

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.

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!