From 47c21a2035d7c80f0eee7d69499c921b131859e3 Mon Sep 17 00:00:00 2001 From: Mikhail Romanko Date: Wed, 29 Jan 2025 09:14:58 +0300 Subject: [PATCH] Refactor math functions, add unit tests After some testing, I decided to ditch the DirectX approach of writing math functions. Additionally, I added unit tests (with reference wxMaxima calculations) for most math functions and fixed several bugs along the way. --- include/bh/math.h | 1325 ++++++++++++++-------------------- src/math.c | 883 ++++++++++------------ test/reference/matrix3f.wxmx | Bin 0 -> 5986 bytes test/reference/matrix4f.wxmx | Bin 0 -> 7100 bytes test/reference/point2f.wxmx | Bin 0 -> 8202 bytes test/reference/point3f.wxmx | Bin 0 -> 8290 bytes test/reference/point4f.wxmx | Bin 0 -> 8910 bytes test/src/testmath.c | 825 +++++++++++++++++++++ 8 files changed, 1760 insertions(+), 1273 deletions(-) create mode 100644 test/reference/matrix3f.wxmx create mode 100644 test/reference/matrix4f.wxmx create mode 100644 test/reference/point2f.wxmx create mode 100644 test/reference/point3f.wxmx create mode 100644 test/reference/point4f.wxmx create mode 100644 test/src/testmath.c diff --git a/include/bh/math.h b/include/bh/math.h index 3d3a53d..25aef35 100644 --- a/include/bh/math.h +++ b/include/bh/math.h @@ -103,7 +103,7 @@ typedef struct bh_point4i_s /** * 3x3 floating point matrix. - * + * * Each vector represent one column of the matrix. */ typedef struct bh_matrix3f_s @@ -121,7 +121,7 @@ typedef struct bh_matrix3f_s /** * 4x4 floating point matrix. - * + * * Each vector represent one column of the matrix. */ typedef struct bh_matrix4f_s @@ -153,6 +153,19 @@ typedef struct bh_line2f_s } bh_line2f_t; +/** + * 3D floating point line. + */ +typedef struct bh_line3f_s +{ + /** Origin */ + bh_point3f_t origin; + + /** Normal vector */ + bh_point3f_t normal; +} bh_line3f_t; + + /** * 3D floating point plane. */ @@ -182,15 +195,7 @@ typedef struct bh_ray2f_s /** * 3D floating point ray. */ -typedef struct bh_ray3f_s -{ - /** Origin */ - bh_point3f_t origin; - - /** Normal or direction */ - bh_point3f_t normal; -} bh_ray3f_t; - +typedef bh_line3f_t bh_ray3f_t; /** * 2D floating point AABB @@ -252,106 +257,94 @@ typedef bh_point4f_t bh_quat_t; /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_add(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_add(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_sub(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_sub(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_mul(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_mul(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_scale(const bh_point4f_t *a, - float b, - bh_point4f_t *result); +void bh_point4f_scale(const bh_point4f_t *a, + float b, + bh_point4f_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_madd(const bh_point4f_t *a, - const bh_point4f_t *b, - const bh_point4f_t *c, - bh_point4f_t *result); +void bh_point4f_madd(const bh_point4f_t *a, + const bh_point4f_t *b, + const bh_point4f_t *c, + bh_point4f_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_negate(const bh_point4f_t *in, - bh_point4f_t *result); +void bh_point4f_negate(const bh_point4f_t *in, + bh_point4f_t *result); /** * Calculates the dot product of two vectors. - * + * * \param a Value * \param b Value - * + * * \return Returns the dot product. */ float bh_point4f_dot(const bh_point4f_t *a, @@ -360,10 +353,10 @@ float bh_point4f_dot(const bh_point4f_t *a, /** * Calculates the dot product of two vectors with w component. - * + * * \param a Value * \param b Value - * + * * \return Returns the dot product. */ float bh_point4f_dot3(const bh_point4f_t *a, @@ -371,26 +364,24 @@ float bh_point4f_dot3(const bh_point4f_t *a, /** - * Calculates the cross product of two vectors without w component. - * + * Calculates the cross product of two vectors without w component. + * * result = a x b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_cross(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_cross(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Calculates the length of the vector. - * + * * \param in Value - * + * * \return Returns the length. */ float bh_point4f_length(const bh_point4f_t *in); @@ -398,186 +389,164 @@ float bh_point4f_length(const bh_point4f_t *in); /** * Normilizes the vector. - * + * * result = in / |in| - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_normal(const bh_point4f_t *in, - bh_point4f_t *result); +void bh_point4f_normal(const bh_point4f_t *in, + bh_point4f_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_min(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_min(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_max(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_point4f_max(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_lerp(const bh_point4f_t *a, - const bh_point4f_t *b, - float t, - bh_point4f_t *result); +void bh_point4f_lerp(const bh_point4f_t *a, + const bh_point4f_t *b, + float t, + bh_point4f_t *result); /** * Calculates spherical linear interpolation between two vectors. - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_point4f_slerp(const bh_point4f_t *a, - const bh_point4f_t *b, - float t, - bh_point4f_t *result); +void bh_point4f_slerp(const bh_point4f_t *a, + const bh_point4f_t *b, + float t, + bh_point4f_t *result); /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_add(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_add(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_sub(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_sub(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_mul(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_mul(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_scale(const bh_point3f_t *a, - float b, - bh_point3f_t *result); +void bh_point3f_scale(const bh_point3f_t *a, + float b, + bh_point3f_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_madd(const bh_point3f_t *a, - const bh_point3f_t *b, - const bh_point3f_t *c, - bh_point3f_t *result); +void bh_point3f_madd(const bh_point3f_t *a, + const bh_point3f_t *b, + const bh_point3f_t *c, + bh_point3f_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_negate(const bh_point3f_t *in, - bh_point3f_t *result); +void bh_point3f_negate(const bh_point3f_t *in, + bh_point3f_t *result); /** * Calculates the dot product of two vectors. - * + * * \param a Value * \param b Value - * + * * \return Returns the dot product. */ float bh_point3f_dot(const bh_point3f_t *a, @@ -585,26 +554,24 @@ float bh_point3f_dot(const bh_point3f_t *a, /** - * Calculates the cross product of two vectors. - * + * Calculates the cross product of two vectors. + * * result = a x b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_cross(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_cross(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Calculates the length of the vector. - * + * * \param in Value - * + * * \return Returns the length. */ float bh_point3f_length(const bh_point3f_t *in); @@ -612,186 +579,164 @@ float bh_point3f_length(const bh_point3f_t *in); /** * Normilizes the vector. - * + * * result = in / |in| - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_normal(const bh_point3f_t *in, - bh_point3f_t *result); +void bh_point3f_normal(const bh_point3f_t *in, + bh_point3f_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_min(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_min(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_max(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_point3f_max(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_lerp(const bh_point3f_t *a, - const bh_point3f_t *b, - float t, - bh_point3f_t *result); +void bh_point3f_lerp(const bh_point3f_t *a, + const bh_point3f_t *b, + float t, + bh_point3f_t *result); /** * Calculates spherical linear interpolation between two vectors. - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_point3f_slerp(const bh_point3f_t *a, - const bh_point3f_t *b, - float t, - bh_point3f_t *result); +void bh_point3f_slerp(const bh_point3f_t *a, + const bh_point3f_t *b, + float t, + bh_point3f_t *result); /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_add(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_point2f_add(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_sub(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_point2f_sub(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_mul(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_point2f_mul(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_scale(const bh_point2f_t *a, - float b, - bh_point2f_t *result); +void bh_point2f_scale(const bh_point2f_t *a, + float b, + bh_point2f_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_madd(const bh_point2f_t *a, - const bh_point2f_t *b, - const bh_point2f_t *c, - bh_point2f_t *result); +void bh_point2f_madd(const bh_point2f_t *a, + const bh_point2f_t *b, + const bh_point2f_t *c, + bh_point2f_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_negate(const bh_point2f_t *in, - bh_point2f_t *result); +void bh_point2f_negate(const bh_point2f_t *in, + bh_point2f_t *result); /** * Calculates the dot product of two vectors. - * + * * \param a Value * \param b Value - * + * * \return Returns the dot product. */ float bh_point2f_dot(const bh_point2f_t *a, @@ -799,13 +744,13 @@ float bh_point2f_dot(const bh_point2f_t *a, /** - * Calculates the cross product of two vectors and returns its z component. - * + * Calculates the cross product of two vectors and returns its z component. + * * result = a x b - * + * * \param a Value * \param b Value - * + * * \return Returns z component of the result vector. */ float bh_point2f_cross(const bh_point2f_t *a, @@ -814,9 +759,9 @@ float bh_point2f_cross(const bh_point2f_t *a, /** * Calculates the length of the vector. - * + * * \param in Value - * + * * \return Returns the length. */ float bh_point2f_length(const bh_point2f_t *in); @@ -824,583 +769,511 @@ float bh_point2f_length(const bh_point2f_t *in); /** * Normilizes the vector. - * + * * result = in / |in| - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_normal(const bh_point2f_t *in, - bh_point2f_t *result); +void bh_point2f_normal(const bh_point2f_t *in, + bh_point2f_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_min(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_point2f_min(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_max(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_point2f_max(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_lerp(const bh_point2f_t *a, - const bh_point2f_t *b, - float t, - bh_point2f_t *result); +void bh_point2f_lerp(const bh_point2f_t *a, + const bh_point2f_t *b, + float t, + bh_point2f_t *result); /** * Calculates spherical linear interpolation between two vectors. - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_point2f_slerp(const bh_point2f_t *a, - const bh_point2f_t *b, - float t, - bh_point2f_t *result); +void bh_point2f_slerp(const bh_point2f_t *a, + const bh_point2f_t *b, + float t, + bh_point2f_t *result); /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_add(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result); +void bh_point4i_add(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_sub(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result); +void bh_point4i_sub(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_mul(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result); +void bh_point4i_mul(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_scale(const bh_point4i_t *a, - int b, - bh_point4i_t *result); +void bh_point4i_scale(const bh_point4i_t *a, + int b, + bh_point4i_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_madd(const bh_point4i_t *a, - const bh_point4i_t *b, - const bh_point4i_t *c, - bh_point4i_t *result); +void bh_point4i_madd(const bh_point4i_t *a, + const bh_point4i_t *b, + const bh_point4i_t *c, + bh_point4i_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_negate(const bh_point4i_t *in, - bh_point4i_t *result); +void bh_point4i_negate(const bh_point4i_t *in, + bh_point4i_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_min(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result); +void bh_point4i_min(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_max(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result); +void bh_point4i_max(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4i_t *bh_point4i_lerp(const bh_point4i_t *a, - const bh_point4i_t *b, - float t, - bh_point4i_t *result); +void bh_point4i_lerp(const bh_point4i_t *a, + const bh_point4i_t *b, + float t, + bh_point4i_t *result); /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_add(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result); +void bh_point3i_add(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_sub(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result); +void bh_point3i_sub(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_mul(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result); +void bh_point3i_mul(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_scale(const bh_point3i_t *a, - int b, - bh_point3i_t *result); +void bh_point3i_scale(const bh_point3i_t *a, + int b, + bh_point3i_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_madd(const bh_point3i_t *a, - const bh_point3i_t *b, - const bh_point3i_t *c, - bh_point3i_t *result); +void bh_point3i_madd(const bh_point3i_t *a, + const bh_point3i_t *b, + const bh_point3i_t *c, + bh_point3i_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_negate(const bh_point3i_t *in, - bh_point3i_t *result); +void bh_point3i_negate(const bh_point3i_t *in, + bh_point3i_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_min(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result); +void bh_point3i_min(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_max(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result); +void bh_point3i_max(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3i_t *bh_point3i_lerp(const bh_point3i_t *a, - const bh_point3i_t *b, - float t, - bh_point3i_t *result); +void bh_point3i_lerp(const bh_point3i_t *a, + const bh_point3i_t *b, + float t, + bh_point3i_t *result); /** * Adds components of two vectors. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_add(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result); +void bh_point2i_add(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result); /** * Subtracts components of two vectors. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_sub(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result); +void bh_point2i_sub(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result); /** * Multiplies components of two vectors. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_mul(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result); +void bh_point2i_mul(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result); /** * Scales the vector. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_scale(const bh_point2i_t *a, - int b, - bh_point2i_t *result); +void bh_point2i_scale(const bh_point2i_t *a, + int b, + bh_point2i_t *result); /** * Multiplies and adds three vectors. - * + * * result = a * b + c - * + * * \param a Value * \param b Value * \param c Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_madd(const bh_point2i_t *a, - const bh_point2i_t *b, - const bh_point2i_t *c, - bh_point2i_t *result); +void bh_point2i_madd(const bh_point2i_t *a, + const bh_point2i_t *b, + const bh_point2i_t *c, + bh_point2i_t *result); /** * Negates the vector. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_negate(const bh_point2i_t *in, - bh_point2i_t *result); +void bh_point2i_negate(const bh_point2i_t *in, + bh_point2i_t *result); /** * Calculates vector, containing minimum components of two vectors. - * + * * result = min(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_min(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result); +void bh_point2i_min(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result); /** * Calculates vector, containing maximum components of two vectors. - * + * * result = max(a, b) - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_max(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result); +void bh_point2i_max(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result); /** * Calculates linear interpolation between two vectors. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2i_t *bh_point2i_lerp(const bh_point2i_t *a, - const bh_point2i_t *b, - float t, - bh_point2i_t *result); +void bh_point2i_lerp(const bh_point2i_t *a, + const bh_point2i_t *b, + float t, + bh_point2i_t *result); /** * Adds components of two quaternions. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_add bh_point4f_add /** * Subtracts components of two quaternions. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_sub bh_point4f_sub /** * Scales the quaternion. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_scale bh_point4f_scale /** * Negates the quaternion. - * + * * result = -in - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_negate bh_point4f_negate /** * Calculates the dot product of two quaternions. - * + * * \param a Value * \param b Value - * + * * \return Returns the dot product. */ #define bh_quat_dot bh_point4f_dot @@ -1408,9 +1281,9 @@ bh_point2i_t *bh_point2i_lerp(const bh_point2i_t *a, /** * Calculates the length of the quaternion. - * + * * \param in Value - * + * * \return Returns the length. */ #define bh_quat_length bh_point4f_length @@ -1418,134 +1291,116 @@ bh_point2i_t *bh_point2i_lerp(const bh_point2i_t *a, /** * Normilizes the quaternion. - * + * * result = in / |in| - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_normal bh_point4f_normal /** * Calculates linear interpolation between two quaternions. - * + * * result = a + (b - a) * t - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_lerp bh_point4f_lerp /** * Calculates spherical linear interpolation between two quaternions. - * + * * \param a Value * \param b Value * \param t Factor * \param result Result - * - * \return Returns pointer to the result. */ #define bh_quat_slerp bh_point4f_slerp /** * Sets quaternions to identity. - * + * * \param result Result - * - * \return Returns pointer to the result. */ -bh_quat_t *bh_quat_identity(bh_quat_t *result); +void bh_quat_identity(bh_quat_t *result); /** * Conjugates the quaternion. - * + * * result = (-in.x, -in.y, -in.z, in.w) - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_quat_t *bh_quat_conjugate(const bh_quat_t *in, - bh_quat_t *result); - - -/** - * Calculates the inverse of the quaternion. - * - * \param in Value - * \param result Result - * - * \return Returns pointer to the result. - */ -bh_quat_t *bh_quat_inverse(const bh_quat_t *in, - bh_quat_t *result); - - -/** - * Multiplies two quaternions. - * - * result = a * b - * - * \param a Value - * \param b Value - * \param result Result - * - * \return Returns pointer to the result. - */ -bh_quat_t *bh_quat_mul(const bh_quat_t *a, - const bh_quat_t *b, +void bh_quat_conjugate(const bh_quat_t *in, bh_quat_t *result); +/** + * Calculates the inverse of the quaternion. + * + * \param in Value + * \param result Result + */ +void bh_quat_inverse(const bh_quat_t *in, + bh_quat_t *result); + + +/** + * Multiplies two quaternions. + * + * result = a * b + * + * \param a Value + * \param b Value + * \param result Result + */ +void bh_quat_mul(const bh_quat_t *a, + const bh_quat_t *b, + bh_quat_t *result); + + /** * Sets quaternion from euler angles (roll, pitch, yaw). - * + * * Order of the rotation is ZYX (yaw, pitch, roll). - * + * * \param roll Roll * \param pitch Pitch * \param yaw Yaw * \param result Result - * - * \return Returns pointer to the result. */ -bh_quat_t *bh_quat_set_euler(float roll, - float pitch, - float yaw, - bh_quat_t *result); +void bh_quat_set_euler(float roll, + float pitch, + float yaw, + bh_quat_t *result); /** * Sets quaternion from axis of rotation and angle. - * + * * \param axis Axis * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_quat_t *bh_quat_set_rotation(const bh_point3f_t *axis, - float angle, - bh_quat_t *result); +void bh_quat_set_rotation(const bh_point3f_t *axis, + float angle, + bh_quat_t *result); /** * Calculates euler angles (roll, pitch, yaw) from quaternion. - * + * * Order of the rotation is ZYX (yaw, pitch, roll). - * + * * \param in Value * \param roll Roll * \param pitch Pitch @@ -1559,7 +1414,7 @@ void bh_quat_euler(const bh_quat_t *in, /** * Calculates axis of rotation and angle from quaternion. - * + * * \param in Value * \param axis Axis * \param angle Angle @@ -1571,109 +1426,95 @@ void bh_quat_rotation(const bh_quat_t *in, /** * Calculates rotation matrix from quaternion. - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_quat_matrix(const bh_quat_t *in, - bh_matrix4f_t *result); +void bh_quat_matrix(const bh_quat_t *in, + bh_matrix4f_t *result); /** * Sets matrix to identity. - * + * * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_identity(bh_matrix4f_t *result); +void bh_matrix4f_identity(bh_matrix4f_t *result); /** * Adds two matricies. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_add(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result); +void bh_matrix4f_add(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result); /** * Subtracts two matricies. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_sub(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result); +void bh_matrix4f_sub(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result); /** * Multiplies two matricies. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_mul(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result); +void bh_matrix4f_mul(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result); /** * Scales the matrix. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_scale(const bh_matrix4f_t *a, - float b, - bh_matrix4f_t *result); +void bh_matrix4f_scale(const bh_matrix4f_t *a, + float b, + bh_matrix4f_t *result); /** * Transposes the matrix. - * + * * result = a^T - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_transpose(const bh_matrix4f_t *in, - bh_matrix4f_t *result); +void bh_matrix4f_transpose(const bh_matrix4f_t *in, + bh_matrix4f_t *result); /** * Calculates the trace of the matrix. * * \param in Value - * + * * \return Returns trace value. */ float bh_matrix4f_trace(const bh_matrix4f_t *in); @@ -1681,9 +1522,9 @@ float bh_matrix4f_trace(const bh_matrix4f_t *in); /** * Calculates the determinant of the matrix. - * + * * \param in Value - * + * * \return Returns determinant value. */ float bh_matrix4f_determinant(const bh_matrix4f_t *in); @@ -1691,136 +1532,120 @@ float bh_matrix4f_determinant(const bh_matrix4f_t *in); /** * Calculates the inverse of the matrix. - * + * * If matrix has no inverse - identity matrix will be returned. - * + * * result = in^-1 - * + * * \param in Value * \param result Result - * + * * \return On success, returns inverse of the matrix. * \return On failure, returns identity matrix. */ -bh_matrix4f_t *bh_matrix4f_inverse(const bh_matrix4f_t *in, - bh_matrix4f_t *result); +int bh_matrix4f_inverse(const bh_matrix4f_t *in, + bh_matrix4f_t *result); /** * Calculates scaling matrix. - * + * * \param x X scale * \param y Y scale * \param z Z scale * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_scaling(float x, - float y, - float z, - bh_matrix4f_t *result); +void bh_matrix4f_scaling(float x, + float y, + float z, + bh_matrix4f_t *result); /** * Calculates translation matrix. - * + * * \param x X scale * \param y Y scale * \param z Z scale * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_translation(float x, - float y, - float z, - bh_matrix4f_t *result); +void bh_matrix4f_translation(float x, + float y, + float z, + bh_matrix4f_t *result); /** * Calculates x-rotation matrix (or rotation around x axis). - * + * * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation_x(float angle, - bh_matrix4f_t *result); +void bh_matrix4f_rotation_x(float angle, + bh_matrix4f_t *result); /** * Calculates y-rotation matrix (or rotation around y axis). - * + * * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation_y(float angle, - bh_matrix4f_t *result); +void bh_matrix4f_rotation_y(float angle, + bh_matrix4f_t *result); /** * Calculates z-rotation matrix (or rotation around z axis). - * + * * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation_z(float angle, - bh_matrix4f_t *result); +void bh_matrix4f_rotation_z(float angle, + bh_matrix4f_t *result); /** * Calculates rotation matrix around axis. - * + * * \param axis Axis * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis, - float angle, - bh_matrix4f_t *result); +void bh_matrix4f_rotation(const bh_point3f_t *axis, + float angle, + bh_matrix4f_t *result); /** * Calculates rotation matrix from euler angles (roll, pitch, yaw). - * + * * Order of the rotation is ZYX (yaw, pitch, roll). - * + * * \param roll Roll * \param pitch Pitch * \param yaw Yaw * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation_euler(float roll, - float pitch, - float yaw, - bh_matrix4f_t *result); +void bh_matrix4f_rotation_euler(float roll, + float pitch, + float yaw, + bh_matrix4f_t *result); /** * Calculates rotation matrix from quaternion. - * + * * \param rotation Quaternion * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_rotation_quat(bh_quat_t *rotation, - bh_matrix4f_t *result); +void bh_matrix4f_rotation_quat(bh_quat_t *rotation, + bh_matrix4f_t *result); /** * Calculates orthographic projection matrix. - * + * * \param x_min Min x * \param x_max Max x * \param y_min Min y @@ -1828,173 +1653,151 @@ bh_matrix4f_t *bh_matrix4f_rotation_quat(bh_quat_t *rotation, * \param z_min Min z * \param z_max Max z * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_ortho(float x_min, - float x_max, - float y_min, - float y_max, - float z_min, - float z_max, - bh_matrix4f_t *result); +void bh_matrix4f_ortho(float x_min, + float x_max, + float y_min, + float y_max, + float z_min, + float z_max, + bh_matrix4f_t *result); /** * Calculates perspective projection matrix. - * + * * \param fov Field of view * \param aspect Aspect ratio * \param z_min Min z * \param z_max Max z * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_perspective(float fov, - float aspect, - float z_min, - float z_max, - bh_matrix4f_t *result); +void bh_matrix4f_perspective(float fov, + float aspect, + float z_min, + float z_max, + bh_matrix4f_t *result); /** * Calculates camera view matrix. - * + * * \param camera Position * \param at Target * \param up Up * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix4f_t *bh_matrix4f_lookat(const bh_point3f_t *camera, - const bh_point3f_t *at, - const bh_point3f_t *up, - bh_matrix4f_t *result); +void bh_matrix4f_lookat(const bh_point3f_t *camera, + const bh_point3f_t *at, + const bh_point3f_t *up, + bh_matrix4f_t *result); /** * Applies matrix to vector. - * + * * \param a Matrix * \param b Vector * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_matrix4f_transform_point3f(const bh_matrix4f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_matrix4f_transform_point3f(const bh_matrix4f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); /** * Applies matrix to vector. - * + * * \param a Matrix * \param b Vector * \param result Result - * - * \return Returns pointer to the result. */ -bh_point4f_t *bh_matrix4f_transform_point4f(const bh_matrix4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result); +void bh_matrix4f_transform_point4f(const bh_matrix4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result); /** * Sets matrix to identity. - * + * * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_identity(bh_matrix3f_t *result); +void bh_matrix3f_identity(bh_matrix3f_t *result); /** * Adds two matricies. - * + * * result = a + b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_add(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result); +void bh_matrix3f_add(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result); /** * Subtracts two matricies. - * + * * result = a - b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_sub(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result); +void bh_matrix3f_sub(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result); /** * Multiplies two matricies. - * + * * result = a * b - * + * * \param a Value * \param b Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_mul(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result); +void bh_matrix3f_mul(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result); /** * Scales the matrix. - * + * * result = a * b - * + * * \param a Value * \param b Factor * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_scale(const bh_matrix3f_t *a, - float b, - bh_matrix3f_t *result); +void bh_matrix3f_scale(const bh_matrix3f_t *a, + float b, + bh_matrix3f_t *result); /** * Transposes the matrix. - * + * * result = a^T - * + * * \param in Value * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_transpose(const bh_matrix3f_t *in, - bh_matrix3f_t *result); +void bh_matrix3f_transpose(const bh_matrix3f_t *in, + bh_matrix3f_t *result); /** * Calculates the trace of the matrix. * * \param in Value - * + * * \return Returns trace value. */ float bh_matrix3f_trace(const bh_matrix3f_t *in); @@ -2002,9 +1805,9 @@ float bh_matrix3f_trace(const bh_matrix3f_t *in); /** * Calculates the determinant of the matrix. - * + * * \param in Value - * + * * \return Returns determinant value. */ float bh_matrix3f_determinant(const bh_matrix3f_t *in); @@ -2012,89 +1815,79 @@ float bh_matrix3f_determinant(const bh_matrix3f_t *in); /** * Calculates the inverse of the matrix. - * + * * If matrix has no inverse - identity matrix will be returned. - * + * * result = in^-1 - * + * * \param in Value * \param result Result - * + * * \return On success, returns inverse of the matrix. * \return On failure, returns identity matrix. */ -bh_matrix3f_t *bh_matrix3f_inverse(const bh_matrix3f_t *in, - bh_matrix3f_t *result); +int bh_matrix3f_inverse(const bh_matrix3f_t *in, + bh_matrix3f_t *result); /** * Calculates scaling matrix. - * + * * \param x X scale * \param y Y scale * \param z Z scale * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_scaling(float x, - float y, - bh_matrix3f_t *result); +void bh_matrix3f_scaling(float x, + float y, + bh_matrix3f_t *result); /** * Calculates translation matrix. - * + * * \param x X scale * \param y Y scale * \param z Z scale * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_translation(float x, - float y, - bh_matrix3f_t *result); +void bh_matrix3f_translation(float x, + float y, + bh_matrix3f_t *result); /** * Calculates rotation matrix. - * + * * \param angle Angle * \param result Result - * - * \return Returns pointer to the result. */ -bh_matrix3f_t *bh_matrix3f_rotation(float angle, - bh_matrix3f_t *result); +void bh_matrix3f_rotation(float angle, + bh_matrix3f_t *result); /** * Applies matrix to vector. - * + * * \param a Matrix * \param b Vector * \param result Result - * - * \return Returns pointer to the result. */ -bh_point2f_t *bh_matrix3f_transform_point2f(const bh_matrix3f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result); +void bh_matrix3f_transform_point2f(const bh_matrix3f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result); /** * Applies matrix to vector. - * + * * \param a Matrix * \param b Vector * \param result Result - * - * \return Returns pointer to the result. */ -bh_point3f_t *bh_matrix3f_transform_point3f(const bh_matrix3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result); +void bh_matrix3f_transform_point3f(const bh_matrix3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result); #endif /* BH_MATH_H */ diff --git a/src/math.c b/src/math.c index 18ec135..2e1d0cd 100644 --- a/src/math.c +++ b/src/math.c @@ -2,101 +2,89 @@ #include -bh_point4f_t *bh_point4f_add(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_add(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; result->z = a->z + b->z; result->w = a->w + b->w; - - return result; } -bh_point4f_t *bh_point4f_sub(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_sub(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; result->z = a->z - b->z; result->w = a->w - b->w; - - return result; } -bh_point4f_t *bh_point4f_mul(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_mul(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; result->z = a->z * b->z; result->w = a->w * b->w; - - return result; } -bh_point4f_t *bh_point4f_scale(const bh_point4f_t *a, - float b, - bh_point4f_t *result) +void bh_point4f_scale(const bh_point4f_t *a, + float b, + bh_point4f_t *result) { result->x = a->x * b; result->y = a->y * b; result->z = a->z * b; result->w = a->w * b; - - return result; } -bh_point4f_t *bh_point4f_madd(const bh_point4f_t *a, - const bh_point4f_t *b, - const bh_point4f_t *c, - bh_point4f_t *result) +void bh_point4f_madd(const bh_point4f_t *a, + const bh_point4f_t *b, + const bh_point4f_t *c, + bh_point4f_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; result->z = a->z * b->z + c->z; result->w = a->w * b->w + c->w; - - return result; } -bh_point4f_t *bh_point4f_negate(const bh_point4f_t *in, - bh_point4f_t *result) +void bh_point4f_negate(const bh_point4f_t *in, + bh_point4f_t *result) { result->x = -in->x; result->y = -in->y; result->z = -in->z; result->w = -in->w; - - return result; } float bh_point4f_dot(const bh_point4f_t *a, const bh_point4f_t *b) { - return a->x * b->x + a->y * b->y + a->z * b->y + a->w * b->w; + return a->x * b->x + a->y * b->y + a->z * b->z + a->w * b->w; } float bh_point4f_dot3(const bh_point4f_t *a, const bh_point4f_t *b) { - return a->x * b->x + a->y * b->y + a->z * b->y; + return a->x * b->x + a->y * b->y + a->z * b->z; } -bh_point4f_t *bh_point4f_cross(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_cross(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { bh_point4f_t tmp; @@ -106,7 +94,6 @@ bh_point4f_t *bh_point4f_cross(const bh_point4f_t *a, tmp.w = 0.0f; *result = tmp; - return result; } @@ -116,57 +103,55 @@ float bh_point4f_length(const bh_point4f_t *in) } -bh_point4f_t *bh_point4f_normal(const bh_point4f_t *in, - bh_point4f_t *result) +void bh_point4f_normal(const bh_point4f_t *in, + bh_point4f_t *result) { float length; length = 1.0f / bh_point4f_length(in); - return bh_point4f_scale(in, length, result); + bh_point4f_scale(in, length, result); } -bh_point4f_t *bh_point4f_min(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_min(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; if (a->z < b->z) result->z = a->z; else result->z = b->z; if (a->w < b->w) result->w = a->w; else result->w = b->w; - - return result; } -bh_point4f_t *bh_point4f_max(const bh_point4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_point4f_max(const bh_point4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; if (a->z > b->z) result->z = a->z; else result->z = b->z; if (a->w > b->w) result->w = a->w; else result->w = b->w; - - return result; } -bh_point4f_t *bh_point4f_lerp(const bh_point4f_t *a, - const bh_point4f_t *b, - float t, - bh_point4f_t *result) +void bh_point4f_lerp(const bh_point4f_t *a, + const bh_point4f_t *b, + float t, + bh_point4f_t *result) { bh_point4f_t tmp; - bh_point4f_scale(bh_point4f_sub(b, a, &tmp), t, &tmp); - return bh_point4f_add(a, &tmp, result); + + bh_point4f_sub(b, a, &tmp); + bh_point4f_scale(&tmp, t, &tmp); + bh_point4f_add(a, &tmp, result); } -bh_point4f_t *bh_point4f_slerp(const bh_point4f_t *a, - const bh_point4f_t *b, - float t, - bh_point4f_t *result) +void bh_point4f_slerp(const bh_point4f_t *a, + const bh_point4f_t *b, + float t, + bh_point4f_t *result) { float angle, denom; bh_point4f_t from, to; @@ -175,97 +160,89 @@ bh_point4f_t *bh_point4f_slerp(const bh_point4f_t *a, /* Special case - reducing to linear interpolation */ if (angle == 0.0f) - return bh_point4f_lerp(a, b, t, result); - - denom = 1.0f / sinf(angle); - bh_point4f_scale(a, sinf((1 - t) * angle) * denom, &from); - bh_point4f_scale(b, sinf(t * angle) * denom, &to); - return bh_point4f_add(&from, &to, result); + { + bh_point4f_lerp(a, b, t, result); + } + else + { + denom = 1.0f / sinf(angle); + bh_point4f_scale(a, sinf((1 - t) * angle) * denom, &from); + bh_point4f_scale(b, sinf(t * angle) * denom, &to); + bh_point4f_add(&from, &to, result); + } } -bh_point3f_t *bh_point3f_add(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_add(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; result->z = a->z + b->z; - - return result; } -bh_point3f_t *bh_point3f_sub(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_sub(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; result->z = a->z - b->z; - - return result; } -bh_point3f_t *bh_point3f_mul(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_mul(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; result->z = a->z * b->z; - - return result; } -bh_point3f_t *bh_point3f_scale(const bh_point3f_t *a, - float b, - bh_point3f_t *result) +void bh_point3f_scale(const bh_point3f_t *a, + float b, + bh_point3f_t *result) { result->x = a->x * b; result->y = a->y * b; result->z = a->z * b; - - return result; } -bh_point3f_t *bh_point3f_madd(const bh_point3f_t *a, - const bh_point3f_t *b, - const bh_point3f_t *c, - bh_point3f_t *result) +void bh_point3f_madd(const bh_point3f_t *a, + const bh_point3f_t *b, + const bh_point3f_t *c, + bh_point3f_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; result->z = a->z * b->z + c->z; - - return result; } -bh_point3f_t *bh_point3f_negate(const bh_point3f_t *in, - bh_point3f_t *result) +void bh_point3f_negate(const bh_point3f_t *in, + bh_point3f_t *result) { result->x = -in->x; result->y = -in->y; result->z = -in->z; - - return result; } float bh_point3f_dot(const bh_point3f_t *a, const bh_point3f_t *b) { - return a->x * b->x + a->y * b->y + a->z * b->y; + return a->x * b->x + a->y * b->y + a->z * b->z; } -bh_point3f_t *bh_point3f_cross(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_cross(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { bh_point3f_t tmp; @@ -274,7 +251,6 @@ bh_point3f_t *bh_point3f_cross(const bh_point3f_t *a, tmp.z = a->x * b->y - a->y * b->x; *result = tmp; - return result; } @@ -284,55 +260,53 @@ float bh_point3f_length(const bh_point3f_t *in) } -bh_point3f_t *bh_point3f_normal(const bh_point3f_t *in, - bh_point3f_t *result) +void bh_point3f_normal(const bh_point3f_t *in, + bh_point3f_t *result) { float length; length = 1.0f / bh_point3f_length(in); - return bh_point3f_scale(in, length, result); + bh_point3f_scale(in, length, result); } -bh_point3f_t *bh_point3f_min(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_min(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; if (a->z < b->z) result->z = a->z; else result->z = b->z; - - return result; } -bh_point3f_t *bh_point3f_max(const bh_point3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_point3f_max(const bh_point3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; if (a->z > b->z) result->z = a->z; else result->z = b->z; - - return result; } -bh_point3f_t *bh_point3f_lerp(const bh_point3f_t *a, - const bh_point3f_t *b, - float t, - bh_point3f_t *result) +void bh_point3f_lerp(const bh_point3f_t *a, + const bh_point3f_t *b, + float t, + bh_point3f_t *result) { bh_point3f_t tmp; - bh_point3f_scale(bh_point3f_sub(b, a, &tmp), t, &tmp); - return bh_point3f_add(a, &tmp, result); + + bh_point3f_sub(b, a, &tmp); + bh_point3f_scale(&tmp, t, &tmp); + bh_point3f_add(a, &tmp, result); } -bh_point3f_t *bh_point3f_slerp(const bh_point3f_t *a, - const bh_point3f_t *b, - float t, - bh_point3f_t *result) +void bh_point3f_slerp(const bh_point3f_t *a, + const bh_point3f_t *b, + float t, + bh_point3f_t *result) { float angle, denom; bh_point3f_t from, to; @@ -341,78 +315,70 @@ bh_point3f_t *bh_point3f_slerp(const bh_point3f_t *a, /* Special case - reducing to linear interpolation */ if (angle == 0.0f) - return bh_point3f_lerp(a, b, t, result); - - denom = 1.0f / sinf(angle); - bh_point3f_scale(a, sinf((1 - t) * angle) * denom, &from); - bh_point3f_scale(b, sinf(t * angle) * denom, &to); - return bh_point3f_add(&from, &to, result); + { + bh_point3f_lerp(a, b, t, result); + } + else + { + denom = 1.0f / sinf(angle); + bh_point3f_scale(a, sinf((1 - t) * angle) * denom, &from); + bh_point3f_scale(b, sinf(t * angle) * denom, &to); + bh_point3f_add(&from, &to, result); + } } -bh_point2f_t *bh_point2f_add(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_point2f_add(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; - - return result; } -bh_point2f_t *bh_point2f_sub(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_point2f_sub(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; - - return result; } -bh_point2f_t *bh_point2f_mul(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_point2f_mul(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; - - return result; } -bh_point2f_t *bh_point2f_scale(const bh_point2f_t *a, - float b, - bh_point2f_t *result) +void bh_point2f_scale(const bh_point2f_t *a, + float b, + bh_point2f_t *result) { result->x = a->x * b; result->y = a->y * b; - - return result; } -bh_point2f_t *bh_point2f_madd(const bh_point2f_t *a, - const bh_point2f_t *b, - const bh_point2f_t *c, - bh_point2f_t *result) +void bh_point2f_madd(const bh_point2f_t *a, + const bh_point2f_t *b, + const bh_point2f_t *c, + bh_point2f_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; - - return result; } -bh_point2f_t *bh_point2f_negate(const bh_point2f_t *in, - bh_point2f_t *result) +void bh_point2f_negate(const bh_point2f_t *in, + bh_point2f_t *result) { result->x = -in->x; result->y = -in->y; - - return result; } @@ -436,53 +402,51 @@ float bh_point2f_length(const bh_point2f_t *in) } -bh_point2f_t *bh_point2f_normal(const bh_point2f_t *in, - bh_point2f_t *result) +void bh_point2f_normal(const bh_point2f_t *in, + bh_point2f_t *result) { float length; length = 1.0f / bh_point2f_length(in); - return bh_point2f_scale(in, length, result); + bh_point2f_scale(in, length, result); } -bh_point2f_t *bh_point2f_min(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_point2f_min(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; - - return result; } -bh_point2f_t *bh_point2f_max(const bh_point2f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_point2f_max(const bh_point2f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; - - return result; } -bh_point2f_t *bh_point2f_lerp(const bh_point2f_t *a, - const bh_point2f_t *b, - float t, - bh_point2f_t *result) +void bh_point2f_lerp(const bh_point2f_t *a, + const bh_point2f_t *b, + float t, + bh_point2f_t *result) { bh_point2f_t tmp; - bh_point2f_scale(bh_point2f_sub(b, a, &tmp), t, &tmp); - return bh_point2f_add(a, &tmp, result); + + bh_point2f_sub(b, a, &tmp); + bh_point2f_scale(&tmp, t, &tmp); + bh_point2f_add(a, &tmp, result); } -bh_point2f_t *bh_point2f_slerp(const bh_point2f_t *a, - const bh_point2f_t *b, - float t, - bh_point2f_t *result) +void bh_point2f_slerp(const bh_point2f_t *a, + const bh_point2f_t *b, + float t, + bh_point2f_t *result) { float angle, denom; bh_point2f_t from, to; @@ -491,123 +455,110 @@ bh_point2f_t *bh_point2f_slerp(const bh_point2f_t *a, /* Special case - reducing to linear interpolation */ if (angle == 0.0f) - return bh_point2f_lerp(a, b, t, result); - - denom = 1.0f / sinf(angle); - bh_point2f_scale(a, sinf((1 - t) * angle) * denom, &from); - bh_point2f_scale(b, sinf(t * angle) * denom, &to); - return bh_point2f_add(&from, &to, result); + { + bh_point2f_lerp(a, b, t, result); + } + else { + denom = 1.0f / sinf(angle); + bh_point2f_scale(a, sinf((1 - t) * angle) * denom, &from); + bh_point2f_scale(b, sinf(t * angle) * denom, &to); + bh_point2f_add(&from, &to, result); + } } -bh_point4i_t *bh_point4i_add(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result) +void bh_point4i_add(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; result->z = a->z + b->z; result->w = a->w + b->w; - - return result; } -bh_point4i_t *bh_point4i_sub(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result) +void bh_point4i_sub(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; result->z = a->z - b->z; result->w = a->w - b->w; - - return result; } -bh_point4i_t *bh_point4i_mul(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result) +void bh_point4i_mul(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; result->z = a->z * b->z; result->w = a->w * b->w; - - return result; } -bh_point4i_t *bh_point4i_scale(const bh_point4i_t *a, - int b, - bh_point4i_t *result) +void bh_point4i_scale(const bh_point4i_t *a, + int b, + bh_point4i_t *result) { result->x = a->x * b; result->y = a->y * b; result->z = a->z * b; result->w = a->w * b; - - return result; } -bh_point4i_t *bh_point4i_madd(const bh_point4i_t *a, - const bh_point4i_t *b, - const bh_point4i_t *c, - bh_point4i_t *result) +void bh_point4i_madd(const bh_point4i_t *a, + const bh_point4i_t *b, + const bh_point4i_t *c, + bh_point4i_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; result->z = a->z * b->z + c->z; result->w = a->w * b->w + c->w; - - return result; } -bh_point4i_t *bh_point4i_negate(const bh_point4i_t *in, - bh_point4i_t *result) +void bh_point4i_negate(const bh_point4i_t *in, + bh_point4i_t *result) { result->x = -in->x; result->y = -in->y; result->z = -in->z; result->w = -in->w; - - return result; } -bh_point4i_t *bh_point4i_min(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result) +void bh_point4i_min(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; if (a->z < b->z) result->z = a->z; else result->z = b->z; if (a->w < b->w) result->w = a->w; else result->w = b->w; - - return result; } -bh_point4i_t *bh_point4i_max(const bh_point4i_t *a, - const bh_point4i_t *b, - bh_point4i_t *result) +void bh_point4i_max(const bh_point4i_t *a, + const bh_point4i_t *b, + bh_point4i_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; if (a->z > b->z) result->z = a->z; else result->z = b->z; if (a->w > b->w) result->w = a->w; else result->w = b->w; - - return result; } -bh_point4i_t *bh_point4i_lerp(const bh_point4i_t *a, - const bh_point4i_t *b, - float t, - bh_point4i_t *result) +void bh_point4i_lerp(const bh_point4i_t *a, + const bh_point4i_t *b, + float t, + bh_point4i_t *result) { bh_point4i_t tmp; @@ -616,110 +567,94 @@ bh_point4i_t *bh_point4i_lerp(const bh_point4i_t *a, tmp.z = (b->z - a->z) * t; tmp.w = (b->w - a->w) * t; - return bh_point4i_add(a, &tmp, result); + bh_point4i_add(a, &tmp, result); } -bh_point3i_t *bh_point3i_add(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result) +void bh_point3i_add(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; result->z = a->z + b->z; - - return result; } -bh_point3i_t *bh_point3i_sub(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result) +void bh_point3i_sub(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; result->z = a->z - b->z; - - return result; } -bh_point3i_t *bh_point3i_mul(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result) +void bh_point3i_mul(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; result->z = a->z * b->z; - - return result; } -bh_point3i_t *bh_point3i_scale(const bh_point3i_t *a, - int b, - bh_point3i_t *result) +void bh_point3i_scale(const bh_point3i_t *a, + int b, + bh_point3i_t *result) { result->x = a->x * b; result->y = a->y * b; result->z = a->z * b; - - return result; } -bh_point3i_t *bh_point3i_madd(const bh_point3i_t *a, - const bh_point3i_t *b, - const bh_point3i_t *c, - bh_point3i_t *result) +void bh_point3i_madd(const bh_point3i_t *a, + const bh_point3i_t *b, + const bh_point3i_t *c, + bh_point3i_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; result->z = a->z * b->z + c->z; - - return result; } -bh_point3i_t *bh_point3i_negate(const bh_point3i_t *in, - bh_point3i_t *result) +void bh_point3i_negate(const bh_point3i_t *in, + bh_point3i_t *result) { result->x = -in->x; result->y = -in->y; result->z = -in->z; - - return result; } -bh_point3i_t *bh_point3i_min(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result) +void bh_point3i_min(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; if (a->z < b->z) result->z = a->z; else result->z = b->z; - - return result; } -bh_point3i_t *bh_point3i_max(const bh_point3i_t *a, - const bh_point3i_t *b, - bh_point3i_t *result) +void bh_point3i_max(const bh_point3i_t *a, + const bh_point3i_t *b, + bh_point3i_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; if (a->z > b->z) result->z = a->z; else result->z = b->z; - - return result; } -bh_point3i_t *bh_point3i_lerp(const bh_point3i_t *a, - const bh_point3i_t *b, - float t, - bh_point3i_t *result) +void bh_point3i_lerp(const bh_point3i_t *a, + const bh_point3i_t *b, + float t, + bh_point3i_t *result) { bh_point3i_t tmp; @@ -727,147 +662,128 @@ bh_point3i_t *bh_point3i_lerp(const bh_point3i_t *a, tmp.y = (b->y - a->y) * t; tmp.z = (b->z - a->z) * t; - return bh_point3i_add(a, &tmp, result); + bh_point3i_add(a, &tmp, result); } -bh_point2i_t *bh_point2i_add(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result) +void bh_point2i_add(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result) { result->x = a->x + b->x; result->y = a->y + b->y; - - return result; } -bh_point2i_t *bh_point2i_sub(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result) +void bh_point2i_sub(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result) { result->x = a->x - b->x; result->y = a->y - b->y; - - return result; } -bh_point2i_t *bh_point2i_mul(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result) +void bh_point2i_mul(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result) { result->x = a->x * b->x; result->y = a->y * b->y; - - return result; } -bh_point2i_t *bh_point2i_scale(const bh_point2i_t *a, - int b, - bh_point2i_t *result) +void bh_point2i_scale(const bh_point2i_t *a, + int b, + bh_point2i_t *result) { result->x = a->x * b; result->y = a->y * b; - - return result; } -bh_point2i_t *bh_point2i_madd(const bh_point2i_t *a, - const bh_point2i_t *b, - const bh_point2i_t *c, - bh_point2i_t *result) +void bh_point2i_madd(const bh_point2i_t *a, + const bh_point2i_t *b, + const bh_point2i_t *c, + bh_point2i_t *result) { result->x = a->x * b->x + c->x; result->y = a->y * b->y + c->y; - - return result; } -bh_point2i_t *bh_point2i_negate(const bh_point2i_t *in, - bh_point2i_t *result) +void bh_point2i_negate(const bh_point2i_t *in, + bh_point2i_t *result) { result->x = -in->x; result->y = -in->y; - - return result; } -bh_point2i_t *bh_point2i_min(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result) +void bh_point2i_min(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result) { if (a->x < b->x) result->x = a->x; else result->x = b->x; if (a->y < b->y) result->y = a->y; else result->y = b->y; - - return result; } -bh_point2i_t *bh_point2i_max(const bh_point2i_t *a, - const bh_point2i_t *b, - bh_point2i_t *result) +void bh_point2i_max(const bh_point2i_t *a, + const bh_point2i_t *b, + bh_point2i_t *result) { if (a->x > b->x) result->x = a->x; else result->x = b->x; if (a->y > b->y) result->y = a->y; else result->y = b->y; - - return result; } -bh_point2i_t *bh_point2i_lerp(const bh_point2i_t *a, - const bh_point2i_t *b, - float t, - bh_point2i_t *result) +void bh_point2i_lerp(const bh_point2i_t *a, + const bh_point2i_t *b, + float t, + bh_point2i_t *result) { bh_point2i_t tmp; tmp.x = (b->x - a->x) * t; tmp.y = (b->y - a->y) * t; - return bh_point2i_add(a, &tmp, result); + bh_point2i_add(a, &tmp, result); } -bh_quat_t *bh_quat_identity(bh_quat_t *result) +void bh_quat_identity(bh_quat_t *result) { static const bh_quat_t ident = {0.0f, 0.0f, 0.0f, 1.0f}; *result = ident; - return result; } -bh_quat_t *bh_quat_conjugate(const bh_quat_t *in, - bh_quat_t *result) +void bh_quat_conjugate(const bh_quat_t *in, + bh_quat_t *result) { result->x = -in->x; result->y = -in->y; result->z = -in->z; result->w = in->w; - - return result; } -bh_quat_t *bh_quat_inverse(const bh_quat_t *in, - bh_quat_t *result) +void bh_quat_inverse(const bh_quat_t *in, + bh_quat_t *result) { float length; length = bh_quat_dot(in, in); bh_quat_conjugate(in, result); - return bh_quat_scale(result, 1.0f / length, result); + bh_quat_scale(result, 1.0f / length, result); } -bh_quat_t *bh_quat_mul(const bh_quat_t *a, - const bh_quat_t *b, - bh_quat_t *result) +void bh_quat_mul(const bh_quat_t *a, + const bh_quat_t *b, + bh_quat_t *result) { bh_quat_t tmp1, tmp2, tmp3; float w; @@ -880,15 +796,13 @@ bh_quat_t *bh_quat_mul(const bh_quat_t *a, bh_point4f_add(&tmp1, &tmp2, result); bh_point4f_add(&tmp3, result, result); result->w = w; - - return result; } -bh_quat_t *bh_quat_set_euler(float roll, - float pitch, - float yaw, - bh_quat_t *result) +void bh_quat_set_euler(float roll, + float pitch, + float yaw, + bh_quat_t *result) { float cr, cp, cy, sr, sp, sy; @@ -903,14 +817,12 @@ bh_quat_t *bh_quat_set_euler(float roll, result->y = cr * sp * cy + sr * cp * sy; result->z = cr * cp * sy - sr * sp * cy; result->w = cr * cp * cy + sr * sp * sy; - - return result; } -bh_quat_t *bh_quat_set_rotation(const bh_point3f_t *axis, - float angle, - bh_quat_t *result) +void bh_quat_set_rotation(const bh_point3f_t *axis, + float angle, + bh_quat_t *result) { float c, s; @@ -921,8 +833,6 @@ bh_quat_t *bh_quat_set_rotation(const bh_point3f_t *axis, result->y = axis->y * s; result->z = axis->z * s; result->w = c; - - return result; } @@ -994,8 +904,8 @@ void bh_quat_rotation(const bh_quat_t *in, } -bh_matrix4f_t *bh_quat_matrix(const bh_quat_t *in, - bh_matrix4f_t *result) +void bh_quat_matrix(const bh_quat_t *in, + bh_matrix4f_t *result) { float xx, xy, xz, xw, yy, yz, yw, zz, zw; @@ -1019,12 +929,10 @@ bh_matrix4f_t *bh_quat_matrix(const bh_quat_t *in, result->z.x = 2.0f * (xz + yw); result->z.y = 2.0f * (yz - xw); result->z.z = 1.0f - 2.0f * (xx + yy); - - return result; } -bh_matrix4f_t *bh_matrix4f_identity(bh_matrix4f_t *result) +void bh_matrix4f_identity(bh_matrix4f_t *result) { static const bh_matrix4f_t ident = { {1.0f, 0.0f, 0.0f, 0.0f}, @@ -1034,39 +942,34 @@ bh_matrix4f_t *bh_matrix4f_identity(bh_matrix4f_t *result) }; *result = ident; - return result; } -bh_matrix4f_t *bh_matrix4f_add(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result) +void bh_matrix4f_add(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result) { bh_point4f_add(&a->x, &b->x, &result->x); bh_point4f_add(&a->y, &b->y, &result->y); bh_point4f_add(&a->z, &b->z, &result->z); bh_point4f_add(&a->w, &b->w, &result->w); - - return result; } -bh_matrix4f_t *bh_matrix4f_sub(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result) +void bh_matrix4f_sub(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result) { bh_point4f_sub(&a->x, &b->x, &result->x); bh_point4f_sub(&a->y, &b->y, &result->y); bh_point4f_sub(&a->z, &b->z, &result->z); bh_point4f_sub(&a->w, &b->w, &result->w); - - return result; } -bh_matrix4f_t *bh_matrix4f_mul(const bh_matrix4f_t *a, - const bh_matrix4f_t *b, - bh_matrix4f_t *result) +void bh_matrix4f_mul(const bh_matrix4f_t *a, + const bh_matrix4f_t *b, + bh_matrix4f_t *result) { bh_matrix4f_t tmp; bh_point4f_t row; @@ -1092,25 +995,22 @@ bh_matrix4f_t *bh_matrix4f_mul(const bh_matrix4f_t *a, row.x = row.y = row.z = row.w = b->w.w; bh_point4f_madd(&a->w, &row, &tmp.w, &tmp.w); *result = tmp; - return result; } -bh_matrix4f_t *bh_matrix4f_scale(const bh_matrix4f_t *a, - float b, - bh_matrix4f_t *result) +void bh_matrix4f_scale(const bh_matrix4f_t *a, + float b, + bh_matrix4f_t *result) { bh_point4f_scale(&a->x, b, &result->x); bh_point4f_scale(&a->y, b, &result->y); bh_point4f_scale(&a->z, b, &result->z); bh_point4f_scale(&a->w, b, &result->w); - - return result; } -bh_matrix4f_t *bh_matrix4f_transpose(const bh_matrix4f_t *in, - bh_matrix4f_t *result) +void bh_matrix4f_transpose(const bh_matrix4f_t *in, + bh_matrix4f_t *result) { bh_matrix4f_t tmp; @@ -1135,7 +1035,6 @@ bh_matrix4f_t *bh_matrix4f_transpose(const bh_matrix4f_t *in, tmp.w.w = in->w.w; *result = tmp; - return result; } @@ -1166,8 +1065,8 @@ float bh_matrix4f_determinant(const bh_matrix4f_t *in) } -bh_matrix4f_t *bh_matrix4f_inverse(const bh_matrix4f_t *in, - bh_matrix4f_t *result) +int bh_matrix4f_inverse(const bh_matrix4f_t *in, + bh_matrix4f_t *result) { float a, b, c, d, e, f, det; bh_matrix4f_t tmp; @@ -1191,7 +1090,7 @@ bh_matrix4f_t *bh_matrix4f_inverse(const bh_matrix4f_t *in, det += in->w.x * tmp.x.w; if (det == 0.0f) - return bh_matrix4f_identity(result); + return BH_ERROR; tmp.y.x = -(in->y.x * f - in->z.x * e + in->w.x * d); tmp.y.y = (in->x.x * f - in->z.x * c + in->w.x * b); @@ -1222,40 +1121,37 @@ bh_matrix4f_t *bh_matrix4f_inverse(const bh_matrix4f_t *in, tmp.w.z = -(in->x.x * e - in->y.x * c + in->w.x * a); tmp.w.w = (in->x.x * d - in->y.x * b + in->z.x * a); - return bh_matrix4f_scale(&tmp, 1.0f / det, result); + bh_matrix4f_scale(&tmp, 1.0f / det, result); + return BH_OK; } -bh_matrix4f_t *bh_matrix4f_scaling(float x, - float y, - float z, - bh_matrix4f_t *result) +void bh_matrix4f_scaling(float x, + float y, + float z, + bh_matrix4f_t *result) { bh_matrix4f_identity(result); result->x.x = x; result->y.y = y; result->z.z = z; - - return result; } -bh_matrix4f_t *bh_matrix4f_translation(float x, - float y, - float z, - bh_matrix4f_t *result) +void bh_matrix4f_translation(float x, + float y, + float z, + bh_matrix4f_t *result) { bh_matrix4f_identity(result); result->w.x = x; result->w.y = y; result->w.z = z; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation_x(float angle, - bh_matrix4f_t *result) +void bh_matrix4f_rotation_x(float angle, + bh_matrix4f_t *result) { float c, s; @@ -1267,13 +1163,11 @@ bh_matrix4f_t *bh_matrix4f_rotation_x(float angle, result->z.z = c; result->z.y = -s; result->y.z = s; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation_y(float angle, - bh_matrix4f_t *result) +void bh_matrix4f_rotation_y(float angle, + bh_matrix4f_t *result) { float c, s; @@ -1285,13 +1179,11 @@ bh_matrix4f_t *bh_matrix4f_rotation_y(float angle, result->z.z = c; result->z.x = s; result->x.z = -s; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation_z(float angle, - bh_matrix4f_t *result) +void bh_matrix4f_rotation_z(float angle, + bh_matrix4f_t *result) { float c, s; @@ -1303,14 +1195,12 @@ bh_matrix4f_t *bh_matrix4f_rotation_z(float angle, result->y.y = c; result->y.x = -s; result->x.y = s; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis, - float angle, - bh_matrix4f_t *result) +void bh_matrix4f_rotation(const bh_point3f_t *axis, + float angle, + bh_matrix4f_t *result) { float x, y, z, length; float c, s, moc, xx, xy, xz, yy, yz, zz; @@ -1318,7 +1208,10 @@ bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis, length = bh_point3f_length(axis); if (length == 0.0f) - return bh_matrix4f_identity(result); + { + bh_matrix4f_identity(result); + return; + } x = axis->x / length; y = axis->y / length; @@ -1332,25 +1225,31 @@ bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis, if (z != 0.0f) { if (z < 0.0f) - return bh_matrix4f_rotation_z(-angle, result); + bh_matrix4f_rotation_z(-angle, result); + else + bh_matrix4f_rotation_z(angle, result); - return bh_matrix4f_rotation_z(angle, result); + return; } } else if (z == 0.0f) { if (y < 0.0f) - return bh_matrix4f_rotation_y(-angle, result); + bh_matrix4f_rotation_y(-angle, result); + else + bh_matrix4f_rotation_y(angle, result); - return bh_matrix4f_rotation_y(angle, result); + return; } } else if (y == 0.0f && z == 0.0f) { if (x < 0.0f) - return bh_matrix4f_rotation_x(-angle, result); + bh_matrix4f_rotation_x(-angle, result); + else + bh_matrix4f_rotation_x(angle, result); - return bh_matrix4f_rotation_x(angle, result); + return; } /* Rotate around arbitrary axis */ @@ -1378,15 +1277,13 @@ bh_matrix4f_t *bh_matrix4f_rotation(const bh_point3f_t *axis, result->x.z = xz * moc - y * s; result->y.z = yz * moc + x * s; result->z.z = c + zz * moc; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation_euler(float roll, - float pitch, - float yaw, - bh_matrix4f_t *result) +void bh_matrix4f_rotation_euler(float roll, + float pitch, + float yaw, + bh_matrix4f_t *result) { float rs, rc, ys, yc, ps, pc; @@ -1407,25 +1304,23 @@ bh_matrix4f_t *bh_matrix4f_rotation_euler(float roll, result->z.x = rs * ys + ps * rc * yc; result->z.y = ps * rc * ys - rs * yc; result->z.z = pc * rc; - - return result; } -bh_matrix4f_t *bh_matrix4f_rotation_quat(bh_quat_t *rotation, - bh_matrix4f_t *result) +void bh_matrix4f_rotation_quat(bh_quat_t *rotation, + bh_matrix4f_t *result) { - return bh_quat_matrix(rotation, result); + bh_quat_matrix(rotation, result); } -bh_matrix4f_t *bh_matrix4f_ortho(float x_min, - float x_max, - float y_min, - float y_max, - float z_min, - float z_max, - bh_matrix4f_t *result) +void bh_matrix4f_ortho(float x_min, + float x_max, + float y_min, + float y_max, + float z_min, + float z_max, + bh_matrix4f_t *result) { float dx, dy, dz; @@ -1441,16 +1336,14 @@ bh_matrix4f_t *bh_matrix4f_ortho(float x_min, result->w.x = -(x_max + x_min) / dx; result->w.y = -(y_max + y_min) / dy; result->w.z = -(z_max + z_min) / dz; - - return result; } -bh_matrix4f_t *bh_matrix4f_perspective(float fov, - float aspect, - float z_min, - float z_max, - bh_matrix4f_t *result) +void bh_matrix4f_perspective(float fov, + float aspect, + float z_min, + float z_max, + bh_matrix4f_t *result) { float t, dz; @@ -1465,15 +1358,13 @@ bh_matrix4f_t *bh_matrix4f_perspective(float fov, result->z.w = -1.0f; result->w.z = -(2.0f * z_max * z_min) / dz; result->w.w = 0.0f; - - return result; } -bh_matrix4f_t *bh_matrix4f_lookat(const bh_point3f_t *camera, - const bh_point3f_t *at, - const bh_point3f_t *up, - bh_matrix4f_t *result) +void bh_matrix4f_lookat(const bh_point3f_t *camera, + const bh_point3f_t *at, + const bh_point3f_t *up, + bh_matrix4f_t *result) { bh_point3f_t cdir, cright, cup; @@ -1500,14 +1391,12 @@ bh_matrix4f_t *bh_matrix4f_lookat(const bh_point3f_t *camera, result->w.y = -bh_point3f_dot(&cup, camera); result->w.z = -bh_point3f_dot(&cdir, camera); result->w.w = 1.0f; - - return result; } -bh_point3f_t *bh_matrix4f_transform_point3f(const bh_matrix4f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_matrix4f_transform_point3f(const bh_matrix4f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { bh_point4f_t tmp, row; @@ -1519,13 +1408,12 @@ bh_point3f_t *bh_matrix4f_transform_point3f(const bh_matrix4f_t *a, result->x = tmp.x; result->y = tmp.y; result->z = tmp.z; - return result; } -bh_point4f_t *bh_matrix4f_transform_point4f(const bh_matrix4f_t *a, - const bh_point4f_t *b, - bh_point4f_t *result) +void bh_matrix4f_transform_point4f(const bh_matrix4f_t *a, + const bh_point4f_t *b, + bh_point4f_t *result) { bh_point4f_t tmp, row; @@ -1535,11 +1423,10 @@ bh_point4f_t *bh_matrix4f_transform_point4f(const bh_matrix4f_t *a, row.x = row.y = row.z = row.w = b->w; bh_point4f_madd(&a->w, &row, &tmp, &tmp); *result = tmp; - return result; } -bh_matrix3f_t *bh_matrix3f_identity(bh_matrix3f_t *result) +void bh_matrix3f_identity(bh_matrix3f_t *result) { static const bh_matrix3f_t ident = { {1.0f, 0.0f, 0.0f}, @@ -1548,37 +1435,32 @@ bh_matrix3f_t *bh_matrix3f_identity(bh_matrix3f_t *result) }; *result = ident; - return result; } -bh_matrix3f_t *bh_matrix3f_add(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result) +void bh_matrix3f_add(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result) { bh_point3f_add(&a->x, &b->x, &result->x); bh_point3f_add(&a->y, &b->y, &result->y); bh_point3f_add(&a->z, &b->z, &result->z); - - return result; } -bh_matrix3f_t *bh_matrix3f_sub(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result) +void bh_matrix3f_sub(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result) { bh_point3f_sub(&a->x, &b->x, &result->x); bh_point3f_sub(&a->y, &b->y, &result->y); bh_point3f_sub(&a->z, &b->z, &result->z); - - return result; } -bh_matrix3f_t *bh_matrix3f_mul(const bh_matrix3f_t *a, - const bh_matrix3f_t *b, - bh_matrix3f_t *result) +void bh_matrix3f_mul(const bh_matrix3f_t *a, + const bh_matrix3f_t *b, + bh_matrix3f_t *result) { bh_matrix3f_t tmp; bh_point3f_t row; @@ -1596,24 +1478,21 @@ bh_matrix3f_t *bh_matrix3f_mul(const bh_matrix3f_t *a, row.x = row.y = row.z = b->z.z; bh_point3f_madd(&a->z, &row, &tmp.z, &tmp.z); *result = tmp; - return result; } -bh_matrix3f_t *bh_matrix3f_scale(const bh_matrix3f_t *a, - float b, - bh_matrix3f_t *result) +void bh_matrix3f_scale(const bh_matrix3f_t *a, + float b, + bh_matrix3f_t *result) { bh_point3f_scale(&a->x, b, &result->x); bh_point3f_scale(&a->y, b, &result->y); bh_point3f_scale(&a->z, b, &result->z); - - return result; } -bh_matrix3f_t *bh_matrix3f_transpose(const bh_matrix3f_t *in, - bh_matrix3f_t *result) +void bh_matrix3f_transpose(const bh_matrix3f_t *in, + bh_matrix3f_t *result) { bh_matrix3f_t tmp; @@ -1630,7 +1509,6 @@ bh_matrix3f_t *bh_matrix3f_transpose(const bh_matrix3f_t *in, tmp.z.z = in->z.z; *result = tmp; - return result; } @@ -1657,8 +1535,8 @@ float bh_matrix3f_determinant(const bh_matrix3f_t *in) } -bh_matrix3f_t *bh_matrix3f_inverse(const bh_matrix3f_t *in, - bh_matrix3f_t *result) +int bh_matrix3f_inverse(const bh_matrix3f_t *in, + bh_matrix3f_t *result) { float a, b, c, det; bh_matrix3f_t tmp; @@ -1677,7 +1555,7 @@ bh_matrix3f_t *bh_matrix3f_inverse(const bh_matrix3f_t *in, det += in->z.x * tmp.x.z; if (det == 0.0f) - return bh_matrix3f_identity(result); + return BH_ERROR; a = in->y.x * in->z.z - in->z.x * in->y.z; b = in->x.x * in->z.z - in->z.x * in->x.z; @@ -1695,38 +1573,35 @@ bh_matrix3f_t *bh_matrix3f_inverse(const bh_matrix3f_t *in, tmp.z.y = -b; tmp.z.z = c; - return bh_matrix3f_scale(&tmp, 1.0f / det, result); + bh_matrix3f_scale(&tmp, 1.0f / det, result); + return BH_OK; } -bh_matrix3f_t *bh_matrix3f_scaling(float x, - float y, - bh_matrix3f_t *result) +void bh_matrix3f_scaling(float x, + float y, + bh_matrix3f_t *result) { bh_matrix3f_identity(result); result->x.x = x; result->y.y = y; - - return result; } -bh_matrix3f_t *bh_matrix3f_translation(float x, - float y, - bh_matrix3f_t *result) +void bh_matrix3f_translation(float x, + float y, + bh_matrix3f_t *result) { bh_matrix3f_identity(result); result->z.x = x; result->z.y = y; - - return result; } -bh_matrix3f_t *bh_matrix3f_rotation(float angle, - bh_matrix3f_t *result) +void bh_matrix3f_rotation(float angle, + bh_matrix3f_t *result) { float c, s; @@ -1738,14 +1613,12 @@ bh_matrix3f_t *bh_matrix3f_rotation(float angle, result->y.y = c; result->y.x = -s; result->x.y = s; - - return result; } -bh_point2f_t *bh_matrix3f_transform_point2f(const bh_matrix3f_t *a, - const bh_point2f_t *b, - bh_point2f_t *result) +void bh_matrix3f_transform_point2f(const bh_matrix3f_t *a, + const bh_point2f_t *b, + bh_point2f_t *result) { bh_point3f_t tmp, row; @@ -1755,14 +1628,12 @@ bh_point2f_t *bh_matrix3f_transform_point2f(const bh_matrix3f_t *a, result->x = tmp.x; result->y = tmp.y; - - return result; } -bh_point3f_t *bh_matrix3f_transform_point3f(const bh_matrix3f_t *a, - const bh_point3f_t *b, - bh_point3f_t *result) +void bh_matrix3f_transform_point3f(const bh_matrix3f_t *a, + const bh_point3f_t *b, + bh_point3f_t *result) { bh_point3f_t tmp, row; @@ -1773,6 +1644,4 @@ bh_point3f_t *bh_matrix3f_transform_point3f(const bh_matrix3f_t *a, result->x = tmp.x; result->y = tmp.y; result->z = tmp.z; - - return result; } diff --git a/test/reference/matrix3f.wxmx b/test/reference/matrix3f.wxmx new file mode 100644 index 0000000000000000000000000000000000000000..592ce6142da6322395cd433b453bfde3212e11a2 GIT binary patch literal 5986 zcmb_gO^@Wn8J<8u;6&mQaV|QFc4l|l{V_AkGTYM#2vN|oVj_WrSdB(yySlrA?P~1m zFMdI;D9kI3xW{_V{IBJ*mSrrKUt*1lw5KxWM=FG7(&e-FW?Ez{T<~-*(>Ym| z8B2L0m{v@rMx9Y+e1cWR)5sHRk?IwXSs-=7m!%H~NJdz=5D5!;$^yXvRmMXNw^ljn z=jpESjm&#%DK;YW0gPao;5nk-EOu$Z{>?m?d()(B*Y5U5 zd1#iAp50Q0JdSrPPw_3os|jqn0FH^AiNF(m^~sgg=aMlHVcx&WGI;XFrT1IM<#tM$3d@_}=h1Sdbaxee@i&fwQ!$GyAA0f(EErA+jiK$iJ`v^eA zxguIsY$Z1~GKK0KJj^v9gYR$|2vLE1$CZ^zjiuTzElX7!8Jzf@_fe|~U@yqjm&jzW zD#%P}ME5jM_dj{ws~E** zV&mmY5lXbOx*~JqQYOAyNt8bn!YxW8^<7jZm;mmHJmgCeop?mvu22q~%>Q&0+(W6%W7o*`ld2+<$uZ|*Js`{xfo{0F-c{eFeL#mdU$UCMvS z`>Wo_ANJ6_3jnSNfc}%-yHn4byw&eB#y&u|y=%%3Rj862lDHp$G%o7!Q~JxBGu?kp@?G$dbF0Vsl$pZkS-FCO=P-UY5XmT zS_~Q?jm9z+)4@abG0GX0rZY*|csQ60%t$$bUlwEAdNBSm4`9mW!8u$$)B}L@3CPQ7+v_59%OmV_{87+~;x=Ew zb>8pDlT{44-;tv*VsXhIj)rYbI0~fs5;c6u>dRx^hV7P444A@SjBfB{k8m}Ne{pt$Z(DVQQ(2Z^zd`%B#6Di%IrLkjh|Ib>4m!Tblxhmz%&=YPV{@ya)0#La zcnK;FDyE{(6qHT$VmgTfoDpLEfm-gadRY5<&+NHcF0XpLhu$eN96Uhd=&H99c|#KO zK%h2wZ+iSYH5#7~NrQMg(E-cUD#ZqNjkc8LS3RArP%V>0XY^k*out!?$snCh2Ij65 zjk=<-CBj^@{7%Q2HCpNz{sL9FurZ2^$_=MB0uixI2cApF*rm| zEKB#ph?dxd5rREoq?rcBi^E`a6pT$9M`?DM)LF2e{`)U~oeb90EDi+JUh42|FKv$c zzQwN6gcgE5p{1Dy+Q)}MJ9aob>R<(gy5#r?k~)B~soc%b*ikJbN3}a#ae-;J;wGF% zv?rj&Tm$Lbhe3Mbg3lov+p;bkXZEmz;to+)i7S;Z#pkxMLX8X4`sC8YwHEJ*?cIEX z?~?=Zwc1n(f`e-|uN}B_b=U|v)OK|^sOiwL-`-@7eH~Cku|J@gYruS`1~Z+$W1?&x z!EUWHU-LND7}?XXt<2aT4=wvez29%YwUJoL_T5n$ODO*F$g*Fgqh-H5)i%K{g?mO_ z%{B%PJeLlA2T6whS?lBAXJcWTj`o&>r`YcDGnWvL%GS)bPIP_0b4+L&YI<#R-IS0$ zdDzfZ*rFbTM+ftyFsL6K2J{?E&%^b5sOn*Qdj0GdFR`QhUsL17fc2?fTDMoV-&5Z$ rxxi)l+8J-H+w0ozAnw+EgE!vR8;R>@uRw5g^fLba1AqViCf)rXj}@X? literal 0 HcmV?d00001 diff --git a/test/reference/matrix4f.wxmx b/test/reference/matrix4f.wxmx new file mode 100644 index 0000000000000000000000000000000000000000..0195e4027d58e33ffedb4583bd77c0e0f91d1680 GIT binary patch literal 7100 zcmd5>%WmYx6;dK;VHeD3aCP6_czE zS?q_uz*}dLwRhR)3k>i56ZwODL40oUp=z=ucV`uidPLr;`#R^|%SYcld*v6uIijB* z{`Kw`|9Sr(AHRuX`n-luA`_vvOQFR^4>tYvCgFOK#5X%iuggFE?);ZWNA&TaG*cP2 z`Ff*0@AHMs*-XZQg(}rtra9wmy?M?zGT|&2c`jATWXkkHFdz0etWx)?Gw4Dm!|Eo9 z`vK2IWDMrDMVv#QGyf~OY-AaW<(JS=k@i%^{78kcOtyUXhnW@`3l}_{%XChjWyVsT z2&NSisWE4anV8^}@ig+pN~F5rF$<(l__B%t3CReG3z4vprz{W*P-Q&S2&>4+K2Nu0 zY~vTNa5KFJkSb$`Krmh#d_gm|Pz5Zw0VXT=vg5VX3uL@Nf^3mq7C@T*#I1y^p{dlQXswnW;0X!A!+K zP{ny!A#;RI+2pG#?o1>i2~Z%Er%6KOp2-NjfnC@F{KUCJ>}6>qXH-*!(1MZ%Q)zby z5y>Sy#2aN&8jc#?NoH&z=Q%k?NRVX$-9SudQWZJi&qP#&0`VY{*-VB~q~Vs}X{G3S zO_Nn+8L4#|D+G@A$yCA?S}*gf!2kd(iogekgIc8@A;{pIKj?7I+nfO~F(f%-qu!u&QyXZ_*0%}j>AzzB<#G~R3tEp_7w``Aks;_BkVG!~F z4FSY}kfN?J4W-aI22J4XnL?}qq4Ed)yVsWQ-Y7o)2-he2{2JF5i|uJB09+FQ{inV6rk*$XZNJYL`vBASZYb9rvGLd+jr}1u^!rn@_pW5itJF`FEU9^u z+TMpMEE208D6Weh`%0+G?)y`O0|Jsm1~>hT{(Mkamq%gY<$WtZ%nBXr3PwCjkEpjlk&= z+C}>%k8sW8kAqgOFY^Kk@_t926fxv}M~)_o#T9=v8n!Lrwj#}!mw!K8S*~=1K#xRwxaC^|4Ib2z* zNYXkx4mx4Ulv)*m&2Sac$L3VSW_x2(9D}m>QSXDg9WczwzDV?9I*9|^h{XB>wcK9! zVCh#q3}unwjt2b^UH7&k-;u;T5NJByn;!pOjZUcYgLpd80n1d8;=*`?ahK-TJ)ITk z!bzet`Y)PJ(&@!ykWME9b5@B)UD3EJy0k=4Hx}>Ao>{Av+2LLy+f&!9BQ%Gn^R6d5 z&8}J7=|R!j&P%fc9kdAy_9ZYd1djh-33Pz(;MB&li?o9pTcHBqvFl+1pL7{_m~}*J zd%BlE8iD(ANP7*9XNS=^as=l{!H&0XS6kLa+yTvgL_TcR=A#P4A$r>7Whc>YxDE{m z3=Xim^T^SPbkW+IN$fRDo*%}fBeuguU0^ykR?~lf{rAaWMN@n~Mr{*q2evhPs?|l- zCDOK5?XpD=Ij~F1sM_B5q1)bX=UzH>5s$l)y@|(OL;S^I#9z8TNp@DrP|%JA61fGg$;yH2{M$Br}|A_qWYJCFM*H8+%dlWKMw zTAv(7>xBcNogr4k=Gb>>%eoMq*~^ug{X}DXTi38FK9{p|+e{U}PQG2!JDv}Uc_)DT zX>A?>_NKPcF!Wv?NUzl&RXTQES0a1JR3f`ex-dBu99TO%*}J-CZKwBx@93$A%{pd@ z!;?Lu98f(-X($e%GsI&Go@JgkRAOqD0qs5;y|f<9_I^&ZA8R1cGTV^!@pS&R;R^c(tiQPkDs+rzgJc6QoV;Gu69T)SxPop>SDZMTu{ zxGdnU*H7(iJ3@{4of5UZJ8as^!-utZWA8e5z`1MP2I+oa)9G-Bg1fH5`vUWNV9>lR z7|dt4?C0$0{x87r%F+6%zYc3_wZ8$oQ@Oxl^@SF`4{PhS-)`RN ceS`1PtaqI^&t8S#=;#&v`zQYX_bod65$gT#AOHXW literal 0 HcmV?d00001 diff --git a/test/reference/point2f.wxmx b/test/reference/point2f.wxmx new file mode 100644 index 0000000000000000000000000000000000000000..76cb0240d44be9a268b829c5993d9d4cd45084a6 GIT binary patch literal 8202 zcmd5>-Hszi6&?s6=pb>!1$Pui5YMdL?Vg>P>`pu#Wdjk>W|c(>Qp9L8s_rhkE7RT8 z+g-NDc>-<$X|Hp~BXGa>yaaE+10eC8s&3oe_JTc1B)sFbed^Tt|EaF?{OMcY`{@zA z{xN_2$A3L}^}C^R|I4!<939cy!KR5S zf#&Kv?Kqz$vSJgN3KpqcbD39+v&G#rekU`|Dp6HZ0N}chdmH`UM7#kCjv54m^6bz;+d88rMtRnh6 zUs~CSy)&0$Axam95v&xvg7%AK$qHU-rY59@H3FHe(lSk1CZ~z6zgGf$AZ5m(TqW{K z7~P>_EOTBi899ns9t@V(3D?H7241LAlexjiatW6#785>8wIi$i9S!qkMG2>f_>z%? zW*gC27Bb>#x@1*`4>HIKmvoexEz~THolL+8hU?0{a5GRS0upWvQ(9csUr3!m;{*z_ zqEsOdWh(XZ*!o5|p`04SR3tGu1Ex}SD8U&k@LFnXXkJE%oD0|aEquo0gv~{1;*4Uj zR4FW|(#l526rz(h)x4Iw6q(3E1PJMAln|9;G=ksYUC@I0$>$2P+t7y2h^82#h1Lxw z($*FtCtLH7-$)ZnI9~akV1^cSo)UA21XwAM4dm%ks#yi|mm;1;0`fqT$wWp{;1`za7M=`e zHkiqc@IMs+TEtRA$S-FV5{u8ROF-=%L^>r9uUKz`NzXCv zp!8Ai*n;5c6#dir|t*{!(m`>*CA`W z)c*)s+UATKdcRT8EZc|&lIy(3zEUc~*U_j)$dQ17sI6Wh%3=Z7Smwn{8%>UDm}uKfW!eeqr!9s+(oU>99@MEEXNPTlkFTAPA* z^7`wKW_d)-!^Q>Dys%}{eCvurz&;L=0a6G)$|fm=9TUR|x&rwD9rwd$&H!(;S7&K|HXm78h?lX5oPUdd)D zt(hT_0 zk0^0&Ls5vYdP`BYASn+;N@zjq*r|c-*!03|^2)BzVN2++CE^=}4z17+?;-U04xuj&6*_7O z9qlJ{WQ9JvhtMd$JH$pkK2&gc`W&(wm!Gc$nZS*347rdJq;@9x3V%f~o(FvF&D*Y? z2jLEwHZTu+Xg7kwZo0gxX7f$2@57OoG>cAA5-KhV?vn&_dimuyV9h z0eW6EdS2|()1>dWsOY4&=*qBYLR;((w#J5|sGV&QTw4pJzP6V&Ps=6kACLln8>DxM zy0QF?a`s@T4PV+gYn;885u4CiQTet+{l78Nu7IawNUJCjV86O#Fik~xcaKwG=P5wEQg0DEdgm`0<=2WylE zyBdXma96%D=g_tS2DGON7MGNGIJ$=t{%Fe^I9gcXK~C7p3OYgWse?f^D){$M;bLdY z_RkLQ**ErB-*$$D?WswPY;-yNptqR^+eg05)x*OK&n0cW0N7J0!ZaGKPk}gBylVod zeHgeg&p2&92DB$9i)(nT4{w`#+uE^eK=a_%^xlpX_K~P9hK21ZM~!R*Ss&hB(y`lS zy@&4|ruH$b&D6s7WLhH|rt6c`zWu>=@aDW%pC~&L+mmAZblL2)5%u5q9a0eJc-wwV zx-p*=i#AeRn9WxIey1Q!gSq(kZ7oDz8dhFZx zEw1s!H`ON(eh$2`R|aioSlFK4sF6vHvwL;Qo$kOz<>5y#6GS^y**CC^DmJpt?$I&V zHy0mZWXIEJmg33{chn=-|H41T4ONC)MU2ceZj|lVfUW0JELNh*f6WV3y@$(xn$F=y zIiZ=`f@WK(Qn&RaClo}LZj$BeS`br>W(pJ!lPdVhltIw-=1u$L*Ir;4ZBvb0z1kZs`f9_3pmztYp3K&zQ__OirFZ{XPIkM{nWZ-|+eD=k)78(&20` literal 0 HcmV?d00001 diff --git a/test/reference/point3f.wxmx b/test/reference/point3f.wxmx new file mode 100644 index 0000000000000000000000000000000000000000..a8c30c8b0d3b35a53eccdb054ce9a0a94246cdcc GIT binary patch literal 8290 zcmd5>PmkkB6>nHTV34?Q;6@QN+N3A3^QV*aG-|N1gtj$mmF-GWGyapY zE9uT2ICF&q=M@s-BXFM&!3W^ViEqH~RoO}Gc-go$E79HQ#IIhx_kQnRJ;%?VzVn@* zoYBu;H%~tQ&-;J*&5!Y!Uf;(nl95o`l~CedIrqK0`-rP$6h1F)`jPzYFD|}!c1AA? zo90OhHe1~*%ld37Gd7o@V15!SF5`@Gc6a}b-^+-zOk|l%VkTpzmV()kf6wymR(^%O z*pp)QJ_>st&qSaFW`#stV?Ss17jm_ur7V=MuqO$Wm88rL5+9ODmd$=OS0ZKplE(`f zFG#aYSP7GQh^Ah?vh~<_QK@rQBCA zYn_pN9&e3pq~6*{aVJt6ju9*sJOlc><(92@s#r277{&?YvP{V^WRYAfRsJ~>&;u(Y z4se->Goi5qVjyFlZW#rN866CsS4*z6Yc+k9q>9`PJw}VSWr3LUb*Lob5{bJPfxii||Gc+3^xasn}hz4g)I^aDvvl^Dn{-7RrDn*N#aIFKgdP zwFKfN0J2q@c-)hrRNIb;jj%kq(2mK-VhRRamE@^}VC=|ytBs?1>M!L+*w(KRGbZP3 zBT}7bl!Iv!!h=benG9LLbV8GDa=TLziO55O5Kaw3WR^yRxFNcb1@}|T6WDH28<>$z z0Zj8u7<8uXJw!n^?xDC55+gX+#hqwc7BDYJIZOgA6{rS^bSjf|2KT2TSo;F@z>@h~ z`clOHmfTZ;Xj!`=%hNJQ?&2_k;V7RpiP%!9Rd(e#aKLiy+3=xLZ0Q9+873=u4YWwt zs%?D?M}=8JX;ow^nQDZR_ait2N z&r6e6h@`hR$xLBH{HYG07T=hVK-#;=bSfa8 zvDSf-mZif%<&`kF1v#aP;zmS#*s}9KLQ%L8E}Ii40Bm?D1NQr8pRhJrNgtL1u}EoA zqA~ias}qi-BSMNVOw;qjgc=@Spmlb2*o%@Ry90P1B}5`M8Oe~K5iD5icb|Q9sTULY z?EO!lwTg^lb8%;7E8$DDvRy@H+N4yxUQ3ie1i~x|BlTTWCNcrJCo-R}M9{G)dHuXA z>*6)#QFQe?>RM=o+(SXYWAIQyRig_kLFH&~!q1jY#KIwz{s@2hZ0Y^;4pm*7N&$X=C&wD+_*azsg`=(sPhz*DKU}*Qj z(CfLHcb~H6l=_;KrES)%koRHYucL!}AiKsb_C=CJ_}GVu2sL_>FTxOn7VV|a)M3Rn zk}eRS&1AeP#Xd#K zbAzf1;g$zD9XWf<%g1lO&t$V!xudjhS8x7_xl zWYA&I>V@u%2Ifp%w^X`D2bw8;8HiA#ZyDOn%u((vb_X*jc4zZAa=SB!-as4H&_0XW7rHcx73)22B55)S_~9KOaedH@cz>l&-kziX&y z=uOc)N-lthlI3D&+#Csj@KNxovhp;bh~jVM&NeQeIh%5lY+SE~rZmmL9@>p`GMlch zbD2h7k#rmPUw{0w-m!7ZJD2X8f6N?|MxlD+J}xmHFc>?^HS{PM=P1W@D0S6;gD~g0 zKX-1$33jBeu`dq7L}%fVz`d_s@Z{~4kBr?tO)f< zPAn2w)^W3BctRXfZNDqtbcr-m+Jxir+kkR3|w%^iirv|YsCkWZPY=CQNs=4_9 zfvUIb4w;Ku>Nux1jap?gB6O$DMut~M?QP8qbwgm|o9tWjtxY*>hIV4ya%K(fK@&r5 zi11zV(HyuBa+APm`zm>9XiWf`%p5*sbm-fY>66i9G930VE+^CR)O3{cG}O1B^v9RO z!DKic4aSq{eBSV2}_Jcia>~Xp^3_ouAH6H)*ffg%zvW(GJogR^7p^E{NC9aJuGaR zCn?x$^`I>4)1}PVT!w=ANvybxGsfBd!!!OMBhE6BWipAGjG0;rW<&l1%ePzkJM6`t z6sr$Wc;WF(1X^HLNW^>W=gj_Gu6DGPh4K~lB!RM$l-WVzLo&&-*{|nHq|9IPcp>8j zX_hIAc_f%hn25DFElk@4t&GQkB{m{fYaTLBs)(<08vsZK*tirC^LflX!QiTt`wC{Q zGm_8at+9>NTN^3vMQXz_f~A6IK!3m7vK3DiOXdW_IDuT2DH(<=l8dFvUuOb(U}eMs zE)#JkG&{}u?MVP@t8L;HqF{$BY?R%+~ zK)eJ%wn`I^doq-2+cB{bmM0h5F&SA*!GNohJe3fP9eHoHaWqf;rQ8VH`YmF{uFbOl0Aq$vJXtGUicPb(gc}Nh#sX>U$(ufc@L>IE)eu{Yl+f8Z%GqNdw zX`Ts#&a}OUD9FY=6gNU*1P8mg6HUtk<^?H-NuZ?y)j*L>WwOrT{!|2OU%(z%GM`Id zirC+hduk9ZYgc4>S_a8|940Uv<&!26TPn56t{n#sSgt)AK6HvL7XeU)$qHTrEz-4W zTOYwuVU|!@71>H=+{+lEGvr~W;4;__li?vMaI0NtDa4dS+qq_$?36ei+p<2YRRQ#Q zY4Qq@^wuVsDU66eH3U}5>75S=v8f#|FSuPTnv52KR50@8IzwUcjR^^)y^Bnz0^%8K zm6WtB9S$n5guyMyDOD6VBI3iAo&OPv!i{j*oHzks!$TRc&z^nE+GHiYSPH}i5*O&`-k(NKmP3Oj2=J4 z*;0zi>^+Kqp7%GczTIn~dm9JbkOMBJt@m8Zn*IFZf-&|1y6wIx7cpXkf!!b2JuqBc zxSDsLvgVZfij<{o)~t~Co5Wv7rFJ9x@=ls^=Yq-^#T1G(!Wc4ROhNnbk5&=@!>iKx&((jB@cSR%Jf$Ks%{_= z+q}!XE>j(LeZ$)Q3)MO2Pt>_rvo<^A#hKF1H~2}`=C;@AI7H;Twdbc3f#rkQI zW!D%WFik}`_F~n>*q6$O_O0x)mtFP>;tpklb|AXbsS6K9yim()mc33Dg3AvWVj42F zBb~Q1QQDvmO4-vp5JZbmROYcqja&$5iK~CWqq7w1<~U|myPUJVLx6f2dK;LbzF9U5 zIArf1Fz+(hG3^5#!zmgHjsw$KBDHj9p@&f}R39X(?Mky>m4KsRczdfY&p zG|;A}qVp^0{NvF1Il93k(BXJ!up8$^0~H5I0~IIAsVFJYhCpgkZn!ghjx<8RDTSy) z^JJnNz~9Q9ZCpNcHq}(yxLyNIX_|vQv>QojHeKK3GL5_JIV^LY?P6-MJP=>4CbF{ZR@P9m)p+_x{2m zlzYrLs1lUw8(4wAlISK=OUqxYW(STcMbl(j5$>a$SR~I*$~R@||BaKHQl5sXN*5!- zag9uKnx-(?mCEtwP*Ybn9k_Zn^?MC%tZz=N6HX$U4XZ#wI1(sv8ldBof$qCi?3&}V z4Dah*J;fauh^y`Z;YfE7r*X&RWOu}F)2Wn)v+NlRB~6pc@DYKh0l$h>&-_QCHM|Dz z^bvR)^LNmc)Was?r6Haa+Jl;=tC%CJezijZ;Uz7&~eaZYB>4A*X;gS7OyL z8`_b;b7l>Fa{6FhuH?hSEw3I9+vU~6vAeu_@&JB^tIeuYKseGP#A)2IpTuK#ViK}C zIguKg5%*UznsU6NVXkRE702$-90xT``U<$JN|TP%Wq1v&{VaRvSI}%LJY|!lI)z@@Qmv<8fZ)$4IReV*gp&h9< zXEth2Kl{yiR*duc1w-9tb0tu{dMGxU3VOswQ(TYOXzK1OHlEV1=!&U&>3^q5M@GQ# zngEoIP>#!RYxqT|wWi{Uj!14sJ%e+54X5tvyjR$KZb<{{5=hRa{*CtK^ zeeBF>cuj;KGj=qMSxqDN*YZKgo%s~58e&5`GR8Tx!TXrO19u`C@)tK58mM2M5T^uL zn_Ww7Lpud`p4`*Zr;ga|*`wZY)SFKGmsgW%uRm-Ge9sz+Lw zUiGJtFdbZt$J49BK?RM&?)4_U{$xD3x*Cmp1Cu@{yR23i+GWR9M$W8LWxAhCj=%E! z@*1x;#YtlVO^@gY`21IY-0SQ<{dMS`6Wx2--SaJOT)EGme(T%p?CoC(!A-c*Pw@qj y`mXwSLiSrmc!|41`8P!B`|9`m_WS;dZ +#include + + +#define ACCEPTABLE_DELTA 0.0001f + + +static int check_point4f(void) +{ + bh_point4f_t a, b, c, r; + float value; + + a.x = 1.0f; a.y = 2.0f; a.z = 3.0f; a.w = 4.0f; + b.x = 5.0f; b.y = 6.0f; b.z = 7.0f; b.w = 8.0f; + c.x = 1.5f; c.y = 2.5f; c.z = 3.5f; c.w = 4.5f; + + bh_point4f_add(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 8.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 12.0000f, ACCEPTABLE_DELTA); + + bh_point4f_sub(&a, &b, &r); + BH_VERIFY_DELTA(r.x, -4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, -4.0000f, ACCEPTABLE_DELTA); + + bh_point4f_mul(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 12.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 21.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 32.0000f, ACCEPTABLE_DELTA); + + bh_point4f_scale(&a, 10.0f, &r); + BH_VERIFY_DELTA(r.x, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 20.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 30.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 40.0000f, ACCEPTABLE_DELTA); + + bh_point4f_madd(&a, &b, &c, &r); + BH_VERIFY_DELTA(r.x, 6.5000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 14.5000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 24.5000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 36.5000f, ACCEPTABLE_DELTA); + + bh_point4f_negate(&a, &r); + BH_VERIFY_DELTA(r.x, -1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, -4.0000f, ACCEPTABLE_DELTA); + + value = bh_point4f_dot(&a, &b); + BH_VERIFY_DELTA(value, 70.0000f, ACCEPTABLE_DELTA); + + value = bh_point4f_dot3(&a, &b); + BH_VERIFY_DELTA(value, 38.0000f, ACCEPTABLE_DELTA); + + bh_point4f_cross(&a, &b, &r); + BH_VERIFY_DELTA(r.x, -4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 8.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -4.0000f, ACCEPTABLE_DELTA); + + value = bh_point4f_length(&a); + BH_VERIFY_DELTA(value, sqrt(30.0f), ACCEPTABLE_DELTA); + + bh_point4f_normal(&a, &r); + BH_VERIFY_DELTA(r.x, 1.0f / sqrt(30.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f / sqrt(30.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0f / sqrt(30.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 4.0f / sqrt(30.0f), ACCEPTABLE_DELTA); + + bh_point4f_min(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 4.0000f, ACCEPTABLE_DELTA); + + bh_point4f_max(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 8.0000f, ACCEPTABLE_DELTA); + + bh_point4f_lerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 4.0000f, ACCEPTABLE_DELTA); + + bh_point4f_lerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 6.0000f, ACCEPTABLE_DELTA); + + bh_point4f_lerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 8.0000f, ACCEPTABLE_DELTA); + + bh_point4f_slerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 4.0000f, ACCEPTABLE_DELTA); + + bh_point4f_slerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 0.50350f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 0.67135f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 0.83918f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 1.00702f, ACCEPTABLE_DELTA); + + bh_point4f_slerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w, 8.0000f, ACCEPTABLE_DELTA); + + return 0; +} + + +static int check_point3f(void) +{ + bh_point3f_t a, b, c, r; + float value; + + a.x = 1.0f; a.y = 2.0f; a.z = 3.0f; + b.x = 5.0f; b.y = 6.0f; b.z = 7.0f; + c.x = 1.5f; c.y = 2.5f; c.z = 3.5f; + + bh_point3f_add(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 6.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 8.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 10.0f, ACCEPTABLE_DELTA); + + bh_point3f_sub(&a, &b, &r); + BH_VERIFY_DELTA(r.x, -4.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -4.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -4.0f, ACCEPTABLE_DELTA); + + bh_point3f_mul(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 12.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 21.0f, ACCEPTABLE_DELTA); + + bh_point3f_scale(&a, 10.0f, &r); + BH_VERIFY_DELTA(r.x, 10.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 20.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 30.0f, ACCEPTABLE_DELTA); + + bh_point3f_madd(&a, &b, &c, &r); + BH_VERIFY_DELTA(r.x, 6.5f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 14.5f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 24.5f, ACCEPTABLE_DELTA); + + bh_point3f_negate(&a, &r); + BH_VERIFY_DELTA(r.x, -1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -2.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -3.0f, ACCEPTABLE_DELTA); + + value = bh_point3f_dot(&a, &b); + BH_VERIFY_DELTA(value, 38.0f, ACCEPTABLE_DELTA); + + bh_point3f_cross(&a, &b, &r); + BH_VERIFY_DELTA(r.x, -4.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 8.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, -4.0f, ACCEPTABLE_DELTA); + + value = bh_point3f_length(&a); + BH_VERIFY_DELTA(value, sqrt(14.0f), ACCEPTABLE_DELTA); + + bh_point3f_normal(&a, &r); + BH_VERIFY_DELTA(r.x, 1.0f / sqrt(14.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f / sqrt(14.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0f / sqrt(14.0f), ACCEPTABLE_DELTA); + + bh_point3f_min(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0f, ACCEPTABLE_DELTA); + + bh_point3f_max(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0f, ACCEPTABLE_DELTA); + + bh_point3f_lerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0f, ACCEPTABLE_DELTA); + + bh_point3f_lerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 3.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 4.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 5.0f, ACCEPTABLE_DELTA); + + bh_point3f_lerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0f, ACCEPTABLE_DELTA); + + bh_point3f_slerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 3.0f, ACCEPTABLE_DELTA); + + bh_point3f_slerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 0.67937f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 0.90582f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 1.13228f, ACCEPTABLE_DELTA); + + bh_point3f_slerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z, 7.0f, ACCEPTABLE_DELTA); + + return 0; +} + + +static int check_point2f(void) +{ + bh_point2f_t a, b, c, r; + float value; + + a.x = 1.0f; a.y = 2.0f; + b.x = 5.0f; b.y = 6.0f; + c.x = 1.5f; c.y = 2.5f; + + bh_point2f_add(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 6.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 8.0f, ACCEPTABLE_DELTA); + + bh_point2f_sub(&a, &b, &r); + BH_VERIFY_DELTA(r.x, -4.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -4.0f, ACCEPTABLE_DELTA); + + bh_point2f_mul(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 12.0f, ACCEPTABLE_DELTA); + + bh_point2f_scale(&a, 10.0f, &r); + BH_VERIFY_DELTA(r.x, 10.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 20.0f, ACCEPTABLE_DELTA); + + bh_point2f_madd(&a, &b, &c, &r); + BH_VERIFY_DELTA(r.x, 6.5f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 14.5f, ACCEPTABLE_DELTA); + + bh_point2f_negate(&a, &r); + BH_VERIFY_DELTA(r.x, -1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, -2.0f, ACCEPTABLE_DELTA); + + value = bh_point2f_dot(&a, &b); + BH_VERIFY_DELTA(value, 17.0f, ACCEPTABLE_DELTA); + + value = bh_point2f_cross(&a, &b); + BH_VERIFY_DELTA(value, -4.0f, ACCEPTABLE_DELTA); + + value = bh_point2f_length(&a); + BH_VERIFY_DELTA(value, sqrt(5.0f), ACCEPTABLE_DELTA); + + bh_point2f_normal(&a, &r); + BH_VERIFY_DELTA(r.x, 1.0f / sqrt(5.0f), ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f / sqrt(5.0f), ACCEPTABLE_DELTA); + + bh_point2f_min(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + + bh_point2f_max(&a, &b, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + + bh_point2f_lerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + + bh_point2f_lerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 3.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 4.0f, ACCEPTABLE_DELTA); + + bh_point2f_lerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + + bh_point2f_slerp(&a, &b, 0.0f, &r); + BH_VERIFY_DELTA(r.x, 1.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 2.0f, ACCEPTABLE_DELTA); + + bh_point2f_slerp(&a, &b, 0.5f, &r); + BH_VERIFY_DELTA(r.x, 1.00000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 1.33333f, ACCEPTABLE_DELTA); + + bh_point2f_slerp(&a, &b, 1.0f, &r); + BH_VERIFY_DELTA(r.x, 5.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y, 6.0f, ACCEPTABLE_DELTA); + + return 0; +} + + +static int check_point4i(void) +{ + bh_point4i_t a, b, c, r; + + a.x = 1; a.y = 2; a.z = 3; a.w = 4; + b.x = 5; b.y = 6; b.z = 7; b.w = 8; + c.x = 4; c.y = 3; c.z = 2; c.w = 1; + + bh_point4i_add(&a, &b, &r); + BH_VERIFY(r.x == 6); + BH_VERIFY(r.y == 8); + BH_VERIFY(r.z == 10); + BH_VERIFY(r.w == 12); + + bh_point4i_sub(&a, &b, &r); + BH_VERIFY(r.x == -4); + BH_VERIFY(r.y == -4); + BH_VERIFY(r.z == -4); + BH_VERIFY(r.w == -4); + + bh_point4i_mul(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 12); + BH_VERIFY(r.z == 21); + BH_VERIFY(r.w == 32); + + bh_point4i_scale(&a, 10, &r); + BH_VERIFY(r.x == 10); + BH_VERIFY(r.y == 20); + BH_VERIFY(r.z == 30); + BH_VERIFY(r.w == 40); + + bh_point4i_madd(&a, &b, &c, &r); + BH_VERIFY(r.x == 9); + BH_VERIFY(r.y == 15); + BH_VERIFY(r.z == 23); + BH_VERIFY(r.w == 33); + + bh_point4i_negate(&a, &r); + BH_VERIFY(r.x == -1); + BH_VERIFY(r.y == -2); + BH_VERIFY(r.z == -3); + BH_VERIFY(r.w == -4); + + bh_point4i_min(&a, &b, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + BH_VERIFY(r.z == 3); + BH_VERIFY(r.w == 4); + + bh_point4i_max(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + BH_VERIFY(r.z == 7); + BH_VERIFY(r.w == 8); + + bh_point4i_lerp(&a, &b, 0.0f, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + BH_VERIFY(r.z == 3); + BH_VERIFY(r.w == 4); + + bh_point4i_lerp(&a, &b, 0.5f, &r); + BH_VERIFY(r.x == 3); + BH_VERIFY(r.y == 4); + BH_VERIFY(r.z == 5); + BH_VERIFY(r.w == 6); + + bh_point4i_lerp(&a, &b, 1.0f, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + BH_VERIFY(r.z == 7); + BH_VERIFY(r.w == 8); + + return 0; +} + + +static int check_point3i(void) +{ + bh_point3i_t a, b, c, r; + + a.x = 1; a.y = 2; a.z = 3; + b.x = 5; b.y = 6; b.z = 7; + c.x = 4; c.y = 3; c.z = 2; + + bh_point3i_add(&a, &b, &r); + BH_VERIFY(r.x == 6); + BH_VERIFY(r.y == 8); + BH_VERIFY(r.z == 10); + + bh_point3i_sub(&a, &b, &r); + BH_VERIFY(r.x == -4); + BH_VERIFY(r.y == -4); + BH_VERIFY(r.z == -4); + + bh_point3i_mul(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 12); + BH_VERIFY(r.z == 21); + + bh_point3i_scale(&a, 10, &r); + BH_VERIFY(r.x == 10); + BH_VERIFY(r.y == 20); + BH_VERIFY(r.z == 30); + + bh_point3i_madd(&a, &b, &c, &r); + BH_VERIFY(r.x == 9); + BH_VERIFY(r.y == 15); + BH_VERIFY(r.z == 23); + + bh_point3i_negate(&a, &r); + BH_VERIFY(r.x == -1); + BH_VERIFY(r.y == -2); + BH_VERIFY(r.z == -3); + + bh_point3i_min(&a, &b, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + BH_VERIFY(r.z == 3); + + bh_point3i_max(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + BH_VERIFY(r.z == 7); + + bh_point3i_lerp(&a, &b, 0.0f, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + BH_VERIFY(r.z == 3); + + bh_point3i_lerp(&a, &b, 0.5f, &r); + BH_VERIFY(r.x == 3); + BH_VERIFY(r.y == 4); + BH_VERIFY(r.z == 5); + + bh_point3i_lerp(&a, &b, 1.0f, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + BH_VERIFY(r.z == 7); + + return 0; +} + + +static int check_point2i(void) +{ + bh_point2i_t a, b, c, r; + + a.x = 1; a.y = 2; + b.x = 5; b.y = 6; + c.x = 4; c.y = 3; + + bh_point2i_add(&a, &b, &r); + BH_VERIFY(r.x == 6); + BH_VERIFY(r.y == 8); + + bh_point2i_sub(&a, &b, &r); + BH_VERIFY(r.x == -4); + BH_VERIFY(r.y == -4); + + bh_point2i_mul(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 12); + + bh_point2i_scale(&a, 10, &r); + BH_VERIFY(r.x == 10); + BH_VERIFY(r.y == 20); + + bh_point2i_madd(&a, &b, &c, &r); + BH_VERIFY(r.x == 9); + BH_VERIFY(r.y == 15); + + bh_point2i_negate(&a, &r); + BH_VERIFY(r.x == -1); + BH_VERIFY(r.y == -2); + + bh_point2i_min(&a, &b, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + + bh_point2i_max(&a, &b, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + + bh_point2i_lerp(&a, &b, 0.0f, &r); + BH_VERIFY(r.x == 1); + BH_VERIFY(r.y == 2); + + bh_point2i_lerp(&a, &b, 0.5f, &r); + BH_VERIFY(r.x == 3); + BH_VERIFY(r.y == 4); + + bh_point2i_lerp(&a, &b, 1.0f, &r); + BH_VERIFY(r.x == 5); + BH_VERIFY(r.y == 6); + + return 0; +} + + +static int check_quat(void) +{ + return 0; +} + + +static int check_matrix4f(void) +{ + bh_matrix4f_t a, b, r; + float value; + + a.x.x = 5.0f; a.y.x = 1.0f; a.z.x = 2.0f; a.w.x = 7.0f; + a.x.y = 3.0f; a.y.y = 0.0f; a.z.y = 0.0f; a.w.y = 2.0f; + a.x.z = 1.0f; a.y.z = 3.0f; a.z.z = 4.0f; a.w.z = 5.0f; + a.x.w = 2.0f; a.y.w = 0.0f; a.z.w = 0.0f; a.w.w = 3.0f; + + b.x.x = 5.0f; b.y.x = 1.0f; b.z.x = 2.0f; b.w.x = 7.0f; + b.x.y = 3.0f; b.y.y = 1.0f; b.z.y = 0.0f; b.w.y = 2.0f; + b.x.z = 4.0f; b.y.z = 2.0f; b.z.z = 4.0f; b.w.z = 5.0f; + b.x.w = 6.0f; b.y.w = 2.0f; b.z.w = 0.0f; b.w.w = 4.0f; + + bh_matrix4f_identity(&r); + BH_VERIFY(r.x.x == 1.0f); + BH_VERIFY(r.x.y == 0.0f); + BH_VERIFY(r.x.z == 0.0f); + BH_VERIFY(r.x.w == 0.0f); + + BH_VERIFY(r.y.x == 0.0f); + BH_VERIFY(r.y.y == 1.0f); + BH_VERIFY(r.y.z == 0.0f); + BH_VERIFY(r.y.w == 0.0f); + + BH_VERIFY(r.z.x == 0.0f); + BH_VERIFY(r.z.y == 0.0f); + BH_VERIFY(r.z.z == 1.0f); + BH_VERIFY(r.z.w == 0.0f); + + BH_VERIFY(r.w.x == 0.0f); + BH_VERIFY(r.w.y == 0.0f); + BH_VERIFY(r.w.z == 0.0f); + BH_VERIFY(r.w.w == 1.0f); + + bh_matrix4f_add(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 10.0f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, 8.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, 2.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 8.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, 14.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, 7.0000f, ACCEPTABLE_DELTA); + + bh_matrix4f_sub(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, -3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, -4.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, -1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, -2.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, -1.0000f, ACCEPTABLE_DELTA); + + bh_matrix4f_mul(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 78.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 27.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 60.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, 28.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 24.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 7.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 22.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, 8.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 18.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 18.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 4.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, 75.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 29.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, 53.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, 26.0000f, ACCEPTABLE_DELTA); + + bh_matrix4f_scale(&a, 10, &r); + BH_VERIFY_DELTA(r.x.x, 50.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 30.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, 20.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 30.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 20.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 40.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, 70.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 20.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, 50.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, 30.0000f, ACCEPTABLE_DELTA); + + bh_matrix4f_transpose(&a, &r); + BH_VERIFY_DELTA(r.x.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, 7.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, 2.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 5.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, 3.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix4f_trace(&a); + BH_VERIFY_DELTA(value, 12.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix4f_determinant(&a); + BH_VERIFY_DELTA(value, 10.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix4f_determinant(&b); + BH_VERIFY_DELTA(value, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY(bh_matrix4f_inverse(&a, &r) == BH_OK); + BH_VERIFY_DELTA(r.x.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, -2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 1.5000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 0.6000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 1.8000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, -1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.w, -0.4000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, -0.5000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.w, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.w.x, -0.4000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.y, 1.8000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.z, -2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.w.w, 0.6000f, ACCEPTABLE_DELTA); + + BH_VERIFY(bh_matrix4f_inverse(&b, &r) != BH_OK); + + return 0; +} + + +static int check_matrix3f(void) +{ + bh_matrix3f_t a, b, r; + float value; + + a.x.x = 5.0f; a.y.x = 1.0f; a.z.x = 2.0f; + a.x.y = 3.0f; a.y.y = 0.0f; a.z.y = 0.0f; + a.x.z = 1.0f; a.y.z = 3.0f; a.z.z = 4.0f; + + b.x.x = 2.0f; b.y.x = 1.0f; b.z.x = 2.0f; + b.x.y = 3.0f; b.y.y = 1.0f; b.z.y = 0.0f; + b.x.z = 4.0f; b.y.z = 2.0f; b.z.z = 4.0f; + + bh_matrix3f_identity(&r); + BH_VERIFY(r.x.x == 1.0f); + BH_VERIFY(r.x.y == 0.0f); + BH_VERIFY(r.x.z == 0.0f); + + BH_VERIFY(r.y.x == 0.0f); + BH_VERIFY(r.y.y == 1.0f); + BH_VERIFY(r.y.z == 0.0f); + + BH_VERIFY(r.z.x == 0.0f); + BH_VERIFY(r.z.y == 0.0f); + BH_VERIFY(r.z.z == 1.0f); + + bh_matrix3f_add(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 7.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 5.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 5.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 4.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 8.0000f, ACCEPTABLE_DELTA); + + bh_matrix3f_sub(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, -3.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, -1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 1.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 0.0000f, ACCEPTABLE_DELTA); + + bh_matrix3f_mul(&a, &b, &r); + BH_VERIFY_DELTA(r.x.x, 21.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 27.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 12.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 18.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 6.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 18.0000f, ACCEPTABLE_DELTA); + + bh_matrix3f_scale(&a, 10, &r); + BH_VERIFY_DELTA(r.x.x, 50.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 30.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 10.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 10.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 30.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 20.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 40.0000f, ACCEPTABLE_DELTA); + + bh_matrix3f_transpose(&a, &r); + BH_VERIFY_DELTA(r.x.x, 5.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 2.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, 4.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix3f_trace(&a); + BH_VERIFY_DELTA(value, 9.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix3f_determinant(&a); + BH_VERIFY_DELTA(value, 6.0000f, ACCEPTABLE_DELTA); + + value = bh_matrix3f_determinant(&b); + BH_VERIFY_DELTA(value, 0.0000f, ACCEPTABLE_DELTA); + + BH_VERIFY(bh_matrix3f_inverse(&a, &r) == BH_OK); + BH_VERIFY_DELTA(r.x.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.y, -2.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.x.z, 1.5000f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.y.x, 0.3333f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.y, 3.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.y.z, -2.3333f, ACCEPTABLE_DELTA); + + BH_VERIFY_DELTA(r.z.x, 0.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.y, 1.0000f, ACCEPTABLE_DELTA); + BH_VERIFY_DELTA(r.z.z, -0.5000f, ACCEPTABLE_DELTA); + + BH_VERIFY(bh_matrix3f_inverse(&b, &r) != BH_OK); + + return 0; +} + + +int main(int argc, char **argv) +{ + (void)argc; + (void)argv; + + bh_unit_add("point4f", check_point4f); + bh_unit_add("point3f", check_point3f); + bh_unit_add("point2f", check_point2f); + bh_unit_add("point4i", check_point4i); + bh_unit_add("point3i", check_point3i); + bh_unit_add("point2i", check_point2i); + bh_unit_add("quat", check_quat); + bh_unit_add("matrix4f", check_matrix4f); + bh_unit_add("matrix3f", check_matrix3f); + + return bh_unit_run(); +}