Moving towards a square

Hi guys,

Fairly new to OpenGL so apologies if the answer is simple!

I have this program which creates a square and moves a camera towards it:

#include <stdio.h>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <stdlib.h>
#include <math.h>


float z = 0;


void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    
    gluLookAt(0.0,0.0,z, 0.0,0.0,1000.0, 0.0,1.0,0.0);
    z += 1;

    glBegin(GL_QUADS);
    glColor3f(0.0,1.0,0.0);
    glVertex3f(-200.0, -200.0, 1000.0);
    glVertex3f(-200.0, 200.0, 1000.0);
    glVertex3f(200.0, 200.0, 1000.0);
    glVertex3f(200.0, -200.0, 1000.0);
    glEnd();
    
    glFlush();
    glutSwapBuffers();
    glutPostRedisplay();
}

void initgl()
{
    
    
    glViewport(-200,-200, 200, 200);
    
    glEnable(GL_DEPTH_TEST);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    
    gluPerspective(60,1, 1,2000);
    glMatrixMode(GL_MODELVIEW);
    
}


int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize (500, 500);
    glutInitWindowPosition (100, 100);
    glutCreateWindow ("Flight Simulator");
    initgl();
    glutDisplayFunc(display);
    
    glutMainLoop();
    return 0;   
}

Now it works as in the camera moves towards the square. However my issue is that it’s movement is “steppy” i.e. not smooth until it get’s closer to the square. I have tried smaller and bigger increments of movement and it doesn’t make a difference

Any ideas on how to fix this?

Thanks
Chris

Hi,

Were you able to solve this issue?