Skip to content

juanakajuan/traffic-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Simulation

A real-time 3D traffic intersection simulation built with C++ and OpenGL, featuring realistic vehicle physics, traffic light control systems, and multiple camera perspectives.

traffic_simulation_demo.mp4

Features

  • Realistic Vehicle Physics: Smooth acceleration, deceleration, and speed-dependent turning
  • Traffic Light System: Automated North-South and East-West signal timing with proper state transitions
  • Multiple Camera Views: Third-person, top-down, and side-angle perspectives
  • 3D Environment: Complete intersection with roads, grass terrain, trees, and infrastructure
  • 3D Models: High-quality car, traffic lights, surveillance cameras, and billboard advertisements
  • Interactive Controls: Arrow key vehicle control with smooth movement and turning
  • HUD Display: Real-time speed, direction, heading, and position information
  • Screenshot Feature: Save simulation snapshots as PPM images

Controls

  • Arrow Keys: Move and turn the vehicle
    • ↑ : Accelerate forward
    • ↓ : Reverse/brake
    • ← : Turn left
    • → : Turn right
  • R: Reset car to starting position
  • B: Apply emergency brakes (stop immediately)
  • S: Save screenshot
  • ESC: Exit simulation

Architecture

The simulation uses a component-based architecture:

  • ObjModel: Handles loading and rendering of Wavefront .obj 3D models
  • TrafficLight: Manages traffic signal states and timing
  • BillBoard: Renders textured advertisement billboards
  • PPMImage: Handles PPM image format for textures and screenshots
  • Simulation Framework: Base classes for extensible simulation systems

Traffic Signal Logic

  • North-South: Green (5s) → Yellow (1s) → Red (6s)
  • East-West: Red (6s) → Green (5s) → Yellow (1s)
  • Total cycle time: 12 seconds

Physics Model

  • Speed-dependent turning radius
  • Realistic acceleration/deceleration curves
  • Momentum-based movement with friction simulation

Camera System

  1. Main View: Third-person camera following the vehicle
  2. Top-Down: Orthographic overhead view for navigation
  3. Side Views: Left and right angled perspectives for spatial awareness

Screenshots

Screenshots are saved as Screenshots/snapshot.ppm and can be converted to other formats using image editing software.

Dependencies

  • OpenGL: Core graphics rendering
  • GLUT: Window management and input handling
  • GLEW: OpenGL extension loading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published