diff --git a/include/hpml/mat4.h b/include/hpml/mat4.h index 8baf936..1c7da8d 100644 --- a/include/hpml/mat4.h +++ b/include/hpml/mat4.h @@ -2,6 +2,7 @@ #include +#include // for vec4_t #include // for sin and cos #include // for variable arugments @@ -66,7 +67,7 @@ static HPML_FORCE_INLINE mat4_t mat4(float v00, float v01, float v02, float v03, float v20, float v21, float v22, float v23, float v30, float v31, float v32, float v33) { - return MAT4 + return MAT4 { v00, v01, v02, v03, v10, v11, v12, v13, @@ -90,13 +91,13 @@ HPML_API float* const* const __mat4_data(mat4_t* m); * NOTE: this function doesn't support rvalue src matrix; use mat4_move instead */ #define mat4_copy(dest, src) __mat4_copy(&(dest), &(src)) -static HPML_FORCE_INLINE void __mat4_copy(mat4_t* const dest, const mat4_t* const src) -{ +static HPML_FORCE_INLINE void __mat4_copy(mat4_t* const dest, const mat4_t* const src) +{ /* - TODO: This should be like this: + TODO: This should be like this: memcpy(dest, src, COMPILE_TIME( 16 * sizeof(float) )); */ - memcpy(dest, src, 16 * sizeof(float)); + memcpy(dest, src, 16 * sizeof(float)); } /* mat4_move: Performs a move operation of 4x4 matrices @@ -110,6 +111,24 @@ static HPML_FORCE_INLINE void __mat4_move(mat4_t* const dest, const mat4_t src) __mat4_copy(dest, &src); } +/* mat4_get_position: Retrieves the position componenets from the 4x4 matrix + * m: Input 4x4 matrix + * returns: vec4 position vector + */ +HPML_API vec4_t mat4_get_position(mat4_t m); + +/* mat4_get_rotation: Retrieves the euler angle rotation from the 4x4 matrix + * m: Input 4x4 matrix + * returns: vec4 euler angles rotation vector (prefer not to use the 4th component, as it might not have any meaning to a typical context) + */ +HPML_API vec4_t mat4_get_rotation(mat4_t m); + +/* mat4_get_scale: Retrieves the scale componenets from the 4x4 matrix + * m: Input 4x4 matrix + * returns: vec4 scale vector + */ +HPML_API vec4_t mat4_get_scale(mat4_t m); + /* mat4_determinant: Calculates the determinant value of a 4x4 matrix * m: Input 4x4 matrix * returns: determinant value @@ -168,7 +187,7 @@ static HPML_FORCE_INLINE mat4_t mat4_diagonal(float x, float y, float z, float w }; } -/* mat4_trace: Calculates trace of 2x2 matrix +/* mat4_trace: Calculates trace of 2x2 matrix * mat4_t m: Matrix of which the trace to be calculated * returns: float trace value */ @@ -247,7 +266,7 @@ HPML_API mat4_t mat4_transpose(mat4_t m); */ HPML_API mat4_t mat4_lerp(mat4_t m1, mat4_t m2, float lerp_value); -/* mat4_inverse: Inverts a 4x4 matrix +/* mat4_inverse: Inverts a 4x4 matrix * mat4_t m: Matrix to be inverted * returns: mat4_t inverted 4x4 matrix */ diff --git a/include/hpml/vec4.h b/include/hpml/vec4.h index ae2f6d2..c064bdf 100644 --- a/include/hpml/vec4.h +++ b/include/hpml/vec4.h @@ -6,6 +6,9 @@ #endif #include +#include +#include +#include /*DATA*/ /*vec4_t struct*/ @@ -21,6 +24,24 @@ typedef union float r, g, b, a; }; + struct + { + vec3_t xyz; + float _pad0; + }; + + struct + { + vec2_t xy; + vec2_t zw; + }; + + struct + { + float _pad1; + vec3_t yzw; + }; + float v[4]; } vec4_t; @@ -229,8 +250,8 @@ HPML_API vec4_t vec4_rotate(vec4_t v, float x, float y, float z); /*vec4_axis_rotate*/ /* - let axis = a; - let vector = v; + let axis = a; + let vector = v; let angle = r; k = v - (v.a)a diff --git a/source/mat4.c b/source/mat4.c index 22d0b28..87837c0 100644 --- a/source/mat4.c +++ b/source/mat4.c @@ -12,6 +12,23 @@ HPML_API float* const* const __mat4_data(mat4_t* m) return (float* const* const)m->data; } +HPML_API vec4_t mat4_get_position(mat4_t m) +{ + return vec4(m.m03, m.m13, m.m23, m.m33); +} + +HPML_API vec4_t mat4_get_rotation(mat4_t m) +{ + /* TODO */ + return vec4_zero(); +} + +HPML_API vec4_t mat4_get_scale(mat4_t m) +{ + /* TODO */ + return vec4_one(); +} + HPML_API float mat4_det(mat4_t m) { return m.m00 * (m.m11 * (m.m22 * m.m33 - m.m23 * m.m32) - m.m12 * (m.m21 * m.m33 - m.m23 * m.m31) + m.m13 * (m.m21 * m.m32 - m.m22 * m.m31)) - @@ -96,7 +113,7 @@ HPML_API mat4_t mat4_add(mat4_t m1, mat4_t m2) HPML_API mat4_t mat4_sub(mat4_t m1, mat4_t m2) { - return MAT4 + return MAT4 { m1.m00 - m2.m00, m1.m01 - m2.m01,