/**************************************************************************************** * \file SHVec2.h * \author Diren D Bharwani, diren.dbharwani, 390002520 * \brief Interface for 2D 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 #include #include namespace SHADE { /*-----------------------------------------------------------------------------------*/ /* Forward Declarations */ /*-----------------------------------------------------------------------------------*/ class SHMatrix; /*-----------------------------------------------------------------------------------*/ /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ class SHVec2 : public DirectX::XMFLOAT2 { public: /*---------------------------------------------------------------------------------*/ /* Static Data Members */ /*---------------------------------------------------------------------------------*/ static constexpr size_t SIZE = 2U; static const SHVec2 Zero; static const SHVec2 One; static const SHVec2 Left; static const SHVec2 Right; static const SHVec2 Up; static const SHVec2 Down; /*---------------------------------------------------------------------------------*/ /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ SHVec2 (const SHVec2& rhs) = default; SHVec2 (SHVec2&& rhs) = default; ~SHVec2 () = default; SHVec2 () noexcept; SHVec2 (float x, float y) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ [[nodiscard]] SHVec2& operator= (const SHVec2& rhs) = default; [[nodiscard]] SHVec2& operator= (SHVec2&& rhs) = default; [[nodiscard]] SHVec2& operator+= (const SHVec2& rhs) noexcept; [[nodiscard]] SHVec2& operator-= (const SHVec2& rhs) noexcept; [[nodiscard]] SHVec2& operator*= (const SHVec2& rhs) noexcept; [[nodiscard]] SHVec2& operator*= (float rhs) noexcept; [[nodiscard]] SHVec2& operator/= (const SHVec2& rhs) noexcept; [[nodiscard]] SHVec2& operator/= (float rhs) noexcept; [[nodiscard]] SHVec2 operator+ (const SHVec2& rhs) const noexcept; [[nodiscard]] SHVec2 operator- (const SHVec2& rhs) const noexcept; [[nodiscard]] SHVec2 operator- () const noexcept; [[nodiscard]] SHVec2 operator* (const SHVec2& rhs) const noexcept; [[nodiscard]] SHVec2 operator* (float rhs) const noexcept; [[nodiscard]] SHVec2 operator/ (const SHVec2& rhs) const noexcept; [[nodiscard]] SHVec2 operator/ (float rhs) const noexcept; [[nodiscard]] bool operator== (const SHVec2& rhs) const noexcept; [[nodiscard]] bool operator!= (const SHVec2& 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 SHVec2& rhs) const noexcept; [[nodiscard]] SHVec2 Cross (const SHVec2& rhs) const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ [[nodiscard]] static SHVec2 Normalise (const SHVec2& vec2) noexcept; [[nodiscard]] static SHVec2 Abs (const SHVec2& vec2) noexcept; [[nodiscard]] static SHVec2 Min (const std::initializer_list& vec2s) noexcept; [[nodiscard]] static SHVec2 Max (const std::initializer_list& vec2s) noexcept; [[nodiscard]] static SHVec2 Clamp (const SHVec2& v, const SHVec2& vMin, const SHVec2& vMax) noexcept; [[nodiscard]] static SHVec2 Lerp (const SHVec2& a, const SHVec2& b, float t) noexcept; [[nodiscard]] static SHVec2 ClampedLerp (const SHVec2& a, const SHVec2& b, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept; [[nodiscard]] static float Distance (const SHVec2& lhs, const SHVec2& rhs) noexcept; [[nodiscard]] static float DistanceSquared (const SHVec2& lhs, const SHVec2& rhs) noexcept; [[nodiscard]] static float Angle (const SHVec2& lhs, const SHVec2& rhs) noexcept; [[nodiscard]] static float Dot (const SHVec2& lhs, const SHVec2& rhs) noexcept; [[nodiscard]] static SHVec2 Project (const SHVec2& v, const SHVec2& u) noexcept; [[nodiscard]] static SHVec2 Reflect (const SHVec2& v, const SHVec2& normal) noexcept; [[nodiscard]] static SHVec2 Rotate (const SHVec2& v, float angleInRad) noexcept; [[nodiscard]] static SHVec2 Transform (const SHVec2& v, const SHMatrix& transformMtx) noexcept; [[nodiscard]] static SHVec2 Cross (float lhs, const SHVec2& rhs) noexcept; [[nodiscard]] static SHVec2 Cross (const SHVec2& lhs, float rhs) noexcept; [[nodiscard]] static float Cross (const SHVec2& lhs, const SHVec2& rhs) noexcept; }; SHVec2 operator* (float lhs, const SHVec2& rhs) noexcept; } // namespace SHADE