Kohi Game Engine
kmath.h File Reference

This file contains definitions for various important constant values as well as functions for many common math types. More...

#include "core/kmemory.h"
#include "defines.h"
#include "math_types.h"

Go to the source code of this file.

Macros

#define K_PI   3.14159265358979323846f
 An approximate representation of PI. More...
 
#define K_2PI   (2.0f * K_PI)
 An approximate representation of PI multiplied by 2. More...
 
#define K_4PI   (4.0f * K_PI)
 An approximate representation of PI multiplied by 4. More...
 
#define K_HALF_PI   (0.5f * K_PI)
 An approximate representation of PI divided by 2. More...
 
#define K_QUARTER_PI   (0.25f * K_PI)
 An approximate representation of PI divided by 4. More...
 
#define K_ONE_OVER_PI   (1.0f / K_PI)
 One divided by an approximate representation of PI. More...
 
#define K_ONE_OVER_TWO_PI   (1.0f / K_2PI)
 One divided by half of an approximate representation of PI. More...
 
#define K_SQRT_TWO   1.41421356237309504880f
 An approximation of the square root of 2. More...
 
#define K_SQRT_THREE   1.73205080756887729352f
 An approximation of the square root of 3. More...
 
#define K_SQRT_ONE_OVER_TWO   0.70710678118654752440f
 One divided by an approximation of the square root of 2. More...
 
#define K_SQRT_ONE_OVER_THREE   0.57735026918962576450f
 One divided by an approximation of the square root of 3. More...
 
#define K_DEG2RAD_MULTIPLIER   (K_PI / 180.0f)
 A multiplier used to convert degrees to radians. More...
 
#define K_RAD2DEG_MULTIPLIER   (180.0f / K_PI)
 A multiplier used to convert radians to degrees. More...
 
#define K_SEC_TO_US_MULTIPLIER   (1000.0f * 1000.0f)
 The multiplier to convert seconds to microseconds. More...
 
#define K_SEC_TO_MS_MULTIPLIER   1000.0f
 The multiplier to convert seconds to milliseconds. More...
 
#define K_MS_TO_SEC_MULTIPLIER   0.001f
 The multiplier to convert milliseconds to seconds. More...
 
#define K_INFINITY   (1e30f * 1e30f)
 A huge number that should be larger than any valid number used. More...
 
#define K_FLOAT_EPSILON   1.192092896e-07f
 Smallest positive number where 1.0 + FLOAT_EPSILON != 0. More...
 
#define KSWAP(type, a, b)
 

Functions

KINLINE void kswapf (f32 *a, f32 *b)
 
KINLINE f32 ksign (f32 x)
 Returns 0.0f if x == 0.0f, -1.0f if negative, otherwise 1.0f. More...
 
KINLINE f32 kstep (f32 edge, f32 x)
 Compares x to edge, returning 0 if x < edge; otherwise 1.0f;. More...
 
KAPI f32 ksin (f32 x)
 Calculates the sine of x. More...
 
KAPI f32 kcos (f32 x)
 Calculates the cosine of x. More...
 
KAPI f32 ktan (f32 x)
 Calculates the tangent of x. More...
 
KAPI f32 kacos (f32 x)
 Calculates the arc cosine of x. More...
 
KAPI f32 ksqrt (f32 x)
 Calculates the square root of x. More...
 
KAPI f32 kabs (f32 x)
 Calculates the absolute value of x. More...
 
KAPI f32 kfloor (f32 x)
 Returns the largest integer value less than or equal to x. More...
 
KAPI f32 klog2 (f32 x)
 Computes the base-2 logarithm of x (i.e. how many times x can be divided by 2). More...
 
KINLINE b8 is_power_of_2 (u64 value)
 Indicates if the value is a power of 2. 0 is considered not a power of 2. More...
 
KAPI i32 krandom (void)
 Returns a random integer. More...
 
KAPI i32 krandom_in_range (i32 min, i32 max)
 Returns a random integer that is within the given range (inclusive). More...
 
KAPI f32 kfrandom (void)
 Returns a random floating-point number. More...
 
KAPI f32 kfrandom_in_range (f32 min, f32 max)
 Returns a random floating-point number that is within the given range (inclusive). More...
 
KINLINE f32 ksmoothstep (f32 edge_0, f32 edge_1, f32 x)
 Perform Hermite interpolation between two values. More...
 
KINLINE b8 kfloat_compare (f32 f_0, f32 f_1)
 Compares the two floats and returns true if both are less than K_FLOAT_EPSILON apart; otherwise false. More...
 
KINLINE vec2 vec2_create (f32 x, f32 y)
 Creates and returns a new 2-element vector using the supplied values. More...
 
KINLINE vec2 vec2_zero (void)
 Creates and returns a 2-component vector with all components set to 0.0f. More...
 
KINLINE vec2 vec2_one (void)
 Creates and returns a 2-component vector with all components set to 1.0f. More...
 
KINLINE vec2 vec2_up (void)
 Creates and returns a 2-component vector pointing up (0, 1). More...
 
KINLINE vec2 vec2_down (void)
 Creates and returns a 2-component vector pointing down (0, -1). More...
 
KINLINE vec2 vec2_left (void)
 Creates and returns a 2-component vector pointing left (-1, 0). More...
 
KINLINE vec2 vec2_right (void)
 Creates and returns a 2-component vector pointing right (1, 0). More...
 
KINLINE vec2 vec2_add (vec2 vector_0, vec2 vector_1)
 Adds vector_1 to vector_0 and returns a copy of the result. More...
 
KINLINE vec2 vec2_sub (vec2 vector_0, vec2 vector_1)
 Subtracts vector_1 from vector_0 and returns a copy of the result. More...
 
KINLINE vec2 vec2_mul (vec2 vector_0, vec2 vector_1)
 Multiplies vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE vec2 vec2_mul_scalar (vec2 vector_0, f32 scalar)
 Multiplies all elements of vector_0 by scalar and returns a copy of the result. More...
 
KINLINE vec2 vec2_mul_add (vec2 vector_0, vec2 vector_1, vec2 vector_2)
 Multiplies vector_0 by vector_1, then adds the result to vector_2. More...
 
KINLINE vec2 vec2_div (vec2 vector_0, vec2 vector_1)
 Divides vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE f32 vec2_length_squared (vec2 vector)
 Returns the squared length of the provided vector. More...
 
KINLINE f32 vec2_length (vec2 vector)
 Returns the length of the provided vector. More...
 
KINLINE void vec2_normalize (vec2 *vector)
 Normalizes the provided vector in place to a unit vector. More...
 
KINLINE vec2 vec2_normalized (vec2 vector)
 Returns a normalized copy of the supplied vector. More...
 
KINLINE b8 vec2_compare (vec2 vector_0, vec2 vector_1, f32 tolerance)
 Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance. More...
 
KINLINE f32 vec2_distance (vec2 vector_0, vec2 vector_1)
 Returns the distance between vector_0 and vector_1. More...
 
