yoyosh
April 21st, 2006, 04:11 PM
we have a point (x,y,z) (vector that begins in 0,0,0)
and a function glRotated(angle,x2,y2,z2) that rotates the system with given angle around vector (x2,y2,z2).
Question: what values should we pass to function glRotated, so that the system would rotate that axis Z would cover with the given vector (x,y,z)
thank you very much in advance for any help :)
surfdabbler
April 23rd, 2006, 05:32 AM
Open GL will not solve this problem for you, but it is easy to do the rotation yourself, in 2 steps.
First, project your vector onto the X,Z plane (i.e. y = 0), and calculate the 2d rotation around the Y axis necessary to bring the vector inline with the Z axis on the XZ plane.
Then rotate the vector by this angle, (i.e. rotate the XZ vector onto the Z axis, and adding the Y component of the original 3d vector, giving a 2d vector in the YZ plane) and find the angle of the vector in the Y,Z plane to rotate it down onto the Z axis. This is your rotation around the X axis.
Then, you have 2 angles, one for the xrotation, and one for the Y rotation.
glRotated(xangle, 1,0,0);
glRotated(yangle, 0,1,0);
(I can never work out theoretically which rotation to apply first, so I always trial and error. I think you'd do the X rotation first, and then the Y rotation, but if it doesn't work, just swap them around. It always seems to be the opposite of what I first think.)
I hope some of this makes sense.