Graphics math library for Kotlin, supports JVM, JS and multiplatform projects, developed with focus on readability, performance, and convenient usage with OpenGL based APIs.
This library is used in the multiplatform game project Skyway
At this moment the library is only available from my repository:
repositories {
maven { url 'https://maven.danielgergely.com/releases' }
}
dependencies {
implementation 'com.danielgergely.cgmath:cgmath:2.1.0'
}
Or you can build it manually:
./gradlew build
Vec2
: a two-dimensional vector of 32-bit floatsVec3
: a two-dimensional vector of 32-bit floatsVec4
: a two-dimensional vector of 32-bit floatsMat3
: a 3x3 column-major matrix of 32-bit floatsMat4
: a 4x4 column-major matrix of 32-bit floats
val v1 = Vec3(1f, 2f, 3f)
val v2 = Vec3(4f, 5f, 6f)
val sum = v1 + v2
val crossProduct = v1 cross v2
val matrix: Mat4
val vector: Vec4
val transformed = matrix * vector
val space = Vec3(…)
val (x, y, z) = space
val plain: Vec2 = space.xy
- All types are based on float arrays. - This is useful when using OpenGL's
uniform*v
methods, and also provides a type hint for Javascript runtimes, so that 32 bit operations can be used instead of the default 64 bit. - All types are inline classes. - This decreases a payload of the garbage collector which can be important for a realtime renderer.
*assign
operators don't use allocations- for build in graphics methods like
perspectiveM
andlookatM
, both assigning and returning versions are provided.