Camera 1

Top  Previous  Next


I was trying to move my camera along the red cube .. so i came across the gluLookAt function, but i am not able to get through this function as to what all it requires ... the content on the Documentation didn't quite help. it will be very helpful if anyone can help me out with the problem in my code and explain the gluLookAt .


  #include <GL/gl.h>

  #include <GL/glut.h>


  using namespace std;

  GLfloat angle = 0.0; //set the angle of rotation

  float Cx=0.0,Cy=0.0,Cz=0.0;

  typedef struct Car


         float x,y,z;

         float angle;

         float zvelocity,xvelocity;


  Car car;

  void keyboard(unsigned char key,int x,int y)


         if(key =='w')


         if( key == 's')


         if(key =='a')


         if(key == 'd')


         if(key==' ')

         angle ++;


  void cube (void) {




         gluLookAt(0,0,Cz+5,0,0,0, 0.0, 1.0, 0.0);

         glColor3f(1.0, 0.0, 0.0);




  void display (void) {

         glClearColor (1.0,1.0,1.0,1.0);

         glClear (GL_COLOR_BUFFER_BIT);















  void reshape (int w, int h) {

         glViewport (0, 0, (GLsizei)w, (GLsizei)h);

         glMatrixMode (GL_PROJECTION);

         glLoadIdentity ();

         gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0)


         glMatrixMode (GL_MODELVIEW);


  int main (int argc, char **argv) {

         glutInit (&argc, argv);

         glutInitDisplayMode (GLUT_DOUBLE); //set up the double

         glutInitWindowSize (500, 500);

         glutInitWindowPosition (100, 100);

         glutCreateWindow ("A basic OpenGL Window");

         glutDisplayFunc (display);

         glutIdleFunc (display);


         glutReshapeFunc (reshape);

         glutMainLoop ();

         return 0;