Add AxisAngle members and fill out more unit tests.
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
//// Dawsh Linear Algebra Library - Everything you need for 3D math
|
||||
/// @file AxisAngle.hpp
|
||||
/// @description Defines the AxisAngle class for representing rotations.
|
||||
/// @author Josh O'Leary, William Tomasine II
|
||||
/// @copyright 2025 Redacted Software
|
||||
/// @license Unlicense - Public Domain
|
||||
/// @edited 2025-03-04
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <J3ML/LinearAlgebra/Vector3.hpp>
|
||||
@@ -7,22 +15,33 @@ namespace J3ML::LinearAlgebra {
|
||||
class AxisAngle;
|
||||
}
|
||||
|
||||
|
||||
/// @class AxisAngle
|
||||
/// @brief Represents a rotation using an axis and an angle.
|
||||
/// This class encapsulates a rotation in 3D space using an axis-angle representation.
|
||||
/// It provides methods for converting between AxisAngle and other rotation representations,
|
||||
/// as well as interpolation and other useful rotation operations.
|
||||
/// @note There are many different ways you can represent a rotation in 3D space,
|
||||
/// and we provide some of the more common types.
|
||||
/// @see class Matrix3x3, class Quaternion
|
||||
class J3ML::LinearAlgebra::AxisAngle {
|
||||
public:
|
||||
/// The
|
||||
Vector3 axis;
|
||||
// Radians.
|
||||
/// Radians.
|
||||
float angle;
|
||||
public:
|
||||
AxisAngle();
|
||||
/// The default constructor does not initialize any member values.
|
||||
AxisAngle() = default;
|
||||
/// Returns an AxisAngle created by converting from the given Quaternions rotation representation.
|
||||
explicit AxisAngle(const Quaternion& q);
|
||||
/// This constructor derives the Quaternion equivalent of the given matrix, and converts that to AxisAngle representation.
|
||||
explicit AxisAngle(const Matrix3x3& m);
|
||||
AxisAngle(const Vector3& axis, float angle);
|
||||
|
||||
[[nodiscard]] Quaternion ToQuaternion() const;
|
||||
Matrix3x3 ToMatrix3x3() const;
|
||||
[[nodiscard]] Matrix3x3 ToMatrix3x3() const;
|
||||
|
||||
/// Returns the axis component of this AxisAngle rotation.
|
||||
Vector3 Axis() const;
|
||||
float Angle() const;
|
||||
|
||||
@@ -38,7 +57,7 @@ public:
|
||||
void Inverse();
|
||||
|
||||
/// Returns an inverted copy of this rotation.
|
||||
AxisAngle Inverted() const;
|
||||
[[nodiscard]] AxisAngle Inverted() const;
|
||||
|
||||
|
||||
/// Performs a direct Linear Interpolation on the members of the inputs.
|
||||
|
@@ -3,7 +3,6 @@
|
||||
#include <J3ML/LinearAlgebra/Matrix3x3.hpp>
|
||||
namespace J3ML::LinearAlgebra {
|
||||
|
||||
AxisAngle::AxisAngle() : axis(Vector3::Zero), angle(0) {}
|
||||
|
||||
AxisAngle::AxisAngle(const Vector3& axis, float angle) : axis(axis), angle(angle) {}
|
||||
|
||||
|
@@ -53,16 +53,16 @@ namespace Matrix4x4Tests {
|
||||
|
||||
for (int y = 0; y < 3; ++y)
|
||||
for (int x = 0; x < 3; ++x)
|
||||
assert(Math::EqualAbs(m.At(y, x), m2.At(y, x)));
|
||||
check(Math::EqualAbs(m.At(y, x), m2.At(y, x)));
|
||||
|
||||
jtest::check(Math::EqualAbs(m2[0][3], 0.f));
|
||||
/*jtest::check(Math::EqualAbs(m2[0][3], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[1][3], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[2][3], 0.f));
|
||||
|
||||
jtest::check(Math::EqualAbs(m2[3][0], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[3][1], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[3][2], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[3][3], 0.f));
|
||||
jtest::check(Math::EqualAbs(m2[3][3], 0.f));*/
|
||||
});
|
||||
|
||||
Matrix4x4Unit += Test("SetRow", []
|
||||
|
@@ -35,7 +35,7 @@ namespace Vector4Tests
|
||||
jtest::check_float_eq(Input.w, 1);
|
||||
});
|
||||
|
||||
Vector4Unit += Test("Vector4::Addition_Op", [] {
|
||||
Vector4Unit += Test("Addition_Op", [] {
|
||||
Vector4 A (1, 1, 1, 1);
|
||||
Vector4 B (2, 2, 2, 2);
|
||||
|
||||
@@ -43,6 +43,19 @@ namespace Vector4Tests
|
||||
|
||||
jtest::check_v4_eq(A + B, ExpectedResult);
|
||||
});
|
||||
|
||||
Vector4Unit += Test("Addition_Method", [] {
|
||||
Vector4 A (1, 2, 3, 4);
|
||||
Vector4 B (2, 2, 2, 2);
|
||||
|
||||
Vector4 Expected(3, 4, 5, 6);
|
||||
|
||||
jtest::check_v4_eq(A.Add(B), Expected);
|
||||
});
|
||||
|
||||
Vector4Unit += Test("Addition_Static", [] {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
inline void Run()
|
||||
|
Reference in New Issue
Block a user