Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: want to draw an arrow with gluCylinder

  1. #1
    Intern Contributor
    Join Date
    Aug 2011
    Posts
    77

    want to draw an arrow with gluCylinder

    Hi

    Code :
    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() ???

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: want to draw an arrow with gluCylinder

    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;

  3. #3
    Intern Contributor
    Join Date
    Aug 2011
    Posts
    77

    Re: want to draw an arrow with gluCylinder

    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:

    Code :
    [ 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)?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •