GameMath provides common types, related functions, and operators used for interactive realtime simulations (games).
GameMath provides common types, related functions, and operators commonly used for interactive realtime simulations (games).
You can use this library to create simple games, or use it as a cornerstone for a more complex engine like GateEngine.
GameMath uses protocols and generics to promote clear type intention. Vector types as an example have many variations including Position3
, Direction3
, and Size3
that all conform toVector3
, a protocol that provides common functionality to these types.
Operators such as multiplication, division, addition, and subtraction, can be used across types so long as they use the same generic constraint. The type returned will be the logical result of the operation, usually the left side.
//Success
let pos: Position3 = Position3(0, 1, 0) * Size3(1, 1, 1)
//Error: Size3 cannot be converted to Position3
let pos: Position3 = Size3(1, 1, 1) * Position3(0, 1, 0)
GameMath is intended to make doing gamming math easier for everyone. An example is interpolation.
The functions lerp()
and slerp()
are commonly seen in game libraries for linear interpolation. Without advanced knowledge of these functions it’s difficult to reason about them and know what they do.
GameMath attempts to improve on this issue by introducing a common syntax for interpolation for all types across the package.
let halfway = source.interpolated(to: destination, .linear(0.5))
This syntax will be expanded with new interpolation methods like easeIn and easeOut in the future.
GameMath uses a Y Up, -Z forward, coordinate system for 3D and Y Up, X Right for 2D.
Matrix types are assumed to always be “left handed”. Use the transposedArray
and transposedSIMD
properties when sending data to Metal, Vulkan, OpenGL, and the array
and simd
properties when sending data to DirectX.
GameMath is tested to work on Windows 10, macOS, Ubuntu, iOS, tvOS, and HTML5.
Other platforms should also work.
This package is seperated for you to enjoy, but it’s built for and used by GateEngine.
If you appreciate this project, and want it to continue, then please consider putting some dollars into it.
Every little bit helps! Support With: GitHub, Ko-fi, Pateron