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 between[T](value, min, max: T): bool {.inline.}
- Returns true if value is between min and max or equal to them. Source Edit
proc bvec3(x`gensym6, y`gensym6, z`gensym6: bool): BVec3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc bvec4(x`gensym6, y`gensym6, z`gensym6, w`gensym6: bool): BVec4 {.inline, ...raises: [], tags: [].}
- 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 dmat2(a`gensym309, b`gensym309: GVec2[float64]): DMat2 {.inline, ...raises: [], tags: [].}
- Source Edit
proc dmat2(m00`gensym309, m01`gensym309, m10`gensym309, m11`gensym309: float64): DMat2 {. inline, ...raises: [], tags: [].}
- Source Edit
proc dmat3(a`gensym309, b`gensym309, c`gensym309: GVec3[float64]): DMat3 {. inline, ...raises: [], tags: [].}
- Source Edit
proc dmat3(m00`gensym309, m01`gensym309, m02`gensym309, m10`gensym309, m11`gensym309, m12`gensym309, m20`gensym309, m21`gensym309, m22`gensym309: float64): DMat3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc dmat4(a`gensym309, b`gensym309, c`gensym309, d`gensym309: GVec4[float64]): DMat4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc dmat4(m00`gensym309, m01`gensym309, m02`gensym309, m03`gensym309, m10`gensym309, m11`gensym309, m12`gensym309, m13`gensym309, m20`gensym309, m21`gensym309, m22`gensym309, m23`gensym309, m30`gensym309, m31`gensym309, m32`gensym309, m33`gensym309: float64): DMat4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc dquat(x`gensym376, y`gensym376, z`gensym376, w`gensym376: float64): DQuat {. inline, ...raises: [], tags: [].}
- Source Edit
proc dvec3(x`gensym94, y`gensym94, z`gensym94: float64): DVec3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc dvec4(x`gensym94, y`gensym94, z`gensym94, w`gensym94: float64): DVec4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc fixAngle[T: SomeFloat](angle: T): T {.inline.}
- Normalize the angle to be from -PI to PI radians. Source Edit
proc fract[T: SomeFloat](v: T): T {.inline.}
-
Returns fractional part of a number. 3.14 -> 0.14Source Edit-3.14 -> 0.14
proc fractional[T: SomeFloat](v: T): T {....deprecated: "Use frac() insetad", inline.}
- Source Edit Returns fractional part of a number.
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 frustum[T](left, right, bottom, top, near, far: T): GMat4[T] {.inline.}
- Create a frustum matrix. Source Edit
proc gmat4[T](m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33: T): GMat4[T] {.inline.}
- 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 ivec3(x`gensym28, y`gensym28, z`gensym28: int32): IVec3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc ivec4(x`gensym28, y`gensym28, z`gensym28, w`gensym28: int32): IVec4 {. inline, ...raises: [], tags: [].}
- 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 lookAt[T](eye, center, up: GVec3[T]): GMat4[T] {....deprecated: "Wrong coordinate system. Use toAngles(eye, center).fromAngles() instead to get right-handed-z-forward coordinate system", inline.}
- Source Edit Create a matrix that would convert eye pos to looking at center.
proc lookAt[T](eye, center: GVec3[T]): GMat4[T] {....deprecated: "Wrong coordinate system. Use toAngles(eye, center).fromAngles() instead to get right-handed-z-forward coordinate system", inline.}
- Source Edit Look center from eye with default UP vector.
proc mat2(a`gensym247, b`gensym247: GVec2[float32]): Mat2 {.inline, ...raises: [], tags: [].}
- Source Edit
proc mat2(m00`gensym247, m01`gensym247, m10`gensym247, m11`gensym247: float32): Mat2 {. inline, ...raises: [], tags: [].}
- Source Edit
proc mat3(a`gensym247, b`gensym247, c`gensym247: GVec3[float32]): Mat3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc mat3(m00`gensym247, m01`gensym247, m02`gensym247, m10`gensym247, m11`gensym247, m12`gensym247, m20`gensym247, m21`gensym247, m22`gensym247: float32): Mat3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc mat4(a`gensym247, b`gensym247, c`gensym247, d`gensym247: GVec4[float32]): Mat4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc mat4(m00`gensym247, m01`gensym247, m02`gensym247, m03`gensym247, m10`gensym247, m11`gensym247, m12`gensym247, m13`gensym247, m20`gensym247, m21`gensym247, m22`gensym247, m23`gensym247, m30`gensym247, m31`gensym247, m32`gensym247, m33`gensym247: float32): Mat4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc mix[T: SomeFloat](a, b, v: T): T {.inline.}
-
Interpolates value between a and b.
- 0 -> a
- 1 -> b
- 0.5 -> between a and b
proc ortho[T](left, right, bottom, top, near, far: T): GMat4[T] {.inline.}
- Create an orthographic 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 quantize[T: SomeFloat](v, n: T): T {.inline.}
- Makes v be multiple of n. Rounding to integer quantize by 1.0. Source Edit
proc quat(x`gensym372, y`gensym372, z`gensym372, w`gensym372: float32): Quat {. inline, ...raises: [], tags: [].}
- Source Edit
proc rotate[T](angle: T): GMat3[T] {.inline.}
- Create a 2D rotation matrix by an angle. All angles assume radians. Source Edit
proc rotate[T](angle: T; axis: GVec3[T]): GMat4[T] {.inline.}
- Return a rotation matrix with axis and angle. Source Edit
proc rotateX[T](angle: T): GMat4[T] {.inline.}
- Return a rotation matrix around X with angle. All angles assume radians. Source Edit
proc rotateY[T](angle: T): GMat4[T] {.inline.}
- Return a rotation matrix around Y with angle. All angles assume radians. Source Edit
proc rotateZ[T](angle: T): GMat4[T] {.inline.}
- Return a rotation matrix around Z with angle. All angles assume radians. 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 toAngles[T](origin, target: GVec3[T]): GVec3[T] {.inline.}
-
- Gives Euler angles from origin to target
- pitch (x rotation) yaw (y rotation) roll (z rotation) - always 0 in vector case
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
proc turnAngle[T: SomeFloat](a, b, speed: T): T {.inline.}
- Move from angle a to angle b with step of v. All angles assume radians. Source Edit
proc uvec3(x`gensym50, y`gensym50, z`gensym50: uint32): UVec3 {.inline, ...raises: [], tags: [].}
- Source Edit
proc uvec4(x`gensym50, y`gensym50, z`gensym50, w`gensym50: uint32): UVec4 {. inline, ...raises: [], tags: [].}
- Source Edit
proc vec3(x`gensym72, y`gensym72, z`gensym72: float32): Vec3 {.inline, ...raises: [], tags: [].}
- 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