Skip to main content
gamedev.net
🔒 Locked

basic rotation

Started by Muncher 3 replies 1.2k views
Original Post
Muncher
Muncher
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
SiCrane
SiCrane
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.
Muncher
Muncher
yes thats exactly what i wanted to do. I was wondering where the other vectors came from, thankyou so much!
Muncher
Muncher
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
Zakwayda
Zakwayda
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.