Algebra
Types and helpers for vectors and matrices.
Types
oc_vec2
typedef union oc_vec2
{
struct
{
f32 x;
f32 y;
};
f32 c[2];
} oc_vec2;
A 2D vector type.
Fields
c
The vector components as an array.
oc_vec3
typedef union oc_vec3
{
struct
{
f32 x;
f32 y;
f32 z;
};
f32 c[3];
} oc_vec3;
A 3D vector type.
Fields
c
The vector components as an array.
oc_vec2i
typedef union oc_vec2i
{
struct
{
i32 x;
i32 y;
};
i32 c[2];
} oc_vec2i;
A 2D integer vector type.
Fields
c
The vector components as an array.
oc_vec4
typedef union oc_vec4
{
struct
{
f32 x;
f32 y;
f32 z;
f32 w;
};
f32 c[4];
} oc_vec4;
A 4D vector type.
Fields
c
The vector components as an array.
oc_mat2x3
typedef struct oc_mat2x3
{
f32 m[6];
} oc_mat2x3;
A 2-by-3 matrix.
Fields
m
The elements of the matrix, stored in row-major order.
oc_rect
typedef union oc_rect
{
struct
{
f32 x;
f32 y;
f32 w;
f32 h;
};
struct
{
oc_vec2 xy;
oc_vec2 wh;
};
f32 c[4];
} oc_rect;
An axis-aligned rectangle.
Fields
c
The rectangle components as an array.
Functions
oc_vec2_equal
bool oc_vec2_equal(oc_vec2 v0, oc_vec2 v1);
Check if two 2D vectors are equal.
Parameters
v0
The first vectorv1
The second vector
Return
true
if v0
and v1
are equal, false
otherwise.
oc_vec2_mul
oc_vec2 oc_vec2_mul(f32 f, oc_vec2 v);
Multiply a 2D vector by a scalar.
Parameters
f
The value by which to scale the vector.v
The vector to scale.
Return
The result of the multiplication.
oc_vec2_add
oc_vec2 oc_vec2_add(oc_vec2 v0, oc_vec2 v1);
Add two 2D vectors
Parameters
v0
The first vector.v1
The second vector.
Return
The result vector.
oc_mat2x3_mul
oc_vec2 oc_mat2x3_mul(oc_mat2x3 m, oc_vec2 p);
Transforms a vector by an affine transformation represented as a 2x3 matrix.
Parameters
m
The input matrix.m
holds an affine transformation. It is treated as a 3x3 matrix with an implicit(0, 0, 1)
bottom row.p
The input vector. It is treated as a 3D homogeneous coordinate vector with an implicit z-coordinate equal to 1.
Return
The result vector.
oc_mat2x3_mul_m
oc_mat2x3 oc_mat2x3_mul_m(oc_mat2x3 lhs, oc_mat2x3 rhs);
Multiply two affine transformations represented as 2x3 matrices. Both matrices are treated as 3x3 matrices with an implicit (0, 0, 1)
bottom row
Parameters
lhs
The left-hand side matrixrhs
The right-hand side matrix
Return
The result matrix.
oc_mat2x3_inv
oc_mat2x3 oc_mat2x3_inv(oc_mat2x3 x);
Invert an affine transform represented as a 2x3 matrix.
Parameters
x
The input matrix. It is treated as a 3x3 matrix with an implicit(0, 0, 1)
bottom row.
Return
The result matrix
oc_mat2x3_rotate
oc_mat2x3 oc_mat2x3_rotate(f32 radians);
Return a 2x3 matrix representing a rotation.
Parameters
radians
The rotation angle, in radians.
Return
The resulting rotation.
oc_mat2x3_translate
oc_mat2x3 oc_mat2x3_translate(f32 x, f32 y);
Return a 2x3 matrix representing a translation.
Parameters
x
The first component of the translation.y
The second component of the translation.
Return
The resulting translation.