KINLINE f32 vec2_distance_squared (vec2 vector_0, vec2 vector_1)
 Returns the squared distance between vector_0 and vector_1. NOTE: If purely for comparison purposes, prefer this over non-squared version to avoid a sqrt call. More...
 
KINLINE vec3 vec3_create (f32 x, f32 y, f32 z)
 Creates and returns a new 3-element vector using the supplied values. More...
 
KINLINE vec3 vec3_from_vec4 (vec4 vector)
 Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component. More...
 
KINLINE vec4 vec3_to_vec4 (vec3 vector, f32 w)
 Returns a new vec4 using vector as the x, y and z components and w for w. More...
 
KINLINE vec3 vec3_zero (void)
 Creates and returns a 3-component vector with all components set to 0.0f. More...
 
KINLINE vec3 vec3_one (void)
 Creates and returns a 3-component vector with all components set to 1.0f. More...
 
KINLINE vec3 vec3_up (void)
 Creates and returns a 3-component vector pointing up (0, 1, 0). More...
 
KINLINE vec3 vec3_down (void)
 Creates and returns a 3-component vector pointing down (0, -1, 0). More...
 
KINLINE vec3 vec3_left (void)
 Creates and returns a 3-component vector pointing left (-1, 0, 0). More...
 
KINLINE vec3 vec3_right (void)
 Creates and returns a 3-component vector pointing right (1, 0, 0). More...
 
KINLINE vec3 vec3_forward (void)
 Creates and returns a 3-component vector pointing forward (0, 0, -1). More...
 
KINLINE vec3 vec3_back (void)
 Creates and returns a 3-component vector pointing backward (0, 0, 1). More...
 
KINLINE vec3 vec3_add (vec3 vector_0, vec3 vector_1)
 Adds vector_1 to vector_0 and returns a copy of the result. More...
 
KINLINE vec3 vec3_sub (vec3 vector_0, vec3 vector_1)
 Subtracts vector_1 from vector_0 and returns a copy of the result. More...
 
KINLINE vec3 vec3_mul (vec3 vector_0, vec3 vector_1)
 Multiplies vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE vec3 vec3_mul_scalar (vec3 vector_0, f32 scalar)
 Multiplies all elements of vector_0 by scalar and returns a copy of the result. More...
 
KINLINE vec3 vec3_mul_add (vec3 vector_0, vec3 vector_1, vec3 vector_2)
 Multiplies vector_0 by vector_1, then adds the result to vector_2. More...
 
KINLINE vec3 vec3_div (vec3 vector_0, vec3 vector_1)
 Divides vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE f32 vec3_length_squared (vec3 vector)
 Returns the squared length of the provided vector. More...
 
KINLINE f32 vec3_length (vec3 vector)
 Returns the length of the provided vector. More...
 
KINLINE void vec3_normalize (vec3 *vector)
 Normalizes the provided vector in place to a unit vector. More...
 
KINLINE vec3 vec3_normalized (vec3 vector)
 Returns a normalized copy of the supplied vector. More...
 
KINLINE f32 vec3_dot (vec3 vector_0, vec3 vector_1)
 Returns the dot product between the provided vectors. Typically used to calculate the difference in direction. More...
 
KINLINE vec3 vec3_cross (vec3 vector_0, vec3 vector_1)
 Calculates and returns the cross product of the supplied vectors. The cross product is a new vector which is orthoganal to both provided vectors. More...
 
KINLINE b8 vec3_compare (vec3 vector_0, vec3 vector_1, f32 tolerance)
 Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance. More...
 
KINLINE f32 vec3_distance (vec3 vector_0, vec3 vector_1)
 Returns the distance between vector_0 and vector_1. More...
 
KINLINE f32 vec3_distance_squared (vec3 vector_0, vec3 vector_1)
 Returns the squared distance between vector_0 and vector_1. Less intensive than calling the non-squared version due to sqrt. More...
 
KINLINE vec3 vec3_transform (vec3 v, f32 w, mat4 m)
 Transform v by m. More...
 
KINLINE vec4 vec4_create (f32 x, f32 y, f32 z, f32 w)
 Creates and returns a new 4-element vector using the supplied values. More...
 
KINLINE vec3 vec4_to_vec3 (vec4 vector)
 Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component. More...
 
KINLINE vec4 vec4_from_vec3 (vec3 vector, f32 w)
 Returns a new vec4 using vector as the x, y and z components and w for w. More...
 
KINLINE vec4 vec4_zero (void)
 Creates and returns a 4-component vector with all components set to 0.0f. More...
 
KINLINE vec4 vec4_one (void)
 Creates and returns a 4-component vector with all components set to 1.0f. More...
 
KINLINE vec4 vec4_add (vec4 vector_0, vec4 vector_1)
 Adds vector_1 to vector_0 and returns a copy of the result. More...
 
KINLINE vec4 vec4_sub (vec4 vector_0, vec4 vector_1)
 Subtracts vector_1 from vector_0 and returns a copy of the result. More...
 
KINLINE vec4 vec4_mul (vec4 vector_0, vec4 vector_1)
 Multiplies vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE vec4 vec4_mul_scalar (vec4 vector_0, f32 scalar)
 Multiplies all elements of vector_0 by scalar and returns a copy of the result. More...
 
KINLINE vec4 vec4_mul_add (vec4 vector_0, vec4 vector_1, vec4 vector_2)
 Multiplies vector_0 by vector_1, then adds the result to vector_2. More...
 
KINLINE vec4 vec4_div (vec4 vector_0, vec4 vector_1)
 Divides vector_0 by vector_1 and returns a copy of the result. More...
 
KINLINE f32 vec4_length_squared (vec4 vector)
 Returns the squared length of the provided vector. More...
 
KINLINE f32 vec4_length (vec4 vector)
 Returns the length of the provided vector. More...
 
KINLINE void vec4_normalize (vec4 *vector)
 Normalizes the provided vector in place to a unit vector. More...
 
KINLINE vec4 vec4_normalized (vec4 vector)
 Returns a normalized copy of the supplied vector. More...
 
KINLINE f32 vec4_dot_f32 (f32 a0, f32 a1, f32 a2, f32 a3, f32 b0, f32 b1, f32 b2, f32 b3)
 Calculates the dot product using the elements of vec4s provided in split-out format. More...
 
KINLINE b8 vec4_compare (vec4 vector_0, vec4 vector_1, f32 tolerance)
 Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance. More...
 
KINLINE mat4 mat4_identity (void)
 Creates and returns an identity matrix: More...
 
KINLINE mat4 mat4_mul (mat4 matrix_0, mat4 matrix_1)
 Returns the result of multiplying matrix_0 and matrix_1. More...
 
KINLINE mat4 mat4_orthographic (f32 left, f32 right, f32 bottom, f32 top, f32 near_clip, f32 far_clip)
 Creates and returns an orthographic projection matrix. Typically used to render flat or 2D scenes. More...
 
