GameMath for real time graphics

Announcing GameMath

As the first part of an adventure I'm on, to open source major parts of my game engine, I'm happy to announce GameMath is now available on GitHub.

What's GameMath?

GameMath is a cross platform cornerstone package for making 2D / 3D games and includes types like vectors, matrices, and quaternions written completely in Swift.

Using GameMath

GameMath attempts to make math easier by using deliberate types and verbose naming for common tasks.

Distance is a simple function that only applies to positions.

let distance = p1.distance(from: p2)

Not sure if you should subtract p1 from p2, or p2 from p1 to get a direction vector?
Direction3 has an initializer for that.

let dirTowardP2 = Direction3<Float>(from: p1, to: p2)

Quaternions can be created with an Euler angle style constraint, which makes creating a "look at" angle easier. You can just use, .justPitch, .justYaw, or .pitchAndYaw.

let quat = Quaternion(lookingAt: target.position, from: self.position, constraint: .justYaw)

Degrees and Radians have their own types which eliminates confusion of which is returned or is accepted as an argument.

let quat1 = Quaternion(Degrees(90), axis: .right)
let quat2 = Quaternion(Radians(1.5708), axis: .right)
let quat3 = Quaternion(Radians(Degrees(90)), axis: .right)

And much more...

Check it out


This package exists because I wanted to see if I could do it. It's part of a much bigger and far more ambitious goal I have, a dream if you will. It was just a hobby and was never meant to become open source. However it turns out I can do it, and I think it's turning out pretty great. So here it is for you to enjoy too! Yay math! :unamused:

More To Come

GameMath is used in my own in-development games. Check them out here!
This is the first of many packages I intend release for use by the Swift community.
Look forward to higher level packages, focused on Gaming, in the future.

Special thanks to @Lantua and @Karl for their helpful tips and advice about moving from closed source to open source.

Terms of Service

Privacy Policy

Cookie Policy