Results 1 to 3 of 3

Thread: why my z axis is point to the inner of the screen?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Location
    china
    Posts
    2

    why my z axis is point to the inner of the screen?

    I'm an opengl beginner.I'm sorry my english is very poor,I am just puzzled by my program,because i think it show me that z axis
    is point to the inner of the screen.Shouldn't it point out?
    the follow is my program;

    #include <gl/glut.h>

    static float angle_x = 0, angle_y=-10,angle_z=0;

    void axis() //draw the axis
    {

    glBegin(GL_LINES);
    glColor3f(1.0,0.0,0.0);
    glVertex3f(-0.25f,0.0f,0.0f); //x red
    glVertex3f(0.8f,0.0f,0.0f);

    glColor3f(0.8f,0.5f,0.9f);
    glVertex3f(0.0f,-0.25f,0.0f); //y
    glVertex3f(0.0f,0.8f,0.0f);

    glColor3f(1.0,1.0,1.0);
    glVertex3f(0.0f,0.0f,-0.5f); //z white
    glVertex3f(0.0f,0.0f,0.8f);
    glEnd();


    glBegin(GL_TRIANGLES);

    glVertex3f(-0.1,-0.1,0.;//z
    glVertex3f(0.1,0.1,0.;
    glVertex3f(0.0,0.0,1.0);

    glColor3f(1.0,0.0,0.0);//x
    glVertex3f(0.8,0.1,0.1);
    glVertex3f(0.8,-0.1,-0.1);
    glVertex3f(1.0,0.0,0.0);
    glColor3f(0.8f,0.5f,0.9f);//y
    glVertex3f(-0.1,0.8,0.1);
    glVertex3f(0.1,0.8,-0.1);
    glVertex3f(0.0,1.0,0.0);

    glEnd();

    }


    void myplay()
    {


    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    /* gluPerspective(60.0f,1,0.1f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0,0,-2);

    */
    glRotatef(-30,0,1,0);
    glRotatef(-30,1,0,0);
    axis();
    glBegin(GL_POLYGON);
    glColor3f(1.0,0.0,0.0);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.0f);
    glVertex3f(0.5f,0.0f,0.0f);
    glEnd();
    glBegin(GL_POLYGON);
    glColor3f(1.0f,1.0,0.0);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.5f,0.0f);
    glVertex3f(0.0f,0.5f,0.5f);
    glVertex3f(0.0f,0.0f,0.5f);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(1.0,0.0,1.0);
    glVertex3f(0.0f,0.0f,0.0f);
    glVertex3f(0.0f,0.0f,0.5f);
    glColor3f(1.0,0.0,0.0);
    glVertex3f(0.5f,0.0f,0.5f);
    glColor3f(0.0,1.0,0.0);
    glVertex3f(0.5f,0.0f,0.0f);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,1.0,0.0);
    glVertex3f(0.0f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.5f);
    glVertex3f(0.0f,0.5f,0.5f);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.0,1.0,1.0);
    glVertex3f(0.5f,0.5f,0.0f);
    glVertex3f(0.5f,0.5f,0.5f);
    glVertex3f(0.5f,0.0f,0.5f);
    glVertex3f(0.5f,0.0f,0.0f);
    glEnd();

    glBegin(GL_POLYGON);
    glColor3f(0.4,1.0,0.6);
    glVertex3f(0.5f,0.5f,0.5f);
    glVertex3f(0.5f,0.0f,0.5f);
    glVertex3f(0.0f,0.0f,0.5f);
    glVertex3f(0.0f,0.5f,0.5f);
    glEnd();

    glFlush();
    }


    int main(int argc, char *argv[])

    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(300,200);
    glutInitWindowSize(400,400);
    glutCreateWindow("cube");
    glutDisplayFunc(&myplay);

    glutMainLoop();
    return 0;
    }

    I think the result tell me that the Z axis is point to the innner of the screen.why?
    and i found that if i add the remarked code in the founction myplay(),the Z axis direction
    will point out,it will be ok,but at this time the rotate angle will be not right .why?
    Thank you very much .Now is the spring festival in china ,I wish
    you happy new year,have a good luck!恭喜发财!

    just walk

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: why my z axis is point to the inner of the screen?

    you are drawing the Z axis in a weird way:

    Code :
    glVertex3f(0.0f,0.0f,-0.5f); //z white
    glVertex3f(0.0f,0.0f,0.8f);

    The common way is to draw a line from origin (0,0,0) to (0,0,1). This way you display a normalized vector along z axis.
    I have noticed that you are computing some rotations before drawing axis, it would change the axis orientation then.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2009
    Location
    china
    Posts
    2

    Re: why my z axis is point to the inner of the screen?

    thank you very much.now i think i know the answer to my second question.but i still don't know the first question.

    I compute some rotation is to look at the z axis ,and as we know the rotation won't change the right-handed cartesian coordinates ,but the program result is left-handed cartesian coordinates.i am puzzled.if you can run the program and tell me more about the result ,it is too greatful,thank you very much
    just walk

Similar Threads

  1. Getting screen location of 3D point.
    By c4ooo123 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-27-2017, 07:25 PM
  2. Move a point with rendered axis
    By jafrbc in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-17-2014, 09:47 AM
  3. how to write text below a point on the screen
    By saman_artorious in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 08-28-2013, 11:13 AM
  4. encircle any point on the screen
    By saman_artorious in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-25-2013, 06:35 AM
  5. Getting textures to always point at the screen?
    By Kirado in forum OpenGL: GLSL
    Replies: 6
    Last Post: 03-26-2008, 10:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean