# basic rotation

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

## 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 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 on other sites
yes thats exactly what i wanted to do. I was wondering where the other vectors came from, thankyou so much!

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

• ### What is your GameDev Story?

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

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634091
• Total Posts
3015433
×