1

I want to implement a camera that follows my 3D object (a car). To set the camera I use the following structure:

glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45, 1, -5, 5);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        gluLookAt(pos_x + (cos(90)*0.5), pos_y + (0.5*sin(90)), 8, pos_x, pos_y, 6, 0, 1, 0);
//pos are the coordinates of the car 

My problem is when I change to that camera, the camera doesn't stay behind the car, just on top of it. Why?

Miguel
  • 89
  • 2
  • 9
  • 1
    Because the first position you give to lookAt is above the car. I'm not sure what you're trying to do with the cos sin here but, you're just adding 0 and 0.5 to pos. – Jerem Oct 21 '15 at 07:19
  • Do you use `gluLookAt` on each frame update? – Danil Prokhorenko Oct 22 '15 at 01:57
  • @Jerem i'm using the cos and sins becuase i want the camera to move in the same way as the car moves with the same speed, i tried those angles just to test if the camera was put in the back of the car. – Miguel Oct 22 '15 at 13:26
  • @DanilProkhorenko Yes glulookat is in every frame. I have a timer func that updates every 10ms – Miguel Oct 22 '15 at 13:29
  • @Miguel Can you provide more code? I would like to see how do you move the car and how do you draw the car. – Danil Prokhorenko Oct 22 '15 at 13:52

0 Answers0