KINLINE mat4 mat4_perspective (f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip)
 Creates and returns a perspective matrix. Typically used to render 3d scenes. More...
 
KINLINE mat4 mat4_look_at (vec3 position, vec3 target, vec3 up)
 Creates and returns a look-at matrix, or a matrix looking at target from the perspective of position. More...
 
KINLINE mat4 mat4_transposed (mat4 matrix)
 Returns a transposed copy of the provided matrix (rows->colums) More...
 
KINLINE f32 mat4_determinant (mat4 matrix)
 Calculates the determinant of the given matrix. More...
 
KINLINE mat4 mat4_inverse (mat4 matrix)
 Creates and returns an inverse of the provided matrix. More...
 
KINLINE mat4 mat4_translation (vec3 position)
 Creates and returns a translation matrix from the given position. More...
 
KINLINE mat4 mat4_scale (vec3 scale)
 Returns a scale matrix using the provided scale. More...
 
KINLINE mat4 mat4_euler_x (f32 angle_radians)
 Creates a rotation matrix from the provided x angle. More...
 
KINLINE mat4 mat4_euler_y (f32 angle_radians)
 Creates a rotation matrix from the provided y angle. More...
 
KINLINE mat4 mat4_euler_z (f32 angle_radians)
 Creates a rotation matrix from the provided z angle. More...
 
KINLINE mat4 mat4_euler_xyz (f32 x_radians, f32 y_radians, f32 z_radians)
 Creates a rotation matrix from the provided x, y and z axis rotations. More...
 
KINLINE vec3 mat4_forward (mat4 matrix)
 Returns a forward vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_backward (mat4 matrix)
 Returns a backward vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_up (mat4 matrix)
 Returns a upward vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_down (mat4 matrix)
 Returns a downward vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_left (mat4 matrix)
 Returns a left vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_right (mat4 matrix)
 Returns a right vector relative to the provided matrix. More...
 
KINLINE vec3 mat4_mul_vec3 (mat4 m, vec3 v)
 Performs m * v. More...
 
KINLINE vec3 vec3_mul_mat4 (vec3 v, mat4 m)
 Performs v * m. More...
 
KINLINE vec4 mat4_mul_vec4 (mat4 m, vec4 v)
 Performs m * v. More...
 
KINLINE vec4 vec4_mul_mat4 (vec4 v, mat4 m)
 Performs v * m. More...
 
KINLINE quat quat_identity (void)
 Creates an identity quaternion. More...
 
KINLINE f32 quat_normal (quat q)
 Returns the normal of the provided quaternion. More...
 
KINLINE quat quat_normalize (quat q)
 Returns a normalized copy of the provided quaternion. More...
 
KINLINE quat quat_conjugate (quat q)
 Returns the conjugate of the provided quaternion. That is, The x, y and z elements are negated, but the w element is untouched. More...
 
KINLINE quat quat_inverse (quat q)
 Returns an inverse copy of the provided quaternion. More...
 
KINLINE quat quat_mul (quat q_0, quat q_1)
 Multiplies the provided quaternions. More...
 
KINLINE f32 quat_dot (quat q_0, quat q_1)
 Calculates the dot product of the provided quaternions. More...
 
KINLINE vec3 vec3_min (vec3 vector_0, vec3 vector_1)
 
KINLINE vec3 vec3_max (vec3 vector_0, vec3 vector_1)
 
KINLINE vec3 vec3_sign (vec3 v)
 
KINLINE vec3 vec3_rotate (vec3 v, quat q)
 
KINLINE mat4 quat_to_mat4 (quat q)
 Creates a rotation matrix from the given quaternion. More...
 
KINLINE mat4 quat_to_rotation_matrix (quat q, vec3 center)
 Calculates a rotation matrix based on the quaternion and the passed in center point. More...
 
KINLINE quat quat_from_axis_angle (vec3 axis, f32 angle, b8 normalize)
 Creates a quaternion from the given axis and angle. More...
 
KINLINE quat quat_slerp (quat q_0, quat q_1, f32 percentage)
 Calculates spherical linear interpolation of a given percentage between two quaternions. More...
 
KINLINE f32 deg_to_rad (f32 degrees)
 Converts provided degrees to radians. More...
 
KINLINE f32 rad_to_deg (f32 radians)
 Converts provided radians to degrees. More...
 
KINLINE f32 range_convert_f32 (f32 value, f32 old_min, f32 old_max, f32 new_min, f32 new_max)
 Converts value from the "old" range to the "new" range. More...
 
KINLINE void rgbu_to_u32 (u32 r, u32 g, u32 b, u32 *out_u32)
 Converts rgb int values [0-255] to a single 32-bit integer. More...
 
KINLINE void u32_to_rgb (u32 rgbu, u32 *out_r, u32 *out_g, u32 *out_b)
 Converts the given 32-bit integer to rgb values [0-255]. More...
 
KINLINE void rgb_u32_to_vec3 (u32 r, u32 g, u32 b, vec3 *out_v)
 Converts rgb integer values [0-255] to a vec3 of floating-point values [0.0-1.0]. More...
 
KINLINE void vec3_to_rgb_u32 (vec3 v, u32 *out_r, u32 *out_g, u32 *out_b)
 Converts a vec3 of rgbvalues [0.0-1.0] to integer rgb values [0-255]. More...
 
KAPI plane_3d plane_3d_create (vec3 p1, vec3 norm)
 
KAPI frustum frustum_create (const vec3 *position, const vec3 *forward, const vec3 *right, const vec3 *up, f32 aspect, f32 fov, f32 near, f32 far)
 Creates and returns a frustum based on the provided position, direction vectors, aspect, field of view, and near/far clipping planes (typically obtained from a camera). This is typically used for frustum culling. More...
 
KAPI f32 plane_signed_distance (const plane_3d *p, const vec3 *position)
 Obtains the signed distance between the plane p and the provided postion. More...
 
KAPI b8 plane_intersects_sphere (const plane_3d *p, const vec3 *center, f32 radius)
 Indicates if plane p intersects a sphere constructed via center and radius. More...
 
KAPI b8 frustum_intersects_sphere (const frustum *f, const vec3 *center, f32 radius)
 Indicates if the frustum intersects (or contains) a sphere constructed via center and radius. More...
 
KAPI b8 plane_intersects_aabb (const plane_3d *p, const vec3 *center, const vec3 *extents)
 Indicates if plane p intersects an axis-aligned bounding box constructed via center and extents. More...
 
KAPI b8 frustum_intersects_aabb (const frustum *f, const vec3 *center, const vec3 *extents)
 Indicates if frustum f intersects an axis-aligned bounding box constructed via center and extents. More...
 

Detailed Description

This file contains definitions for various important constant values as well as functions for many common math types.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2022-01-10

Macro Definition Documentation

◆ K_2PI

#define K_2PI   (2.0f * K_PI)

An approximate representation of PI multiplied by 2.

◆ K_4PI

#define K_4PI   (4.0f * K_PI)

An approximate representation of PI multiplied by 4.

◆ K_DEG2RAD_MULTIPLIER

#define K_DEG2RAD_MULTIPLIER   (K_PI / 180.0f)

A multiplier used to convert degrees to radians.

◆ K_FLOAT_EPSILON

#define K_FLOAT_EPSILON   1.192092896e-07f

Smallest positive number where 1.0 + FLOAT_EPSILON != 0.

◆ K_HALF_PI

#define K_HALF_PI   (0.5f * K_PI)

An approximate representation of PI divided by 2.

◆ K_INFINITY

#define K_INFINITY   (1e30f * 1e30f)

A huge number that should be larger than any valid number used.

◆ K_MS_TO_SEC_MULTIPLIER

#define K_MS_TO_SEC_MULTIPLIER   0.001f

The multiplier to convert milliseconds to seconds.

◆ K_ONE_OVER_PI

#define K_ONE_OVER_PI   (1.0f / K_PI)

One divided by an approximate representation of PI.

◆ K_ONE_OVER_TWO_PI

#define K_ONE_OVER_TWO_PI   (1.0f / K_2PI)

One divided by half of an approximate representation of PI.

◆ K_PI

#define K_PI   3.14159265358979323846f

An approximate representation of PI.

◆ K_QUARTER_PI

#define K_QUARTER_PI   (0.25f * K_PI)

An approximate representation of PI divided by 4.

◆ K_RAD2DEG_MULTIPLIER

#define K_RAD2DEG_MULTIPLIER   (180.0f / K_PI)

A multiplier used to convert radians to degrees.

◆ K_SEC_TO_MS_MULTIPLIER

#define K_SEC_TO_MS_MULTIPLIER   1000.0f

The multiplier to convert seconds to milliseconds.

◆ K_SEC_TO_US_MULTIPLIER

#define K_SEC_TO_US_MULTIPLIER   (1000.0f * 1000.0f)

The multiplier to convert seconds to microseconds.

◆ K_SQRT_ONE_OVER_THREE

#define K_SQRT_ONE_OVER_THREE   0.57735026918962576450f

One divided by an approximation of the square root of 3.

◆ K_SQRT_ONE_OVER_TWO

#define K_SQRT_ONE_OVER_TWO   0.70710678118654752440f

One divided by an approximation of the square root of 2.

◆ K_SQRT_THREE

#define K_SQRT_THREE   1.73205080756887729352f

An approximation of the square root of 3.

◆ K_SQRT_TWO

#define K_SQRT_TWO   1.41421356237309504880f

An approximation of the square root of 2.

◆ KSWAP

#define KSWAP (   type,
  a,
 
)
Value:
{ \
type temp = a; \
a = b; \
b = temp; \
}

Function Documentation

◆ deg_to_rad()

KINLINE f32 deg_to_rad ( f32  degrees)

Converts provided degrees to radians.

Parameters
degreesThe degrees to be converted.
Returns
The amount in radians.

◆ frustum_create()

KAPI frustum frustum_create ( const vec3 position,
const vec3 forward,
const vec3 right,
const vec3 up,
f32  aspect,
f32  fov,
f32  near,
f32  far 
)

Creates and returns a frustum based on the provided position, direction vectors, aspect, field of view, and near/far clipping planes (typically obtained from a camera). This is typically used for frustum culling.

Parameters
positionA constant pointer to the position to be used.
forwardA constant pointer to the forward vector to be used.
rightA constant pointer to the right vector to be used.
upA constant pointer to the up vector to be used.
aspectThe aspect ratio.
fovThe vertical field of view.
nearThe near clipping plane distance.
farThe far clipping plane distance.
Returns
A shiny new frustum.

◆ frustum_intersects_aabb()

KAPI b8 frustum_intersects_aabb ( const frustum f,
const vec3 center,
const vec3 extents 
)

Indicates if frustum f intersects an axis-aligned bounding box constructed via center and extents.

Parameters
fA constant pointer to a frustum.
centerA constant pointer to a position representing the center of an axis-aligned bounding box.
extentsThe half-extents of an axis-aligned bounding box.
Returns
True if the axis-aligned bounding box is intersected by or contained within the frustum f; otherwise false.

◆ frustum_intersects_sphere()

KAPI b8 frustum_intersects_sphere ( const frustum f,
const vec3 center,
f32  radius 
)

Indicates if the frustum intersects (or contains) a sphere constructed via center and radius.

Parameters
fA constant pointer to a frustum.
centerA constant pointer to a position representing the center of a sphere.
radiusThe radius of the sphere.
Returns
True if the sphere is intersected by or contained within the frustum f; otherwise false.

◆ is_power_of_2()

KINLINE b8 is_power_of_2 ( u64  value)

Indicates if the value is a power of 2. 0 is considered not a power of 2.

Parameters
valueThe value to be interpreted.
Returns
True if a power of 2, otherwise false.

◆ kabs()

KAPI f32 kabs ( f32  x)

Calculates the absolute value of x.

Parameters
xThe number to get the absolute value of.
Returns
The absolute value of x.

◆ kacos()

KAPI f32 kacos ( f32  x)

Calculates the arc cosine of x.

Parameters
xThe number to calculate the arc cosine of.
Returns
The arc cosine of x.

◆ kcos()

KAPI f32 kcos ( f32  x)

Calculates the cosine of x.

Parameters
xThe number to calculate the cosine of.
Returns
The cosine of x.

◆ kfloat_compare()

KINLINE b8 kfloat_compare ( f32  f_0,
f32  f_1 
)

Compares the two floats and returns true if both are less than K_FLOAT_EPSILON apart; otherwise false.

◆ kfloor()

KAPI f32 kfloor ( f32  x)

Returns the largest integer value less than or equal to x.

Parameters
xThe value to be examined.
Returns
the largest integer value less than or equal to x.

◆ kfrandom()

KAPI f32 kfrandom ( void  )

Returns a random floating-point number.

Returns
A random floating-point number.

◆ kfrandom_in_range()

KAPI f32 kfrandom_in_range ( f32  min,
f32  max 
)

Returns a random floating-point number that is within the given range (inclusive).

Parameters
minThe minimum of the range.
maxThe maximum of the range.
Returns
A random floating-point number.

◆ klog2()

KAPI f32 klog2 ( f32  x)

Computes the base-2 logarithm of x (i.e. how many times x can be divided by 2).

Parameters
xThe value to be examined.
Returns
The base-2 logarithm of x.

◆ krandom()

KAPI i32 krandom ( void  )

Returns a random integer.

Returns
A random integer.

◆ krandom_in_range()

KAPI i32 krandom_in_range ( i32  min,
i32  max 
)

Returns a random integer that is within the given range (inclusive).

Parameters
minThe minimum of the range.
maxThe maximum of the range.
Returns
A random integer.

◆ ksign()

KINLINE f32 ksign ( f32  x)

