2024-10-30 07:30:20 +00:00
|
|
|
#ifndef NIPOINT3_H
|
|
|
|
#define NIPOINT3_H
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
\file NiPoint3.hpp
|
|
|
|
\brief Defines a point in space in XYZ coordinates
|
|
|
|
*/
|
|
|
|
|
|
|
|
class NiPoint3;
|
|
|
|
class NiQuaternion;
|
|
|
|
typedef NiPoint3 Vector3; //!< The Vector3 class is technically the NiPoint3 class, but typedef'd for clarity in some cases
|
|
|
|
|
|
|
|
//! A custom class the defines a point in space
|
|
|
|
class NiPoint3 {
|
|
|
|
public:
|
2024-01-29 07:53:12 +00:00
|
|
|
float x{ 0 }; //!< The x position
|
|
|
|
float y{ 0 }; //!< The y position
|
|
|
|
float z{ 0 }; //!< The z position
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Initializer
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3() = default;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Initializer
|
|
|
|
/*!
|
|
|
|
\param x The x coordinate
|
|
|
|
\param y The y coordinate
|
|
|
|
\param z The z coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3(const float x, const float y, const float z) noexcept
|
|
|
|
: x{ x }
|
|
|
|
, y{ y }
|
|
|
|
, z{ z } {
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Copy Constructor
|
|
|
|
/*!
|
|
|
|
\param point The point to copy
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3(const NiPoint3& point) noexcept
|
|
|
|
: x{ point.x }
|
|
|
|
, y{ point.y }
|
|
|
|
, z{ point.z } {
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// MARK: Getters / Setters
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Gets the X coordinate
|
|
|
|
/*!
|
|
|
|
\return The x coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr float GetX() const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Sets the X coordinate
|
|
|
|
/*!
|
|
|
|
\param x The x coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr void SetX(const float x) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Gets the Y coordinate
|
|
|
|
/*!
|
|
|
|
\return The y coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr float GetY() const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Sets the Y coordinate
|
|
|
|
/*!
|
|
|
|
\param y The y coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr void SetY(const float y) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Gets the Z coordinate
|
|
|
|
/*!
|
|
|
|
\return The z coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr float GetZ() const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Sets the Z coordinate
|
|
|
|
/*!
|
|
|
|
\param z The z coordinate
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr void SetZ(const float z) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// MARK: Member Functions
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Gets the length of the vector
|
|
|
|
/*!
|
|
|
|
\return The scalar length of the vector
|
2022-07-28 13:39:57 +00:00
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] float Length() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Gets the squared length of a vector
|
|
|
|
/*!
|
|
|
|
\return The squared length of a vector
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr float SquaredLength() const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Returns the dot product of the vector dotted with another vector
|
|
|
|
/*!
|
|
|
|
\param vec The second vector
|
|
|
|
\return The dot product of the two vectors
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr float DotProduct(const Vector3& vec) const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Returns the cross product of the vector crossed with another vector
|
|
|
|
/*!
|
|
|
|
\param vec The second vector
|
|
|
|
\return The cross product of the two vectors
|
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr Vector3 CrossProduct(const Vector3& vec) const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Unitize the vector
|
2022-07-28 13:39:57 +00:00
|
|
|
/*!
|
2021-12-05 17:54:36 +00:00
|
|
|
\returns The current vector
|
2022-07-28 13:39:57 +00:00
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] NiPoint3 Unitize() const;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// MARK: Operators
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator to check for equality
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr bool operator==(const NiPoint3& point) const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator to check for inequality
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr bool operator!=(const NiPoint3& point) const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator for subscripting
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr float& operator[](const int i) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator for subscripting
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr const float& operator[](const int i) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Operator for addition of vectors
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator+(const NiPoint3& point) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-03-25 10:26:39 +00:00
|
|
|
//! Operator for addition of vectors
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3& operator+=(const NiPoint3& point) noexcept;
|
2023-03-25 10:26:39 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3& operator*=(const float scalar) noexcept;
|
2023-08-10 05:13:20 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator for subtraction of vectors
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator-(const NiPoint3& point) const noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Operator for addition of a scalar on all vector components
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator+(const float fScalar) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Operator for subtraction of a scalar on all vector components
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator-(const float fScalar) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Operator for scalar multiplication of a vector
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator*(const float fScalar) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
//! Operator for scalar division of a vector
|
2024-01-29 07:53:12 +00:00
|
|
|
constexpr NiPoint3 operator/(const float fScalar) const noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// MARK: Helper Functions
|
|
|
|
|
|
|
|
//! Checks to see if the point (or vector) is with an Axis-Aligned Bounding Box
|
2022-07-28 13:39:57 +00:00
|
|
|
/*!
|
2021-12-05 17:54:36 +00:00
|
|
|
\param minPoint The minimum point of the bounding box
|
|
|
|
\param maxPoint The maximum point of the bounding box
|
|
|
|
\return Whether or not this point lies within the box
|
2022-07-28 13:39:57 +00:00
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr bool IsWithinAxisAlignedBox(const NiPoint3& minPoint, const NiPoint3& maxPoint) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
//! Checks to see if the point (or vector) is within a sphere
|
2022-07-28 13:39:57 +00:00
|
|
|
/*!
|
2021-12-05 17:54:36 +00:00
|
|
|
\param sphereCenter The sphere center
|
|
|
|
\param radius The radius
|
2022-07-28 13:39:57 +00:00
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] constexpr bool IsWithinSphere(const NiPoint3& sphereCenter, const float radius) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
/*!
|
2021-12-05 17:54:36 +00:00
|
|
|
\param a Start of line
|
|
|
|
\param b End of line
|
|
|
|
\param p Refrence point
|
|
|
|
\return The point of line AB which is closest to P
|
2022-07-28 13:39:57 +00:00
|
|
|
*/
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] static constexpr NiPoint3 ClosestPointOnLine(const NiPoint3& a, const NiPoint3& b, const NiPoint3& p) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] static float Angle(const NiPoint3& a, const NiPoint3& b);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] static float Distance(const NiPoint3& a, const NiPoint3& b);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] static constexpr float DistanceSquared(const NiPoint3& a, const NiPoint3& b) noexcept;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
[[nodiscard]] static NiPoint3 MoveTowards(const NiPoint3& current, const NiPoint3& target, const float maxDistanceDelta);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-01-29 07:53:12 +00:00
|
|
|
//This code is yoinked from the MS XNA code, so it should be right, even if it's horrible.
|
|
|
|
[[nodiscard]] constexpr NiPoint3 RotateByQuaternion(const NiQuaternion& rotation) noexcept;
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|
2024-01-29 07:53:12 +00:00
|
|
|
|
|
|
|
// Static Variables
|
|
|
|
namespace NiPoint3Constant {
|
|
|
|
constexpr NiPoint3 ZERO(0.0f, 0.0f, 0.0f);
|
|
|
|
constexpr NiPoint3 UNIT_X(1.0f, 0.0f, 0.0f);
|
|
|
|
constexpr NiPoint3 UNIT_Y(0.0f, 1.0f, 0.0f);
|
|
|
|
constexpr NiPoint3 UNIT_Z(0.0f, 0.0f, 1.0f);
|
|
|
|
constexpr NiPoint3 UNIT_ALL(1.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// .inl file needed for code organization and to circumvent circular dependency issues
|
|
|
|
#include "NiPoint3.inl"
|
|
|
|
|
2024-10-30 07:30:20 +00:00
|
|
|
#endif // !NIPOINT3_H
|