How To Make A Moving car In OpenGL C++










#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>
#include <math.h>

GLint b=300;
float  counter=600.0;
void initOpenGl()
{
    glClearColor(0.5,0.5,0.5,1); //Background Color
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0,700,0,500);
    glMatrixMode(GL_MODELVIEW);
}

void wheel(int x,int y)
{
   float th;
   glBegin(GL_POLYGON);
   glColor3f(0,0,0);
   for(int i=0;i<360;i++)
   {
       th=i*(3.1416/180);
       glVertex2f(x+20*cos(th),y+20*sin(th));
   }

   glEnd();

}

void car()
{


   //Bottom Part
   glLoadIdentity();
   counter=counter-0.05;
   glTranslated(counter,100,0.0);
   //glScaled(0.1,0.1,0.0);
   glBegin(GL_POLYGON);
   glVertex2f(100,100);
   glVertex2f(100,160);
   glVertex2f(450,160);
   glVertex2f(450,100);

   //Top Part
   glBegin(GL_POLYGON);
   glVertex2f(150,160);
   glVertex2f(200,200);
   glVertex2f(400,200);
   glVertex2f(450,160);

   glEnd();

   wheel(200,100);
   wheel(380,100);

}

void display()
{

  glClear(GL_COLOR_BUFFER_BIT);
  //Push and pop matrix for separating circle object from Background
  glColor3f(0.0,1.0,0.0);
  car();
  glutSwapBuffers();
  glFlush();


}

int main(int argc, char **argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
    glutInitWindowSize(700,500);
    glutInitWindowPosition(0,0);
    glutCreateWindow("Car Moving");
    initOpenGl();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMainLoop();
    return 0;
}
Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

5 comments:

  1. man and van dublin See whether the workers are prepared, ensured, authorized and reinforced. You need to realize that your hardware is in proficient hands. This will improve the probability of your things being maneuvered carefully and showing up free from any danger to their new area. It doesn't make any difference how proficient and gifted the staff are at moving your things, it is a smart thought for you to consider buying movers protection for your gear.

    ReplyDelete
  2. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. car covers

    ReplyDelete
  3. Autoankauf Oberhausen ohne Lockangebote – ihr kompetenter Gebrauchtwagen Ankauf! Versprechen hält man! Wir haben keinen Onlinerechner und locken nicht mit hohen Onlinepreisen bei der Autobewertung. Sie erhalten eine Erste Bewertung am Telefon und müssen Ihr Fahrzeug nicht vorführen, um einen Preis erhalten zu können. Hierauf haben wir uns spezialisiert. Autoankauf Oberhausen

    ReplyDelete
  4. Different advantages incorporate exceptions from the blockage charge and parking spot charges in the UK's significant urban communities. In the event that an organization utilizes electric vehicles as organization cars, the advantages for the business will be in worth of two or three thousand pounds each year, because of different expense reserve funds. home ev charging point

    ReplyDelete
  5. Full Service Deluxe Moving Companies-These are the huge and notable moving organizations. They offer full assistance moving bundles. Europa-Road túlméretes szállítás

    ReplyDelete