2 Commit-ok e456fd0936 ... 3da553b4e9

Szerző SHA1 Üzenet Dátum
  Kajetan Johannes Hammerle 3da553b4e9 Expect radians for angle functions 2 hónapja
  Kajetan Johannes Hammerle 68de7fc295 Use anonymous union/struct 2 hónapja

+ 3 - 3
include/core/Matrix.h

@@ -23,9 +23,9 @@ Matrix* translateMatrixX(Matrix* m, float tx);
 Matrix* translateMatrixY(Matrix* m, float ty);
 Matrix* translateMatrixZ(Matrix* m, float tz);
 Matrix* translateMatrixTo(Matrix* m, const Vector3* v);
-Matrix* rotateMatrixX(Matrix* m, float degrees);
-Matrix* rotateMatrixY(Matrix* m, float degrees);
-Matrix* rotateMatrixZ(Matrix* m, float degrees);
+Matrix* rotateMatrixX(Matrix* m, float radians);
+Matrix* rotateMatrixY(Matrix* m, float radians);
+Matrix* rotateMatrixZ(Matrix* m, float radians);
 Matrix* rotateMatrix(Matrix* m, const Quaternion* q);
 size_t toStringMatrix(const Matrix* m, char* buffer, size_t n);
 

+ 14 - 1
include/core/Vector.h

@@ -6,9 +6,22 @@
 #define VECTOR_OP2(name) name *r, const name *a
 #define VECTOR_OP3(name) VECTOR_OP2(name), const name* b
 
+#define VECTOR_ARG_Z2(type)
+#define VECTOR_ARG_Z3(type) type z;
+#define VECTOR_ARG_Z4(type) type z;
+
+#define VECTOR_ARG_W2(type)
+#define VECTOR_ARG_W3(type)
+#define VECTOR_ARG_W4(type) type w;
+
 #define DEFINE_VECTOR(N, name, sname, type)                                    \
-    typedef struct {                                                           \
+    typedef union {                                                            \
         type data[N];                                                          \
+        struct {                                                               \
+            type x;                                                            \
+            type y;                                                            \
+            VECTOR_ARG_Z##N(type) VECTOR_ARG_W##N(type)                        \
+        };                                                                     \
     } name;                                                                    \
     name* addSet##sname(VECTOR_OP2(name));                                     \
     name* add##sname(VECTOR_OP3(name));                                        \

+ 5 - 9
src/Box.c

@@ -21,12 +21,9 @@ void offsetBox(Box* box, const Vector3* offset) {
 }
 
 bool collidesWithBox(const Box* box, const Box* other) {
-    return box->max.data[0] > other->min.data[0] &&
-           box->min.data[0] < other->max.data[0] &&
-           box->max.data[1] > other->min.data[1] &&
-           box->min.data[1] < other->max.data[1] &&
-           box->max.data[2] > other->min.data[2] &&
-           box->min.data[2] < other->max.data[2];
+    return box->max.x > other->min.x && box->min.x < other->max.x &&
+           box->max.y > other->min.y && box->min.y < other->max.y &&
+           box->max.z > other->min.z && box->min.z < other->max.z;
 }
 
 void expandBox(Box* box, const Vector3* offset) {
@@ -58,7 +55,6 @@ void growBox(Box* box, const Vector3* growth) {
 
 size_t toStringBox(const Box* box, char* buffer, size_t n) {
     return toString(buffer, n, "Box([%.3f, %.3f, %.3f], [%.3f, %.3f, %.3f])",
-                    (double)box->min.data[0], (double)box->min.data[1],
-                    (double)box->min.data[2], (double)box->max.data[0],
-                    (double)box->max.data[1], (double)box->max.data[2]);
+                    (double)box->min.x, (double)box->min.y, (double)box->min.z,
+                    (double)box->max.x, (double)box->max.y, (double)box->max.z);
 }

+ 3 - 4
src/Frustum.c

@@ -3,10 +3,9 @@
 #include <math.h>
 
 #include "core/Generic.h"
-#include "core/Utility.h"
 
 void initFrustum(Frustum* f, float fieldOfView, float nearClip, float farClip) {
-    f->tan = tanf(degreeToRadian(fieldOfView) * 0.5f);
+    f->tan = tanf(fieldOfView * 0.5f);
     f->nearClip = nearClip;
     f->farClip = farClip;
 
@@ -19,7 +18,7 @@ void initFrustum(Frustum* f, float fieldOfView, float nearClip, float farClip) {
 }
 
 const Matrix* updateProjection(Frustum* f, const IntVector2* size) {
-    float x = (float)size->data[1] / (f->tan * (float)size->data[0]);
+    float x = (float)size->y / (f->tan * (float)size->x);
     f->projection.data[0] = V(x, 0.0f, 0.0f, 0.0f);
     return &f->projection;
 }
@@ -27,7 +26,7 @@ const Matrix* updateProjection(Frustum* f, const IntVector2* size) {
 void updateFrustumPlanes(Frustum* f, const Vector3* pos, const Vector3* right,
                          const Vector3* up, const Vector3* front,
                          const IntVector2* size) {
-    float aspect = (float)size->data[0] / (float)size->data[1];
+    float aspect = (float)size->x / (float)size->y;
 
     float hNearHeight = f->tan * f->nearClip;
     float hNearWidth = hNearHeight * aspect;

+ 29 - 30
src/Matrix.c

@@ -21,10 +21,10 @@ Matrix* transposeMatrix(Matrix* m) {
 Matrix* mulSetMatrix(Matrix* m, const Matrix* a) {
     for(int i = 0; i < 4; i++) {
         Vector4 d = VECTOR4;
-        addSet(&d, mul(a->data + 0, m->data[i].data[0]));
-        addSet(&d, mul(a->data + 1, m->data[i].data[1]));
-        addSet(&d, mul(a->data + 2, m->data[i].data[2]));
-        addSet(&d, mul(a->data + 3, m->data[i].data[3]));
+        addSet(&d, mul(a->data + 0, m->data[i].x));
+        addSet(&d, mul(a->data + 1, m->data[i].y));
+        addSet(&d, mul(a->data + 2, m->data[i].z));
+        addSet(&d, mul(a->data + 3, m->data[i].w));
         m->data[i] = d;
     }
     return m;
@@ -37,18 +37,18 @@ Matrix* mulMatrix(Matrix* m, const Matrix* a, const Matrix* b) {
 }
 
 Vector3* mulMatrixV3(Vector3* v, const Matrix* m, const Vector3* a) {
-    Vector4 v4 = V(a->data[0], a->data[1], a->data[2], 1.0f);
-    v->data[0] = dot(m->data + 0, &v4);
-    v->data[1] = dot(m->data + 1, &v4);
-    v->data[2] = dot(m->data + 2, &v4);
+    Vector4 v4 = V(a->x, a->y, a->z, 1.0f);
+    v->x = dot(m->data + 0, &v4);
+    v->y = dot(m->data + 1, &v4);
+    v->z = dot(m->data + 2, &v4);
     mulSet(v, 1.0f / dot(m->data + 3, &v4));
     return v;
 }
 
 Matrix* scaleMatrix(Matrix* m, const Vector3* v) {
-    mulSet(m->data + 0, v->data[0]);
-    mulSet(m->data + 1, v->data[1]);
-    mulSet(m->data + 2, v->data[2]);
+    mulSet(m->data + 0, v->x);
+    mulSet(m->data + 1, v->y);
+    mulSet(m->data + 2, v->z);
     return m;
 }
 
@@ -57,9 +57,9 @@ Matrix* scaleMatrixF(Matrix* m, float f) {
 }
 
 Matrix* translateMatrix(Matrix* m, const Vector3* v) {
-    translateMatrixX(m, v->data[0]);
-    translateMatrixY(m, v->data[1]);
-    translateMatrixZ(m, v->data[2]);
+    translateMatrixX(m, v->x);
+    translateMatrixY(m, v->y);
+    translateMatrixZ(m, v->z);
     return m;
 }
 
@@ -79,33 +79,32 @@ Matrix* translateMatrixZ(Matrix* m, float tz) {
 }
 
 Matrix* translateMatrixTo(Matrix* m, const Vector3* v) {
-    m->data[0] = V(1.0f, 0.0f, 0.0f, v->data[0]);
-    m->data[1] = V(0.0f, 1.0f, 0.0f, v->data[1]);
-    m->data[2] = V(0.0f, 0.0f, 1.0f, v->data[2]);
+    m->data[0] = V(1.0f, 0.0f, 0.0f, v->x);
+    m->data[1] = V(0.0f, 1.0f, 0.0f, v->y);
+    m->data[2] = V(0.0f, 0.0f, 1.0f, v->z);
     m->data[3] = V(0.0f, 0.0f, 0.0f, 1.0f);
     return m;
 }
 
-static Matrix* rotate(Matrix* m, float degrees, int a, int b) {
-    degrees = degreeToRadian(degrees);
-    float sin = sinf(degrees);
-    float cos = cosf(degrees);
+static Matrix* rotate(Matrix* m, float radians, int a, int b) {
+    float sin = sinf(radians);
+    float cos = cosf(radians);
     Vector4 v = m->data[a];
     sub(m->data + a, mul(&v, cos), mul(m->data + b, sin));
     add(m->data + b, mul(&v, sin), mul(m->data + b, cos));
     return m;
 }
 
-Matrix* rotateMatrixX(Matrix* m, float degrees) {
-    return rotate(m, degrees, 1, 2);
+Matrix* rotateMatrixX(Matrix* m, float radians) {
+    return rotate(m, radians, 1, 2);
 }
 
-Matrix* rotateMatrixY(Matrix* m, float degrees) {
-    return rotate(m, -degrees, 0, 2);
+Matrix* rotateMatrixY(Matrix* m, float radians) {
+    return rotate(m, -radians, 0, 2);
 }
 
-Matrix* rotateMatrixZ(Matrix* m, float degrees) {
-    return rotate(m, degrees, 0, 1);
+Matrix* rotateMatrixZ(Matrix* m, float radians) {
+    return rotate(m, radians, 0, 1);
 }
 
 Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
@@ -117,9 +116,9 @@ Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
     mul(&b, q, &V(M(m, 0, 1), M(m, 1, 1), M(m, 2, 1)));
     mul(&c, q, &V(M(m, 0, 2), M(m, 1, 2), M(m, 2, 2)));
     mul(&d, q, &V(M(m, 0, 3), M(m, 1, 3), M(m, 2, 3)));
-    m->data[0] = V(a.data[0], b.data[0], c.data[0], d.data[0]);
-    m->data[1] = V(a.data[1], b.data[1], c.data[1], d.data[1]);
-    m->data[2] = V(a.data[2], b.data[2], c.data[2], d.data[2]);
+    m->data[0] = V(a.x, b.x, c.x, d.x);
+    m->data[1] = V(a.y, b.y, c.y, d.y);
+    m->data[2] = V(a.z, b.z, c.z, d.z);
     return m;
 }
 

+ 2 - 2
src/Plane.c

@@ -15,6 +15,6 @@ float signedDistance(const Plane* p, const Vector3* v) {
 
 size_t toStringPlane(const Plane* p, char* buffer, size_t n) {
     return toString(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
-                    (double)p->abc.data[0], (double)p->abc.data[1],
-                    (double)p->abc.data[2], (double)p->d);
+                    (double)p->abc.x, (double)p->abc.y, (double)p->abc.z,
+                    (double)p->d);
 }

+ 3 - 4
src/Quaternion.c

@@ -2,12 +2,11 @@
 
 #include "core/Generic.h"
 #include "core/ToString.h"
-#include "core/Utility.h"
 
 Quaternion* axisAngleQ(Quaternion* q, const Vector3* axis, float angle) {
     q->xyz = *axis;
     normalize(&q->xyz);
-    angle = degreeToRadian(angle) * 0.5f;
+    angle *= 0.5f;
     q->w = cosf(angle);
     mulSet(&q->xyz, sinf(angle));
     return q;
@@ -47,6 +46,6 @@ Vector3* mulQV3(Vector3* r, const Quaternion* q, const Vector3* v) {
 
 size_t toStringQ(const Quaternion* q, char* buffer, size_t n) {
     return toString(buffer, n, "(%.3f i + %.3f j + %.3f k + %.3f)",
-                    (double)q->xyz.data[0], (double)q->xyz.data[1],
-                    (double)q->xyz.data[2], (double)q->w);
+                    (double)q->xyz.x, (double)q->xyz.y, (double)q->xyz.z,
+                    (double)q->w);
 }

+ 14 - 21
src/Vector.c

@@ -3,7 +3,6 @@
 #include <math.h>
 
 #include "core/ToString.h"
-#include "core/Utility.h"
 
 typedef Vector2 V2;
 typedef Vector3 V3;
@@ -13,24 +12,21 @@ typedef IntVector3 IV3;
 typedef IntVector4 IV4;
 
 V3* angles(V3* r, float lengthAngle, float widthAngle) {
-    lengthAngle = degreeToRadian(lengthAngle);
-    widthAngle = degreeToRadian(widthAngle);
-
     float sWidth = sinf(widthAngle);
     float cWidth = cosf(widthAngle);
     float sLength = sinf(lengthAngle);
     float cLength = cosf(lengthAngle);
 
-    r->data[0] = cWidth * cLength;
-    r->data[1] = sWidth;
-    r->data[2] = -sLength * cWidth;
+    r->x = cWidth * cLength;
+    r->y = sWidth;
+    r->z = -sLength * cWidth;
     return r;
 }
 
 V3* cross(V3* r, const V3* a, const V3* b) {
-    r->data[0] = a->data[1] * b->data[2] - a->data[2] * b->data[1];
-    r->data[1] = a->data[2] * b->data[0] - a->data[0] * b->data[2];
-    r->data[2] = a->data[0] * b->data[1] - a->data[1] * b->data[0];
+    r->x = a->y * b->z - a->z * b->y;
+    r->y = a->z * b->x - a->x * b->z;
+    r->z = a->x * b->y - a->y * b->x;
     return r;
 }
 
@@ -158,30 +154,27 @@ VECTOR_IMPL_FLOAT(V3, 3, IV3)
 VECTOR_IMPL_FLOAT(V4, 4, IV4)
 
 size_t toStringV2(const V2* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%.3f, %.3f]", (double)a->data[0],
-                    (double)a->data[1]);
+    return toString(buffer, n, "[%.3f, %.3f]", (double)a->x, (double)a->y);
 }
 
 size_t toStringV3(const V3* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%.3f, %.3f, %.3f]", (double)a->data[0],
-                    (double)a->data[1], (double)a->data[2]);
+    return toString(buffer, n, "[%.3f, %.3f, %.3f]", (double)a->x, (double)a->y,
+                    (double)a->z);
 }
 
 size_t toStringV4(const V4* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%.3f, %.3f, %.3f, %.3f]", (double)a->data[0],
-                    (double)a->data[1], (double)a->data[2], (double)a->data[3]);
+    return toString(buffer, n, "[%.3f, %.3f, %.3f, %.3f]", (double)a->x,
+                    (double)a->y, (double)a->z, (double)a->w);
 }
 
 size_t toStringIV2(const IV2* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%d, %d]", a->data[0], a->data[1]);
+    return toString(buffer, n, "[%d, %d]", a->x, a->y);
 }
 
 size_t toStringIV3(const IV3* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%d, %d, %d]", a->data[0], a->data[1],
-                    a->data[2]);
+    return toString(buffer, n, "[%d, %d, %d]", a->x, a->y, a->z);
 }
 
 size_t toStringIV4(const IV4* a, char* buffer, size_t n) {
-    return toString(buffer, n, "[%d, %d, %d, %d]", a->data[0], a->data[1],
-                    a->data[2], a->data[3]);
+    return toString(buffer, n, "[%d, %d, %d, %d]", a->x, a->y, a->z, a->w);
 }

+ 3 - 5
src/View.c

@@ -36,11 +36,9 @@ void updateDirectionsQ(View* v, const Quaternion* q) {
 
 Matrix* updateMatrix(View* v, const Vector3* pos) {
     Vector4* d = v->view.data;
-    d[0] = V(v->right.data[0], v->right.data[1], v->right.data[2],
-             -dot(&v->right, pos));
-    d[1] = V(v->up.data[0], v->up.data[1], v->up.data[2], -dot(&v->up, pos));
-    d[2] = V(v->back.data[0], v->back.data[1], v->back.data[2],
-             -dot(&v->back, pos));
+    d[0] = V(v->right.x, v->right.y, v->right.z, -dot(&v->right, pos));
+    d[1] = V(v->up.x, v->up.y, v->up.z, -dot(&v->up, pos));
+    d[2] = V(v->back.x, v->back.y, v->back.z, -dot(&v->back, pos));
     d[3] = V(0.0f, 0.0f, 0.0f, 1.0f);
     return &v->view;
 }

+ 7 - 5
test/modules/FrustumTests.c

@@ -1,10 +1,12 @@
 #include "../Tests.h"
 #include "core/Frustum.h"
-#include "core/ToString.h"
+#include "core/Utility.h"
+
+#define R60 degreeToRadian(60.0f)
 
 static void testToString() {
     Frustum f;
-    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    initFrustum(&f, R60, 0.1f, 1000.0f);
     TEST_FLOAT(0.577f, f.tan, 0.01f);
     TEST_FLOAT(0.100f, f.nearClip, 0.01f);
     TEST_FLOAT(1000.0f, f.farClip, 0.01f);
@@ -12,7 +14,7 @@ static void testToString() {
 
 static void testPointIsInside() {
     Frustum f;
-    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    initFrustum(&f, R60, 0.1f, 1000.0f);
     updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1),
                         &IV(200, 100));
 
@@ -28,7 +30,7 @@ static void testPointIsInside() {
 static void testSphereIsInside() {
     IntVector2 size = {{200, 100}};
     Frustum f;
-    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    initFrustum(&f, R60, 0.1f, 1000.0f);
     updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1),
                         &size);
 
@@ -51,7 +53,7 @@ static void testSphereIsInside() {
 
 static void testUpdateProjection() {
     Frustum f;
-    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    initFrustum(&f, R60, 0.1f, 1000.0f);
     const Matrix* m = updateProjection(&f, &IV(400, 300));
     char buffer[128];
     toStringMatrix(m, buffer, sizeof(buffer));

+ 10 - 10
test/modules/MatrixTests.c

@@ -1,6 +1,6 @@
 #include "../Tests.h"
 #include "core/Generic.h"
-#include "core/ToString.h"
+#include "core/Utility.h"
 
 static void testInit() {
     Matrix m = UNIT_MATRIX;
@@ -116,7 +116,7 @@ static void testMatrixCombination() {
 
 static void testRotateX() {
     Matrix m = UNIT_MATRIX;
-    rotateMatrixX(&m, 90.0f);
+    rotateMatrixX(&m, degreeToRadian(90.0f));
     TEST_V3(&V(1.0f, 0.0f, 0.0f), mul(&m, &V(1.0f, 0.0f, 0.0f)));
     TEST_V3(&V(0.0f, 0.0f, 1.0f), mul(&m, &V(0.0f, 1.0f, 0.0f)));
     TEST_V3(&V(0.0f, -1.0f, 0.0f), mul(&m, &V(0.0f, 0.0f, 1.0f)));
@@ -124,7 +124,7 @@ static void testRotateX() {
 
 static void testRotateY() {
     Matrix m = UNIT_MATRIX;
-    rotateMatrixY(&m, 90.0f);
+    rotateMatrixY(&m, degreeToRadian(90.0f));
     TEST_V3(&V(0.0f, 0.0f, -1.0f), mul(&m, &V(1.0f, 0.0f, 0.0f)));
     TEST_V3(&V(0.0f, 1.0f, 0.0f), mul(&m, &V(0.0f, 1.0f, 0.0f)));
     TEST_V3(&V(1.0f, 0.0f, 0.0f), mul(&m, &V(0.0f, 0.0f, 1.0f)));
@@ -132,7 +132,7 @@ static void testRotateY() {
 
 static void testRotateZ() {
     Matrix m = UNIT_MATRIX;
-    rotateMatrixZ(&m, 90.0f);
+    rotateMatrixZ(&m, degreeToRadian(90.0f));
     TEST_V3(&V(0.0f, 1.0f, 0.0f), mul(&m, &V(1.0f, 0.0f, 0.0f)));
     TEST_V3(&V(-1.0f, 0.0f, 0.0f), mul(&m, &V(0.0f, 1.0f, 0.0f)));
     TEST_V3(&V(0.0f, 0.0f, 1.0f), mul(&m, &V(0.0f, 0.0f, 1.0f)));
@@ -140,11 +140,11 @@ static void testRotateZ() {
 
 static void testQuaternionMatrix() {
     Quaternion q1 = UNIT_QUATERNION;
-    axisAngleQ(&q1, &V(1.0f, 0.0f, 0.0f), 48.0f);
+    axisAngleQ(&q1, &V(1.0f, 0.0f, 0.0f), degreeToRadian(48.0f));
     Quaternion q2 = UNIT_QUATERNION;
-    axisAngleQ(&q2, &V(0.0f, 1.0f, 0.0f), 52.0f);
+    axisAngleQ(&q2, &V(0.0f, 1.0f, 0.0f), degreeToRadian(52.0f));
     Quaternion q3 = UNIT_QUATERNION;
-    axisAngleQ(&q3, &V(0.0f, 0.0f, 1.0f), 60.0f);
+    axisAngleQ(&q3, &V(0.0f, 0.0f, 1.0f), degreeToRadian(60.0f));
 
     Matrix m = UNIT_MATRIX;
     translateMatrix(&m, &V(1.0f, 2.0f, 3.0f));
@@ -155,9 +155,9 @@ static void testQuaternionMatrix() {
 
     Matrix check = UNIT_MATRIX;
     translateMatrix(&check, &V(1.0f, 2.0f, 3.0f));
-    rotateMatrixX(&check, 48.0f);
-    rotateMatrixY(&check, 52.0f);
-    rotateMatrixZ(&check, 60.0f);
+    rotateMatrixX(&check, degreeToRadian(48.0f));
+    rotateMatrixY(&check, degreeToRadian(52.0f));
+    rotateMatrixZ(&check, degreeToRadian(60.0f));
     translateMatrix(&check, &V(1.0f, 2.0f, 3.0f));
 
     for(int i = 0; i < 16; i++) {

+ 13 - 12
test/modules/QuaternionTests.c

@@ -1,5 +1,6 @@
 #include "../Tests.h"
 #include "core/Generic.h"
+#include "core/Utility.h"
 
 #define CV3(a, b, c) (&(Vector3){{a, b, c}})
 #define CV30 CV3(0.0f, 0.0f, 0.0f)
@@ -13,7 +14,7 @@ static void testInit() {
 
 static void testAxisAndDegreesInit() {
     Quaternion q = UNIT_QUATERNION;
-    axisAngleQ(&q, CV3(1.0f, 2.0f, 3.0f), 142.0f);
+    axisAngleQ(&q, CV3(1.0f, 2.0f, 3.0f), degreeToRadian(142.0f));
     char buffer[128];
     toStringQ(&q, buffer, sizeof(buffer));
     TEST_STRING("(0.253 i + 0.505 j + 0.758 k + 0.326)", buffer);
@@ -21,9 +22,9 @@ static void testAxisAndDegreesInit() {
 
 static void testLerp() {
     Quaternion q1 = UNIT_QUATERNION;
-    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), 130.0f);
+    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(130.0f));
     Quaternion q2 = UNIT_QUATERNION;
-    axisAngleQ(&q2, CV3(1.0f, 2.0f, 4.0f), 260.0f);
+    axisAngleQ(&q2, CV3(1.0f, 2.0f, 4.0f), degreeToRadian(260.0f));
     Quaternion q3;
     lerpQ(&q3, &q1, 0.3f, &q2);
 
@@ -34,9 +35,9 @@ static void testLerp() {
 
 static void testMulSet() {
     Quaternion q1 = UNIT_QUATERNION;
-    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), 50.0f);
+    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(50.0f));
     Quaternion q2 = UNIT_QUATERNION;
-    axisAngleQ(&q2, CV3(2.0f, 5.0f, 7.0f), 60.0f);
+    axisAngleQ(&q2, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(60.0f));
     Quaternion q3 = UNIT_QUATERNION;
     mulSet(&q3, &q1);
 
@@ -49,7 +50,7 @@ static void testMulSet() {
     mulSet(&q3, &q2);
     toStringQ(&q3, bufferQ3, sizeof(bufferQ3));
 
-    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), 110.0f);
+    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(110.0f));
     toStringQ(&q1, bufferQ1, sizeof(bufferQ1));
 
     TEST_STRING(bufferQ1, bufferQ3);
@@ -57,9 +58,9 @@ static void testMulSet() {
 
 static void testMul() {
     Quaternion q1 = UNIT_QUATERNION;
-    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), 50.0f);
+    axisAngleQ(&q1, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(50.0f));
     Quaternion q2 = UNIT_QUATERNION;
-    axisAngleQ(&q2, CV3(2.0f, 5.0f, 7.0f), 60.0f);
+    axisAngleQ(&q2, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(60.0f));
     Quaternion q3 = UNIT_QUATERNION;
     mul(&q3, &q1, &q2);
 
@@ -67,7 +68,7 @@ static void testMul() {
     toStringQ(&q3, bufferQ3, sizeof(bufferQ3));
 
     Quaternion q = UNIT_QUATERNION;
-    axisAngleQ(&q, CV3(2.0f, 5.0f, 7.0f), 110.0f);
+    axisAngleQ(&q, CV3(2.0f, 5.0f, 7.0f), degreeToRadian(110.0f));
     char bufferQ[128];
     toStringQ(&q, bufferQ, sizeof(bufferQ));
 
@@ -76,11 +77,11 @@ static void testMul() {
 
 static void testMulVector() {
     Quaternion q1 = UNIT_QUATERNION;
-    axisAngleQ(&q1, CV3(1.0f, 0.0f, 0.0f), 90.0f);
+    axisAngleQ(&q1, CV3(1.0f, 0.0f, 0.0f), degreeToRadian(90.0f));
     Quaternion q2 = UNIT_QUATERNION;
-    axisAngleQ(&q2, CV3(0.0f, 1.0f, 0.0f), 90.0f);
+    axisAngleQ(&q2, CV3(0.0f, 1.0f, 0.0f), degreeToRadian(90.0f));
     Quaternion q3 = UNIT_QUATERNION;
-    axisAngleQ(&q3, CV3(0.0f, 0.0f, 1.0f), 90.0f);
+    axisAngleQ(&q3, CV3(0.0f, 0.0f, 1.0f), degreeToRadian(90.0f));
 
     Vector3 v1 = {{1.0f, 0.0f, 0.0f}};
     Vector3 v2 = {{0.0f, 1.0f, 0.0f}};

+ 38 - 29
test/modules/VectorTests.c

@@ -2,6 +2,7 @@
 
 #include "../Tests.h"
 #include "core/Generic.h"
+#include "core/Utility.h"
 
 static const float eps = 0.0001f;
 
@@ -35,38 +36,46 @@ static const float eps = 0.0001f;
 
 #define TESTS X(V2) X(V3) X(V4) X(IV2) X(IV3) X(IV4)
 
+#define R45 degreeToRadian(45.0f)
+#define R90 degreeToRadian(90.0f)
+#define R135 degreeToRadian(135.0f)
+#define R180 degreeToRadian(180.0f)
+#define R225 degreeToRadian(225.0f)
+#define R270 degreeToRadian(270.0f)
+#define R315 degreeToRadian(315.0f)
+
 static void testSetAngles() {
     float root = sqrtf(2) * 0.5f;
     TEST_V3(FV3(1, 0, 0), angles(CV30, 0, 0));
-    TEST_V3(FV3(root, 0, -root), angles(CV30, 45, 0));
-    TEST_V3(FV3(0, 0, -1), angles(CV30, 90, 0));
-    TEST_V3(FV3(-root, 0, -root), angles(CV30, 135, 0));
-    TEST_V3(FV3(-1, 0, 0), angles(CV30, 180, 0));
-    TEST_V3(FV3(-root, 0, root), angles(CV30, 225, 0));
-    TEST_V3(FV3(0, 0, 1), angles(CV30, 270, 0));
-    TEST_V3(FV3(root, 0, root), angles(CV30, 315, 0));
-
-    TEST_V3(FV3(0, 1, 0), angles(CV30, 0, 90));
-    TEST_V3(FV3(0, 1, 0), angles(CV30, 90, 90));
-    TEST_V3(FV3(0, 1, 0), angles(CV30, 180, 90));
-    TEST_V3(FV3(0, 1, 0), angles(CV30, 270, 90));
-
-    TEST_V3(FV3(0, -1, 0), angles(CV30, 0, -90));
-    TEST_V3(FV3(0, -1, 0), angles(CV30, 90, -90));
-    TEST_V3(FV3(0, -1, 0), angles(CV30, 180, -90));
-    TEST_V3(FV3(0, -1, 0), angles(CV30, 270, -90));
-
-    TEST_V3(FV3(root, root, 0), angles(CV30, 0, 45));
-    TEST_V3(FV3(0, root, -root), angles(CV30, 90, 45));
-    TEST_V3(FV3(-root, root, 0), angles(CV30, 180, 45));
-    TEST_V3(FV3(0, root, root), angles(CV30, 270, 45));
-
-    TEST_V3(FV3(root, -root, 0), angles(CV30, 0, -45));
-    TEST_V3(FV3(0, -root, -root), angles(CV30, 90, -45));
-    TEST_V3(FV3(-root, -root, 0), angles(CV30, 180, -45));
-    TEST_V3(FV3(0, -root, root), angles(CV30, 270, -45));
-
-    TEST_V3(FV3(0.5f, root, -0.5f), angles(CV30, 45, 45));
+    TEST_V3(FV3(root, 0, -root), angles(CV30, R45, 0));
+    TEST_V3(FV3(0, 0, -1), angles(CV30, R90, 0));
+    TEST_V3(FV3(-root, 0, -root), angles(CV30, R135, 0));
+    TEST_V3(FV3(-1, 0, 0), angles(CV30, R180, 0));
+    TEST_V3(FV3(-root, 0, root), angles(CV30, R225, 0));
+    TEST_V3(FV3(0, 0, 1), angles(CV30, R270, 0));
+    TEST_V3(FV3(root, 0, root), angles(CV30, R315, 0));
+
+    TEST_V3(FV3(0, 1, 0), angles(CV30, 0, R90));
+    TEST_V3(FV3(0, 1, 0), angles(CV30, R90, R90));
+    TEST_V3(FV3(0, 1, 0), angles(CV30, R180, R90));
+    TEST_V3(FV3(0, 1, 0), angles(CV30, R270, R90));
+
+    TEST_V3(FV3(0, -1, 0), angles(CV30, 0, -R90));
+    TEST_V3(FV3(0, -1, 0), angles(CV30, R90, -R90));
+    TEST_V3(FV3(0, -1, 0), angles(CV30, R180, -R90));
+    TEST_V3(FV3(0, -1, 0), angles(CV30, R270, -R90));
+
+    TEST_V3(FV3(root, root, 0), angles(CV30, 0, R45));
+    TEST_V3(FV3(0, root, -root), angles(CV30, R90, R45));
+    TEST_V3(FV3(-root, root, 0), angles(CV30, R180, R45));
+    TEST_V3(FV3(0, root, root), angles(CV30, R270, R45));
+
+    TEST_V3(FV3(root, -root, 0), angles(CV30, 0, -R45));
+    TEST_V3(FV3(0, -root, -root), angles(CV30, R90, -R45));
+    TEST_V3(FV3(-root, -root, 0), angles(CV30, R180, -R45));
+    TEST_V3(FV3(0, -root, root), angles(CV30, R270, -R45));
+
+    TEST_V3(FV3(0.5f, root, -0.5f), angles(CV30, R45, R45));
 }
 
 static void testCross() {