123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "tests/QuaternionTests.h"
- #include "math/Quaternion.h"
- #include "test/Test.h"
- const float eps = 0.0001f;
- template<int N, typename T>
- static void compareVectors(const Core::Vector<N, T>& wanted,
- const Core::Vector<N, T>& actual) {
- for(int i = 0; i < N; i++) {
- CORE_TEST_FLOAT(wanted[i], actual[i], eps);
- }
- }
- 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(Core::Vector3(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(Core::Vector3(2.0f, 5.0f, 7.0f), 130.0f);
- Core::Quaternion q2(Core::Vector3(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(Core::Vector3(2.0f, 5.0f, 7.0f), 50.0f);
- Core::Quaternion q2(Core::Vector3(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(Core::Vector3(2.0f, 5.0f, 7.0f), 110.0f),
- q3);
- }
- static void testMul() {
- Core::Quaternion q1(Core::Vector3(2.0f, 5.0f, 7.0f), 50.0f);
- Core::Quaternion q2(Core::Vector3(2.0f, 5.0f, 7.0f), 60.0f);
- Core::Quaternion q3 = q1 * q2;
- CORE_TEST_STRING(Core::Quaternion(Core::Vector3(2.0f, 5.0f, 7.0f), 110.0f),
- q3);
- }
- static void testMulVector() {
- Core::Quaternion q1(Core::Vector3(1.0f, 0.0f, 0.0f), 90.0f);
- Core::Quaternion q2(Core::Vector3(0.0f, 1.0f, 0.0f), 90.0f);
- Core::Quaternion q3(Core::Vector3(0.0f, 0.0f, 1.0f), 90.0f);
- Core::Vector3 v1(1.0f, 0.0f, 0.0f);
- Core::Vector3 v2(0.0f, 1.0f, 0.0f);
- Core::Vector3 v3(0.0f, 0.0f, 1.0f);
- compareVectors(Core::Vector3(1.0f, 0.0f, 0.0f), q1 * v1);
- compareVectors(Core::Vector3(0.0f, 0.0f, 1.0f), q1 * v2);
- compareVectors(Core::Vector3(0.0f, -1.0f, 0.0f), q1 * v3);
- compareVectors(Core::Vector3(0.0f, 0.0f, -1.0f), q2 * v1);
- compareVectors(Core::Vector3(0.0f, 1.0f, 0.0f), q2 * v2);
- compareVectors(Core::Vector3(1.0f, 0.0f, 0.0f), q2 * v3);
- compareVectors(Core::Vector3(0.0f, 1.0f, 0.0f), q3 * v1);
- compareVectors(Core::Vector3(-1.0f, 0.0f, 0.0f), q3 * v2);
- compareVectors(Core::Vector3(0.0f, 0.0f, 1.0f), q3 * v3);
- }
- void Core::QuaternionTests::test() {
- testInit();
- testAxisAndDegreesInit();
- testLerp();
- testMulSet();
- testMul();
- testMulVector();
- }
|