Skip to content

Commit

Permalink
[core.matrix] documentation pass for matrix and quaternion
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Nov 17, 2024
1 parent 8353c5b commit 16d5e6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion include/tz/core/matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

namespace tz
{
/**
* @ingroup tz_core_math
* @brief Represents the generic matrix.
* @internal
*/
template<typename T, int N>
requires std::integral<T> || std::floating_point<T>
struct matrix
{
/// Retrieve a matrix filled with zeroes.
static constexpr matrix<T, N> zero()
{
return matrix<T, N>::filled(T{0});
}

/// Retrieve an identity matrix that represents no transform.
static constexpr matrix<T, N> iden()
{
auto ret = matrix<T, N>::zero();
Expand All @@ -23,7 +30,8 @@ namespace tz
}
return ret;
}


/// Retrieve a matrix filled with the given value.
static constexpr matrix<T, N> filled(T t)
{
matrix<T, N> ret;
Expand All @@ -43,7 +51,9 @@ namespace tz
const T& operator()(std::size_t x, std::size_t y) const;
T& operator()(std::size_t x, std::size_t y);

/// Create a matrix that causes the inverse transformation. Such that the product of this and the result are the identity matrix.
matrix<T, N> inverse() const;
/// Retrieve a copy of this matrix but with its rows and columns swapped.
matrix<T, N> transpose() const;

// matrix-scalar
Expand Down
14 changes: 14 additions & 0 deletions include/tz/core/quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@

namespace tz
{
/**
* @ingroup tz_core_math
* @brief Quaternion. Represents a rotation in 3D space.
*/
struct quat : public tz::v4f
{
/// Retrieve the identity quaternion, that is - represents no transformation.
static quat iden()
{
return {tz::v4f{0.0f, 0.0f, 0.0f, 1.0f}};
}
quat() = default;
/// Create a quaternion directly from xyzw components.
quat(tz::v4f vec);
/// Create a quaternion that represents a rotation about a certain axis.
static quat from_axis_angle(tz::v3f axis, float angle);
/// Create a quaternion that represents a rotation equivalent to the provided euler angles.
static quat from_euler_angles(tz::v3f euler_angles);
/// Create a rotation matrix that transforms identically to the quaternion.
tz::m4f matrix() const;
/// Create a quaternion that causes the inverse transformation. Such that the product of this and the result are the identity quaternion.
quat inverse() const;
/// Combine one quaternion with another, producing a result equal to applying both rotations.
quat combine(const quat& rhs) const;
/// Rotate a 3D position by this quaternion.
tz::v3f rotate(tz::v3f pos) const;
/// Retrieve a normalised copy of the quaternion.
quat normalise() const;
/// Retrieve a quaternion that represents a spherical interpolation between this quaternion and another, based upon a given factor.
quat slerp(const quat& rhs, float factor) const;

quat& operator*=(const quat& rhs);
Expand Down

0 comments on commit 16d5e6c

Please sign in to comment.