0

I'm having trouble orienting the camera the way I want. I got that I need to use gluLookAt to set the camera. As far as I understood the first three is for the location of the camera, the second set is for destination and the third set is for the camera upvector and I'm trying to implement a box which the camera should be looking at its center. This box consists of 6 triangles, does not necessarily make a decent box. To get its center, I get the average of all triangle's vertices (x, y, and z).

So this is inside my display function :

 Vect v=getBoxCenter();
 gluLookAt(camera.pos.x, camera.pos.y, camera.pos.z,   
        v.x,v.y,v.z,   
        camera.upVector.x, camera.upVector.y, camera.upVector.z);    
 glColor3f(1, 0, 0);    
 glBegin(GL_TRIANGLES);    
 glVertex3f(0, 0, 0); glVertex3f(100, 0, 0); glVertex3f(0, 100, 0);    
 glEnd();    
 glutSwapBuffers();

When I do not use gluLookAt, the triangle shows up just fine at the center of the screen. What am I doing wrong?

J. D.
  • 113
  • 13
hebele
  • 75
  • 9
  • Since this is old-school OpenGL: what does your projection matrix look like? –  May 15 '18 at 13:35
  • I have these in the main function: glMatrixMode(GL_PROJECTION); glLoadIdentity(); and what is the new school OpenGL? – hebele May 15 '18 at 13:38
  • Well there's your problem. you should read up on gluPerspective() –  May 15 '18 at 13:39
  • modern opengl doesn't have matrix modes or glBegin()/glEnd(), and uses shaders and vertex buffers instead. it's a completely different way of working. ("modern" as: for the past 10 years) –  May 15 '18 at 13:40
  • @Rabbid76 They already said that they use glLoadIdentity() as the projection matrix... –  May 15 '18 at 13:45
  • @Rabbid76 I just tried setting near plane 1, far plane 1000, and fov to 80. I still didn't get anything: gluPerspective(80, 1, 1, 1000); let me try your last message, thanks. – hebele May 15 '18 at 13:56
  • @Rabbid76 I had these before my display function was called: glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0, 1.0, -1.0, 1.0, -1000.0, 1000.0); glMatrixMode(GL_MODELVIEW); and still nothing – hebele May 15 '18 at 13:59
  • @hebele Hi, maybe your `v` is just wrong. – YesThatIsMyName May 15 '18 at 14:34
  • @Rabbid76, thanks for all the help. `camera.upVector` is `0,1,0` and `camera.position` is `20,20,40`. `v` in my case is the center of the box that my camera is supposed to look at. Basically, I have 6 triangles forming a box. I find its center by averaging the 6 triangles' `x`,`y`, and `z` coordinates. – hebele May 18 '18 at 13:49
  • `gluLookAt` _multiplies_ the current matrix with some view transformation matrix. If your current matrix is not well-defined, the result will be meaningless. – derhass Aug 06 '18 at 15:59

0 Answers0