Archive Pages Design$type=blogging

Running Train Opengl Projects Example

Creating a Train in Computer graphics is not that much hard but logical. In this post we are going...

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

COMMENTS

Name

3D Bi-Cycle 3D Game 3D Laptop 3D Objects 3D Projects 3D Zoo Algorithm Android Aquarium Bellman-Ford Algorithm Block Breaker Blockshooting Bucket Sort C# Chess Clock Code Blocks Colors Complex Project Complex Projects Crab Pong Cross Zero DSAV Escapa First Come First Serve Fluids Font Demo Games Gear Motion GlutDino Glutplane Graphics Editor iOS iPhone Java Java OpenGL Graphics Programming Light Torus Linked List Ludo Board Game Mancala board games Memory blocks game Memory Game Menu Mickey Mouse Minesweeper Miniature Steam Engine moth Motion Blur MoveLight moving car Moving Ship Multiplex Networking Based Project Nuclear Power Plant Olympic opengl c++ examples OpenGL ES OpenGL Tutorial Origami OS Based Projects Paint Paper Folding Particles Drop Path Finding ping pong Pong Game Project Report Projects Report Puzzles qix like Random Flowing lines Rigid Body Rings Robot sample c++ opengl code Screen Saver Screen Saver Ship Shadow Cube Shadowfun Ship Iceberg Simple Drawing Simple Haloed Lined Wireframe Simple Move Light Simple Project Simulation SNAKE XENZIA GAME Solar system Sorting Sphere Spot Light Swing Stars Taj Mahal The Edge Game Tic Tac Toe Tower of Hanoi Traffic Signal Transformation Triangular Animation Tutorial water ripple effects Whirlpool
false
ltr
item
OpenGL Projects: Running Train Opengl Projects Example
Running Train Opengl Projects Example
http://3.bp.blogspot.com/-2o2a9tRyjGM/Uznp8NVOJAI/AAAAAAAAGUM/TNLfjSjM_hM/s1600/Running+Train+Opengl+Projects+Example.JPG
http://3.bp.blogspot.com/-2o2a9tRyjGM/Uznp8NVOJAI/AAAAAAAAGUM/TNLfjSjM_hM/s72-c/Running+Train+Opengl+Projects+Example.JPG
OpenGL Projects
http://www.openglprojects.in/2014/04/running-train-opengl-projects-example.html
http://www.openglprojects.in/
http://www.openglprojects.in/
http://www.openglprojects.in/2014/04/running-train-opengl-projects-example.html
true
2020194800836807725
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago