Modern OpenGL Programming
A practical, engine‑oriented journey into today’s programmable graphics pipeline.
OpenGL Banner
Chapter 4. Math Foundations for Graphics & Simulation
Designing a Lightweight, Engine Ready Math Module for Real Time Rendering & Physics

Math is the backbone of any engine. But the math needed for simple games and real time physics simulation is not the same as the math needed for CAE or scientific computing.

The GusOnGames engine needs a math module that is:

This article defines the exact math foundations required for the engine — no more, no less.

Vectors & Matrices: The Core Building Blocks

Vectors and points are the fundamental building blocks for representing positions, directions, and displacements in 3D space. In the GusOnGames engine, we distinguish between points (which represent positions) and vectors (which represent directions and magnitudes).

The math module provides:

These types must be:

We avoid operator overloading that hides cost or intent.

1. vec2 / vec3 / vec4

Required operations:

Design principles:

Summary:

Vectors must behave like simple structs with clear math operations.

2. mat3 / mat4

Required operations:

Design principles:

Summary:

Matrices must be predictable and compatible with GPU expectations.

Transformations: The Heart of Rendering & Simulation

A Transform represents:

1. Composition

Transforms must support:

2. Rotation Representation

We start with:

Later articles may introduce:

3. Coordinate Spaces

Transforms define movement between:

Understanding these spaces is essential for rendering.

Coordinate Spaces: The Engine’s Mental Model
1. Local Space

The object’s own coordinate system.

2. World Space

All objects placed together.

3. View Space

The world as seen from the camera.

4. Projection Space

Perspective or orthographic projection.

5. Screen Space

Normalized device coordinates → viewport.

6. Why this matters

Every rendering operation is a chain of transforms:

vertex_local
→ model_matrix
→ world_space
→ view_matrix
→ view_space
→ projection_matrix
→ clip_space
→ screen_space

The math module must make this pipeline easy to express.

Numerical Stability: Real Time Constraints

Real time engines face different numerical challenges than CAE tools.

1. Floating Point Pitfalls
2. Practical Rules for Real Time Engines
3. Determinism Considerations

Physics simulations require:

This is why the math module must be simple and explicit.

Designing the Math Module

The math module must be:

1. Header Only Structure

These headers define the core math types and operations for the engine.

engine/math/include
    vector.h
    matrix.h
    projections.h
    transformations.h
    math_utils.hpp
2. No External Dependencies

We avoid:

Why?

Because the engine needs:

3. GPU Friendly Layout

Matrices must be column major to match OpenGL’s expectations.

Vectors must be contiguous and trivially copyable.

4. API Design Principles

This makes the math module easy to use and easy to teach.

Math Module API Reference

The following is a quick reference for the math module API:

The math module provides the foundational types and operations used throughout the GusOnGames engine:

It is:

1. Vector Types

vectors (vec2, vec3, vec4)

Members

Key Methods

2. Matrix Types

matX (mat2, mat3, mat4)

Storage

Key Methods

3. Transform

Transform

Members

Key Methods

4. Math Utilities

math_utils

Functions

5. Design Principles
Summary
Math Module API Reference

This article defined the math foundations required for the GusOnGames engine:

This math module is the foundation for both rendering and simulation. It is intentionally simple, intentionally explicit, and intentionally educational.