3D Game Engine
A custom-built component-based 3D game engine featuring real-time physics simulation, forward rendering pipeline, and flexible entity architecture.
📖 Overview
This project is a from-scratch 3D game engine developed in C++11 with OpenGL 3.3, demonstrating proficiency in real-time graphics programming, physics simulation, and game engine architecture. The engine implements industry-standard patterns including an Entity-Component System (ECS), a finite state machine for game states, and a multi-phase physics solver with impulse-based collision resolution.
✨ Key Highlights
- 🎯 Custom Physics Engine — Full rigid body dynamics with OBB collision detection, impulse resolution, and friction
- 🧩 Component-Based Architecture — Flexible ECS pattern enabling modular game object composition
- 💡 Forward Rendering Pipeline — Multi-light shader system supporting directional, point, and spot lights
- 🧠 Memory-Efficient Object Pooling — Pre-allocated entity arrays with deferred creation/deletion queues
- 🔍 Real-Time Debug Visualization — Collision wireframes and object orientation gizmos
🛠️ Tech Stack
| Category | Technology |
|---|---|
| Language | C++11 |
| Graphics API | OpenGL 3.3 Core Profile |
| Windowing | GLFW 3.x |
| OpenGL Loading | GLEW 2.x |
| Mathematics | GLM (OpenGL Mathematics) |
| Model Loading | Assimp (Open Asset Import Library) |
| Texture Loading | SOIL (Simple OpenGL Image Library) |
| Build System | CMake 3.15+ |
| Compiler | MSVC (Visual Studio Build Tools) |
🏗️ Architecture
┌──────────────────────────────────────────────────────────────────┐ │ GameEngine │ │ ┌─────────────────────────────────────────────────────────────┐ │ │ │ GameStateManager │ │ │ │ ┌────────────────────────────────────────────────────────┐ │ │ │ │ │ Level │ │ │ │ │ │ ┌──────────────────┐ ┌─────────────────────────────┐ │ │ │ │ │ │ │ PhysicsSystem │ │ ObjectManager │ │ │ │ │ │ │ │ ┌────────────┐ │ │ ┌───────────────────────┐ │ │ │ │ │ │ │ │ │ Collision │ │ │ │ GameObject[] │ │ │ │ │ │ │ │ │ │ Detection │ │ │ │ ┌─────────────────┐ │ │ │ │ │ │ │ │ │ ├────────────┤ │ │ │ │ Component[] │ │ │ │ │ │ │ │ │ │ │ Impulse │ │ │ │ │ • Transform │ │ │ │ │ │ │ │ │ │ │ Solver │ │ │ │ │ • RigidBody │ │ │ │ │ │ │ │ │ │ ├────────────┤ │ │ │ │ • Collider │ │ │ │ │ │ │ │ │ │ │ Integration│ │ │ │ │ • Behaviors │ │ │ │ │ │ │ │ │ │ └────────────┘ │ │ │ └─────────────────┘ │ │ │ │ │ │ │ │ └──────────────────┘ │ └───────────────────────┘ │ │ │ │ │ │ └────────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────┘ │ │ ┌─────────────────────────────────────────────────────────────┐ │ │ │ Rendering System │ │ │ │ Forward Renderer • Shader Management • Model/Mesh Pipeline │ │ │ └─────────────────────────────────────────────────────────────┘ │ └──────────────────────────────────────────────────────────────────┘
🧩 Entity-Component System (ECS)
The engine employs a component-based architecture where game entities (GameObject)
are containers for modular components that define behavior and properties:
// Component system uses CRTP pattern for type-safe component identification
class Transform : public Component<TRANSFORM> { ... };
class RigidBody : public Component<RIGIDBODY> { ... };
class Collider : public Component<COLLIDER> { ... };
Supported Components
Transform— Position, rotation, scale with matrix compositionRigidBody— Mass, velocity, angular velocity, inertia tensorsCollider— Box, Sphere, Capsule shapes with layer/mask filteringForceAccumulator— Force/impulse/torque applicationCollisionEvents— Callback-based collision event routingHUD— 2D overlay rendering component
⚙️ Physics System
A custom rigid body physics engine implementing a 6-phase simulation pipeline:
| Phase | Description |
|---|---|
| 1. Gather | Collect active bodies with physics components from ObjectManager |
| 2. Integrate Forces | Apply gravity and external forces to update velocities |
| 3. Detect Collisions | OBB vs OBB intersection testing using Separating Axis Theorem |
| 4. Solve Contacts | Sequential impulse solver with friction and restitution |
| 5. Integrate Velocities | Semi-implicit Euler integration for positions and orientations |
| 6. Sync Transforms | Write physics state back to Transform components |
Physics Features
- 🎲 Collision Shapes: Box (OBB), Sphere, Capsule
- 🏃 Body Types: Static, Dynamic, Kinematic
- 💥 Collision Response: Impulse-based with configurable restitution (bounciness)
- 🧲 Friction Model: Coulomb friction with tangent velocity projection
- 📐 Penetration Resolution: Baumgarte stabilization + positional correction
- 🏷️ Collision Layers: 32-bit layer/mask system for selective collision filtering
- 📊 Inertia Tensors: Auto-computed for boxes and spheres
- 📡 Event System: Enter/Stay/Exit callbacks for collisions and triggers
// Physics update pipeline (called each frame)
void PhysicsSystem::Update(float dt) {
GatherBodies(); // Phase 1
IntegrateForces(dt); // Phase 2
DetectCollisions(); // Phase 3
SolveContacts(dt); // Phase 4
IntegrateVelocities(dt); // Phase 5
SyncTransforms(); // Phase 6
}
🎨 Rendering System
A forward rendering pipeline with shader-based lighting using the Blinn-Phong model:
Lighting Types
- ☀️ Directional Light — Sun/ambient illumination
- 💡 Point Lights — Omni-directional with attenuation (up to 4 simultaneous)
- 🔦 Spot Light — Camera-attached flashlight with cutoff angles
Shader System
| Shader | Purpose |
|---|---|
MultiLight |
Primary PBR-style lighting with multi-source support |
DebugLine |
Wireframe rendering for collision visualization |
HUDText |
Bitmap font rendering for UI overlays |
DeferredGeometry |
(Experimental) G-buffer generation for deferred path |
Rendering Features
- Depth testing with
GL_LESScomparison - Back-face culling for performance
- Normal matrix computation for correct lighting under non-uniform scaling
- Automatic model/shader loading with error reporting
📊 Technical Specifications
| Metric | Value |
|---|---|
| OpenGL Version | 3.3 Core |
| GLSL Version | 130 |
| Max Point Lights | 4 (configurable) |
| Physics Solver Iterations | 8 (configurable) |
| Default Object Pool | 256 per model type |
| Collision Layers | 32 (bitmask) |
| Supported Model Formats | OBJ, FBX (via Assimp) |
✅ Implemented Features
🎮 Controls
| Key | Action |
|---|---|
| W A S D | Move camera |
| Mouse | Look around |
| C | Spawn dynamic box |
| V | Spawn static platform |
| M | Delete object in crosshair |
| P | Toggle collision debug view |
| ESC | Quit |
🚀 Future Enhancements
- ⬜ Broadphase optimization (spatial hashing / BVH)
- ⬜ Deferred rendering path
- ⬜ Shadow mapping
- ⬜ Skeletal animation support
- ⬜ Audio integration (FMOD ready)
- ⬜ Scene serialization
- ⬜ Editor tools