Muncher 101 Report post Posted September 6, 2005 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 0 Share this post Link to post Share on other sites
SiCrane 11839 Report post Posted September 6, 2005 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. 0 Share this post Link to post Share on other sites
Muncher 101 Report post Posted September 6, 2005 yes thats exactly what i wanted to do. I was wondering where the other vectors came from, thankyou so much! 0 Share this post Link to post Share on other sites
Muncher 101 Report post Posted September 7, 2005 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?CheersMuncher 0 Share this post Link to post Share on other sites
jyk 2094 Report post Posted September 7, 2005 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. 0 Share this post Link to post Share on other sites