Question

I am wondering if gluLookAt together with glFrustum is distorting the rendered picture.

This is how a scene is rendered:

enter image description here

And here's the code that rendered it.

InitCamera is called once and should, as I understand it now, set up a matrix so as if I looked from a position 2 units above and 3 units in front of the origin towards the origin. Also glFrustum is used in order to create a perspective`.

void InitCamera() {

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  gluLookAt (
    0,  2  ,   3, 
    0,  0  ,   0,
    0,  1  , - 0 
  );

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum   (-  1,     1, 
               -  1,     1, 
                  1,1000.0);

  glMatrixMode(GL_MODELVIEW);
}

Then TheScene is what actually draws the picture:

void TheScene() {

  glClear(
    GL_COLOR_BUFFER_BIT | 
    GL_DEPTH_BUFFER_BIT    
  );

  glMatrixMode(GL_MODELVIEW);

  // Draw red circle around origin and radius 2 units:    
  glColor3d(1,0,0);
  glBegin(GL_LINE_LOOP);
  for (double i = 0; i<=2 * M_PI; i+=M_PI / 20.0) {
    glVertex3d(std::sin(i) * 2.0, 0, std::cos(i) * 2.0);
  }
  glEnd();

  // draw green sphere at origin:
  glColor3d(0,1,0);
  glutSolidSphere(0.2,128, 128);


  // draw pink sphere a bit away    
  glPushMatrix();
    glColor3d(1,0,1);
    glTranslated(8, 3, -10);
    glutSolidSphere(0.8, 128, 128);
  glPopMatrix();

  SwapBuffers(hDC_opengl);
}

The red ball should be drawn in the origin and at the center of the red circle around it. But looking at it just feels wierd, and gives me the imprssion that the green ball is not in the center at all.

Also, the pink ball should, imho, be drawn as a perfect circle, not as an ellipse.

So, am I wrong, and the picture is drawn correctly, or am I setting up something wrong?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top