Adding code x3

This commit is contained in:
2023-12-27 21:42:38 -06:00
parent f90f1cf40b
commit 24cc2e79bc
8 changed files with 152 additions and 35 deletions

View File

@@ -2,9 +2,12 @@
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Vector4.h>
#include <J3ML/LinearAlgebra/AxisAngle.h>
namespace LinearAlgebra
{
class Quaternion
class Quaternion : public Vector4
{
public:
Quaternion();
@@ -12,15 +15,25 @@ namespace LinearAlgebra
explicit Quaternion(const Matrix3x3& rotationMtrx);
explicit Quaternion(const Matrix4x4& rotationMtrx);
// @note The input data is not normalized after construction, this has to be done manually.
Quaternion(float x, float y, float z, float w);
Quaternion(float X, float Y, float Z, float W);
// Constructs this quaternion by specifying a rotation axis and the amount of rotation to be performed about that axis
// @param rotationAxis The normalized rotation axis to rotate about. If using Vector4 version of the constructor, the w component of this vector must be 0.
Quaternion(const Vector3& rotationAxis, float rotationAngleBetween) { SetFromAxisAngle(rotationAxis, rotationAngleBetween); }
Quaternion(const Vector4& rotationAxis, float rotationAngleBetween) { SetFromAxisAngle(rotationAxis, rotationAngleBetween); }
//void Inverse();
explicit Quaternion(Vector4 vector4);
void SetFromAxisAngle(const Vector3 &vector3, float between);
void SetFromAxisAngle(const Vector4 &vector4, float between);
Quaternion Inverse() const;
Quaternion Conjugate() const;
//void Normalize();
Quaternion Normalize() const;
Vector3 GetWorldX() const;
Vector3 GetWorldY() const;
Vector3 GetWorldZ() const;
@@ -35,22 +48,21 @@ namespace LinearAlgebra
Quaternion GetInverse() const;
Quaternion Lerp(const Quaternion& b, float t) const;
Quaternion Slerp(const Quaternion& target) const;
Quaternion Slerp(const Quaternion& q2, float t) const;
void SetFromAxisAngle(const Vector3& axis, float angle);
void SetFromAxisAngle(const Vector4& axis, float angle)
{
}
Quaternion Normalize() const;
static Quaternion LookAt(const Vector3& position, const Vector3& direction, const Vector3& axisUp);
// TODO: Document (But do not override!) certain math functions that are the same for Vec4
// TODO: Double Check which operations need to be overriden for correct behavior!
// Multiplies two quaternions together.
// The product q1 * q2 returns a quaternion that concatenates the two orientation rotations.
// The rotation q2 is applied first before q1.
Quaternion operator * (const Quaternion& rhs) const;
Quaternion operator * (const Quaternion& rhs) const;
Quaternion operator * (float scalar) const;
@@ -59,14 +71,16 @@ namespace LinearAlgebra
Vector4 operator * (const Vector4& rhs) const;
// Divides a quaternion by another. Divison "a / b" results in a quaternion that rotates the orientation b to coincide with orientation of
Quaternion operator / (const Quaternion& rhs) const;
//Quaternion operator / (const Quaternion& rhs) const;
Quaternion operator +(const Quaternion& rhs) const;
Quaternion operator +() const;
Quaternion operator -() const;
public:
float x = 0;
float y = 0;
float z = 0;
float w = 0;
float Dot(const Quaternion &quaternion) const;
float Angle() const;
float AngleBetween(const Quaternion& target) const;
AxisAngle ToAxisAngle() const;
};
}