2 Commits

Author SHA1 Message Date
99f423c4a3 upload 2026-03-20 20:38:12 -06:00
18923c4b20 deleted file 2026-03-20 20:28:57 -06:00

View File

@@ -1,31 +1,31 @@
#include <iostream> #include <iostream>
template<typename T> template<typename T>
struct Quaternion { struct Quaternion {
T w, x, y, z; T w, x, y, z;
}; };
template<typename T> template<typename T>
Quaternion<T> quat_multiply(Quaternion<T> A, Quaternion<T> B) { Quaternion<T> quat_multiply(Quaternion<T> A, Quaternion<T> B) {
return { return {
B.w * A.w - B.x * A.x - B.y * A.y - B.z * A.z, 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.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.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 B.w * A.z - B.x * A.y + B.y * A.x + B.z * A.w
}; };
} }
int main() { int main() {
Quaternion<double> q1 = {1.0f, 0.0f, 0.0f, 0.0f}; Quaternion<double> q1 = {1.0f, 0.0f, 0.0f, 0.0f};
Quaternion<double> q2 = {0.5f, 0.5f, 0.5f, 0.5f}; Quaternion<double> q2 = {0.5f, 0.5f, 0.5f, 0.5f};
Quaternion<double> result = quat_multiply(q1, q2); // Returns the result! Quaternion<double> result = quat_multiply(q1, q2); // Returns the result!
std::cout << "Result: (" std::cout << "Result: ("
<< result.w << ", " << result.w << ", "
<< result.x << ", " << result.x << ", "
<< result.y << ", " << result.y << ", "
<< result.z << ")" << std::endl; << result.z << ")" << std::endl;
return 0; return 0;
} }