Project 2: Vector Math Library with SIMD

A 3D math library with Vec2, Vec3, Vec4, Mat4, and Quaternion types using Odin’s built-in SIMD and array programming, plus operations like dot, cross, normalize, and matrix multiplication.

Quick Reference

Attribute Value
Primary Language Odin
Alternative Languages C (with intrinsics), Rust
Difficulty Level 2: Intermediate
Time Estimate 1 week
Knowledge Area SIMD / Math / Performance
Tooling Odin’s built-in SIMD
Prerequisites Basic linear algebra (vectors, matrices)

What You Will Build

A 3D math library with Vec2, Vec3, Vec4, Mat4, and Quaternion types using Odin’s built-in SIMD and array programming, plus operations like dot, cross, normalize, and matrix multiplication.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Using #simd vectors efficiently → maps to hardware SIMD understanding
  • Implementing quaternion operations → maps to using Odin’s built-in quaternion type
  • Matrix operations with proper layout → maps to column-major matrices for SIMD
  • Leveraging swizzling → maps to elegant vector manipulation

Key Concepts

  • SIMD in Odin: Odin SIMD Package
  • Array Programming: Odin Overview
  • Linear Algebra for Games: “Computer Graphics from Scratch” Ch. 2-4
  • Quaternions: “3D Math Primer for Graphics and Game Development” Ch. 8

Real-World Outcome

$ odin run math_lib_demo

Vector Operations
-----------------
a = {1.0, 2.0, 3.0}
b = {4.0, 5.0, 6.0}
a + b = {5.0, 7.0, 9.0}
a · b = 32.0
a × b = {-3.0, 6.0, -3.0}
|a| = 3.742

Swizzling Demo
--------------
v = {1.0, 2.0, 3.0, 4.0}
v.xy = {1.0, 2.0}
v.zyx = {3.0, 2.0, 1.0}
v.wwww = {4.0, 4.0, 4.0, 4.0}

Quaternion Demo
---------------
q1 = rotation(45°, Y_AXIS)
q2 = rotation(30°, X_AXIS)
q_combined = q1 * q2
Rotating point {1, 0, 0}: {0.707, 0.354, 0.612}

Matrix Demo
-----------
M = perspective(fov=60°, aspect=16/9, near=0.1, far=100)
V = look_at(eye={0,5,10}, target={0,0,0}, up={0,1,0})
MVP = M * V

SIMD Benchmark (1M operations)
------------------------------
Scalar dot product: 8.2ms
SIMD dot product:   1.1ms
Speedup: 7.5x

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_ODIN_PROGRAMMING_LANGUAGE.md
  • “Computer Graphics from Scratch” by Gabriel Gambetta