top of page

Custom 3D Math Engine & Solar Simulation (More Technical)

Engine: Unity

Language: C#

Focus: Engine Architecture, 3D Mathematics, Physics Simulation

​​

This project is a technical case study in engine architecture. The goal was to build a fully functional solar system simulation in Unity without using any of the engine's built-in math or physics libraries.

​

I recreated the core mathematical foundations of a game engine from scratch—including Vectors, Quaternions, and Transformation Matrices—to demonstrate a deep understanding of linear algebra and 3D spatial logic.​

Overview

The Core Math Library

Custom Math Library (Built from Scratch):

Vector Arithmetic:

Developed a custom MyVector3 struct to handle vector arithmetic (Dot Product, Cross Product, Normalization) completely independent of UnityEngine.Vector3.

Transformation Matrices:

Built a Matrix4x4 class to handle complex spatial transformations (Position, Rotation, Scale) manually.

Quaternions & Spherical Interpolation:

Implemented a Quaternion class to handle rotational logic and prevent Gimbal Lock. This included engineering a custom Slerp (Spherical Linear Interpolation) function for smooth camera movement and orbital mechanics.

Engine Architecture & Tracking

Engine Architecture & Tracking:

  • The "MyTransform" Component: I built a custom component that completely replaces Unity’s default Transform. It handles parent-child hierarchies and Local-to-World space conversions manually, allowing planets to orbit parent stars while simultaneously maintaining their own axial rotation (e.g., Uranus's unique tilt).

  • Smooth-Dampening Camera System: Implemented a custom tracking camera utilizing my math library to follow planets without jitter. This solved early prototyping issues where fast-moving objects (like Mercury) caused heavy stuttering in the default engine camera.

Engineering Solutions & Post-Mortem

The "Mesh Distortion" Bug:

The Challenge:

Early in development, re-applying matrix transformations every frame caused the planet meshes to slowly distort and stretch due to floating-point errors accumulating in the scale matrix.

The Solution:

I engineered a Cached Vertex System. Instead of modifying the mesh permanently each frame, the script caches the original vertex positions at start-up. Every frame, it applies the new transformation matrix to the original data, ensuring the mesh integrity remains mathematically perfect regardless of rotation speed or simulation duration.

​

Post-Mortem: Critical Reflection & Takeaways

Reinventing the Wheel vs. Native Optimization:

Critically evaluating the project’s architecture, while the custom C# math library successfully proved the theoretical concepts of linear algebra, running these calculations natively in C# introduces a performance overhead at scale. Unity’s built-in UnityEngine.Mathf and Vector3 libraries are deeply optimized at the C++ engine level and utilize SIMD (Single Instruction, Multiple Data) instructions, which C# cannot inherently match in a standard Update() loop.

​

The Takeaway:

"Reinventing the wheel" is an invaluable learning exercise to understand the spatial mechanics underlying a game engine. However, in a commercial AAA production environment, leveraging the engine's deeply optimized, native mathematical libraries is critical for maintaining strict rendering and performance budgets. Moving forward, I will utilize my deeper understanding of Quaternions and Matrices to write more efficient native engine code, rather than attempting to replace the foundational infrastructure.

bottom of page