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

14 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
  6. On the Craigslist page, navigate to your location's web page, then click Cars and Trucks by Owner. In the search settings, set the range from $0 - (Your Max Limit). fuel burn calculator

    ReplyDelete
  7. Acting thusly, will help you a ton in managing and choosing the assistance which satisfies all your moving prerequisites other than being sensibly appraised. Flyttebyrå Oslo

    ReplyDelete
  8. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. vinfast Fadil Vinh

    ReplyDelete
  9. shippingsolutionsworldwide Worldwide Inc. is an international & local moving company that provides secure and reliable services to embassies, companies, and individuals from the Washington D.C. Metropolitan area to anywhere around the globe. Although we specialize primarily in international moves, we also have extensive experience in import and destination services. Your belongings or commercial products are custom-packed by our experienced team, and shipped door-to-door, by land, sea or air.

    ReplyDelete
  10. Getting the best one is just a matter of selecting the right one. A good limousine service takes pride in its full commitment to meet and exceed your expectations. Luxury Car Rental Near Me

    ReplyDelete
  11. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. moving company

    ReplyDelete
  12. Rent Luxury Car in Miami the next time you travel down to south Florida, mphclub.com offers great deals on luxury and exotic car rental in Miami. Rent Luxury Car in Miami

    ReplyDelete
  13. Open your 'chute ahead of schedule to fly across the guide: If you're out of the airplane and you can see masses of individuals previously falling underneath you, maybe you need to be somewhere else. Clicks Test

    ReplyDelete
  14. An evaporative cooler enjoys a great deal of upper hands over a standard air conditoner in light of the fact that it has a lower cost of establishment, requires less support and works with less energy. Since they are more uncommon in certain pieces of the country, it appears as though a many individuals don't have a clue how an evaporative cooler functions.HVAC Services
    hydronic heating system

    ReplyDelete