Sign in to follow this  
Muncher

basic rotation

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
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

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