Returns 0.0f if x == 0.0f, -1.0f if negative, otherwise 1.0f.

◆ ksin()

KAPI f32 ksin ( f32  x)

Calculates the sine of x.

Parameters
xThe number to calculate the sine of.
Returns
The sine of x.

◆ ksmoothstep()

KINLINE f32 ksmoothstep ( f32  edge_0,
f32  edge_1,
f32  x 
)

Perform Hermite interpolation between two values.

Parameters
edge_0The lower edge of the Hermite function.
edge_1The upper edge of the Hermite function.
xThe value to interpolate.
Returns
The interpolated value.

◆ ksqrt()

KAPI f32 ksqrt ( f32  x)

Calculates the square root of x.

Parameters
xThe number to calculate the square root of.
Returns
The square root of x.

◆ kstep()

KINLINE f32 kstep ( f32  edge,
f32  x 
)

Compares x to edge, returning 0 if x < edge; otherwise 1.0f;.

◆ kswapf()

KINLINE void kswapf ( f32 a,
f32 b 
)

Swaps the values in the given float pointers.

Parameters
aA pointer to the first float.
bA pointer to the second float.

◆ ktan()

KAPI f32 ktan ( f32  x)

Calculates the tangent of x.

Parameters
xThe number to calculate the tangent of.
Returns
The tangent of x.

◆ mat4_backward()

KINLINE vec3 mat4_backward ( mat4  matrix)

Returns a backward vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ mat4_determinant()

KINLINE f32 mat4_determinant ( mat4  matrix)

Calculates the determinant of the given matrix.

Parameters
matrixThe matrix to calculate the determinant of.
Returns
The determinant of the given matrix.

◆ mat4_down()

KINLINE vec3 mat4_down ( mat4  matrix)

Returns a downward vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ mat4_euler_x()

KINLINE mat4 mat4_euler_x ( f32  angle_radians)

Creates a rotation matrix from the provided x angle.

Parameters
angle_radiansThe x angle in radians.
Returns
A rotation matrix.

◆ mat4_euler_xyz()

KINLINE mat4 mat4_euler_xyz ( f32  x_radians,
f32  y_radians,
f32  z_radians 
)

Creates a rotation matrix from the provided x, y and z axis rotations.

Parameters
x_radiansThe x rotation.
y_radiansThe y rotation.
z_radiansThe z rotation.
Returns
A rotation matrix.

◆ mat4_euler_y()

KINLINE mat4 mat4_euler_y ( f32  angle_radians)

Creates a rotation matrix from the provided y angle.

Parameters
angle_radiansThe y angle in radians.
Returns
A rotation matrix.

◆ mat4_euler_z()

KINLINE mat4 mat4_euler_z ( f32  angle_radians)

Creates a rotation matrix from the provided z angle.

Parameters
angle_radiansThe z angle in radians.
Returns
A rotation matrix.

◆ mat4_forward()

KINLINE vec3 mat4_forward ( mat4  matrix)

Returns a forward vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ mat4_identity()

KINLINE mat4 mat4_identity ( void  )

Creates and returns an identity matrix:

{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }

Returns
A new identity matrix

◆ mat4_inverse()

KINLINE mat4 mat4_inverse ( mat4  matrix)

Creates and returns an inverse of the provided matrix.

Parameters
matrixThe matrix to be inverted.
Returns
A inverted copy of the provided matrix.

◆ mat4_left()

KINLINE vec3 mat4_left ( mat4  matrix)

Returns a left vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ mat4_look_at()

KINLINE mat4 mat4_look_at ( vec3  position,
vec3  target,
vec3  up 
)

Creates and returns a look-at matrix, or a matrix looking at target from the perspective of position.

Parameters
positionThe position of the matrix.
targetThe position to "look at".
upThe up vector.
Returns
A matrix looking at target from the perspective of position.

◆ mat4_mul()

KINLINE mat4 mat4_mul ( mat4  matrix_0,
mat4  matrix_1 
)

Returns the result of multiplying matrix_0 and matrix_1.

Parameters
matrix_0The first matrix to be multiplied.
matrix_1The second matrix to be multiplied.
Returns
The result of the matrix multiplication.

◆ mat4_mul_vec3()

KINLINE vec3 mat4_mul_vec3 ( mat4  m,
vec3  v 
)

Performs m * v.

Parameters
mThe matrix to be multiplied.
vThe vector to multiply by.
Returns
The transformed vector.

◆ mat4_mul_vec4()

KINLINE vec4 mat4_mul_vec4 ( mat4  m,
vec4  v 
)

Performs m * v.

Parameters
mThe matrix to be multiplied.
vThe vector to multiply by.
Returns
The transformed vector.

◆ mat4_orthographic()

KINLINE mat4 mat4_orthographic ( f32  left,
f32  right,
f32  bottom,
f32  top,
f32  near_clip,
f32  far_clip 
)

Creates and returns an orthographic projection matrix. Typically used to render flat or 2D scenes.

Parameters
leftThe left side of the view frustum.
rightThe right side of the view frustum.
bottomThe bottom side of the view frustum.
topThe top side of the view frustum.
near_clipThe near clipping plane distance.
far_clipThe far clipping plane distance.
Returns
A new orthographic projection matrix.

◆ mat4_perspective()

KINLINE mat4 mat4_perspective ( f32  fov_radians,
f32  aspect_ratio,
f32  near_clip,
f32  far_clip 
)

Creates and returns a perspective matrix. Typically used to render 3d scenes.

Parameters
fov_radiansThe field of view in radians.
aspect_ratioThe aspect ratio.
near_clipThe near clipping plane distance.
far_clipThe far clipping plane distance.
Returns
A new perspective matrix.

◆ mat4_right()

KINLINE vec3 mat4_right ( mat4  matrix)

Returns a right vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ mat4_scale()

KINLINE mat4 mat4_scale ( vec3  scale)

Returns a scale matrix using the provided scale.

Parameters
scaleThe 3-component scale.
Returns
A scale matrix.

◆ mat4_translation()

KINLINE mat4 mat4_translation ( vec3  position)

Creates and returns a translation matrix from the given position.

Parameters
positionThe position to be used to create the matrix.
Returns
A newly created translation matrix.

◆ mat4_transposed()

KINLINE mat4 mat4_transposed ( mat4  matrix)

Returns a transposed copy of the provided matrix (rows->colums)

Parameters
matrixThe matrix to be transposed.
Returns
A transposed copy of of the provided matrix.

◆ mat4_up()

KINLINE vec3 mat4_up ( mat4  matrix)

Returns a upward vector relative to the provided matrix.

Parameters
matrixThe matrix from which to base the vector.
Returns
A 3-component directional vector.

◆ plane_3d_create()

KAPI plane_3d plane_3d_create ( vec3  p1,
vec3  norm 
)

◆ plane_intersects_aabb()

KAPI b8 plane_intersects_aabb ( const plane_3d p,
const vec3 center,
const vec3 extents 
)

