Your one stop shop for vector math routines for 2d and 3d graphics.
- Pure Nim with no dependencies.
- Very similar to GLSL Shader Language with extra stuff.
- Extensively benchmarked.
| Type | Constructor | Description |
|---|---|---|
| BVec# | bvec# | vector of booleans |
| IVec# | ivec# | vector of signed integers |
| UVec# | uvec# | vector of unsigned integers |
| Vec# | vec# | vector of single-precision floating-point numbers |
| DVec# | dvec# | vector of double-precision floating-point numbers |
You can use these constructors to make them:
| NIM | GLSL | 2 | 3 | 4 | 9 | 16 | 4 |
|---|---|---|---|---|---|---|---|
| bool | bool | BVec2 | BVec3 | BVec4 | |||
| int32 | int | IVec2 | IVec3 | IVec4 | |||
| uint32 | uint | UVec2 | UVec3 | UVec4 | |||
| float32 | float | Vec2 | Vec3 | Vec4 | Mat3 | Mat4 | Quat |
| float64 | double | DVec2 | DVec3 | DVec4 | DMat3 | DMat4 | DQuat |
Procs
proc angleBetween[T: SomeFloat](a, b: T): T {.inline.}
- Angle between angle a and angle b. All angles assume radians. Source Edit
proc clamp(v: Vec2; min, max: float32): Vec2 {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc determinant[T](a: GMat2[T]): T {.inline.}
- Compute a determinant of the matrix. Source Edit
proc determinant[T](a: GMat3[T]): T {.inline.}
- Compute a determinant of the matrix. Source Edit
proc determinant[T](a: GMat4[T]): T {.inline.}
- Compute a determinant of the matrix. Source Edit
proc dmat4(a`gensym363, b`gensym363, c`gensym363, d`gensym363: GVec4[float64]): DMat4 {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc dmat4(m00`gensym363, m01`gensym363, m02`gensym363, m03`gensym363, m10`gensym363, m11`gensym363, m12`gensym363, m13`gensym363, m20`gensym363, m21`gensym363, m22`gensym363, m23`gensym363, m30`gensym363, m31`gensym363, m32`gensym363, m33`gensym363: float64): DMat4 {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc dquat(x`gensym430, y`gensym430, z`gensym430, w`gensym430: float64): DQuat {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc fractional[T: SomeFloat](v: T): T {....deprecated: "Use fract() instead", inline.}
- Returns fractional part of a number. Source Edit
proc fromAngles[T](a: GVec3[T]): GMat4[T] {.inline.}
- Takes a vector containing Euler angles and returns a matrix. All angles assume radians. Source Edit
proc fromAxisAngle[T](axis: GVec3[T]; angle: T): GVec4[T] {.inline.}
- Create a quaternion from axis and angle. Source Edit
proc fromTwoVectors[T](a, b: GVec3[T]): GVec4[T] {.inline.}
- Return a quat that would take a and rotate it into b. Source Edit
proc greaterThan[T](a`gensym189, b`gensym189: GVec2[T]): BVec2 {.inline.}
- Source Edit
proc greaterThan[T](a`gensym189, b`gensym189: GVec3[T]): BVec3 {.inline.}
- Source Edit
proc greaterThan[T](a`gensym189, b`gensym189: GVec4[T]): BVec4 {.inline.}
- Source Edit
proc greaterThanEqual[T](a`gensym199, b`gensym199: GVec2[T]): BVec2 {.inline.}
- Source Edit
proc greaterThanEqual[T](a`gensym199, b`gensym199: GVec3[T]): BVec3 {.inline.}
- Source Edit
proc greaterThanEqual[T](a`gensym199, b`gensym199: GVec4[T]): BVec4 {.inline.}
- Source Edit
proc inversesqrt[T: float32 | float64](v: T): T {.inline.}
- Returns inverse square root. Source Edit
proc inversesqrt[T](v`gensym174: GVec2[T]): GVec2[T] {.inline.}
- Source Edit
proc inversesqrt[T](v`gensym174: GVec3[T]): GVec3[T] {.inline.}
- Source Edit
proc inversesqrt[T](v`gensym174: GVec4[T]): GVec4[T] {.inline.}
- Source Edit
proc lessThanEqual[T](a`gensym188, b`gensym188: GVec2[T]): BVec2 {.inline.}
- Source Edit
proc lessThanEqual[T](a`gensym188, b`gensym188: GVec3[T]): BVec3 {.inline.}
- Source Edit
proc lessThanEqual[T](a`gensym188, b`gensym188: GVec4[T]): BVec4 {.inline.}
- Source Edit
proc mat4(a`gensym301, b`gensym301, c`gensym301, d`gensym301: GVec4[float32]): Mat4 {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc mat4(m00`gensym301, m01`gensym301, m02`gensym301, m03`gensym301, m10`gensym301, m11`gensym301, m12`gensym301, m13`gensym301, m20`gensym301, m21`gensym301, m22`gensym301, m23`gensym301, m30`gensym301, m31`gensym301, m32`gensym301, m33`gensym301: float32): Mat4 {. inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc mat4(m: DMat4): Mat4 {.inline, inline, ...raises: [], tags: [], forbids: [].}
- Convert a double precision matrix to a single precision matrix. Source Edit
proc orthogonal[T](v: GVec3[T]): GVec3[T] {.inline.}
- Returns orthogonal vector to given vector. Source Edit
proc perspective[T](fovy, aspect, near, far: T): GMat4[T] {.inline.}
- Create a perspective matrix. Source Edit
proc quatInverse[T](q: GVec4[T]): GVec4[T] {.inline.}
- Return the inverse of a quaternion. For unit quaternions this is the conjugate. Source Edit
proc quatRotateX[T](angle: T): GVec4[T] {.inline.}
- Return a quaternion that would rotate around the X axis. Source Edit
proc quatRotateY[T](angle: T): GVec4[T] {.inline.}
- Return a quaternion that would rotate around the Y axis. Source Edit
proc quatRotateZ[T](angle: T): GVec4[T] {.inline.}
- Return a quaternion that would rotate around the Z axis. Source Edit
proc rotationOnly[T](a: GMat4[T]): GMat4[T] {.inline, inline.}
- Clears the positional component and returns rotation only. Assumes matrix has not been scaled. Source Edit
proc toAngles[T](a: GVec3[T]): GVec3[T] {.inline.}
- Given a 3d vector, computes Euler angles: pitch and yaw pitch (x rotation) yaw (y rotation) roll (z rotation) - always 0 in vector case All angles assume radians. Source Edit
proc toAngles[T](m: GMat4[T]): GVec3[T] {.inline.}
- Decomposes the matrix into Euler angles: pitch (x rotation) yaw (y rotation) roll (z rotation) Assumes matrix has not been scaled. All angles assume radians. Source Edit
proc toAxisAngle[T](q: GVec4[T]): (GVec3[T], T) {.inline.}
- Convert a quaternion to axis and angle. Source Edit
Templates
template genMatConstructor(lower, upper, T: untyped) {..}
- Generate matrix constructor for your own type. Source Edit
template genQuatConstructor(lower, upper, typ: untyped) {..}
- Generate quaternion constructor for your own type. Source Edit
template genVecConstructor(lower, upper, typ: untyped) {..}
- Generate vector constructor for your own type. Source Edit