Source
Edit
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 |
proc `$`(a`gensym6: BVec2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym6: BVec3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym6: BVec4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym28: IVec2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym28: IVec3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym28: IVec4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym50: UVec2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym50: UVec3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym50: UVec4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym72: Vec2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym72: Vec3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym72: Vec4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym94: DVec2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym94: DVec3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym94: DVec4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym247: Mat2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym247: Mat3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym247: Mat4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym309: DMat2): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym309: DMat3): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc `$`(a`gensym309: DMat4): string {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
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 bvec2(x`gensym6, y`gensym6: bool): BVec2 {.inline, ...raises: [], tags: [],
forbids: [].}
-
Source
Edit
proc bvec3(x`gensym6, y`gensym6, z`gensym6: bool): BVec3 {.inline, ...raises: [],
tags: [], forbids: [].}
-
Source
Edit
proc bvec4(x`gensym6, y`gensym6, z`gensym6, w`gensym6: bool): BVec4 {.inline,
...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc dmat2(m00`gensym309, m01`gensym309, m10`gensym309, m11`gensym309: float64): DMat2 {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc dmat3(a`gensym309, b`gensym309, c`gensym309: GVec3[float64]): DMat3 {.
inline, ...raises: [], tags: [], forbids: [].}
-
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: [],
forbids: [].}
-
Source
Edit
proc dmat4(a`gensym309, b`gensym309, c`gensym309, d`gensym309: GVec4[float64]): DMat4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
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: [], forbids: [].}
-
Source
Edit
proc dquat(x`gensym376, y`gensym376, z`gensym376, w`gensym376: float64): DQuat {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc dquat(x`gensym376: float64): DQuat {.inline, ...raises: [], tags: [],
forbids: [].}
-
Source
Edit
proc dvec2(x`gensym94, y`gensym94: float64): DVec2 {.inline, ...raises: [],
tags: [], forbids: [].}
-
Source
Edit
proc dvec3(x`gensym94, y`gensym94, z`gensym94: float64): DVec3 {.inline,
...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc dvec4(x`gensym94, y`gensym94, z`gensym94, w`gensym94: float64): DVec4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
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.14
Source
Edit
proc fractional[T: SomeFloat](v: T): T {....deprecated: "Use frac() insetad",
inline.}
-
Deprecated: Use frac() insetad
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 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 isNan(x: SomeFloat): bool {.inline.}
-
Returns true if number is a NaN.
Source
Edit
proc ivec2(x`gensym28, y`gensym28: int32): IVec2 {.inline, ...raises: [], tags: [],
forbids: [].}
-
Source
Edit
proc ivec3(x`gensym28, y`gensym28, z`gensym28: int32): IVec3 {.inline,
...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc ivec4(x`gensym28, y`gensym28, z`gensym28, w`gensym28: int32): IVec4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc lerp[V, T](a, b: V; v: T): type(a) {....deprecated: "use mix instead", inline.}
-
Deprecated: use mix instead
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.}
-
Deprecated: Wrong coordinate system. Use toAngles(eye, center).fromAngles() instead to get right-handed-z-forward coordinate system
Create a matrix that would convert eye pos to looking at center.
Source
Edit
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.}
-
Deprecated: Wrong coordinate system. Use toAngles(eye, center).fromAngles() instead to get right-handed-z-forward coordinate system
Look center from eye with default UP vector.
Source
Edit
proc mat2(a`gensym247, b`gensym247: GVec2[float32]): Mat2 {.inline, ...raises: [],
tags: [], forbids: [].}
-
Source
Edit
proc mat2(m00`gensym247, m01`gensym247, m10`gensym247, m11`gensym247: float32): Mat2 {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc mat3(a`gensym247, b`gensym247, c`gensym247: GVec3[float32]): Mat3 {.inline,
...raises: [], tags: [], forbids: [].}
-
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: [],
forbids: [].}
-
Source
Edit
proc mat4(a`gensym247, b`gensym247, c`gensym247, d`gensym247: GVec4[float32]): Mat4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
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: [], forbids: [].}
-
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
Source
Edit
proc mix[T: SomeFloat](a, b: GVec234[T]; v: T): type(a) {.inline.}
-
Source
Edit
proc ortho[T](left, right, bottom, top, near, far: T): GMat4[T] {.inline.}
-
Create an orthographic 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: [], forbids: [].}
-
Source
Edit
proc quat(x`gensym372: float32): Quat {.inline, ...raises: [], tags: [],
forbids: [].}
-
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 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 sign[T](v: T): T {.inline.}
-
Returns the sign of a number, -1 or 1.
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 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 uvec2(x`gensym50, y`gensym50: uint32): UVec2 {.inline, ...raises: [],
tags: [], forbids: [].}
-
Source
Edit
proc uvec3(x`gensym50, y`gensym50, z`gensym50: uint32): UVec3 {.inline,
...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc uvec4(x`gensym50, y`gensym50, z`gensym50, w`gensym50: uint32): UVec4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc vec2(x`gensym72, y`gensym72: float32): Vec2 {.inline, ...raises: [], tags: [],
forbids: [].}
-
Source
Edit
proc vec2(x`gensym72: float32): Vec2 {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc vec3(x`gensym72, y`gensym72, z`gensym72: float32): Vec3 {.inline,
...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc vec3(x`gensym72: float32): Vec3 {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc vec4(x`gensym72, y`gensym72, z`gensym72, w`gensym72: float32): Vec4 {.
inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc vec4(x`gensym72: float32): Vec4 {.inline, ...raises: [], tags: [], forbids: [].}
-
Source
Edit
proc zmod(a, b: float32): float32 {.inline, ...raises: [], tags: [], forbids: [].}
-
Float point mod.
Source
Edit
proc `~=`[T: SomeFloat](a, b: T): bool {.inline.}
-
Almost equal.
Source
Edit