summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/mat.c2
-rw-r--r--src/math/math.h4
-rw-r--r--src/math/quat.c2
-rw-r--r--src/math/vec3.c6
4 files changed, 10 insertions, 4 deletions
diff --git a/src/math/mat.c b/src/math/mat.c
index 592dd5e..c254c02 100644
--- a/src/math/mat.c
+++ b/src/math/mat.c
@@ -748,7 +748,7 @@ void mat4_toquat(Mat4* in, Quat* out) {
quat_normalize(out, out);
}
-void mat3_applytovec3(Mat3* m, Vec3* v, Vec3* out) {
+void mat3_multvec3(Mat3* m, Vec3* v, Vec3* out) {
ssr_assert(m && v && out);
out->x = m->e00 * v->x + m->e01 * v->y + m->e02 * v->z;
out->y = m->e10 * v->x + m->e11 * v->y + m->e12 * v->z;
diff --git a/src/math/math.h b/src/math/math.h
index 03e156e..a69dabe 100644
--- a/src/math/math.h
+++ b/src/math/math.h
@@ -11,7 +11,7 @@
#define PI 3.141592653f
#define RAD2DEG 57.295779523f /*180.f/PI*/
#define DEG2RAG 0.0174532925f /*PI/180.f*/
-#define EPSILON 1e-6f
+#define EPSILON 1e-4f
/* 用来打印的公共buffer */
extern char printbuffer[1024];
@@ -251,7 +251,7 @@ void mat4_toquat(Mat4* in, Quat* out); /*in是正交矩阵*/
#define ROWMAT(A, ...)\
Mat4 A={__VA_ARGS__};mat4_transpose(&A, &A);
-void mat3_applytovec3(Mat3* m, Vec3* v, Vec3* out);
+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);
diff --git a/src/math/quat.c b/src/math/quat.c
index 4dedbed..8f7274d 100644
--- a/src/math/quat.c
+++ b/src/math/quat.c
@@ -81,6 +81,7 @@ void euler_toquat(Euler* euler, Quat* out) {
quat_fromeuler(euler, out);
}
+/*这里精度不对*/
bool quat_isidentity(Quat* q) {
return compare(quat_magnitude(q), 1.f);
}
@@ -147,6 +148,7 @@ void quat_applytovec3(Quat* q, Vec3* v, Vec3* out) {
void quat_tomat4(Quat* q, Mat4* out) {
ssr_assert(q && out);
ssr_assert(quat_isidentity(q));
+
mat4_setidentity(out);
float x = q->x * 2.0F; /*从quat_applytovec3能得到矩阵形式*/
diff --git a/src/math/vec3.c b/src/math/vec3.c
index 5d273d8..df56f3f 100644
--- a/src/math/vec3.c
+++ b/src/math/vec3.c
@@ -110,7 +110,11 @@ void vec3_multiply(Vec3* v1, Vec3* v2, Quat* out) {
void vec3_normalize(Vec3* v, Vec3* out) {
ssr_assert(v && out);
//float mag = rsqrt(v->x * v->x + v->y * v->y + v->z * v->z);
- float mag = 1.f / vec3_magnitude(v);
+ float mag = vec3_magnitude(v);
+ if (compare(mag, 0)) {
+ return;
+ }
+ mag = 1.f / mag;
out->x = v->x * mag;
out->y = v->y * mag;
out->z = v->z * mag;