View Full Version : Vector Angles - Math - Help Please :)
09-28-2000, 05:25 AM
I'm doing some billboarding but It's a bit different.
I have a vector for the billboard that points towards the camera's position.
Now I need to get the angles from this vector in degrees so I can rotate the billboard with openGL using the glRotate functions.
So how can I get the 3 angle measures from the vector??
09-28-2000, 05:40 AM
I 'think' this might be the answer,
to get the three angles, using your vector apply the dot product three times, once against the X axis, Once against the Y and once against the Z axis. This should give you three angles.
But my trig is not quite what it should be!
09-28-2000, 07:36 AM
well, actually you can do it by rotating about 1 arbitrary axis.
Say you have A, which is your current vector, and B, which is your goal vector. Your intention is to find out how to make vector A coincide with vector B.
First handle the 2 easy cases. Take A dot B. If the result is 1, they are the same vector. Nothing more to do. If the result is -1, they are 180 degrees apart, so you can rotate A 180 about ANY axis and you have the problem solve.
The third case is the trick. First you want to find an axis that is perpendicular to both vectors. You can then use this vector to rotate A into position with B (after finding the proper angle).
To find this axis of rotation, take the cross product of A and B, normalize the result, and you have your axis of rotation, which we will denote as the vector (Rx,Ry,Rz). Next you need to find the angle of rotation. Take the equation:
A dot B = cos(angle)*length(a)*length(b)
with manipulation, you can turn this into:
angle = arccos((a dot B)/(length(a)*length(b)))
now, you can use glRotatef(angle, Rx, Ry, Rz)
be warned, you may need to use -angle or -Rx, -Ry, -Rz. But this is pretty much what you want
Hope this helps
09-29-2000, 07:15 AM
I really suggest you learn matrix math..
Create matrix functions, and do your own rotation & translation and pass your own camera matrix to opengl..
That way you can create an inverse view matrix at the same time to do all your billboarding for you..
Once you know matrices, it really is the simplest and most elegant way
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.