I built a fully functional flight simulator from scratch using C++, OpenGL, and ImGui. This isn't just a simple visualization—it's a physics-accurate simulation that models real aircraft behavior using 6-degree-of-freedom (6-DOF) dynamics. The simulator runs at 60 Hz with a 4th-order Runge-Kutta (RK4) integrator to ensure numerical stability and accuracy, just like professional flight simulation software.
The system features a complete cockpit instrument panel including an airspeed indicator, altimeter, attitude indicator, heading indicator, vertical speed indicator, and turn coordinator—all rendered in real-time using ImGui's DrawList API. The 3D visualization provides a pilot's perspective with an artificial horizon, ground reference, and compass tape.
Real-time 60Hz physics simulation with full cockpit instrumentation and 3D visualization
┌─────────────────────────────────────────────────────────┐
│ Main Loop (60 Hz) │
│ (main.cpp) │
└────────────┬────────────────────────────┬────────────────┘
│ │
▼ ▼
┌────────────────┐ ┌─────────────────┐
│ Input Handler │ │ Renderer │
│ │ │ (OpenGL + │
│ - Keyboard │ │ ImGui) │
│ - Controls │ │ │
└────────┬───────┘ └────────┬────────┘
│ │
▼ │
┌────────────────┐ │
│ Aircraft │◄─────────────────┘
│ │ (renders)
│ - State │
│ - Properties │
│ - Aero Coeff │
└────────┬───────┘
│
▼
┌──────────────────┐
│ Flight Dynamics │
│ │
│ - Forces │
│ - Moments │
│ - RK4 Integration│
└────────┬─────────┘
│
▼
┌──────────────────┐
│ Atmosphere │
│ │
│ - ISA Model │
│ - ρ, P, T, a │
└──────────────────┘
User Input ──► InputHandler ──► Aircraft State
│
▼
FlightDynamics.update()
│
┌─────────────────┴─────────────────┐
│ │
▼ ▼
calculateForces() calculateMoments()
│ │
└─────────────────┬─────────────────┘
│
▼
RK4 Integration (4 steps)
│
▼
Update Aircraft State
│
┌─────────────────┴─────────────────┐
│ │
▼ ▼
Instruments.render() Renderer.render3D()
Purpose: Manages aircraft state and aerodynamic properties
Purpose: Physics integration using RK4
Purpose: ISA atmospheric properties
Purpose: Real-time cockpit display
The simulator uses a complete 6-degree-of-freedom aerodynamic model with stability derivatives:
The simulation uses 4th-order Runge-Kutta integration for superior numerical accuracy compared to Euler or midpoint methods. This is the industry standard for flight simulation.
Advantages:
Keyboard → Aircraft Control
──────────────────────────────────────
W/S, ↑/↓ → Elevator (pitch)
A/D, ←/→ → Aileron (roll)
Q/E → Rudder (yaw)
Z/X, PgUp/PgDn → Throttle
Space → Center controls
P → Pause/Resume
R → Reset
ESC → Exit
The simulator uses two primary coordinate frames:
Inertial reference frame
North (x)
↑
│
│
└────► East (y)
╱
╱
↓ Down (z)
Aircraft-fixed reference
Forward (x)
↑
│ (nose)
│
└────► Right (y)
╱
╱
↓ Down (z)
Transformations between frames use rotation matrices R(φ,θ,ψ) based on Euler angles.
#include "aircraft.hpp"
#include "flight_dynamics.hpp"
#include "renderer.hpp"
#include "input_handler.hpp"
#include <chrono>
int main() {
// Initialize systems
Renderer renderer;
Aircraft aircraft;
FlightDynamics dynamics(&aircraft);
InputHandler input(&aircraft);
// Main loop at 60 Hz
const double dt = 1.0 / 60.0;
double accumulator = 0.0;
auto lastTime = std::chrono::high_resolution_clock::now();
while (!renderer.shouldClose()) {
auto currentTime = std::chrono::high_resolution_clock::now();
double frameTime = std::chrono::duration<double>(
currentTime - lastTime).count();
lastTime = currentTime;
accumulator += frameTime;
// Physics update with fixed timestep
while (accumulator >= dt) {
input.processInput();
dynamics.update(dt);
accumulator -= dt;
}
// Render frame
renderer.render(aircraft);
}
return 0;
}
The modular architecture makes it easy to extend the simulator:
This project demonstrates:
Building this flight simulator taught me the fundamentals of physics-based simulation, real-time systems, and the mathematics behind aircraft flight. The project combines aerospace engineering principles with software engineering practices to create a realistic and performant simulation.