summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-02-22 23:33:06 +0800
committerchai <chaifix@163.com>2020-02-22 23:33:06 +0800
commitb656c9415a8e7e3b5b7d8bf1f3c8a5444f830c79 (patch)
treef4f0578d58e5f12b00d2753efef83aaedc03137e /src/math
parent9c89460e136ed6c6c43704d9a3a15105e0f006b0 (diff)
*misc
Diffstat (limited to 'src/math')
-rw-r--r--src/math/math.h4
-rw-r--r--src/math/quat.c8
-rw-r--r--src/math/vec3.c12
3 files changed, 24 insertions, 0 deletions
diff --git a/src/math/math.h b/src/math/math.h
index 1c65c01..03e156e 100644
--- a/src/math/math.h
+++ b/src/math/math.h
@@ -159,9 +159,11 @@ extern Vec4 vec4zero; /*(0,0,0)*/
void vec3_tostring(Vec3* v, char buf[]);
void vec3_print(Vec3* v);
+Vec3 vec3_make(float x, float y, float z);
float vec3_intersection(Vec3* v1, Vec3* v2); /*夹角*/
void vec3_projection(Vec3* v1, Vec3* v2, Vec3* out);/*v1在v2上的投影*/
void vec3_scale(Vec3* v, float k, Vec3* out);
+void vec3_scale3(Vec3* v, Vec3* scalar, Vec3* out);
void vec3_plus(Vec3* v1, Vec3* v2, Vec3* out);
void vec3_offset(Vec3* v, float offset, Vec3* out);
void vec3_normalize(Vec3* v, Vec3* out);
@@ -260,6 +262,8 @@ void mat43_applytovec3(Mat43* m, Vec3* v, Vec4* out);
void quat_tostring(Quat* q, char str[]);
void quat_print(Quat* q);
+Quat quat_make(float rx, float ry, float rz);
+
void euler_toquat(Euler* e, Quat* out);
void euler_deg2rad(Euler* in, Euler* out);
void euler_rad2deg(Euler* in, Euler* out);
diff --git a/src/math/quat.c b/src/math/quat.c
index e68e254..4dedbed 100644
--- a/src/math/quat.c
+++ b/src/math/quat.c
@@ -69,6 +69,13 @@ void euler_rad2deg(Euler* in, Euler* out) {
out->z = degree(in->z);
}
+Quat quat_make(float rx, float ry, float rz) {
+ Quat rot;
+ Euler euler = {rx, ry, rz};
+ quat_fromeuler(&euler, &rot);
+ return rot;
+}
+
void euler_toquat(Euler* euler, Quat* out) {
ssr_assert(euler && out);
quat_fromeuler(euler, out);
@@ -230,6 +237,7 @@ void quat_minus(Quat* q1, Quat* q2, Quat* out) {
quat_multiply(q1, &q2i, out);
}
+/*q1*q2*/
void quat_multiply(Quat* q1, Quat* q2, Quat* out) {
ssr_assert(q1 && q2 && out);
diff --git a/src/math/vec3.c b/src/math/vec3.c
index d2fb652..5d273d8 100644
--- a/src/math/vec3.c
+++ b/src/math/vec3.c
@@ -16,6 +16,11 @@ void vec3_cross(Vec3* v1, Vec3* v2, Vec3* out) {
out->z = v1->x*v2->y - v1->y*v2->x;
}
+Vec3 vec3_make(float x, float y, float z) {
+ Vec3 v = {x, y, z};
+ return v;
+}
+
void vec3_scale(Vec3* v, float k, Vec3* out) {
ssr_assert(v && out);
out->x = v->x * k;
@@ -23,6 +28,13 @@ void vec3_scale(Vec3* v, float k, Vec3* out) {
out->z = v->z * k;
}
+void 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) {
ssr_assert(v1 && v2 && out);
out->x = v1->x + v2->x;