Kohi Game Engine
|
This file contains definitions for various important constant values as well as functions for many common math types. More...
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... | |
This file contains definitions for various important constant values as well as functions for many common math types.
#define K_2PI (2.0f * K_PI) |
An approximate representation of PI multiplied by 2.
#define K_4PI (4.0f * K_PI) |
An approximate representation of PI multiplied by 4.
#define K_DEG2RAD_MULTIPLIER (K_PI / 180.0f) |
A multiplier used to convert degrees to radians.
#define K_FLOAT_EPSILON 1.192092896e-07f |
Smallest positive number where 1.0 + FLOAT_EPSILON != 0.
#define K_HALF_PI (0.5f * K_PI) |
An approximate representation of PI divided by 2.
#define K_INFINITY (1e30f * 1e30f) |
A huge number that should be larger than any valid number used.
#define K_MS_TO_SEC_MULTIPLIER 0.001f |
The multiplier to convert milliseconds to seconds.
#define K_ONE_OVER_PI (1.0f / K_PI) |
One divided by an approximate representation of PI.
#define K_ONE_OVER_TWO_PI (1.0f / K_2PI) |
One divided by half of an approximate representation of PI.
#define K_PI 3.14159265358979323846f |
An approximate representation of PI.
#define K_QUARTER_PI (0.25f * K_PI) |
An approximate representation of PI divided by 4.
#define K_RAD2DEG_MULTIPLIER (180.0f / K_PI) |
A multiplier used to convert radians to degrees.
#define K_SEC_TO_MS_MULTIPLIER 1000.0f |
The multiplier to convert seconds to milliseconds.
#define K_SEC_TO_US_MULTIPLIER (1000.0f * 1000.0f) |
The multiplier to convert seconds to microseconds.
#define K_SQRT_ONE_OVER_THREE 0.57735026918962576450f |
One divided by an approximation of the square root of 3.
#define K_SQRT_ONE_OVER_TWO 0.70710678118654752440f |
One divided by an approximation of the square root of 2.
#define K_SQRT_THREE 1.73205080756887729352f |
An approximation of the square root of 3.
#define K_SQRT_TWO 1.41421356237309504880f |
An approximation of the square root of 2.
#define KSWAP | ( | type, | |
a, | |||
b | |||
) |
Converts provided degrees to radians.
degrees | The degrees to be converted. |
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.
position | A constant pointer to the position to be used. |
forward | A constant pointer to the forward vector to be used. |
right | A constant pointer to the right vector to be used. |
up | A constant pointer to the up vector to be used. |
aspect | The aspect ratio. |
fov | The vertical field of view. |
near | The near clipping plane distance. |
far | The far clipping plane distance. |
Indicates if frustum f intersects an axis-aligned bounding box constructed via center and extents.
f | A constant pointer to a frustum. |
center | A constant pointer to a position representing the center of an axis-aligned bounding box. |
extents | The half-extents of an axis-aligned bounding box. |
Indicates if the frustum intersects (or contains) a sphere constructed via center and radius.
f | A constant pointer to a frustum. |
center | A constant pointer to a position representing the center of a sphere. |
radius | The radius of the sphere. |
Indicates if the value is a power of 2. 0 is considered not a power of 2.
value | The value to be interpreted. |
Calculates the absolute value of x.
x | The number to get the absolute value of. |
Calculates the arc cosine of x.
x | The number to calculate the arc cosine of. |
Calculates the cosine of x.
x | The number to calculate the cosine of. |
Compares the two floats and returns true if both are less than K_FLOAT_EPSILON apart; otherwise false.
Returns the largest integer value less than or equal to x.
x | The value to be examined. |
Returns a random floating-point number.
Returns a random floating-point number that is within the given range (inclusive).
min | The minimum of the range. |
max | The maximum of the range. |
Computes the base-2 logarithm of x (i.e. how many times x can be divided by 2).
x | The value to be examined. |
Returns a random integer that is within the given range (inclusive).
min | The minimum of the range. |
max | The maximum of the range. |
Calculates the sine of x.
x | The number to calculate the sine of. |
Perform Hermite interpolation between two values.
edge_0 | The lower edge of the Hermite function. |
edge_1 | The upper edge of the Hermite function. |
x | The value to interpolate. |
Calculates the square root of x.
x | The number to calculate the square root of. |
Swaps the values in the given float pointers.
a | A pointer to the first float. |
b | A pointer to the second float. |
Calculates the tangent of x.
x | The number to calculate the tangent of. |
Returns a backward vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Calculates the determinant of the given matrix.
matrix | The matrix to calculate the determinant of. |
Returns a downward vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Creates a rotation matrix from the provided x angle.
angle_radians | The x angle in radians. |
Creates a rotation matrix from the provided x, y and z axis rotations.
x_radians | The x rotation. |
y_radians | The y rotation. |
z_radians | The z rotation. |
Creates a rotation matrix from the provided y angle.
angle_radians | The y angle in radians. |
Creates a rotation matrix from the provided z angle.
angle_radians | The z angle in radians. |
Returns a forward vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Creates and returns an identity matrix:
{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }
Creates and returns an inverse of the provided matrix.
matrix | The matrix to be inverted. |
Returns a left vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Creates and returns a look-at matrix, or a matrix looking at target from the perspective of position.
position | The position of the matrix. |
target | The position to "look at". |
up | The up vector. |
Returns the result of multiplying matrix_0 and matrix_1.
matrix_0 | The first matrix to be multiplied. |
matrix_1 | The second matrix to be multiplied. |
Performs m * v.
m | The matrix to be multiplied. |
v | The vector to multiply by. |
Performs m * v.
m | The matrix to be multiplied. |
v | The vector to multiply by. |
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.
left | The left side of the view frustum. |
right | The right side of the view frustum. |
bottom | The bottom side of the view frustum. |
top | The top side of the view frustum. |
near_clip | The near clipping plane distance. |
far_clip | The far clipping plane distance. |
Creates and returns a perspective matrix. Typically used to render 3d scenes.
fov_radians | The field of view in radians. |
aspect_ratio | The aspect ratio. |
near_clip | The near clipping plane distance. |
far_clip | The far clipping plane distance. |
Returns a right vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Returns a scale matrix using the provided scale.
scale | The 3-component scale. |
Creates and returns a translation matrix from the given position.
position | The position to be used to create the matrix. |
Returns a transposed copy of the provided matrix (rows->colums)
matrix | The matrix to be transposed. |
Returns a upward vector relative to the provided matrix.
matrix | The matrix from which to base the vector. |
Indicates if plane p intersects an axis-aligned bounding box constructed via center and extents.
p | A constant pointer to a plane. |
center | A constant pointer to a position representing the center of an axis-aligned bounding box. |
extents | The half-extents of an axis-aligned bounding box. |
Indicates if plane p intersects a sphere constructed via center and radius.
p | A constant pointer to a plane. |
center | A constant pointer to a position representing the center of a sphere. |
radius | The radius of the sphere. |
Obtains the signed distance between the plane p and the provided postion.
p | A constant pointer to a plane. |
position | A constant pointer to a position. |
Returns the conjugate of the provided quaternion. That is, The x, y and z elements are negated, but the w element is untouched.
q | The quaternion to obtain a conjugate of. |
Calculates the dot product of the provided quaternions.
q_0 | The first quaternion. |
q_1 | The second quaternion. |
Creates a quaternion from the given axis and angle.
axis | The axis of rotation. |
angle | The angle of rotation. |
normalize | Indicates if the quaternion should be normalized. |
Returns an inverse copy of the provided quaternion.
q | The quaternion to invert. |
Multiplies the provided quaternions.
q_0 | The first quaternion. |
q_1 | The second quaternion. |
Returns the normal of the provided quaternion.
q | The quaternion. |
Returns a normalized copy of the provided quaternion.
q | The quaternion to normalize. |
Calculates spherical linear interpolation of a given percentage between two quaternions.
q_0 | The first quaternion. |
q_1 | The second quaternion. |
percentage | The percentage of interpolation, typically a value from 0.0f-1.0f. |
Creates a rotation matrix from the given quaternion.
q | The quaternion to be used. |
Calculates a rotation matrix based on the quaternion and the passed in center point.
q | The quaternion. |
center | The center point. |
Converts provided radians to degrees.
radians | The radians to be converted. |
Converts value from the "old" range to the "new" range.
value | The value to be converted. |
from_min | The minimum value from the old range. |
from_max | The maximum value from the old range. |
to_min | The minimum value from the new range. |
to_max | The maximum value from the new range. |
Converts rgb integer values [0-255] to a vec3 of floating-point values [0.0-1.0].
r | The red value [0-255]. |
g | The green value [0-255]. |
b | The blue value [0-255]. |
out_v | A pointer to hold the vector of floating-point values. |
Converts rgb int values [0-255] to a single 32-bit integer.
r | The red value [0-255]. |
g | The green value [0-255]. |
b | The blue value [0-255]. |
out_u32 | A pointer to hold the resulting integer. |
Converts the given 32-bit integer to rgb values [0-255].
rgbu | The integer holding a rgb value. |
out_r | A pointer to hold the red value. |
out_g | A pointer to hold the green value. |
out_b | A pointer to hold the blue value. |
Adds vector_1 to vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
vector_0 | The first vector. |
vector_1 | The second vector. |
tolerance | The difference tolerance. Typically K_FLOAT_EPSILON or similar. |
Creates and returns a new 2-element vector using the supplied values.
x | The x value. |
y | The y value. |
Returns the distance between vector_0 and vector_1.
vector_0 | The first vector. |
vector_1 | The second vector. |
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.
vector_0 | The first vector. |
vector_1 | The second vector. |
Divides vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Returns the length of the provided vector.
vector | The vector to retrieve the length of. |
Returns the squared length of the provided vector.
vector | The vector to retrieve the squared length of. |
Multiplies vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Multiplies vector_0 by vector_1, then adds the result to vector_2.
vector_0 | The first vector. |
vector_1 | The second vector. |
vector_2 | The third vector. |
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
vector_0 | The vector to be multiplied. |
scalar | The scalar value. |
Normalizes the provided vector in place to a unit vector.
vector | A pointer to the vector to be normalized. |
Returns a normalized copy of the supplied vector.
vector | The vector to be normalized. |
Creates and returns a 2-component vector with all components set to 1.0f.
Subtracts vector_1 from vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Creates and returns a 2-component vector with all components set to 0.0f.
Adds vector_1 to vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Creates and returns a 3-component vector pointing backward (0, 0, 1).
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
vector_0 | The first vector. |
vector_1 | The second vector. |
tolerance | The difference tolerance. Typically K_FLOAT_EPSILON or similar. |
Creates and returns a new 3-element vector using the supplied values.
x | The x value. |
y | The y value. |
z | The z value. |
Calculates and returns the cross product of the supplied vectors. The cross product is a new vector which is orthoganal to both provided vectors.
vector_0 | The first vector. |
vector_1 | The second vector. |
Returns the distance between vector_0 and vector_1.
vector_0 | The first vector. |
vector_1 | The second vector. |
Returns the squared distance between vector_0 and vector_1. Less intensive than calling the non-squared version due to sqrt.
vector_0 | The first vector. |
vector_1 | The second vector. |
Divides vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Returns the dot product between the provided vectors. Typically used to calculate the difference in direction.
vector_0 | The first vector. |
vector_1 | The second vector. |
Creates and returns a 3-component vector pointing forward (0, 0, -1).
Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component.
vector | The 4-component vector to extract from. |
Returns the length of the provided vector.
vector | The vector to retrieve the length of. |
Returns the squared length of the provided vector.
vector | The vector to retrieve the squared length of. |
Multiplies vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Multiplies vector_0 by vector_1, then adds the result to vector_2.
vector_0 | The first vector. |
vector_1 | The second vector. |
vector_2 | The third vector. |
Performs v * m.
v | The vector to bemultiplied. |
m | The matrix to be multiply by. |
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
vector_0 | The vector to be multiplied. |
scalar | The scalar value. |
Normalizes the provided vector in place to a unit vector.
vector | A pointer to the vector to be normalized. |
Returns a normalized copy of the supplied vector.
vector | The vector to be normalized. |
Creates and returns a 3-component vector with all components set to 1.0f.
Subtracts vector_1 from vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Converts a vec3 of rgbvalues [0.0-1.0] to integer rgb values [0-255].
v | The vector of rgb values [0.0-1.0] to be converted. |
out_r | A pointer to hold the red value. |
out_g | A pointer to hold the green value. |
out_b | A pointer to hold the blue value. |
Returns a new vec4 using vector as the x, y and z components and w for w.
vector | The 3-component vector. |
w | The w component. |
Transform v by m.
v | The vector to transform. |
w | Pass 1.0f for a point, or 0.0f for a direction. |
m | The matrix to transform by. |
Creates and returns a 3-component vector with all components set to 0.0f.
Adds vector_1 to vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
vector_0 | The first vector. |
vector_1 | The second vector. |
tolerance | The difference tolerance. Typically K_FLOAT_EPSILON or similar. |
Creates and returns a new 4-element vector using the supplied values.
x | The x value. |
y | The y value. |
z | The z value. |
w | The w value. |
Divides vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Calculates the dot product using the elements of vec4s provided in split-out format.
a0 | The first element of the a vector. |
a1 | The second element of the a vector. |
a2 | The third element of the a vector. |
a3 | The fourth element of the a vector. |
b0 | The first element of the b vector. |
b1 | The second element of the b vector. |
b2 | The third element of the b vector. |
b3 | The fourth element of the b vector. |
Returns a new vec4 using vector as the x, y and z components and w for w.
vector | The 3-component vector. |
w | The w component. |
Returns the length of the provided vector.
vector | The vector to retrieve the length of. |
Returns the squared length of the provided vector.
vector | The vector to retrieve the squared length of. |
Multiplies vector_0 by vector_1 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Multiplies vector_0 by vector_1, then adds the result to vector_2.
vector_0 | The first vector. |
vector_1 | The second vector. |
vector_2 | The third vector. |
Performs v * m.
v | The vector to bemultiplied. |
m | The matrix to be multiply by. |
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
vector_0 | The vector to be multiplied. |
scalar | The scalar value. |
Normalizes the provided vector in place to a unit vector.
vector | A pointer to the vector to be normalized. |
Returns a normalized copy of the supplied vector.
vector | The vector to be normalized. |
Creates and returns a 4-component vector with all components set to 1.0f.
Subtracts vector_1 from vector_0 and returns a copy of the result.
vector_0 | The first vector. |
vector_1 | The second vector. |
Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping the w component.
vector | The 4-component vector to extract from. |