Adding code x3

This commit is contained in:
2023-12-28 16:04:31 -06:00
parent 24cc2e79bc
commit 7e32c2ec62
10 changed files with 71 additions and 27 deletions

View File

@@ -47,4 +47,6 @@ EulerAngle EulerAngle::movementAngle() const
a.roll = (sin(Math::Radians(yaw)) * cos(Math::Radians(pitch)));
return a;
}
EulerAngle::EulerAngle() : pitch(0), yaw(0), roll(0) {}
}

View File

@@ -135,11 +135,34 @@ namespace LinearAlgebra {
y*reciprocalSinAngle,
z*reciprocalSinAngle
};
return {axis, angle};
return AxisAngle(axis, angle);
}
float Quaternion::AngleBetween(const Quaternion &target) const {
Quaternion delta = target / *this;
return delta.Normalize().Angle();
}
Quaternion Quaternion::operator/(const Quaternion &rhs) const {
return {
x*rhs.w - y*rhs.z + z*rhs.y - w*rhs.x,
x*rhs.z + y*rhs.w - z*rhs.x - w*rhs.y,
-x*rhs.y + y*rhs.x + z*rhs.w - w*rhs.z,
x*rhs.x + y*rhs.y + z*rhs.z + w*rhs.w
};
}
Matrix3x3 Quaternion::ToMatrix3x3() const {
return {
1 - 2 *(y*y) - 2*(z*z), 2*x*y - 2*z*w, 2*x*z + 2*y*w,
2*x*y + 2*z*w, 1-2*x*x - 2*z*z, 2*y*z - 2*x*w,
2*x*z - 2*y*w, 2*y*z + 2*x*w, 1-2*x*x - 2*y*y
};
}
Quaternion Quaternion::operator+(const Quaternion &rhs) const {
return {
x + rhs.x, y + rhs.y, z + rhs.z,w + rhs.w
};
}
}

View File

@@ -1,6 +1,9 @@
#include <J3ML/LinearAlgebra/Vector4.h>
#pragma region vector4
#include <J3ML/LinearAlgebra/Vector4.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <cmath>
#include <algorithm>
@@ -131,6 +134,11 @@ Vector4 Vector4::operator-(const Vector4& rhs) const
return this->Distance(rhs) <= margin;
}
Vector4::Vector4(const Vector3 &xyz, float w) : x(xyz.x), y(xyz.y), z(xyz.z), w(w)
{
}
}
#pragma endregion