summaryrefslogtreecommitdiff
path: root/src/math/math.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/math.h')
-rw-r--r--src/math/math.h117
1 files changed, 12 insertions, 105 deletions
diff --git a/src/math/math.h b/src/math/math.h
index 8f59137..8fa748b 100644
--- a/src/math/math.h
+++ b/src/math/math.h
@@ -6,14 +6,13 @@
#include <math.h>
#include <limits.h>
-#include "../util/type.h"
+#include "structs.h"
#define PI 3.141592653f
#define RAD2DEG 57.295779523f /*180.f/PI*/
#define DEG2RAG 0.0174532925f /*PI/180.f*/
#define EPSILON 1e-4f
-/* 用来打印的公共buffer */
extern char printbuffer[1024];
#define min(a, b) ((a) < (b) ? (a) : (b))
@@ -28,113 +27,15 @@ extern char printbuffer[1024];
float rsqrt(float n);
float lerp(float from, float to, float t);
-typedef struct {
- float x, y;
-} Vec2;
-
-typedef union {
- struct {
- float x, y, z;
- };
- struct {
- float A, B, C; /*重心坐标*/
- };
- Vec2 xy;
-} Vec3;
-
-typedef union {
- struct {
- float x, y, z, w;
- };
- struct {
- float r, g, b, a;
- };
- Vec3 xyz;
-} Vec4;
-
-typedef union { /*in degree, for visualize quaternion*/
- struct {
- float x, y, z;
- };
- struct {
- float pitch, yaw, roll;
- };
-} Euler;
-
-typedef struct {
- float x, y, z, w;
-} Quat;
-
-typedef union {
- float l[16];
- float m[4][4];
- struct {
- float
- e00, e10, e20, e30, /*colum 0*/
- e01, e11, e21, e31,
- e02, e12, e22, e32,
- e03, e13, e23, e33;
- };
- struct {
- Vec4 x;/*colum 0*/
- Vec4 y;
- Vec4 z;
- Vec4 w;
- } axis; /*轴*/
- struct {
- Vec4 x;/*colum 0*/
- Vec4 y;
- Vec4 z;
- Vec4 w;
- } basis; /*基向量*/
- struct {
- Vec4 axisx;
- Vec4 axisy;
- Vec4 axisz;
- Vec4 pos;
- };
- Vec4 colums[4];
-} Mat4;
-
-typedef union {
- struct {
- float
- e00, e10, e20, /*colum 0*/
- e01, e11, e21,
- e02, e12, e22;
- };
-} Mat3;
-
-typedef union {
- struct {
- float
- e00, e10, /*colum 0*/
- e01, e11,
- e02, e12;
- };
-} Mat23;
-
-typedef union {
- struct {
- float
- e00, e10, e20, e30, /*colum 0*/
- e01, e11, e21, e31,
- e02, e12, e22, e32;
- };
- struct { /*三个齐次裁剪坐标*/
- Vec4 p1;
- Vec4 p2;
- Vec4 p3;
- };
-} Mat43;
-
#define MAT(M, r, c) (M->m[c][r])
+
/************************************************************************/
/* Vec */
/************************************************************************/
void internal_vec2_scale(Vec2* v, float k, Vec2* out);
void internal_vec2_plus(Vec2* v1, Vec2* v2, Vec2* out);
+void internal_vec2_minus(Vec2* v1, Vec2* v2, Vec2* out);
void internal_vec2_offset(Vec2* v, float offset, Vec2* out);
void internal_vec2_rotate(Vec2* v, float angle, Vec2* out);
@@ -192,6 +93,10 @@ void internal_vec4_scale(Vec4* v, float t, Vec4* out);
void internal_vec4_add(Vec4* v1, Vec4* v2, Vec4* out);
+void internal_vec4_minus(Vec4* v1, Vec4* v2, Vec4* out);
+
+void internal_vec4_plus(Vec4* v1, Vec4* v2, Vec4* out);
+
/************************************************************************/
/* Matrix */
@@ -251,9 +156,11 @@ void internal_mat4_toquat(Mat4* in, Quat* out); /*in是正交矩阵*/
#define ROWMAT(A, ...)\
Mat4 A={__VA_ARGS__};internal_mat4_transpose(&A, &A);
-void mat3_multvec3(Mat3* m, Vec3* v, Vec3* out);
-void mat23_applytovec3(Mat23* m, Vec3* v, Vec2* out);
-void mat43_applytovec3(Mat43* m, Vec3* v, Vec4* out);
+void internal_mat3_multvec3(Mat3* m, Vec3* v, Vec3* out);
+void internal_mat3_multmat3(Mat3* m1, Mat3* m2, Mat3* out);
+void internal_mat23_applytovec3(Mat23* m, Vec3* v, Vec2* out);
+void internal_mat43_applytovec3(Mat43* m, Vec3* v, Vec4* out);
+bool internal_mat3_isidentity(Mat3* m);
/************************************************************************/
/* Quat */