GAME DEV ยท FEB 2026

Pong Clone + Custom VectorMath Library

A custom vector maths library written in C++ and compiled as a DLL, used from Unity to run a Pong clone without any of Unity's built-in vector maths.

  • C++
  • Unity
  • DLL
  • Mathematics
  • Low-Level
Pong Clone + Custom VectorMath Library screenshot

At a glance

ROLE
Solo developer
TEAM
Solo

What I built

  • Vec2 and Vec3 libraries: add, subtract, scale, magnitude, normalize, dot, cross, lerp, slerp, reflect, project, move towards and clamp magnitude.
  • Unity interop with DllImport and sequential struct layouts.
  • Unit tests for the library in C++, in Visual Studio.
  • A performance test in Unity that compares the DLL with Unity's built-in vectors using a stopwatch.
  • Ball bounces computed with the library's own reflection.
  • A win and lose system with score tracking and restart.

Technical decision

A slerp that cannot return NaN

Slerp takes the angle between two unit vectors and builds the result from the first vector and a perpendicular one. Two guards keep it safe. The dot product is clamped to the range -1 to 1 before acos(), because rounding errors can push it just outside and acos() would return NaN. And Normalize() returns a zero vector instead of dividing by zero, so slerping between two identical vectors simply gives back the first one.

VectorMath.cpp
EXPORT Vec3 Vector3Normalize(Vec3 v) {
	float mag = Vector3Magnitude(v);

	if (mag == 0.0f)
		return { 0.0f, 0.0f, 0.0f };

	return {
		v.x / mag,
		v.y / mag,
		v.z / mag
	};
}

EXPORT Vec3 Vector3Slerp(Vec3 a, Vec3 b, float t)
{
	float dot = Vector3Dot(a, b);
	dot = std::fmax(-1.0f, std::fmin(dot, 1.0f));

	float theta = std::acos(dot) * t;

	Vec3 relative = Vector3Normalize(
		Vector3Subtraction(b, Vector3Scale(a, dot))
	);

	return Vector3Add(
		Vector3Scale(a, std::cos(theta)),
		Vector3Scale(relative, std::sin(theta))
	);
}
Two functions from the DLL. Slerp expects unit vectors. The full library is in the public repo.โ†— VIEW ON GITHUB