SHADE_Y3/SHADE_Engine/src/Math/Vector/SHVec3.h

130 lines
7.8 KiB
C
Raw Normal View History

/****************************************************************************************
* \file SHVec3.h
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Interface for 3D Vector.
*
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
#pragma once
#include <DirectXMath.h>
#include <string>
#include <initializer_list>
namespace SHADE
{
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
class SHMatrix;
/*-----------------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SHVec3 : public DirectX::XMFLOAT3
{
public:
/*---------------------------------------------------------------------------------*/
/* Static Data Members */
/*---------------------------------------------------------------------------------*/
static constexpr size_t SIZE = 3U;
static const SHVec3 Zero;
static const SHVec3 One;
static const SHVec3 Left;
static const SHVec3 Right;
static const SHVec3 Up;
static const SHVec3 Down;
static const SHVec3 Forward;
static const SHVec3 Back;
static const SHVec3 UnitX;
static const SHVec3 UnitY;
static const SHVec3 UnitZ;
/*---------------------------------------------------------------------------------*/
/* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/
SHVec3 (const SHVec3& rhs) = default;
SHVec3 (SHVec3&& rhs) = default;
~SHVec3 () = default;
SHVec3 () noexcept;
2022-09-19 16:50:06 +08:00
SHVec3 (float n) noexcept;
SHVec3 (float x, float y, float z) noexcept;
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
SHVec3& operator= (const SHVec3& rhs) = default;
SHVec3& operator= (SHVec3&& rhs) = default;
SHVec3& operator+= (const SHVec3& rhs) noexcept;
SHVec3& operator-= (const SHVec3& rhs) noexcept;
SHVec3& operator*= (const SHVec3& rhs) noexcept;
SHVec3& operator*= (float rhs) noexcept;
SHVec3& operator/= (const SHVec3& rhs) noexcept;
SHVec3& operator/= (float rhs) noexcept;
[[nodiscard]] SHVec3 operator+ (const SHVec3& rhs) const noexcept;
[[nodiscard]] SHVec3 operator- (const SHVec3& rhs) const noexcept;
[[nodiscard]] SHVec3 operator- () const noexcept;
[[nodiscard]] SHVec3 operator* (const SHVec3& rhs) const noexcept;
[[nodiscard]] SHVec3 operator* (float rhs) const noexcept;
[[nodiscard]] SHVec3 operator/ (const SHVec3& rhs) const noexcept;
[[nodiscard]] SHVec3 operator/ (float rhs) const noexcept;
[[nodiscard]] bool operator== (const SHVec3& rhs) const noexcept;
[[nodiscard]] bool operator!= (const SHVec3& rhs) const noexcept;
[[nodiscard]] float operator[] (int index);
[[nodiscard]] float operator[] (size_t index);
[[nodiscard]] float operator[] (int index) const;
[[nodiscard]] float operator[] (size_t index) const;
/*---------------------------------------------------------------------------------*/
/* Function Members */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] float Length () const noexcept;
[[nodiscard]] float LengthSquared () const noexcept;
[[nodiscard]] std::string ToString () const noexcept;
[[nodiscard]] float Dot (const SHVec3& rhs) const noexcept;
[[nodiscard]] SHVec3 Cross (const SHVec3& rhs) const noexcept;
/*---------------------------------------------------------------------------------*/
/* Static Function Members */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] static SHVec3 Normalise (const SHVec3& v) noexcept;
[[nodiscard]] static SHVec3 Abs (const SHVec3& v) noexcept;
[[nodiscard]] static SHVec3 Min (const std::initializer_list<SHVec3>& vs) noexcept;
[[nodiscard]] static SHVec3 Max (const std::initializer_list<SHVec3>& vs) noexcept;
[[nodiscard]] static SHVec3 Clamp (const SHVec3& v, const SHVec3& vMin, const SHVec3& vMax) noexcept;
[[nodiscard]] static SHVec3 Lerp (const SHVec3& a, const SHVec3& b, float t) noexcept;
[[nodiscard]] static SHVec3 ClampedLerp (const SHVec3& a, const SHVec3& b, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept;
[[nodiscard]] static float Distance (const SHVec3& lhs, const SHVec3& rhs) noexcept;
[[nodiscard]] static float DistanceSquared (const SHVec3& lhs, const SHVec3& rhs) noexcept;
[[nodiscard]] static float Angle (const SHVec3& lhs, const SHVec3& rhs) noexcept;
[[nodiscard]] static float Dot (const SHVec3& lhs, const SHVec3& rhs) noexcept;
[[nodiscard]] static SHVec3 Cross (const SHVec3& lhs, const SHVec3& rhs) noexcept;
[[nodiscard]] static SHVec3 Project (const SHVec3& v, const SHVec3& u) noexcept;
[[nodiscard]] static SHVec3 Reflect (const SHVec3& v, const SHVec3& normal) noexcept;
[[nodiscard]] static SHVec3 Rotate (const SHVec3& v, const SHVec3& axis, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateX (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateY (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateZ (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 Transform (const SHVec3& v, const SHMatrix& transformMtx) noexcept;
};
SHVec3 operator* (float lhs, const SHVec3& rhs) noexcept;
} // namespace SHADE