glRotate,glTranslate problems
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 AB 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, 510 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!
Well, it doesn't work. I know this should be simple, 510 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!
What exactly do you mean by "it doesn't work"? Is the arrow in the wrong place?
Try applying the rotations before the translation.
Try applying the rotations before the translation.
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 AB vector to (1,0,0) and (0,1,0). Then, I aplied those angles (glRotate, twice) and finaly I draw the 3d object.Here's the order you want.
Well, it doesn't work. I know this should be simple, 510 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!
 Translate to your world starting point
 rotate to the direction you'd like the arrow to point
 scale to the size of the arrow you want
 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
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!]
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!]
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...Use quaternions dude. Then once you got your quaternion, do a simple matrix multiply.
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)
Kelvin
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
OpenGL: glRotate and some 3D questions.  mikey  1  5,175 
May 19, 2009 05:11 PM Last Post: ThemsAllTook 

To glTranslate, or not to glTranslate  Nick  11  7,613 
Mar 25, 2005 08:56 AM Last Post: tigakub 

glRotate and glTranslate are messing up my lighting?!?  Jake  5  6,173 
Oct 17, 2003 01:08 PM Last Post: MacFiend 