true isometric projection with opengl

前端 未结 4 453
深忆病人
深忆病人 2020-12-01 08:28

I am a newbie in OpenGL programming with C++ and not very good at mathematics. Is there a simple way to have isometric projection?

I mean the true isometric projecti

4条回答
  •  失恋的感觉
    2020-12-01 08:59

    Try using gluLookAt

    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    /* use this length so that camera is 1 unit away from origin */
    double dist = sqrt(1 / 3.0);
    
    gluLookAt(dist, dist, dist,  /* position of camera */
              0.0,  0.0,  0.0,   /* where camera is pointing at */
              0.0,  1.0,  0.0);  /* which direction is up */
    glMatrixMode(GL_MODELVIEW);
    
    glBegin(GL_LINES);
    
    glColor3d(1.0, 0.0, 0.0);
    glVertex3d(0.0, 0.0, 0.0);
    glVertex3d(1.0, 0.0, 0.0);
    
    glColor3d(0.0, 1.0, 0.0);
    glVertex3d(0.0, 0.0, 0.0);
    glVertex3d(0.0, 1.0, 0.0);
    
    glColor3d(0.0, 0.0, 1.0);
    glVertex3d(0.0, 0.0, 0.0);
    glVertex3d(0.0, 0.0, 1.0);
    
    glEnd();
    
    glFlush();
    

    Results in

    alt text

    We can draw a cube to check that parallel lines are indeed parallel

    glPushMatrix();
    glTranslated(0.5, 0.5, 0.5);
    glColor3d(0.5, 0.5, 0.5);
    glutWireCube(1);
    glPopMatrix();
    

    alt text

提交回复
热议问题