Indicates if plane p intersects an axis-aligned bounding box constructed via center and extents.

Parameters
pA constant pointer to a plane.
centerA constant pointer to a position representing the center of an axis-aligned bounding box.
extentsThe half-extents of an axis-aligned bounding box.
Returns
True if the axis-aligned bounding box intersects the plane; otherwise false.

◆ plane_intersects_sphere()

KAPI b8 plane_intersects_sphere ( const plane_3d p,
const vec3 center,
f32  radius 
)

Indicates if plane p intersects a sphere constructed via center and radius.

Parameters
pA constant pointer to a plane.
centerA constant pointer to a position representing the center of a sphere.
radiusThe radius of the sphere.
Returns
True if the sphere intersects the plane; otherwise false.

◆ plane_signed_distance()

KAPI f32 plane_signed_distance ( const plane_3d p,
const vec3 position 
)

Obtains the signed distance between the plane p and the provided postion.

Parameters
pA constant pointer to a plane.
positionA constant pointer to a position.
Returns
The signed distance from the point to the plane.

◆ quat_conjugate()

KINLINE quat quat_conjugate ( quat  q)

Returns the conjugate of the provided quaternion. That is, The x, y and z elements are negated, but the w element is untouched.

Parameters
qThe quaternion to obtain a conjugate of.
Returns
The conjugate quaternion.

◆ quat_dot()

KINLINE f32 quat_dot ( quat  q_0,
quat  q_1 
)

Calculates the dot product of the provided quaternions.

Parameters
q_0The first quaternion.
q_1The second quaternion.
Returns
The dot product of the provided quaternions.

◆ quat_from_axis_angle()

KINLINE quat quat_from_axis_angle ( vec3  axis,
f32  angle,
b8  normalize 
)

Creates a quaternion from the given axis and angle.

Parameters
axisThe axis of rotation.
angleThe angle of rotation.
normalizeIndicates if the quaternion should be normalized.
Returns
A new quaternion.

◆ quat_identity()

KINLINE quat quat_identity ( void  )

Creates an identity quaternion.

Returns
An identity quaternion.

◆ quat_inverse()

KINLINE quat quat_inverse ( quat  q)

Returns an inverse copy of the provided quaternion.

Parameters
qThe quaternion to invert.
Returns
An inverse copy of the provided quaternion.

◆ quat_mul()

KINLINE quat quat_mul ( quat  q_0,
quat  q_1 
)

Multiplies the provided quaternions.

Parameters
q_0The first quaternion.
q_1The second quaternion.
Returns
The multiplied quaternion.

◆ quat_normal()

KINLINE f32 quat_normal ( quat  q)

Returns the normal of the provided quaternion.

Parameters
qThe quaternion.
Returns
The normal of the provided quaternion.

◆ quat_normalize()

KINLINE quat quat_normalize ( quat  q)

Returns a normalized copy of the provided quaternion.

Parameters
qThe quaternion to normalize.
Returns
A normalized copy of the provided quaternion.

◆ quat_slerp()

KINLINE quat quat_slerp ( quat  q_0,
quat  q_1,
f32  percentage 
)

Calculates spherical linear interpolation of a given percentage between two quaternions.

Parameters
q_0The first quaternion.
q_1The second quaternion.
percentageThe percentage of interpolation, typically a value from 0.0f-1.0f.
Returns
An interpolated quaternion.

◆ quat_to_mat4()

KINLINE mat4 quat_to_mat4 ( quat  q)

Creates a rotation matrix from the given quaternion.

Parameters
qThe quaternion to be used.
Returns
A rotation matrix.

◆ quat_to_rotation_matrix()

KINLINE mat4 quat_to_rotation_matrix ( quat  q,
vec3  center 
)

Calculates a rotation matrix based on the quaternion and the passed in center point.

Parameters
qThe quaternion.
centerThe center point.
Returns
A rotation matrix.

◆ rad_to_deg()

KINLINE f32 rad_to_deg ( f32  radians)

Converts provided radians to degrees.

Parameters
radiansThe radians to be converted.
Returns
The amount in degrees.

◆ range_convert_f32()

KINLINE f32 range_convert_f32 ( f32  value,
f32  old_min,
f32  old_max,
f32  new_min,
f32  new_max 
)

Converts value from the "old" range to the "new" range.

Parameters
valueThe value to be converted.
from_minThe minimum value from the old range.
from_maxThe maximum value from the old range.
to_minThe minimum value from the new range.
to_maxThe maximum value from the new range.
Returns
The converted value.

◆ rgb_u32_to_vec3()

KINLINE void rgb_u32_to_vec3 ( u32  r,
u32  g,
u32  b,
vec3 out_v 
)

Converts rgb integer values [0-255] to a vec3 of floating-point values [0.0-1.0].

Parameters
rThe red value [0-255].
gThe green value [0-255].
bThe blue value [0-255].
out_vA pointer to hold the vector of floating-point values.

◆ rgbu_to_u32()

KINLINE void rgbu_to_u32 ( u32  r,
u32  g,
u32  b,
u32 out_u32 
)

Converts rgb int values [0-255] to a single 32-bit integer.

Parameters
rThe red value [0-255].
gThe green value [0-255].
bThe blue value [0-255].
out_u32A pointer to hold the resulting integer.

◆ u32_to_rgb()

KINLINE void u32_to_rgb ( u32  rgbu,
u32 out_r,
u32 out_g,
u32 out_b 
)

Converts the given 32-bit integer to rgb values [0-255].

Parameters
rgbuThe integer holding a rgb value.
out_rA pointer to hold the red value.
out_gA pointer to hold the green value.
out_bA pointer to hold the blue value.

◆ vec2_add()

KINLINE vec2 vec2_add ( vec2  vector_0,
vec2  vector_1 
)

Adds vector_1 to vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec2_compare()

KINLINE b8 vec2_compare ( vec2  vector_0,
vec2  vector_1,
f32  tolerance 
)

Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.

Parameters
vector_0The first vector.
vector_1The second vector.
toleranceThe difference tolerance. Typically K_FLOAT_EPSILON or similar.
Returns
True if within tolerance; otherwise false.

◆ vec2_create()

KINLINE vec2 vec2_create ( f32  x,
f32  y 
)

Creates and returns a new 2-element vector using the supplied values.

Parameters
xThe x value.
yThe y value.
Returns
A new 2-element vector.

◆ vec2_distance()

KINLINE f32 vec2_distance ( vec2  vector_0,
vec2  vector_1 
)

Returns the distance between vector_0 and vector_1.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The distance between vector_0 and vector_1.

◆ vec2_distance_squared()

KINLINE f32 vec2_distance_squared ( vec2  vector_0,
vec2  vector_1 
)

Returns the squared distance between vector_0 and vector_1. NOTE: If purely for comparison purposes, prefer this over non-squared version to avoid a sqrt call.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The distance between vector_0 and vector_1.

◆ vec2_div()

KINLINE vec2 vec2_div ( vec2  vector_0,
vec2  vector_1 
)

Divides vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec2_down()

KINLINE vec2 vec2_down ( void  )

Creates and returns a 2-component vector pointing down (0, -1).

◆ vec2_left()

KINLINE vec2 vec2_left ( void  )

Creates and returns a 2-component vector pointing left (-1, 0).

◆ vec2_length()

KINLINE f32 vec2_length ( vec2  vector)

Returns the length of the provided vector.

Parameters
vectorThe vector to retrieve the length of.
Returns
The length.

◆ vec2_length_squared()

KINLINE f32 vec2_length_squared ( vec2  vector)

Returns the squared length of the provided vector.

Parameters
vectorThe vector to retrieve the squared length of.
Returns
The squared length.

◆ vec2_mul()

KINLINE vec2 vec2_mul ( vec2  vector_0,
vec2  vector_1 
)

Multiplies vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec2_mul_add()

KINLINE vec2 vec2_mul_add ( vec2  vector_0,
vec2  vector_1,
vec2  vector_2 
)

Multiplies vector_0 by vector_1, then adds the result to vector_2.

Parameters
vector_0The first vector.
vector_1The second vector.
vector_2The third vector.
Returns
The resulting vector.

◆ vec2_mul_scalar()

KINLINE vec2 vec2_mul_scalar ( vec2  vector_0,
f32  scalar 
)

Multiplies all elements of vector_0 by scalar and returns a copy of the result.

Parameters
vector_0The vector to be multiplied.
scalarThe scalar value.
Returns
A copy of the resulting vector.

◆ vec2_normalize()

KINLINE void vec2_normalize ( vec2 vector)

Normalizes the provided vector in place to a unit vector.

Parameters
vectorA pointer to the vector to be normalized.

◆ vec2_normalized()

KINLINE vec2 vec2_normalized ( vec2  vector)

Returns a normalized copy of the supplied vector.

Parameters
vectorThe vector to be normalized.
Returns
A normalized copy of the supplied vector

◆ vec2_one()

KINLINE vec2 vec2_one ( void  )

Creates and returns a 2-component vector with all components set to 1.0f.

◆ vec2_right()

KINLINE vec2 vec2_right ( void  )

Creates and returns a 2-component vector pointing right (1, 0).

◆ vec2_sub()

KINLINE vec2 vec2_sub ( vec2  vector_0,
vec2  vector_1 
)

Subtracts vector_1 from vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec2_up()

KINLINE vec2 vec2_up ( void  )

Creates and returns a 2-component vector pointing up (0, 1).

◆ vec2_zero()

KINLINE vec2 vec2_zero ( void  )

Creates and returns a 2-component vector with all components set to 0.0f.

◆ vec3_add()

KINLINE vec3 vec3_add ( vec3  vector_0,
vec3  vector_1 
)

Adds vector_1 to vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec3_back()

KINLINE vec3 vec3_back ( void  )

Creates and returns a 3-component vector pointing backward (0, 0, 1).

◆ vec3_compare()

KINLINE b8 vec3_compare ( vec3  vector_0,
vec3  vector_1,
f32  tolerance 
)

Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.

Parameters
vector_0The first vector.
vector_1The second vector.
toleranceThe difference tolerance. Typically K_FLOAT_EPSILON or similar.
Returns
True if within tolerance; otherwise false.

◆ vec3_create()

KINLINE vec3 vec3_create ( f32  x,
f32  y,
f32  z 
)

Creates and returns a new 3-element vector using the supplied values.

Parameters
xThe x value.
yThe y value.
zThe z value.
Returns
A new 3-element vector.

◆ vec3_cross()

KINLINE vec3 vec3_cross ( vec3  vector_0,
vec3  vector_1 
)

Calculates and returns the cross product of the supplied vectors. The cross product is a new vector which is orthoganal to both provided vectors.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The cross product.

◆ vec3_distance()

KINLINE f32 vec3_distance ( vec3  vector_0,
vec3  vector_1 
)

Returns the distance between vector_0 and vector_1.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The distance between vector_0 and vector_1.

◆ vec3_distance_squared()

KINLINE f32 vec3_distance_squared ( vec3  vector_0,
vec3  vector_1 
)

Returns the squared distance between vector_0 and vector_1. Less intensive than calling the non-squared version due to sqrt.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The squared distance between vector_0 and vector_1.

◆ vec3_div()

KINLINE vec3 vec3_div ( vec3  vector_0,
vec3  vector_1 
)

Divides vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec3_dot()

KINLINE f32 vec3_dot ( vec3  vector_0,
vec3  vector_1 
)

Returns the dot product between the provided vectors. Typically used to calculate the difference in direction.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The dot product.

◆ vec3_down()

KINLINE vec3 vec3_down ( void  )

Creates and returns a 3-component vector pointing down (0, -1, 0).

◆ vec3_forward()

KINLINE vec3 vec3_forward ( void  )

Creates and returns a 3-component vector pointing forward (0, 0, -1).

◆ vec3_from_vec4()

KINLINE vec3 vec3_from_vec4 ( vec4  vector)

Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component.

Parameters
vectorThe 4-component vector to extract from.
Returns
A new vec3

◆ vec3_left()

KINLINE vec3 vec3_left ( void  )

Creates and returns a 3-component vector pointing left (-1, 0, 0).

◆ vec3_length()

KINLINE f32 vec3_length ( vec3  vector)

Returns the length of the provided vector.

Parameters
vectorThe vector to retrieve the length of.
Returns
The length.

◆ vec3_length_squared()

KINLINE f32 vec3_length_squared ( vec3  vector)

Returns the squared length of the provided vector.

Parameters
vectorThe vector to retrieve the squared length of.
Returns
The squared length.

◆ vec3_max()

KINLINE vec3 vec3_max ( vec3  vector_0,
vec3  vector_1 
)

◆ vec3_min()

KINLINE vec3 vec3_min ( vec3  vector_0,
vec3  vector_1 
)

◆ vec3_mul()

KINLINE vec3 vec3_mul ( vec3  vector_0,
vec3  vector_1 
)

Multiplies vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec3_mul_add()

KINLINE vec3 vec3_mul_add ( vec3  vector_0,
vec3  vector_1,
vec3  vector_2 
)

Multiplies vector_0 by vector_1, then adds the result to vector_2.

Parameters
vector_0The first vector.
vector_1The second vector.
vector_2The third vector.
Returns
The resulting vector.

◆ vec3_mul_mat4()

KINLINE vec3 vec3_mul_mat4 ( vec3  v,
mat4  m 
)

Performs v * m.

Parameters
vThe vector to bemultiplied.
mThe matrix to be multiply by.
Returns
The transformed vector.

◆ vec3_mul_scalar()

KINLINE vec3 vec3_mul_scalar ( vec3  vector_0,
f32  scalar 
)

Multiplies all elements of vector_0 by scalar and returns a copy of the result.

