Vectors & Matrices

Thanks to Conjure’s focus on game development and graphics programming, it includes built-in support for vectors and matrices. These types are optimized for performance and ease of use in mathematical computations.

All vector and matrix types default to 64-bits, with the standard vec* and mat* types having f64 components unless a u or i prefix is used to indicate unsigned or signed integer types, respectively. So vec3 is a 3-dimensional vector of f64, while ivec4 is a 4-dimensional vector of i64.

Vector Types

Conjure provides built-in vector types for 2D, 3D, and 4D vectors. These types support common vector operations such as addition, subtraction, dot product, cross product (for 3D vectors), normalization, and so forth.

var pos = vec3(1.0, 2.0, 3.0)
pos.cross()

Swizzling

Vector components support swizzling, allowing you to access and rearrange components using their names. For example, x, y, z, and w can be used to access the respective components of a vector. Each swizzle results in a new vector of the appropriate size.

var v   = vec4(1.0, 2.0, 3.0, 4.0)
var xy  = v.xy        // vec2(1.0, 2.0)
var zzz = v.zzz       // vec3(3.0, 3.0, 3.0)

Matrix Types

TODO