PDA

View Full Version : want to draw an arrow with gluCylinder



newsb
04-21-2012, 08:46 PM
Hi



def arrow(x,y,z):
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
#glLoadIdentity()
glLineWidth(3)
glColor3f(1.0, 1.0, 1.0)
L = sqrt(x**2+y**2+z**2)
glBegin(GL_LINES)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f( float(x), float(y), float(z))
glEnd()

arrcyl = gluNewQuadric()
# gluCylinder: quadr., base, top, hgt, slices, stack
gluCylinder(arrcyl, 0., 0.3, 1.0, 6, 6)
glPopMatrix()


This code is incorrect, because I need to rotate the gluCylinder correctly. Unfortunately, I don't know exactly what is the best way to do this (currently, gluCylinder just points in the z-direction, independent of the GL_LINES-piece)...

Also, why doesn't it work with glLoadIdentity() ???

BionicBytes
04-22-2012, 04:32 AM
why don't you draw the arrow in the same initial direction as the cylinder (along the Z).
Then, draw doth ojects orientated in the direction you want. At least then both objects are aligned.

use somthing like..
glpushmatrix;
gltranslatef ( position to draw objects)
glrotatef (angle, 0,1,0); or what ever axis you want to rotate about
drawarrow
gluCylinder ....
glpopmatrix;

newsb
04-22-2012, 05:38 AM
But I don't know how many degrees to rotate in each of the directions..........?

I have float(x), float(y), float(z) - how to rotate the (is it modelview???) so z-axis is coincident with (x,y,z) ?

I don't think acos/asin/atan2 is the best way in any case. I think I should do something with transformation matrix, i.e. some 4x4 matrix is something like:



[ x 0 0 0 ]
[ 0 y 0 0 ]
[ 0 0 z 0 ]
[ 0 0 0 1 ]


Is that right? I'm just guessing... How do I do this rotation on the matrix with/without glrotatef (hopefully without)?