
The Toll Tax Collection Booth Simulation is a popular Computer Graphics mini-project developed using C/C++ with the GLUT/OpenGL library. The project creates a simple interactive highway environment where vehicles move through toll booths, stop at barriers, and continue once the gates are opened.
Key Project Features
-
Welcome Screen: Displays the project title, student details, and basic instructions for operating the simulation.
-
Dual-Lane Highway: Represents a two-way highway with separate lanes and toll booths for vehicles traveling in opposite directions.
-
Interactive Barriers: Vehicles automatically stop when they reach a toll booth. The user can manually raise the barrier to allow the vehicle to pass.
-
Dynamic Vehicle Control: Users can adjust vehicle speed and manage traffic using predefined keyboard controls.
-
Interactive Environment: Keyboard inputs make the simulation more engaging by allowing the user to control vehicle movement and toll barriers in real time.
Overall, the project demonstrates fundamental computer graphics concepts such as 2D object drawing, animation, transformations, user interaction, and keyboard-based controls in an easy-to-understand highway toll booth simulation.
🚧 Toll Tax Collection Computer Graphics Project User Controls
Complete Source Code Implementation
You can compile and run this full working program using CodeBlocks, Visual Studio, or a standard GCC/Clang compiler with GLUT linked.
Step-by-Step Execution Guide
To run this project seamlessly on your computer, follow these setup stages:
- Setup IDE: Open CodeBlocks or your environment of choice and start a new GLUT project.
- Library Linking: Ensure your compiler options are linking the required dependencies:
-lglut -lGLU -lGL. - Overwrite Main File: Replace all auto-generated code inside
main.cppwith the script written above. - Compile: Hit Build and Run. Tap
ENTERon the welcome screen to launch into the toll layout!
Full Source Code
#include
#include
#include
// Global State Variables
int screenMode = 0; // 0 = Welcome Screen, 1 = Toll Simulation
float car1X = -250.0f, car2X = 250.0f;
float speed1 = 2.0f, speed2 = 2.0f;
bool gate1Open = false, gate2Open = false;
float gate1Angle = 0.0f, gate2Angle = 0.0f;
// Utility to render text strings
void renderText(float x, float y, void* font, const char* string) {
glRasterPos2f(x, y);
for (int i = 0; i = -60) && (car1X 300) { // Loop back around
car1X = -300;
gate1Open = false;
}
}
// Handle Right Car Stopping / Moving Logic
if (!gate2Open && (car2X - 40 60)) {
car2X = 100; // Force full stop at booth entry boundary
} else {
car2X -= speed2;
if (car2X 0.0f) gate1Angle -= 5.0f;
if (gate2Open && gate2Angle 0.0f) gate2Angle -= 5.0f;
}
glutPostRedisplay();
glutTimerFunc(16, update, 0); // Roughly 60 Frames Per Second
}
// Configures coordinate projections
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-300, 300, -200, 200);
glMatrixMode(GL_MODELVIEW);
}
// User Input Evaluator
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 13: // ENTER key
screenMode = 1;
break;
case 'L': case 'l':
gate1Open = true;
break;
case 'R': case 'r':
gate2Open = true;
break;
case 'Z': case 'z':
speed1 += 0.5f;
break;
case 'V': case 'v':
speed2 += 0.5f;
break;
case 27: // ESC key
exit(0);
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL Toll Booth Simulation");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc(0, update, 0);
glutMainLoop();
return 0;
}