Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Moving towards a square

  1. #1
    Newbie Newbie
    Join Date
    May 2014
    Posts
    1

    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:

    Code :
    #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

  2. #2
    Intern Contributor
    Join Date
    Jun 2009
    Posts
    92
    Hi,

    Were you able to solve this issue?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •