DarkflameServer/dCommon/NiPoint3.h

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

192 lines
4.5 KiB
C
Raw Normal View History

#pragma once
/*!
\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:
float x; //!< The x position
float y; //!< The y position
float z; //!< The z position
2022-07-28 13:39:57 +00:00
//! Initializer
NiPoint3(void);
2022-07-28 13:39:57 +00:00
//! Initializer
/*!
\param x The x coordinate
\param y The y coordinate
\param z The z coordinate
*/
NiPoint3(float x, float y, float z);
2022-07-28 13:39:57 +00:00
//! Copy Constructor
/*!
\param point The point to copy
*/
NiPoint3(const NiPoint3& point);
2022-07-28 13:39:57 +00:00
//! Destructor
~NiPoint3(void);
2022-07-28 13:39:57 +00:00
// MARK: Constants
static const NiPoint3 ZERO; //!< Point(0, 0, 0)
static const NiPoint3 UNIT_X; //!< Point(1, 0, 0)
static const NiPoint3 UNIT_Y; //!< Point(0, 1, 0)
static const NiPoint3 UNIT_Z; //!< Point(0, 0, 1)
static const NiPoint3 UNIT_ALL; //!< Point(1, 1, 1)
2022-07-28 13:39:57 +00:00
// MARK: Getters / Setters
2022-07-28 13:39:57 +00:00
//! Gets the X coordinate
/*!
\return The x coordinate
*/
float GetX(void) const;
2022-07-28 13:39:57 +00:00
//! Sets the X coordinate
/*!
\param x The x coordinate
*/
void SetX(float x);
2022-07-28 13:39:57 +00:00
//! Gets the Y coordinate
/*!
\return The y coordinate
*/
float GetY(void) const;
2022-07-28 13:39:57 +00:00
//! Sets the Y coordinate
/*!
\param y The y coordinate
*/
void SetY(float y);
2022-07-28 13:39:57 +00:00
//! Gets the Z coordinate
/*!
\return The z coordinate
*/
float GetZ(void) const;
2022-07-28 13:39:57 +00:00
//! Sets the Z coordinate
/*!
\param z The z coordinate
*/
void SetZ(float z);
2022-07-28 13:39:57 +00:00
// MARK: Member Functions
2022-07-28 13:39:57 +00:00
//! Gets the length of the vector
/*!
\return The scalar length of the vector
2022-07-28 13:39:57 +00:00
*/
float Length(void) const;
2022-07-28 13:39:57 +00:00
//! Gets the squared length of a vector
/*!
\return The squared length of a vector
*/
float SquaredLength(void) const;
2022-07-28 13:39:57 +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
*/
float DotProduct(const Vector3& vec) const;
2022-07-28 13:39:57 +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
*/
Vector3 CrossProduct(const Vector3& vec) const;
2022-07-28 13:39:57 +00:00
//! Unitize the vector
2022-07-28 13:39:57 +00:00
/*!
\returns The current vector
2022-07-28 13:39:57 +00:00
*/
NiPoint3 Unitize(void) const;
2022-07-28 13:39:57 +00:00
// MARK: Operators
2022-07-28 13:39:57 +00:00
//! Operator to check for equality
bool operator==(const NiPoint3& point) const;
2022-07-28 13:39:57 +00:00
//! Operator to check for inequality
bool operator!=(const NiPoint3& point) const;
2022-07-28 13:39:57 +00:00
//! Operator for subscripting
float& operator[](int i);
2022-07-28 13:39:57 +00:00
//! Operator for subscripting
const float& operator[](int i) const;
//! Operator for addition of vectors
NiPoint3 operator+(const NiPoint3& point) const;
//! Operator for addition of vectors
NiPoint3& operator+=(const NiPoint3& point);
//! Operator for subtraction of vectors
NiPoint3 operator-(const NiPoint3& point) const;
2022-07-28 13:39:57 +00:00
//! Operator for addition of a scalar on all vector components
NiPoint3 operator+(float fScalar) const;
//! Operator for subtraction of a scalar on all vector components
NiPoint3 operator-(float fScalar) const;
//! Operator for scalar multiplication of a vector
NiPoint3 operator*(float fScalar) const;
//! Operator for scalar division of a vector
NiPoint3 operator/(float fScalar) const;
// 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
/*!
\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
*/
bool IsWithinAxisAlignedBox(const NiPoint3& minPoint, const NiPoint3& maxPoint);
2022-07-28 13:39:57 +00:00
//! Checks to see if the point (or vector) is within a sphere
2022-07-28 13:39:57 +00:00
/*!
\param sphereCenter The sphere center
\param radius The radius
2022-07-28 13:39:57 +00:00
*/
bool IsWithinSpehere(const NiPoint3& sphereCenter, float radius);
2022-07-28 13:39:57 +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
*/
static NiPoint3 ClosestPointOnLine(const NiPoint3& a, const NiPoint3& b, const NiPoint3& p);
2022-07-28 13:39:57 +00:00
static float Angle(const NiPoint3& a, const NiPoint3& b);
2022-07-28 13:39:57 +00:00
static float Distance(const NiPoint3& a, const NiPoint3& b);
2022-07-28 13:39:57 +00:00
static float DistanceSquared(const NiPoint3& a, const NiPoint3& b);
2022-07-28 13:39:57 +00:00
static NiPoint3 MoveTowards(const NiPoint3& current, const NiPoint3& target, float maxDistanceDelta);
2022-07-28 13:39:57 +00:00
NiPoint3 RotateByQuaternion(const NiQuaternion& rotation);
};