#include "../Tests.hpp" #include "core/math/Quaternion.hpp" using V3 = Core::Vector3; static void testInit() { Core::Quaternion q; CORE_TEST_STRING("(0.00 i + 0.00 j + 0.00 k + 1.00)", q); } static void testAxisAndDegreesInit() { Core::Quaternion q(V3(1.0f, 2.0f, 3.0f), 142.0f); CORE_TEST_STRING("(0.25 i + 0.51 j + 0.76 k + 0.33)", q); } static void testLerp() { Core::Quaternion q1(V3(2.0f, 5.0f, 7.0f), 130.0f); Core::Quaternion q2(V3(1.0f, 2.0f, 4.0f), 260.0f); Core::Quaternion q3 = q1.lerp(0.3f, q2); CORE_TEST_STRING("(0.22 i + 0.53 j + 0.81 k + 0.12)", q3); } static void testMulSet() { Core::Quaternion q1(V3(2.0f, 5.0f, 7.0f), 50.0f); Core::Quaternion q2(V3(2.0f, 5.0f, 7.0f), 60.0f); Core::Quaternion q3; q3 *= q1; CORE_TEST_STRING(q1, q3); q3 *= q2; CORE_TEST_STRING(Core::Quaternion(V3(2.0f, 5.0f, 7.0f), 110.0f), q3); } static void testMul() { Core::Quaternion q1(V3(2.0f, 5.0f, 7.0f), 50.0f); Core::Quaternion q2(V3(2.0f, 5.0f, 7.0f), 60.0f); Core::Quaternion q3 = q1 * q2; CORE_TEST_STRING(Core::Quaternion(V3(2.0f, 5.0f, 7.0f), 110.0f), q3); } static void testMulVector() { Core::Quaternion q1(V3(1.0f, 0.0f, 0.0f), 90.0f); Core::Quaternion q2(V3(0.0f, 1.0f, 0.0f), 90.0f); Core::Quaternion q3(V3(0.0f, 0.0f, 1.0f), 90.0f); V3 v1(1.0f, 0.0f, 0.0f); V3 v2(0.0f, 1.0f, 0.0f); V3 v3(0.0f, 0.0f, 1.0f); CORE_TEST_VECTOR(V3(1.0f, 0.0f, 0.0f), q1 * v1); CORE_TEST_VECTOR(V3(0.0f, 0.0f, 1.0f), q1 * v2); CORE_TEST_VECTOR(V3(0.0f, -1.0f, 0.0f), q1 * v3); CORE_TEST_VECTOR(V3(0.0f, 0.0f, -1.0f), q2 * v1); CORE_TEST_VECTOR(V3(0.0f, 1.0f, 0.0f), q2 * v2); CORE_TEST_VECTOR(V3(1.0f, 0.0f, 0.0f), q2 * v3); CORE_TEST_VECTOR(V3(0.0f, 1.0f, 0.0f), q3 * v1); CORE_TEST_VECTOR(V3(-1.0f, 0.0f, 0.0f), q3 * v2); CORE_TEST_VECTOR(V3(0.0f, 0.0f, 1.0f), q3 * v3); } void Core::testQuaternion() { testInit(); testAxisAndDegreesInit(); testLerp(); testMulSet(); testMul(); testMulVector(); }