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.h36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/math/math.h b/src/math/math.h
index 90c7521..35219a3 100644
--- a/src/math/math.h
+++ b/src/math/math.h
@@ -11,14 +11,11 @@
#define PI 3.141592653f
#define RAD2DEG 57.295779523f /*180.f/PI*/
#define DEG2RAG 0.0174532925f /*PI/180.f*/
-#define EPSILON 0.000001f
+#define EPSILON 1e-6f
/* 用来打印的公共buffer */
-extern char printbuffer[2048];
+extern char printbuffer[1024];
-/*
-** 数学函数
-*/
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define clamp(v, l, h) ((v) > (l) ? ((v) < (h) ? (v) : (h)) : (l))
@@ -30,16 +27,10 @@ extern char printbuffer[2048];
float rsqrt(float n);
float lerp(float from, float to, float t);
-/*
-** 二维向量,用来做屏幕上的一些计算
-*/
typedef struct Vec2 {
float x, y;
} Vec2;
-/*
-** 三维向量,用来做三维空间的计算
-*/
typedef union Vec3 {
struct {
float x, y, z;
@@ -50,9 +41,6 @@ typedef union Vec3 {
Vec2 xy;
} Vec3;
-/*
-** 齐次坐标,列主项,平移变换和透视投影需要
-*/
typedef union Vec4 {
struct {
float x, y, z, w;
@@ -63,10 +51,7 @@ typedef union Vec4 {
Vec3 xyz;
} Vec4;
-/*
-** 用来可视化四元数,欧拉角默认使用角度存储,用euler_deg2rad()转弧度
-*/
-typedef union Euler {
+typedef union Euler { /*in degree, for visualize quaternion*/
struct {
float x, y, z;
};
@@ -75,17 +60,10 @@ typedef union Euler {
};
} Euler;
-/*
-** 四元数,用来做旋转变换。在进行变换复合以及插值的时候用,但最终还是需要通过quat_mat4转换成矩阵和其他变换矩阵
-** 一起对向量进行变换
-*/
typedef struct Quat {
float x, y, z, w;
} Quat;
-/*
-** 4x4矩阵,列主项,用来做平移和缩放变换。之所以用列主序存储,是为了快速读取矩阵的基向量
-*/
typedef union Mat4 {
float l[16];
float m[4][4];
@@ -149,7 +127,6 @@ typedef union Mat43 {
};
} Mat43;
-//#define MAT(m, r, c) (m->l[r + (c<<2)])
#define MAT(M, r, c) (M->m[c][r])
/************************************************************************/
/* Vec */
@@ -170,6 +147,13 @@ void vec2_print(Vec2* v);
extern Vec3 vec3forward; /*(0,0,1)*/
extern Vec3 vec3up; /*(0,1,0)*/
extern Vec3 vec3left;/*(1,0,0)*/
+extern Vec3 vec3zero; /*(0,0,0)*/
+extern Vec2 vec2zero; /*(0,0,0)*/
+extern Vec4 vec4zero; /*(0,0,0)*/
+
+#define zerovec3 {0, 0, 0}
+#define zerovec2 {0, 0}
+#define zerovec4 {0, 0, 0}
void vec3_tostring(Vec3* v, char buf[]);
void vec3_print(Vec3* v);