## glRotate,glTranslate problems

Moderator
Posts: 776
Joined: 2003.04
Post: #1
Hi, I'm trying to, given 2 points (x,y,z), be able to draw something like an arrow (a tube & a cone) starting from point A and goint to point B. Basically, I tried adding the startig vector (point A) to the starting position of the arrow (glTranslate), and then getting the angle of the A-B vector to (1,0,0) and (0,1,0). Then, I aplied those angles (glRotate, twice) and finaly I draw the 3d object.
Well, it doesn't work. I know this should be simple, 5-10 lines tops! I just can't figure it out!
I have a vector class, so I can calculate angles, dot products, etc.
Please, if anybody knows how to do this, post some sample code.
Thanks!
Member
Posts: 177
Joined: 2002.08
Post: #2
What exactly do you mean by "it doesn't work"? Is the arrow in the wrong place?

Try applying the rotations before the translation.
Member
Posts: 469
Joined: 2002.10
Post: #3
PowerMacX Wrote:Hi, I'm trying to, given 2 points (x,y,z), be able to draw something like an arrow (a tube & a cone) starting from point A and goint to point B. Basically, I tried adding the startig vector (point A) to the starting position of the arrow (glTranslate), and then getting the angle of the A-B vector to (1,0,0) and (0,1,0). Then, I aplied those angles (glRotate, twice) and finaly I draw the 3d object.
Well, it doesn't work. I know this should be simple, 5-10 lines tops! I just can't figure it out!
I have a vector class, so I can calculate angles, dot products, etc.
Please, if anybody knows how to do this, post some sample code.
Thanks!
Here's the order you want.
1. Translate to your world starting point
2. rotate to the direction you'd like the arrow to point
3. scale to the size of the arrow you want
4. then draw the arrow from <0,0,0> to <1,0,0> (or something orthogonal to that)

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Moderator
Posts: 776
Joined: 2003.04
Post: #4
My problem is that I have 2 angles: one in relation to the X axis and one in relation to the Y axis (or Z, any 2 axes will do). I can calculate those 2 angles BUT, when I try to apply them before drawing my object (to simplify, let's assume it's origin is <0,0,0> so I don't need to do any translation) I get incorrect results. This is caused (I think) by the fact that I'm doing 2 rotations, one on the X axis and one on the y axis, but when I do the X axis rotation, the Y axis changes, so the second rotation is wrong. I was able to make this work on 2D, but that second rotation complicates everything! I'll probably figure it out...
One of the uses for this code is so I can draw a "shot" aligned to the direction the shot is travelling.
I originally planned to use this function to draw "normals" as 3D arrows, for debugging purposes, but since it seems to be an "expensive" function (square roots, rotations, translations, etc) now I just draw a line between the 2 points using GL_LINE_STRIP. (for some strange reason, GL_LINE doesn¥t seem to work) [Update: I was using GL_LINE, but it should have been GL_LINES, duh!]
Member
Posts: 469
Joined: 2002.10
Post: #5
PowerMacX Wrote:My problem is that I have 2 angles: one in relation to the X axis and one in relation to the Y axis (or Z, any 2 axes will do). I can calculate those 2 angles BUT, when I try to apply them before drawing my object (to simplify, let's assume it's origin is <0,0,0> so I don't need to do any translation) I get incorrect results. This is caused (I think) by the fact that I'm doing 2 rotations, one on the X axis and one on the y axis, but when I do the X axis rotation, the Y axis changes, so the second rotation is wrong. I was able to make this work on 2D, but that second rotation complicates everything! I'll probably figure it out...
One of the uses for this code is so I can draw a "shot" aligned to the direction the shot is travelling.
I originally planned to use this function to draw "normals" as 3D arrows, for debugging purposes, but since it seems to be an "expensive" function (square roots, rotations, translations, etc) now I just draw a line between the 2 points using GL_LINE_STRIP. (for some strange reason, GL_LINE doesn¥t seem to work)
Use quaternions dude. Then once you got your quaternion, do a simple matrix multiply.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB