summaryrefslogtreecommitdiff
path: root/src/math/vec3.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/vec3.c')
-rw-r--r--src/math/vec3.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/math/vec3.c b/src/math/vec3.c
index df56f3f..e9c12a4 100644
--- a/src/math/vec3.c
+++ b/src/math/vec3.c
@@ -9,58 +9,58 @@ Vec3 vec3up = {0, 1, 0};
Vec3 vec3left = {1, 0, 0};
Vec3 vec3zero = {0, 0, 0};
-void vec3_cross(Vec3* v1, Vec3* v2, Vec3* out) {
+void internal_vec3_cross(Vec3* v1, Vec3* v2, Vec3* out) {
ssr_assert(v1 && v2 && out);
out->x = v1->y*v2->z - v1->z*v2->y;
out->y = v1->z*v2->x - v1->x*v2->z;
out->z = v1->x*v2->y - v1->y*v2->x;
}
-Vec3 vec3_make(float x, float y, float z) {
+Vec3 internal_vec3_make(float x, float y, float z) {
Vec3 v = {x, y, z};
return v;
}
-void vec3_scale(Vec3* v, float k, Vec3* out) {
+void internal_vec3_scale(Vec3* v, float k, Vec3* out) {
ssr_assert(v && out);
out->x = v->x * k;
out->y = v->y * k;
out->z = v->z * k;
}
-void vec3_scale3(Vec3* v, Vec3* scalar, Vec3* out) {
+void internal_vec3_scale3(Vec3* v, Vec3* scalar, Vec3* out) {
ssr_assert(v && scalar && out);
out->x = v->x * scalar->x;
out->y = v->y * scalar->y;
out->z = v->z * scalar->z;
}
-void vec3_plus(Vec3* v1, Vec3* v2, Vec3* out) {
+void internal_vec3_plus(Vec3* v1, Vec3* v2, Vec3* out) {
ssr_assert(v1 && v2 && out);
out->x = v1->x + v2->x;
out->y = v1->y + v2->y;
out->z = v1->z + v2->z;
}
-void vec3_offset(Vec3* v, float offset, Vec3* out) {
+void internal_vec3_offset(Vec3* v, float offset, Vec3* out) {
ssr_assert(v && out);
out->x = v->x + offset;
out->y = v->y + offset;
out->z = v->z + offset;
}
-float vec3_magnitude(Vec3* v) {
+float internal_vec3_magnitude(Vec3* v) {
ssr_assert(v);
- float l2 = vec3_magnitude2(v);
+ float l2 = internal_vec3_magnitude2(v);
return sqrt(l2);
}
-float vec3_magnitude2(Vec3* v) {
+float internal_vec3_magnitude2(Vec3* v) {
ssr_assert(v);
return v->x*v->x + v->y*v->y + v->z*v->z;
}
-void vec3_lerp(Vec3* v1, Vec3* v2, float t, Vec3* out) {
+void internal_vec3_lerp(Vec3* v1, Vec3* v2, float t, Vec3* out) {
ssr_assert(v1 && v2 && out);
float t2 = 1 - t;
out->x = v1->x * t2 + v2->x * t;
@@ -68,49 +68,49 @@ void vec3_lerp(Vec3* v1, Vec3* v2, float t, Vec3* out) {
out->z = v1->z * t2 + v2->z * t;
}
-void vec3_slerp(Vec3* v1, Vec3* v2, float t, Vec3* out) {
+void internal_vec3_slerp(Vec3* v1, Vec3* v2, float t, Vec3* out) {
ssr_assert(v1 && v2 && out);
- float mag1 = vec3_magnitude(v1);
- float mag2 = vec3_magnitude(v2);
+ float mag1 = internal_vec3_magnitude(v1);
+ float mag2 = internal_vec3_magnitude(v2);
if (mag1 < EPSILON || mag2 < EPSILON) {
- vec3_lerp(v1, v2, t, out);
+ internal_vec3_lerp(v1, v2, t, out);
return;
}
float lerplen = lerp(mag1, mag2, t);
/*分为长度上的lerp和角度上的slerp*/
- float dot = vec3_dot(v1, v2) / (mag1 * mag2);
+ float dot = internal_vec3_dot(v1, v2) / (mag1 * mag2);
if (dot > 1.f - EPSILON) { /*几乎是同向*/
- vec3_lerp(v1, v2, t, out);
+ internal_vec3_lerp(v1, v2, t, out);
return;
} else if (dot < -1 + EPSILON) { /*几乎是反向*/
} else {
- Vec3 axis; vec3_cross(v1, v2, &axis); vec3_normalize(&axis, &axis);
- Vec3 v1n; vec3_normalize(v1, &v1n);
+ Vec3 axis; internal_vec3_cross(v1, v2, &axis); internal_vec3_normalize(&axis, &axis);
+ Vec3 v1n; internal_vec3_normalize(v1, &v1n);
float angle = acos(dot) * t;
- //Mat4 m; mat4_setaxisangle(&axis, angle, &m);
- //mat4_mulvec4(&m, &v1n, &v1n);
- Quat q; quat_fromaxisangle(&axis, angle, &q);
- quat_applytovec3(&q, &v1n, &v1n);
- vec3_scale(&v1n, lerplen, out);
+ //Mat4 m; internal_mat4_setaxisangle(&axis, angle, &m);
+ //internal_mat4_mulvec4(&m, &v1n, &v1n);
+ Quat q; internal_quat_fromaxisangle(&axis, angle, &q);
+ internal_quat_applytovec3(&q, &v1n, &v1n);
+ internal_vec3_scale(&v1n, lerplen, out);
}
}
-float vec3_dot(Vec3* v1, Vec3* v2) {
+float internal_vec3_dot(Vec3* v1, Vec3* v2) {
ssr_assert(v1 && v2);
return v1->x * v2->x + v1->y * v2->y + v1->z * v2->z;
}
-void vec3_multiply(Vec3* v1, Vec3* v2, Quat* out) {
+void internal_vec3_multiply(Vec3* v1, Vec3* v2, Quat* out) {
ssr_assert(v1 && v2 && out);
- vec3_cross(v1, v2, out);
- out->w = -vec3_dot(v1, v2);
+ internal_vec3_cross(v1, v2, out);
+ out->w = -internal_vec3_dot(v1, v2);
}
-void vec3_normalize(Vec3* v, Vec3* out) {
+void internal_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 = vec3_magnitude(v);
+ float mag = internal_vec3_magnitude(v);
if (compare(mag, 0)) {
return;
}
@@ -120,16 +120,16 @@ void vec3_normalize(Vec3* v, Vec3* out) {
out->z = v->z * mag;
}
-void vec3_tostring(Vec3* v, char buf[]) {
+void internal_vec3_tostring(Vec3* v, char buf[]) {
sprintf(buf, "%8.3f %8.3f %8.3f", v->x, v->y, v->z);
}
-void vec3_print(Vec3* v) {
- vec3_tostring(v, printbuffer);
+void internal_vec3_print(Vec3* v) {
+ internal_vec3_tostring(v, printbuffer);
printf("\n%s\n", printbuffer);
}
-void vec3_minus(Vec3* v1, Vec3* v2, Vec3* out) {
+void internal_vec3_minus(Vec3* v1, Vec3* v2, Vec3* out) {
ssr_assert(v1 && v2 && out);
out->x = v1->x - v2->x;
out->y = v1->y - v2->y;