From b4560c208f9e8188dca90275ede0ea395e849cc5 Mon Sep 17 00:00:00 2001 From: Kittycannon Date: Sat, 21 Mar 2026 10:08:24 -0600 Subject: [PATCH] integrated quaternions into code --- src/spider/runtime/math/Quat.cpp | 22 ++++++++++++++++ src/spider/runtime/math/Quat.hpp | 24 ++++++++++++++++++ src/spider/runtime/math/Quat_Multiply.cpp | 31 ----------------------- 3 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 src/spider/runtime/math/Quat.cpp create mode 100644 src/spider/runtime/math/Quat.hpp delete mode 100644 src/spider/runtime/math/Quat_Multiply.cpp diff --git a/src/spider/runtime/math/Quat.cpp b/src/spider/runtime/math/Quat.cpp new file mode 100644 index 0000000..ae40493 --- /dev/null +++ b/src/spider/runtime/math/Quat.cpp @@ -0,0 +1,22 @@ +#include "Quat.hpp" + +#include + +namespace spider { + + int quatMain() { + Quat q1 = { 1.0f, 0.0f, 0.0f, 0.0f }; + Quat q2 = { 0.5f, 0.5f, 0.5f, 0.5f }; + + Quat result = quat_multiply(q1, q2); // Returns the result! + + std::cout << "Result: (" + << result.w << ", " + << result.x << ", " + << result.y << ", " + << result.z << ")" << std::endl; + + return 0; + } + +} diff --git a/src/spider/runtime/math/Quat.hpp b/src/spider/runtime/math/Quat.hpp new file mode 100644 index 0000000..676778c --- /dev/null +++ b/src/spider/runtime/math/Quat.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +namespace spider { + + template + struct Quat { + T w, x, y, z; + }; + + /** + * Multiplies two quaternions together. + */ + template inline Quat quat_multiply(Quat A, Quat B) { + return { + B.w * A.w - B.x * A.x - B.y * A.y - B.z * A.z, + B.w * A.x + B.x * A.w - B.y * A.z + B.z * A.y, + B.w * A.y + B.x * A.z + B.y * A.w - B.z * A.x, + B.w * A.z - B.x * A.y + B.y * A.x + B.z * A.w + }; + } + +} diff --git a/src/spider/runtime/math/Quat_Multiply.cpp b/src/spider/runtime/math/Quat_Multiply.cpp deleted file mode 100644 index f41651c..0000000 --- a/src/spider/runtime/math/Quat_Multiply.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -template -struct Quaternion { - T w, x, y, z; -}; - -template -Quaternion quat_multiply(Quaternion A, Quaternion B) { - return { - B.w * A.w - B.x * A.x - B.y * A.y - B.z * A.z, - B.w * A.x + B.x * A.w - B.y * A.z + B.z * A.y, - B.w * A.y + B.x * A.z + B.y * A.w - B.z * A.x, - B.w * A.z - B.x * A.y + B.y * A.x + B.z * A.w - }; -} - -int main() { - Quaternion q1 = {1.0f, 0.0f, 0.0f, 0.0f}; - Quaternion q2 = {0.5f, 0.5f, 0.5f, 0.5f}; - - Quaternion result = quat_multiply(q1, q2); // Returns the result! - - std::cout << "Result: (" - << result.w << ", " - << result.x << ", " - << result.y << ", " - << result.z << ")" << std::endl; - - return 0; -} \ No newline at end of file