Skip to content

Commit

Permalink
make default Quaternion c'tor constexpr (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
McCallisterRomer authored Jan 27, 2025
1 parent 93ab5db commit a821d34
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions include/ncmath/Quaternion.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Quaternion.h
* @copyright Jaremie Romer and McCallister Romer 2024
* @copyright Jaremie Romer and McCallister Romer 2025
*/
#pragma once

Expand All @@ -13,50 +13,50 @@ struct Quaternion
{
float x, y, z, w;

Quaternion()
constexpr explicit Quaternion()
: x{0.0f}, y{0.0f}, z{0.0f}, w{1.0f}
{
}

Quaternion(float X, float Y, float Z, float W);
explicit Quaternion(float X, float Y, float Z, float W);

Vector3 ToEulerAngles() const noexcept;
auto ToEulerAngles() const noexcept -> Vector3;
void ToAxisAngle(Vector3* axisOut, float* angleOut) const noexcept;

static Quaternion Identity() { return Quaternion{0.0f, 0.0f, 0.0f, 1.0f}; }
static Quaternion FromEulerAngles(const Vector3& angles);
static Quaternion FromEulerAngles(float x, float y, float z);
static Quaternion FromAxisAngle(const Vector3& axis, float radians); // axis cannot be zero
static constexpr auto Identity() -> Quaternion { return Quaternion{}; }
static auto FromEulerAngles(const Vector3& angles) -> Quaternion;
static auto FromEulerAngles(float x, float y, float z) -> Quaternion;
static auto FromAxisAngle(const Vector3& axis, float radians) -> Quaternion; // axis cannot be zero
};

/** @brief Return a normalized quaternion. */
Quaternion Normalize(const Quaternion& quat);
auto Normalize(const Quaternion& quat) -> Quaternion;

/**
* @brief Multiplies two quaternions.
* @note For consistency with DirectXMath, the argument order is reversed from the order in which they are
* multiplied. In other words, this computes the lhs rotation followed by rhs (or the product rhs*lhs).
*/
Quaternion Multiply(const Quaternion& lhs, const Quaternion& rhs);
auto Multiply(const Quaternion& lhs, const Quaternion& rhs) -> Quaternion;

/** @brief Finds rotation between lhs and rhs such that result * lhs == rhs. */
Quaternion Difference(const Quaternion& lhs, const Quaternion& rhs);
auto Difference(const Quaternion& lhs, const Quaternion& rhs) -> Quaternion;

/** @brief Interpolates from lhs to rhs. */
Quaternion Slerp(const Quaternion& lhs, const Quaternion& rhs, float factor);
auto Slerp(const Quaternion& lhs, const Quaternion& rhs, float factor) -> Quaternion;

/** @brief Slerp from Identity to quat. */
Quaternion Scale(const Quaternion& quat, float factor);
auto Scale(const Quaternion& quat, float factor) -> Quaternion;

inline bool operator==(const Quaternion& lhs, const Quaternion& rhs)
inline auto operator==(const Quaternion& lhs, const Quaternion& rhs) -> bool
{
return FloatEqual(lhs.x, rhs.x) &&
FloatEqual(lhs.y, rhs.y) &&
FloatEqual(lhs.z, rhs.z) &&
FloatEqual(lhs.w, rhs.w);
}

inline bool operator!=(const Quaternion& lhs, const Quaternion& rhs)
inline auto operator!=(const Quaternion& lhs, const Quaternion& rhs) -> bool
{
return !(lhs == rhs);
}
Expand Down

0 comments on commit a821d34

Please sign in to comment.