DarkflameServer/dCommon/NiQuaternion.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

159 lines
4.0 KiB
C
Raw Permalink Normal View History

#ifndef __NIQUATERNION_H__
#define __NIQUATERNION_H__
// Custom Classes
#include "NiPoint3.h"
/*!
\file NiQuaternion.hpp
\brief Defines a quaternion in space in WXYZ coordinates
*/
class NiQuaternion;
typedef NiQuaternion Quaternion; //!< A typedef for a shorthand version of NiQuaternion
//! A class that defines a rotation in space
class NiQuaternion {
public:
float w{ 1 }; //!< The w coordinate
float x{ 0 }; //!< The x coordinate
float y{ 0 }; //!< The y coordinate
float z{ 0 }; //!< The z coordinate
2022-07-28 13:39:57 +00:00
//! The initializer
constexpr NiQuaternion() = default;
2022-07-28 13:39:57 +00:00
//! The initializer
/*!
\param w The w coordinate
\param x The x coordinate
\param y The y coordinate
\param z The z coordinate
*/
constexpr NiQuaternion(const float w, const float x, const float y, const float z) noexcept
: w{ w }
, x{ x }
, y{ y }
, z{ z } {
}
2022-07-28 13:39:57 +00:00
// MARK: Setters / Getters
2022-07-28 13:39:57 +00:00
//! Gets the W coordinate
/*!
\return The w coordinate
*/
[[nodiscard]] constexpr float GetW() const noexcept;
2022-07-28 13:39:57 +00:00
//! Sets the W coordinate
/*!
\param w The w coordinate
*/
constexpr void SetW(const float w) noexcept;
2022-07-28 13:39:57 +00:00
//! Gets the X coordinate
/*!
\return The x coordinate
*/
[[nodiscard]] constexpr float GetX() const noexcept;
2022-07-28 13:39:57 +00:00
//! Sets the X coordinate
/*!
\param x The x coordinate
*/
constexpr void SetX(const float x) noexcept;
2022-07-28 13:39:57 +00:00
//! Gets the Y coordinate
/*!
\return The y coordinate
*/
[[nodiscard]] constexpr float GetY() const noexcept;
2022-07-28 13:39:57 +00:00
//! Sets the Y coordinate
/*!
\param y The y coordinate
*/
constexpr void SetY(const float y) noexcept;
2022-07-28 13:39:57 +00:00
//! Gets the Z coordinate
/*!
\return The z coordinate
*/
[[nodiscard]] constexpr float GetZ() const noexcept;
2022-07-28 13:39:57 +00:00
//! Sets the Z coordinate
/*!
\param z The z coordinate
*/
constexpr void SetZ(const float z) noexcept;
2022-07-28 13:39:57 +00:00
// MARK: Member Functions
2022-07-28 13:39:57 +00:00
//! Returns the forward vector from the quaternion
/*!
\return The forward vector of the quaternion
*/
[[nodiscard]] constexpr Vector3 GetForwardVector() const noexcept;
2022-07-28 13:39:57 +00:00
//! Returns the up vector from the quaternion
/*!
\return The up vector fo the quaternion
*/
[[nodiscard]] constexpr Vector3 GetUpVector() const noexcept;
2022-07-28 13:39:57 +00:00
//! Returns the right vector from the quaternion
/*!
\return The right vector of the quaternion
*/
[[nodiscard]] constexpr Vector3 GetRightVector() const noexcept;
2022-07-28 13:39:57 +00:00
[[nodiscard]] Vector3 GetEulerAngles() const;
2022-07-28 13:39:57 +00:00
// MARK: Operators
2022-07-28 13:39:57 +00:00
//! Operator to check for equality
constexpr bool operator==(const NiQuaternion& rot) const noexcept;
2022-07-28 13:39:57 +00:00
//! Operator to check for inequality
constexpr bool operator!=(const NiQuaternion& rot) const noexcept;
2022-07-28 13:39:57 +00:00
// MARK: Helper Functions
2022-07-28 13:39:57 +00:00
//! Look from a specific point in space to another point in space (Y-locked)
/*!
\param sourcePoint The source location
\param destPoint The destination location
\return The Quaternion with the rotation towards the destination
*/
[[nodiscard]] static NiQuaternion LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint);
2022-07-28 13:39:57 +00:00
//! Look from a specific point in space to another point in space
/*!
\param sourcePoint The source location
\param destPoint The destination location
\return The Quaternion with the rotation towards the destination
*/
[[nodiscard]] static NiQuaternion LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint);
2022-07-28 13:39:57 +00:00
//! Creates a Quaternion from a specific axis and angle relative to that axis
/*!
\param axis The axis that is used
\param angle The angle relative to this axis
\return A quaternion created from the axis and angle
*/
[[nodiscard]] static NiQuaternion CreateFromAxisAngle(const Vector3& axis, float angle);
2022-07-28 13:39:57 +00:00
[[nodiscard]] static NiQuaternion FromEulerAngles(const NiPoint3& eulerAngles);
};
// Static Variables
namespace NiQuaternionConstant {
constexpr NiQuaternion IDENTITY(1, 0, 0, 0);
}
// Include constexpr and inline function definitions in a seperate file for readability
#include "NiQuaternion.inl"
#endif // !__NIQUATERNION_H__