PDA

View Full Version : I need to rotate an object in the X,Y,and Z plane at the same time.



John Jenkins
10-09-2002, 01:00 PM
Using direction cosines, I know the difference in the X Y and Z angles of the two points in space. Here is a little background on what I am doing. I am drawing pipes. I draw a ring at the origin and then translate it to its correct position. To make it look correct I have to rotate the ring so that it lines up with the other rings infront and in back of it.

Like I said I have the angles from math.
Let's say the the angles are Z=42 X=68 and Y = 56 (got these from my math book). Well how should I rotate this?

Should I:
glrotate 42,0,0,1
glrotate 68,1,0,0
glrotate 56,0,1,0

I haven't tried it yet but my hunch is that it is not going to work. Is there any way to group these to rotations into one command that the computer can figure out for me?
Can I use one statement like this?
glrotate 68,1,.5,.8
.5 being approximately 42
.8 being approximately 56

J P
10-09-2002, 01:10 PM
You only need 2 rotations to bring any object in to position.

See the OpenGL draw cylinder between points at
http://www.mfcogl.com/OpenGL%20-%20draw%20cylinder%20between%202%20pts.htm

jwatte
10-09-2002, 04:37 PM
If you want to find a rotation that moves point P1 to point P2, around point P3, here's how to do it:

1) find axis of rotation: (P1-P3) x (P2-P3) and normalize
2) find amount of rotation: acos( normalize(P1-P3) . normalize (P2-P3) )

Now, plug these values into your favourite rotate-around-axis function and you're done!