glRotate,glTranslate problems

Moderator
Posts: 771
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! Wacko
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!
Quote this message in a reply
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.
Quote this message in a reply
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! Wacko
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
Quote this message in a reply
Moderator
Posts: 771
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... Wacko
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!]
Quote this message in a reply
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... Wacko
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL: glRotate and some 3D questions. mikey 1 3,696 May 19, 2009 05:11 PM
Last Post: ThemsAllTook
  To glTranslate, or not to glTranslate Nick 11 5,061 Mar 25, 2005 08:56 AM
Last Post: tigakub
  glRotate and glTranslate are messing up my lighting?!? Jake 5 3,894 Oct 17, 2003 01:08 PM
Last Post: MacFiend