Search Projects

Tuesday, April 1, 2014

Running Train Opengl Projects Example

Creating a Train in Computer graphics is not that much hard but logical. In this post we are going to see an OpenGL Projects Example on trains. Our objective is to develop a simple cg projects for running train. Here we need to draw the following things -
  • Train - the bogies and the engine
  • Train Tracks
  • Sky with surrounds (Environment)
After we finish the drawing our next aim would be to give motion to the train. As we are going to draw a simple train so our track will be a straight not in zigzag manner.

Running Train Opengl Projects Example

Design and Implementation


For developing the train - it's bogies and engine we have defined a simple function. In this simple opengl projects example we are coding this function so we can make any no trains, by just calling it. The following is sample code for drawing train -

void TRAINS(int x1,int y1,int a,int b) 
{
int i=0; glBegin(GL_QUADS); 
glColor3f(0,0.0,1.0); //ENGINE 
glVertex2f(x1,y1); //lengh of engine=60;height of engine=30; 
glColor3f(0,0.0,1.0); 
glVertex2f(x1+60,y1); 
glColor3f(1.0,0.0,0.0); 
glVertex2f(x1+60,y1-30); 
glColor3f(0,0.0,0.0); 
glVertex2f(x1,y1-30); 
glEnd();
while(i<3)
glBegin(GL_QUADS); //BOGIES 
glColor3f(1.0,0.0,0.0); //For right train a=795,b=510 
glVertex2f(a,b); 
glColor3f(1.0,0.0,0.0); 
glVertex2f(a+60,b); 
glColor3f(1.0,0.0,0.0); 
glVertex2f(a+60,b-20); 
glColor3f(1.0,0.0,0.0); 
glVertex2f(a,b-20); 
glEnd(); 
a+=65; i++; 
}
}

This function can be called any where hence easy to create the sample trains. In similar fashion we have different functions for Sky, Environments and Tracks.  You can download the free cg source code below. All the things made in the opengl projects example have used primitive opengl objects.

Next level of difficulty  is to move the whole Train - bogies and engine. For the motion of train we have logically used the call-list, push-pop matrix and the most important  Clock() function. The clock() is defined in <time.h> header so you need to include it as well in the project.

clock_t goal = mseconds + clock(); while (goal > clock());

Our new function will help the train runs according a time level else we may go so fast or so slow. We have fixed a goal and add  certain time for it to move the objects. The above code is called in a function and we give the parameter mseconds according to our requirement of speed we want.

That's all we finished the things up. I have just summarised the Running Train Opengl Projects Example while you can easily understand the things when you start running the program.

You can improve Opengl Projects Example


How you can improve the running train projects -
  • Make the trains more attractive with your creative mind.
  • Add smokes coming from the engines while it runs
  • Use Keyword or Mouse function to make it more interactive for start, stop and other functions
How you Liked this simple cg projects example on trains please let me know through the comments. 

Download free cg source code

16 comments:

  1. You want everything readymade?


    Try yourself then problems will come out will help you solve them

    ReplyDelete
  2. i cannot download the cg source code..there is no captcha being shown..

    ReplyDelete
  3. i cannot download the cg source code..there is no captcha being shown..

    ReplyDelete
  4. If you have installed the adblocker removed it.

    ReplyDelete
  5. it worked..thanku sir..

    ReplyDelete
  6. sir can u send report of client-server to this mail id dhanalakkhmi1993@gmail.com

    ReplyDelete
  7. can u send report of running train to this mail id dhanalakkhmi1993@gmail.com

    ReplyDelete
  8. hey you can go to download page in menu at the top and there are few reports you can download it and modify as per your project.


    Still don't want to do it then pay Rs 200 and i will deliver the soft copy to you with everything written as per your project.


    I believe first one is better option


    Thanks for visiting the site do refer other as well and let them become writer and share their projects with their own name.

    ReplyDelete
  9. Already said below you are running adblocker kindly remove it!

    ReplyDelete
  10. Hey Rahul!

    Add smoke with tiny rectangle moving upward and keep their color black

    ReplyDelete
  11. sir can u send function for displaying numbers in opengl

    ReplyDelete
  12. can i get source code for rocket launching plz.....
    this s my email ID- sowmya.tr009nakshatra@gmail.com

    ReplyDelete
  13. hi sir gd mng n hw r u sir ... this is someshwar sir pls send me the source code for how to add smokes from the train engine n mouse source code for train stop n end pls sir and send me the project report for runnig train pls sir someshwar48@gmail.com send me report of running train pls sir i hav to submit on monday sir plss

    ReplyDelete
  14. Sir can you send the code to fly a plane at ametvikram95@gmail.com and after filling the captcha it is showing blank page

    ReplyDelete
  15. Sir can you send the code to fly a plane at ametvikram95@gmail.com and after filling the captcha it is showing blank page

    ReplyDelete