Parameters
vector_0The vector to be multiplied.
scalarThe scalar value.
Returns
A copy of the resulting vector.

◆ vec3_normalize()

KINLINE void vec3_normalize ( vec3 vector)

Normalizes the provided vector in place to a unit vector.

Parameters
vectorA pointer to the vector to be normalized.

◆ vec3_normalized()

KINLINE vec3 vec3_normalized ( vec3  vector)

Returns a normalized copy of the supplied vector.

Parameters
vectorThe vector to be normalized.
Returns
A normalized copy of the supplied vector

◆ vec3_one()

KINLINE vec3 vec3_one ( void  )

Creates and returns a 3-component vector with all components set to 1.0f.

◆ vec3_right()

KINLINE vec3 vec3_right ( void  )

Creates and returns a 3-component vector pointing right (1, 0, 0).

◆ vec3_rotate()

KINLINE vec3 vec3_rotate ( vec3  v,
quat  q 
)

◆ vec3_sign()

KINLINE vec3 vec3_sign ( vec3  v)

◆ vec3_sub()

KINLINE vec3 vec3_sub ( vec3  vector_0,
vec3  vector_1 
)

Subtracts vector_1 from vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec3_to_rgb_u32()

KINLINE void vec3_to_rgb_u32 ( vec3  v,
u32 out_r,
u32 out_g,
u32 out_b 
)

Converts a vec3 of rgbvalues [0.0-1.0] to integer rgb values [0-255].

Parameters
vThe vector of rgb values [0.0-1.0] to be converted.
out_rA pointer to hold the red value.
out_gA pointer to hold the green value.
out_bA pointer to hold the blue value.

◆ vec3_to_vec4()

KINLINE vec4 vec3_to_vec4 ( vec3  vector,
f32  w 
)

Returns a new vec4 using vector as the x, y and z components and w for w.

Parameters
vectorThe 3-component vector.
wThe w component.
Returns
A new vec4

◆ vec3_transform()

KINLINE vec3 vec3_transform ( vec3  v,
f32  w,
mat4  m 
)

Transform v by m.

Parameters
vThe vector to transform.
wPass 1.0f for a point, or 0.0f for a direction.
mThe matrix to transform by.
Returns
A transformed copy of v.

◆ vec3_up()

KINLINE vec3 vec3_up ( void  )

Creates and returns a 3-component vector pointing up (0, 1, 0).

◆ vec3_zero()

KINLINE vec3 vec3_zero ( void  )

Creates and returns a 3-component vector with all components set to 0.0f.

◆ vec4_add()

KINLINE vec4 vec4_add ( vec4  vector_0,
vec4  vector_1 
)

Adds vector_1 to vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec4_compare()

KINLINE b8 vec4_compare ( vec4  vector_0,
vec4  vector_1,
f32  tolerance 
)

Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.

Parameters
vector_0The first vector.
vector_1The second vector.
toleranceThe difference tolerance. Typically K_FLOAT_EPSILON or similar.
Returns
True if within tolerance; otherwise false.

◆ vec4_create()

KINLINE vec4 vec4_create ( f32  x,
f32  y,
f32  z,
f32  w 
)

Creates and returns a new 4-element vector using the supplied values.

Parameters
xThe x value.
yThe y value.
zThe z value.
wThe w value.
Returns
A new 4-element vector.

◆ vec4_div()

KINLINE vec4 vec4_div ( vec4  vector_0,
vec4  vector_1 
)

Divides vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec4_dot_f32()

KINLINE f32 vec4_dot_f32 ( f32  a0,
f32  a1,
f32  a2,
f32  a3,
f32  b0,
f32  b1,
f32  b2,
f32  b3 
)

Calculates the dot product using the elements of vec4s provided in split-out format.

Parameters
a0The first element of the a vector.
a1The second element of the a vector.
a2The third element of the a vector.
a3The fourth element of the a vector.
b0The first element of the b vector.
b1The second element of the b vector.
b2The third element of the b vector.
b3The fourth element of the b vector.
Returns
The dot product of vectors and b.

◆ vec4_from_vec3()

KINLINE vec4 vec4_from_vec3 ( vec3  vector,
f32  w 
)

Returns a new vec4 using vector as the x, y and z components and w for w.

Parameters
vectorThe 3-component vector.
wThe w component.
Returns
A new vec4

◆ vec4_length()

KINLINE f32 vec4_length ( vec4  vector)

Returns the length of the provided vector.

Parameters
vectorThe vector to retrieve the length of.
Returns
The length.

◆ vec4_length_squared()

KINLINE f32 vec4_length_squared ( vec4  vector)

Returns the squared length of the provided vector.

Parameters
vectorThe vector to retrieve the squared length of.
Returns
The squared length.

◆ vec4_mul()

KINLINE vec4 vec4_mul ( vec4  vector_0,
vec4  vector_1 
)

Multiplies vector_0 by vector_1 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec4_mul_add()

KINLINE vec4 vec4_mul_add ( vec4  vector_0,
vec4  vector_1,
vec4  vector_2 
)

Multiplies vector_0 by vector_1, then adds the result to vector_2.

Parameters
vector_0The first vector.
vector_1The second vector.
vector_2The third vector.
Returns
The resulting vector.

◆ vec4_mul_mat4()

KINLINE vec4 vec4_mul_mat4 ( vec4  v,
mat4  m 
)

Performs v * m.

Parameters
vThe vector to bemultiplied.
mThe matrix to be multiply by.
Returns
The transformed vector.

◆ vec4_mul_scalar()

KINLINE vec4 vec4_mul_scalar ( vec4  vector_0,
f32  scalar 
)

Multiplies all elements of vector_0 by scalar and returns a copy of the result.

Parameters
vector_0The vector to be multiplied.
scalarThe scalar value.
Returns
A copy of the resulting vector.

◆ vec4_normalize()

KINLINE void vec4_normalize ( vec4 vector)

Normalizes the provided vector in place to a unit vector.

Parameters
vectorA pointer to the vector to be normalized.

◆ vec4_normalized()

KINLINE vec4 vec4_normalized ( vec4  vector)

Returns a normalized copy of the supplied vector.

Parameters
vectorThe vector to be normalized.
Returns
A normalized copy of the supplied vector

◆ vec4_one()

KINLINE vec4 vec4_one ( void  )

Creates and returns a 4-component vector with all components set to 1.0f.

◆ vec4_sub()

KINLINE vec4 vec4_sub ( vec4  vector_0,
vec4  vector_1 
)

Subtracts vector_1 from vector_0 and returns a copy of the result.

Parameters
vector_0The first vector.
vector_1The second vector.
Returns
The resulting vector.

◆ vec4_to_vec3()

KINLINE vec3 vec4_to_vec3 ( vec4  vector)

Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component.

Parameters
vectorThe 4-component vector to extract from.
Returns
A new vec3

◆ vec4_zero()

KINLINE vec4 vec4_zero ( void  )

Creates and returns a 4-component vector with all components set to 0.0f.