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 4 of 4

Thread: draw xyz axes

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Dallas, TX, USA
    Posts
    2

    draw xyz axes

    Does anyone know how to draw xyz axes? I search the forum, but couldn't get any related message.
    What I need is to draw an axis in the lower left corner, show the rotation, and no response to zoom or panning.

    An example is great helpfull.

    Thanks for help.

    Xueming

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2001
    Posts
    1

    Re: draw xyz axes

    okay... well first i'll assume your window has the dimensions 8x6 (in terms of ogl distances, not pixels... in other words, if your orgin is in the center of the screen you should be able to see from -4 to 4 across the x dimension and -3 to 3 across the y). i'll also assume you have the variables rotX, rotY, and rotZ, which control the angles of rotation. lastly, i'll assume you're using glut...

    in your display function, at the end, add this code:

    // save previous matrix
    glPushMatrix();
    // clear matrix
    glLoadIdentity();
    // apply rotations
    glRotate3f(rotX, 1.0, 0.0, 0.0);
    glRotate3f(rotY, 0.0, 1.0, 0.0);
    glRotate3f(rotZ, 0.0, 0.0, 1.0);
    // move the axes to the screen corner
    glTranslatef(-3.0, -2.0, 0.0);
    // draw our axes
    glBegin(GL_LINES);
    // draw line for x axis
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(1.0, 0.0, 0.0);
    // draw line for y axis
    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);
    // draw line for Z axis
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 1.0);
    glEnd();
    // load the previous matrix
    glPopMatrix();

    that's it. i didnt test this code so lemme know if there are any problems. hope it helps.

    - Jon Nadal

    [This message has been edited by moox (edited 03-06-2001).]

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2001
    Location
    Dallas, TX, USA
    Posts
    2

    Re: draw xyz axes

    Thanks for your help.

    From the assumption of your code, I need to keep track the dimension, what if the model has been panned or zoomed?

    I was thinking it would be easy if opengl can accept the pixel units, but I don't know how?

    Thanks again.

    Xueming

    Originally posted by moox:
    okay... well first i'll assume your window has the dimensions 8x6 (in terms of ogl distances, not pixels... in other words, if your orgin is in the center of the screen you should be able to see from -4 to 4 across the x dimension and -3 to 3 across the y). i'll also assume you have the variables rotX, rotY, and rotZ, which control the angles of rotation. lastly, i'll assume you're using glut...

    in your display function, at the end, add this code:

    // save previous matrix
    glPushMatrix();
    // clear matrix
    glLoadIdentity();
    // apply rotations
    glRotate3f(rotX, 1.0, 0.0, 0.0);
    glRotate3f(rotY, 0.0, 1.0, 0.0);
    glRotate3f(rotZ, 0.0, 0.0, 1.0);
    // move the axes to the screen corner
    glTranslatef(-3.0, -2.0, 0.0);
    // draw our axes
    glBegin(GL_LINES);
    // draw line for x axis
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(1.0, 0.0, 0.0);
    // draw line for y axis
    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);
    // draw line for Z axis
    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 1.0);
    glEnd();
    // load the previous matrix
    glPopMatrix();

    that's it. i didnt test this code so lemme know if there are any problems. hope it helps.

    - Jon Nadal

    [This message has been edited by moox (edited 03-06-2001).]

  4. #4
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Vancouver BC Canada
    Posts
    433

    Re: draw xyz axes

    (OK... I posted this without reading the *whole* question first... this, of course,draws axes at the origin of the world... but I'm sure you can figure out how to draw them in the lower left corner easily enough )

    Here's what I do:

    Code :
    /* Axes display list */
    static GLuint axes_list;
     
    ....
     
    /* In some initialisation function... */
     
        /* Create a display list for drawing axes */
        axes_list = glGenLists(1);
        glNewList(axes_list, GL_COMPILE);
     
        glColor4ub(0, 0, 255, 255);
        glBegin(GL_LINE_STRIP);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(1.0f, 0.0f, 0.0f);
        glVertex3f(0.75f, 0.25f, 0.0f);
        glVertex3f(0.75f, -0.25f, 0.0f);
        glVertex3f(1.0f, 0.0f, 0.0f);
        glVertex3f(0.75f, 0.0f, 0.25f);
        glVertex3f(0.75f, 0.0f, -0.25f);
        glVertex3f(1.0f, 0.0f, 0.0f);
        glEnd();
        glBegin(GL_LINE_STRIP);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(0.0f, 1.0f, 0.0f);
        glVertex3f(0.0f, 0.75f, 0.25f);
        glVertex3f(0.0f, 0.75f, -0.25f);
        glVertex3f(0.0f, 1.0f, 0.0f);
        glVertex3f(0.25f, 0.75f, 0.0f);
        glVertex3f(-0.25f, 0.75f, 0.0f);
        glVertex3f(0.0f, 1.0f, 0.0f);
        glEnd();
        glBegin(GL_LINE_STRIP);
        glVertex3f(0.0f, 0.0f, 0.0f);
        glVertex3f(0.0f, 0.0f, 1.0f);
        glVertex3f(0.25f, 0.0f, 0.75f);
        glVertex3f(-0.25f, 0.0f, 0.75f);
        glVertex3f(0.0f, 0.0f, 1.0f);
        glVertex3f(0.0f, 0.25f, 0.75f);
        glVertex3f(0.0f, -0.25f, 0.75f);
        glVertex3f(0.0f, 0.0f, 1.0f);
        glEnd();
     
        glColor4ub(255, 255, 0, 255);
        glRasterPos3f(1.1f, 0.0f, 0.0f);
     
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'x');
        glRasterPos3f(0.0f, 1.1f, 0.0f);
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'y');
        glRasterPos3f(0.0f, 0.0f, 1.1f);
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'z');
     
        glEndList();
     
    ...
     
    /* In my display function */
     
        /* Draw axes */
        glPushMatrix();
        glCallList(axes_list);
        glPopMatrix();
    Hope this helps

    [This message has been edited by rts (edited 03-08-2001).]

Posting Permissions

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