diff --git a/SHADE_Managed/SHADE_Managed.vcxproj.filters b/SHADE_Managed/SHADE_Managed.vcxproj.filters new file mode 100644 index 00000000..86a64c06 --- /dev/null +++ b/SHADE_Managed/SHADE_Managed.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {DBC7D3B0-C769-FE86-B024-12DB9C6585D7} + + + {AFF4887C-9B2B-8A0D-4418-7010302E060F} + + + {4D6F1AE8-B94E-9983-C266-245A2EC5FFE4} + + + + + Engine + + + Math + + + Math + + + Math + + + + + + Engine + + + Math + + + Math + + + Math + + + + \ No newline at end of file diff --git a/SHADE_Managed/premake5.lua b/SHADE_Managed/premake5.lua index 55ab382c..61f42fc2 100644 --- a/SHADE_Managed/premake5.lua +++ b/SHADE_Managed/premake5.lua @@ -16,6 +16,10 @@ project "SHADE_Managed" "%{prj.location}/src/**.hxx", "%{prj.location}/src/**.h++", "%{prj.location}/src/**.cxx", + "%{prj.location}/src/**.h", + "%{prj.location}/src/**.hpp", + "%{prj.location}/src/**.c", + "%{prj.location}/src/**.cpp", } includedirs diff --git a/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.cxx b/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.cxx new file mode 100644 index 00000000..7ee674a4 --- /dev/null +++ b/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.cxx @@ -0,0 +1,36 @@ +/************************************************************************************//*! +\file DisposableAssemblyLoadContext.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Jan 20, 2022 +\brief Contains the implementation of the managed DisposableAssemblyLoadContext + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "DisposableAssemblyLoadContext.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructor */ + /*---------------------------------------------------------------------------------*/ + DisposableAssemblyLoadContext::DisposableAssemblyLoadContext() + : AssemblyLoadContext { true } + {} + + /*---------------------------------------------------------------------------------*/ + /* Helper Functions */ + /*---------------------------------------------------------------------------------*/ + System::Reflection::Assembly^ DisposableAssemblyLoadContext::Load(System::Reflection::AssemblyName^ assemblyName) + { + return nullptr; + } +} // namespace PlushieAPI \ No newline at end of file diff --git a/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.hxx b/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.hxx new file mode 100644 index 00000000..433dd85e --- /dev/null +++ b/SHADE_Managed/src/Engine/DisposableAssemblyLoadContext.hxx @@ -0,0 +1,39 @@ +/************************************************************************************//*! +\file DisposableAssemblyLoadContext.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Jan 20, 2022 +\brief Contains the definitions of the managed DisposableAssemblyLoadContext + class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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 + +namespace SHADE +{ + /// + /// Custom AssemblyLoadContext marked as collectible so that it can be unloaded. + /// + private ref class DisposableAssemblyLoadContext : public System::Runtime::Loader::AssemblyLoadContext + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constructor */ + /*-----------------------------------------------------------------------------*/ + /// + /// Default Constructor + /// + DisposableAssemblyLoadContext(); + + protected: + /*-----------------------------------------------------------------------------*/ + /* Helper Functions */ + /*-----------------------------------------------------------------------------*/ + System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override; + }; +} // namespace PlushieAPI \ No newline at end of file diff --git a/SHADE_Managed/src/Math/Math.cxx b/SHADE_Managed/src/Math/Math.cxx new file mode 100644 index 00000000..5ec850a1 --- /dev/null +++ b/SHADE_Managed/src/Math/Math.cxx @@ -0,0 +1,57 @@ +/************************************************************************************//*! +\file Math.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 11, 2021 +\brief Contains the implementation of the functions of the managed Math struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Math/Math.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Utility Functions */ + /*---------------------------------------------------------------------------------*/ + double Math::Wrap(double value, double min, double max) + { + while (value < min) + { + value = max - (min - value); + } + while (value > max) + { + value = min + (value - max); + } + return value; + } + double Math::DegreesToRadians(double degrees) + { + return degrees * Deg2Rad; + } + double Math::RadiansToDegrees(double radians) + { + return radians * Rad2Deg; + } + double Math::Lerp(double a, double b, double t) + { + return LerpUnclamped(a, b, System::Math::Clamp(t, 0.0, 1.0)); + } + double Math::LerpUnclamped(double a, double b, double t) + { + return a + t * (b - a); + } + + double Math::InverseLerp(double a, double b, double value) + { + return (value - a) / (b - a); + } +} diff --git a/SHADE_Managed/src/Math/Math.hxx b/SHADE_Managed/src/Math/Math.hxx new file mode 100644 index 00000000..3ddc5149 --- /dev/null +++ b/SHADE_Managed/src/Math/Math.hxx @@ -0,0 +1,92 @@ +/************************************************************************************//*! +\file Math.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 11, 2021 +\brief Contains the definition of the managed Math static class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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 + +namespace SHADE +{ + /// + /// Contains utility Math functions. + /// + public ref class Math abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Static Constants */ + /*-----------------------------------------------------------------------------*/ + /// + /// Degrees-to-radians conversion constant + /// + static constexpr double Deg2Rad = System::Math::PI / 180.0; + /// + /// Radians-to-degrees conversion constant + /// + static constexpr double Rad2Deg = 180.0 / System::Math::PI; + /// + /// Small value used for single precision floating point comparisons. + /// + static constexpr float Epsilon = 0.001f; + + /*-----------------------------------------------------------------------------*/ + /* Utility Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Wraps a value if they get to low or too high. + /// + /// Value to wrap. + /// Minimum value to wrap at. + /// Maximum value to wrap at. + /// Wrapped value. + static double Wrap(double value, double min, double max); + /// + /// Converts an angle from degree representation to radian representation. + /// + /// Degree-based angle to convert. + /// The specified angle in radians. + static double DegreesToRadians(double degrees); + /// + /// Converts an angle from radian representation to degree representation. + /// + /// Radian-based angle to convert. + /// The specified angle in degrees. + static double RadiansToDegrees(double radians); + /// + /// Linearly interpolates between a and b by t. + /// The parameter t is clamped to the range [0, 1]. + /// + /// The start value. + /// The end value. + /// The interpolation value between the two double. + /// The interpolated double result between the two double values. + static double Lerp(double a, double b, double t); + /// + /// Linearly interpolates between a and b by t. + /// The parameter t is not clamped and a value based on a and b is supported. + /// If t is less than zero, or greater than one, then LerpUnclamped will result + /// in a return value outside the range a to b. + /// + /// The start value. + /// The end value. + /// The interpolation value between the two double. + /// The interpolated double result between the two double values. + static double LerpUnclamped(double a, double b, double t); + /// + /// Calculates the linear parameter t that produces the interpolant value within the range [a, b]. + /// + /// Start value. + /// End value. + /// Value between start and end. + /// Percentage of value between start and end. + static double InverseLerp(double a, double b, double value); + }; +} diff --git a/SHADE_Managed/src/Math/Vector2.cxx b/SHADE_Managed/src/Math/Vector2.cxx new file mode 100644 index 00000000..276c6ea8 --- /dev/null +++ b/SHADE_Managed/src/Math/Vector2.cxx @@ -0,0 +1,266 @@ +/************************************************************************************//*! +\file Vector2.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 2, 2021 +\brief Contains the definitions of functions of the Vector2 struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Math/Vector2.hxx" +// Standard Libraries +#include +#include +// Project Headers +#include "Math.hxx" +// Undefinitions +#undef min +#undef max + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Vector2::Vector2(double _x) + : Vector2 { _x, 0.0 } + {} + Vector2::Vector2(double _x, double _y) + : x { _x } + , y { _y } + {} + + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + void Vector2::Normalise() + { + *this = GetNormalised(); + } + + Vector2 Vector2::GetNormalised() + { + return *this / GetMagnitude(); + } + + double Vector2::GetMagnitude() + { + return sqrt(x * x + y * y); + } + + double Vector2::GetSqrMagnitude() + { + return x * x + y * y; + } + + double Vector2::AngleFromRightRadians() + { + return atan2(y, x); + } + + double Vector2::AngleFromRightDegrees() + { + return Math::RadiansToDegrees(AngleFromRightRadians()); + } + + bool Vector2::IsNearPoint(Vector2 point) + { + return IsNearPoint(point, Math::Epsilon); + } + + bool Vector2::IsNearPoint(Vector2 point, double tolerance) + { + return (*this - point).GetSqrMagnitude() < (tolerance * tolerance); + } + + /*---------------------------------------------------------------------------------*/ + /* IEquatable */ + /*---------------------------------------------------------------------------------*/ + bool Vector2::Equals(Object^ o) + { + try + { + Vector2 vec = safe_cast(o); + return Equals(vec); + } + catch (System::InvalidCastException^) + { + return false; + } + } + + /*---------------------------------------------------------------------------------*/ + /* Object Overrides */ + /*---------------------------------------------------------------------------------*/ + bool Vector2::Equals(Vector2 other) + { + return IsNear(*this, other); + } + int Vector2::GetHashCode() + { + const int HASH = 19; + return x.GetHashCode() * HASH + y.GetHashCode(); + } + + /*---------------------------------------------------------------------------------*/ + /* Static Functions */ + /*---------------------------------------------------------------------------------*/ + bool Vector2::IsNear(Vector2 lhs, Vector2 rhs) + { + return IsNear(lhs, rhs, Math::Epsilon); + } + bool Vector2::IsNear(Vector2 lhs, Vector2 rhs, double tolerance) + { + return (std::abs(lhs.x) - std::abs(rhs.x)) < tolerance + && + (std::abs(lhs.y) - std::abs(rhs.y)) < tolerance; + } + double Vector2::Dot(Vector2 lhs, Vector2 rhs) + { + return lhs.x * rhs.x + lhs.y * rhs.y; + } + + Vector2 Vector2::Perpendicular(Vector2 lhs) + { + return Perpendicular(lhs, true); + } + + Vector2 Vector2::Perpendicular(Vector2 lhs, bool inward) + { + if (inward) + { + return Vector2 + ( + -lhs.y, lhs.x + ); + } + else + { + return Vector2 + ( + lhs.y, -lhs.x + ); + } + } + + Vector2 Vector2::Project(Vector2 vec, Vector2 direction) + { + return direction.GetNormalised() * vec.GetMagnitude(); + } + Vector2 Vector2::Reflect(Vector2 vec, Vector2 normal) + { + return vec - (Project(vec, normal.GetNormalised()) * 2.0); + } + Vector2 Vector2::RotateRadians(Vector2 vec, double radians) + { + const double SINE = sin(radians); + const double COSINE = cos(radians); + + return Vector2 + ( + vec.x * COSINE - vec.y * SINE, + vec.x * SINE + vec.y * COSINE + ); + } + Vector2 Vector2::RotateDegrees(Vector2 vec, double degrees) + { + return RotateRadians(vec, Math::DegreesToRadians(degrees)); + } + Vector2 Vector2::Min(Vector2 lhs, Vector2 rhs) + { + double lx = lhs.x, rx = rhs.x; + double ly = lhs.y, ry = rhs.y; + + return Vector2(std::min(lx, rx), + std::min(ly, ry)); + } + Vector2 Vector2::Max(Vector2 lhs, Vector2 rhs) + { + double lx = lhs.x, rx = rhs.x; + double ly = lhs.y, ry = rhs.y; + + return Vector2(std::max(lx, rx), + std::max(ly, ry)); + } + Vector2 Vector2::Lerp(Vector2 a, Vector2 b, double t) + { + return LerpUnclamped(a, b, std::clamp(t, 0.0, 1.0)); + } + Vector2 Vector2::LerpUnclamped(Vector2 a, Vector2 b, double t) + { + return a + ((b - a) * t); + } + Vector2 Vector2::MoveTowards(Vector2 current, Vector2 target, double maxDistanceDelta) + { + // Ignore if it is exactly on the same point + if (current == target) + return target; + + // Calculate new position + const Vector2 DELTA = (target - current).GetNormalised() * maxDistanceDelta; + Vector2 newPos = current + DELTA; + + // Check if check if is behind or ahead of target + const Vector2 DIFF = target - newPos; + if (Dot(DELTA, DIFF) < 0.0) + { + newPos = target; + } + return newPos; + } + Vector2 Vector2::operator+(Vector2 lhs, Vector2 rhs) + { + return Vector2 + ( + lhs.x + rhs.x, + lhs.y + rhs.y + ); + } + Vector2 Vector2::operator-(Vector2 lhs, Vector2 rhs) + { + return Vector2 + ( + lhs.x - rhs.x, + lhs.y - rhs.y + ); + } + Vector2 Vector2::operator*(Vector2 lhs, Vector2 rhs) + { + return Vector2 + ( + lhs.x * rhs.x, + lhs.y * rhs.y + ); + } + Vector2 Vector2::operator*(Vector2 lhs, double rhs) + { + return Vector2 + ( + lhs.x * rhs, + lhs.y * rhs + ); + } + Vector2 Vector2::operator/(Vector2 lhs, double rhs) + { + return Vector2 + ( + lhs.x / rhs, + lhs.y / rhs + ); + } + bool Vector2::operator==(Vector2 lhs, Vector2 rhs) + { + return lhs.Equals(rhs); + } + bool Vector2::operator!=(Vector2 lhs, Vector2 rhs) + { + return !(lhs == rhs); + } +} // namespace PlushieAPI::Mathematics \ No newline at end of file diff --git a/SHADE_Managed/src/Math/Vector2.hxx b/SHADE_Managed/src/Math/Vector2.hxx new file mode 100644 index 00000000..c52cdc72 --- /dev/null +++ b/SHADE_Managed/src/Math/Vector2.hxx @@ -0,0 +1,398 @@ +/************************************************************************************//*! +\file Vector2.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Nov 2, 2021 +\brief Contains the definitions of Vector2 struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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 + +// Standard Libraries +#include + +namespace SHADE +{ + /// + /// CLR version of the the PlushieEngine's Vector2 class that represents a + /// 2-Dimensional Vector. Designed to closely match Unity's Vector2 struct. + /// + [StructLayout(LayoutKind::Sequential)] + public value struct Vector2 : public System::IEquatable + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ + #pragma region Constants + /// + /// Shorthand for writing Vector2(0, -1). + /// + static const Vector2 Down = Vector2(0.0, -1.0); + /// + /// Shorthand for writing Vector2(-1, 0). + /// + static const Vector2 Left = Vector2(-1.0, 0.0); + /// + /// Shorthand for writing Vector2(double.NegativeInfinity, + /// double.NegativeInfinity). + /// + static const Vector2 NegativeInfinity = Vector2(std::numeric_limits::lowest(), + std::numeric_limits::lowest()); + /// + /// Shorthand for writing Vector2(1, 1). + /// + static const Vector2 One = Vector2(1.0, 1.0); + /// + /// Shorthand for writing Vector2(double.PositiveInfinity, + /// double.PositiveInfinity). + /// + static const Vector2 PositiveInfinity = Vector2(std::numeric_limits::max(), + std::numeric_limits::max()); + /// + /// Shorthand for writing Vector2(1, 0). + /// + static const Vector2 Right = Vector2(1.0, 0.0); + /// + /// Shorthand for writing Vector2(0, 1). + /// + static const Vector2 Up = Vector2(0.0, 1.0); + /// + /// Shorthand for writing Vector2(0, 0). + /// + static const Vector2 Zero = Vector2(0.0, 0.0); + #pragma endregion + + /*-----------------------------------------------------------------------------*/ + /* Public Members */ + /*-----------------------------------------------------------------------------*/ + /// + /// X-component of the Vector2. + /// + double x; + /// + /// Y-component of the Vector2. + /// + double y; + + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor to construct a Vector2 with the specified components with the + /// Y-component set to 0.0. + /// + /// X-coordinate to set. + Vector2(double _x); + /// + /// Constructor to construct a Vector2 with the specified components.. + /// + /// X-coordinate to set. + /// Y-coordinate to set. + Vector2(double _x, double _y); + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Normalises this current Vector2. This changes the data of this Vector2. + /// If you would like to get a copy, use GetNormalised() instead. + /// This function does nothing to a zero vector. + /// + void Normalise(); + /// + /// Creates a copy of this Vector2 and returns a normalized version. + /// + /// + /// Returns a normalised copy of this Vector2. + /// If this Vector2 is a zero vector, a zero vector will be returned. + /// + Vector2 GetNormalised(); + /// + /// Calculates and returns the magnitude of this Vector2. Note that this function + /// incurs a performance cost from the square root calculation. If you do not + /// need the precise magnitude, consider using GetSqrMagnitude() instead. + /// + /// Returns the length of this Vector2. + double GetMagnitude(); + /// + /// Calculates and returns the squared magnitude of this Vector2. + /// + /// Returns the squared length of this Vector2. + double GetSqrMagnitude(); + /// + /// Calculates and returns the angle of this vector from the right vector. This + /// function returns values between -Math.PI and Math.PI. + /// + /// Returns the angle of this vector from the right vector in radians. + double AngleFromRightRadians(); + /// + /// Calculates and returns the angle of this vector from the right vector. This + /// function returns values between -180.0 and 180.0. + /// + /// Returns the angle of this vector from the right vector in degrees. + double AngleFromRightDegrees(); + /// + /// Checks if a specified point is near this Vector2 that represents a point with + /// a tolerance value of PLS_EPSILON. + /// + /// The other point to check if we are near. + /// + /// True if this Vector2 representing a point and the specified point are within + /// the range of the specified tolerance. False otherwise. + /// + bool IsNearPoint(Vector2 point); + /// + /// Checks if a specified point is near this Vector2 that represents a point. + /// + /// The other point to check if we are near. + /// + /// The amount of tolerance before we consider these points as "near". + /// + /// + /// True if this Vector2 representing a point and the specified point are within + /// the range of the specified tolerance. False otherwise. + /// + bool IsNearPoint(Vector2 point, double tolerance); + + /*-----------------------------------------------------------------------------*/ + /* IEquatable */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with an object of the same type. + /// + /// The object to compare with. + /// True if both objects are the same. + virtual bool Equals(Vector2 other); + + /*-----------------------------------------------------------------------------*/ + /* Object */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with another unboxed object. + /// + /// The unboxed object to compare with. + /// True if both objects are the same. + bool Equals(Object^ o) override; + /// + /// Gets a unique hash for this object. + /// + /// Unique hash for this object. + int GetHashCode() override; + + /*-----------------------------------------------------------------------------*/ + /* Static Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Checks if two specified Vector2s are near in value. + /// + /// Vector2 to check if is near in value. + /// Another Vector2 to check if is near in value. + /// + /// True if the two Vector2s are within the tolerance value specified + /// + static bool IsNear(Vector2 lhs, Vector2 rhs); + /// + /// Checks if two specified Vector2s are near in value. + /// + /// Vector2 to check if is near in value. + /// Another Vector2 to check if is near in value. + /// + /// Amount of tolerance to do the comparison with. + /// + /// + /// True if the two Vector2s are within the tolerance value specified + /// + static bool IsNear(Vector2 lhs, Vector2 rhs, double tolerance); + /// + /// Computes and returns the dot product of 2 specified Vector2s. + /// + /// Vector2 to calculate dot product with. + /// Another Vector2 to calculate dot product with. + /// + /// Scalar value representing the dot product of the two Vector2s. + /// + static double Dot(Vector2 lhs, Vector2 rhs); + /// + /// Computes the inward perpendicular Vector2 to the specified Vector2. + /// Equivalent to calling Perpendicular(lhs, true). This means, the + /// resultant Vector2 is rotated 90-degrees in a counter-clockwise. + /// + /// Vector2 to find a perpendicular of. + /// + /// The perpendicular Vector2 relative to the specified Vector2. + /// + static Vector2 Perpendicular(Vector2 lhs); + /// + /// Computes a perpendicular Vector2 to the specified Vector2. + /// + /// Vector2 to find a perpendicular of. + /// + /// Whether the inward perpendicular Vector is retrieved. If true, the + /// resultant vector is rotated 90-degrees in a counter-clockwise. + /// + /// The perpendicular Vector2 relative to the specified Vector2. + /// + static Vector2 Perpendicular(Vector2 lhs, bool inward); + /// + /// Computes and returns a Vector2 projection. + /// + /// Vector2 to project. + /// Vector2 to project onto. + /// The Vector2 that represents the projected vec onto direction. + static Vector2 Project(Vector2 vec, Vector2 direction); + /// + /// Reflects a Vector2 across another Vector2. + /// + /// A Vector2 to reflect. + /// A normal to reflect the Vector2 across. + /// The Vector2 that represents vec reflected across normal. + static Vector2 Reflect(Vector2 vec, Vector2 normal); + /// + /// Rotates a Vector2 on the Z-axis by a specified angle in an anti-clockwise + /// direction. + /// + /// A Vector2 to rotate. + /// + /// Angle to rotate the vector by in an anti-clockwise direction in radians. + /// + /// The Vector2 that represents the rotated vector. + static Vector2 RotateRadians(Vector2 vec, double radians); + /// + /// Rotates a Vector2 on the Z-axis by a specified angle in an anti-clockwise + /// direction. + /// + /// A Vector2 to rotate. + /// + /// Angle to rotate the vector by in an anti-clockwise direction in degrees. + /// + /// The Vector2 that represents the rotated vector. + static Vector2 RotateDegrees(Vector2 vec, double degrees); + /// + /// Computes and returns a Vector2 that is made from the smallest components of + /// the two specified Vector2s. + /// + /// Vector2 to calculate minimum Vector2 with. + /// Another Vector2 to calculate minimum Vector2 with. + /// + /// The Vector2 that contains the smallest components of the two specified + /// Vector2s. + /// + static Vector2 Min(Vector2 lhs, Vector2 rhs); + /// + /// Computes and returns a Vector2 that is made from the largest components of + /// the two specified Vector2s. + /// + /// Vector2 to calculate maximum Vector2 with. + /// Another Vector2 to calculate maximum Vector2 with. + /// + /// The Vector2 that contains the largest components of the two specified + /// Vector2s. + /// + static Vector2 Max(Vector2 lhs, Vector2 rhs); + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// + /// The start Vector2, returned when t = 0.0. + /// The end Vector2, returned when t = 1.0. + /// + /// Value used to interpolate between a and b which is clamped to + /// the range[0, 1]. + /// + /// The interpolated Vector2. + static Vector2 Lerp(Vector2 a, Vector2 b, double t); + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// Unlike Lerp(), t is not clamped to a range at all. + /// + /// The start Vector2, returned when t = 0.0. + /// The end Vector2, returned when t = 1.0. + /// Value used to interpolate between a and b. + /// The interpolated Vector2. + static Vector2 LerpUnclamped(Vector2 a, Vector2 b, double t); + /// + /// Moves a point current towards target. + /// Similar to Lerp(), however, the function will ensure that the distance never + /// exceeds maxDistanceDelta. Negative values of maxDistanceDelta pushes the + /// vector away from target + /// + /// The current position of the point. + /// The target position to move to. + /// Maximum distance moved per call. + /// Vector representing the moved point. + static Vector2 MoveTowards(Vector2 current, Vector2 target, double maxDistanceDelta); + + /*-----------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Adds two Vector2s together and returns the result. + /// + /// Vector2 to add. + /// Another Vector2 to add. + /// The result of lhs added to rhs + static Vector2 operator+(Vector2 lhs, Vector2 rhs); + /// + /// Subtracts a Vector2 from another Vector2 and returns the result. + /// + /// Vector2 to subtract from. + /// Another Vector2 to subtract. + /// The result of rhs subtracted from lhs. + static Vector2 operator-(Vector2 lhs, Vector2 rhs); + /// + /// Calculates the component-wise multiplication of two Vector2s and returns the + /// result. + /// + /// Vector2 to multiply with. + /// Another Vector2 to multiply with. + /// The result of rhs subtracted from lhs. + static Vector2 operator*(Vector2 lhs, Vector2 rhs); + /// + /// Calculates the multiplication of a Vector2 with a scalar value and returns + /// the result. + /// + /// Vector2 to multiply with. + /// Scalar to multiply with. + /// The result of the scalar multiplication. + static Vector2 operator*(Vector2 lhs, double rhs); + /// + /// Calculates the division of a Vector2 with a scalar value and returns + /// the result. + /// + /// Scalar to divide with. + /// Vector2 to divide with. + /// The result of the scalar division. + static Vector2 operator/(Vector2 lhs, double rhs); + /// + /// Checks if two Vector2s are approximately equal. This is equivalent to + /// calling Vector2.IsNear() with default tolerance values. + /// + /// Vector2 to compare. + /// Another Vector2 to compare. + /// + /// True if all components are approximately equal within the default + /// tolerance value. + /// + static bool operator==(Vector2 lhs, Vector2 rhs); + /// + /// Checks if two Vector2s are not approximately equal. This is equivalent to + /// calling !Vector2.IsNear() with default tolerance values. + /// + /// Vector2 to compare. + /// Another Vector2 to compare. + /// + /// True if all components are not approximately equal within the default + /// tolerance value. + /// + static bool operator!=(Vector2 lhs, Vector2 rhs); + }; +} diff --git a/SHADE_Managed/src/Math/Vector3.cxx b/SHADE_Managed/src/Math/Vector3.cxx new file mode 100644 index 00000000..4f8ea8b0 --- /dev/null +++ b/SHADE_Managed/src/Math/Vector3.cxx @@ -0,0 +1,281 @@ +/************************************************************************************//*! +\file Vector3.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 24, 2021 +\brief Contains the definitions of functions of the Vector3 struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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. +*//*************************************************************************************/ +// Precompiled Headers +#include "SHpch.h" +// Primary Header +#include "Vector3.hxx" +// Standard Libraries +#include +#include +// Project Headers +#include "Math.hxx" +// Undefinitions +#undef min +#undef max + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Constructors */ + /*---------------------------------------------------------------------------------*/ + Vector3::Vector3(double _x) + : Vector3 {_x, 0.0, 0.0} + {} + Vector3::Vector3(double _x, double _y) + : Vector3 {_x, _y, 0.0} + {} + Vector3::Vector3(double _x, double _y, double _z) + : x { _x } + , y { _y } + , z { _z } + {} + Vector3::Vector3(Vector2 vec) + : Vector3(vec.x, vec.y) + {} + + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + void Vector3::Normalise() + { + *this = GetNormalised(); + } + + Vector3 Vector3::GetNormalised() + { + return *this / GetSqrMagnitude(); + } + + double Vector3::GetMagnitude() + { + return sqrt(x * x + y * y + z * z); + } + + double Vector3::GetSqrMagnitude() + { + return x * x + y * y + z * z; + } + + double Vector3::Angle2DFromRightRadians() + { + return atan2(y, x); + } + + double Vector3::Angle2DFromRightDegrees() + { + return Math::RadiansToDegrees(Angle2DFromRightRadians()); + } + + bool Vector3::IsNearPoint(Vector3 point) + { + return IsNearPoint(point, Math::Epsilon); + } + + bool Vector3::IsNearPoint(Vector3 point, double tolerance) + { + return (*this - point).GetSqrMagnitude() < (tolerance * tolerance); + } + + /*---------------------------------------------------------------------------------*/ + /* IEquatable */ + /*---------------------------------------------------------------------------------*/ + bool Vector3::Equals(Object^ o) + { + try + { + Vector3 vec = safe_cast(o); + return Equals(vec); + } + catch (System::InvalidCastException^) + { + return false; + } + } + + /*---------------------------------------------------------------------------------*/ + /* Object Overrides */ + /*---------------------------------------------------------------------------------*/ + bool Vector3::Equals(Vector3 other) + { + return IsNear(*this, other); + } + int Vector3::GetHashCode() + { + const int HASH = 19; + const int HASH2 = 23; + return x.GetHashCode() * HASH + y.GetHashCode() * HASH2 + z.GetHashCode(); + } + + /*---------------------------------------------------------------------------------*/ + /* Static Functions */ + /*---------------------------------------------------------------------------------*/ + bool Vector3::IsNear(Vector3 lhs, Vector3 rhs) + { + return IsNear(lhs, rhs, Math::Epsilon); + } + bool Vector3::IsNear(Vector3 lhs, Vector3 rhs, double tolerance) + { + return (std::abs(lhs.x) - std::abs(rhs.x)) < tolerance + && + (std::abs(lhs.y) - std::abs(rhs.y)) < tolerance + && + (std::abs(lhs.z) - std::abs(rhs.z)) < tolerance; + } + double Vector3::Dot(Vector3 lhs, Vector3 rhs) + { + return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z; + } + Vector3 Vector3::Cross(Vector3 lhs, Vector3 rhs) + { + return Vector3(lhs.y * rhs.z - lhs.z * rhs.y, + lhs.z * rhs.x - lhs.x * rhs.z, + lhs.x * rhs.y - lhs.y * rhs.x); + } + Vector3 Vector3::Project(Vector3 vec, Vector3 direction) + { + return direction.GetNormalised() * vec.GetMagnitude(); + } + Vector3 Vector3::Reflect(Vector3 vec, Vector3 normal) + { + return vec - (Project(vec, normal.GetNormalised()) * 2.0); + } + Vector3 Vector3::RotateRadians(Vector3 vec, double radians) + { + const double SINE = sin(radians); + const double COSINE = cos(radians); + + return Vector3 + ( + vec.x * COSINE - vec.y * SINE, + vec.x * SINE + vec.y * COSINE, + vec.z + ); + } + Vector3 Vector3::RotateDegrees(Vector3 vec, double degrees) + { + return RotateRadians(vec, Math::DegreesToRadians(degrees)); + } + Vector3 Vector3::Min(Vector3 lhs, Vector3 rhs) + { + double lx = lhs.x, rx = rhs.x; + double ly = lhs.y, ry = rhs.y; + double lz = lhs.z, rz = rhs.z; + + return Vector3(std::min(lx, rx), + std::min(ly, ry), + std::min(lz, rz)); + } + Vector3 Vector3::Max(Vector3 lhs, Vector3 rhs) + { + double lx = lhs.x, rx = rhs.x; + double ly = lhs.y, ry = rhs.y; + double lz = lhs.z, rz = rhs.z; + + return Vector3(std::max(lx, rx), + std::max(ly, ry), + std::max(lz, rz)); + } + Vector3 Vector3::Lerp(Vector3 a, Vector3 b, double t) + { + return LerpUnclamped(a, b, std::clamp(t, 0.0, 1.0)); + } + Vector3 Vector3::LerpUnclamped(Vector3 a, Vector3 b, double t) + { + return a + ((b - a) * t); + } + Vector3 Vector3::MoveTowards(Vector3 current, Vector3 target, double maxDistanceDelta) + { + // Ignore if it is exactly on the same point + if (current == target) + return target; + + // Calculate new position + const Vector3 DELTA = (target - current).GetNormalised() * maxDistanceDelta; + Vector3 newPos = current + DELTA; + + // Check if check if is behind or ahead of target + const Vector3 DIFF = target - newPos; + if (Dot(DELTA, DIFF) < 0.0) + { + newPos = target; + } + return newPos; + } + Vector3 Vector3::operator+(Vector3 lhs, Vector3 rhs) + { + return Vector3 + ( + lhs.x + rhs.x, + lhs.y + rhs.y, + lhs.z + rhs.z + ); + } + Vector3 Vector3::operator-(Vector3 lhs, Vector3 rhs) + { + return Vector3 + ( + lhs.x - rhs.x, + lhs.y - rhs.y, + lhs.z - rhs.z + ); + } + Vector3 Vector3::operator*(Vector3 lhs, Vector3 rhs) + { + return Vector3 + ( + lhs.x * rhs.x, + lhs.y * rhs.y, + lhs.z * rhs.z + ); + } + Vector3 Vector3::operator*(Vector3 lhs, double rhs) + { + return Vector3 + ( + lhs.x * rhs, + lhs.y * rhs, + lhs.z * rhs + ); + } + Vector3 Vector3::operator/(Vector3 lhs, double rhs) + { + return Vector3 + ( + lhs.x / rhs, + lhs.y / rhs, + lhs.z / rhs + ); + } + bool Vector3::operator==(Vector3 lhs, Vector3 rhs) + { + return lhs.Equals(rhs); + } + bool Vector3::operator!=(Vector3 lhs, Vector3 rhs) + { + return !(lhs == rhs); + } + + /*---------------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*---------------------------------------------------------------------------------*/ + Vector3::operator Vector2(Vector3 vec) + { + return Vector2(vec.x, vec.y); + } + + Vector3::operator Vector3(Vector2 vec) + { + return Vector3(vec); + } +} // namespace PlushieAPI::Mathematics \ No newline at end of file diff --git a/SHADE_Managed/src/Math/Vector3.hxx b/SHADE_Managed/src/Math/Vector3.hxx new file mode 100644 index 00000000..ab05ddc9 --- /dev/null +++ b/SHADE_Managed/src/Math/Vector3.hxx @@ -0,0 +1,425 @@ +/************************************************************************************//*! +\file Vector3.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 24, 2021 +\brief Contains the definitions of Vector3 struct. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2021 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 + +// Standard Libraries +#include +// Project Includes +#include "Vector2.hxx" + +namespace SHADE +{ + /// + /// CLR version of the the PlushieEngine's Vector3 class that represents a + /// 3-Dimensional Vector. Designed to closely match Unity's Vector3 struct. + /// + [StructLayout(LayoutKind::Sequential)] + public value struct Vector3 : public System::IEquatable + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constants */ + /*-----------------------------------------------------------------------------*/ + #pragma region Constants + /// + /// Shorthand for writing Vector3(0, 0, -1). + /// + static const Vector3 Back = Vector3(0.0, 0.0, -1.0); + /// + /// Shorthand for writing Vector3(0, -1, 0). + /// + static const Vector3 Down = Vector3(0.0, -1.0, 0.0); + /// + /// Shorthand for writing Vector3(0, 0, 1). + /// + static const Vector3 Forward = Vector3(0.0, 0.0, 1.0); + /// + /// Shorthand for writing Vector3(-1, 0, 0). + /// + static const Vector3 Left = Vector3(-1.0, 0.0, 0.0); + /// + /// Shorthand for writing Vector3(double.NegativeInfinity, + /// double.NegativeInfinity, double.NegativeInfinity). + /// + static const Vector3 NegativeInfinity = Vector3(std::numeric_limits::lowest(), + std::numeric_limits::lowest(), + std::numeric_limits::lowest()); + /// + /// Shorthand for writing Vector3(1, 1, 1). + /// + static const Vector3 One = Vector3(1.0, 1.0, 1.0); + /// + /// Shorthand for writing Vector3(double.PositiveInfinity, + /// double.PositiveInfinity, double.PositiveInfinity). + /// + static const Vector3 PositiveInfinity = Vector3(std::numeric_limits::max(), + std::numeric_limits::max(), + std::numeric_limits::max()); + /// + /// Shorthand for writing Vector3(1, 0, 0). + /// + static const Vector3 Right = Vector3(1.0, 0.0, 0.0); + /// + /// Shorthand for writing Vector3(0, 1, 0). + /// + static const Vector3 Up = Vector3(0.0, 1.0, 0.0); + /// + /// Shorthand for writing Vector3(0, 0, 0). + /// + static const Vector3 Zero = Vector3(0.0, 0.0, 0.0); + #pragma endregion + + /*-----------------------------------------------------------------------------*/ + /* Public Members */ + /*-----------------------------------------------------------------------------*/ + /// + /// X-component of the Vector3. + /// + double x; + /// + /// Y-component of the Vector3. + /// + double y; + /// + /// Z-component of the Vector3. + /// + double z; + + /*-----------------------------------------------------------------------------*/ + /* Constructors */ + /*-----------------------------------------------------------------------------*/ + /// + /// Constructor to construct a Vector3 with the specified components with the + /// Y and Z-component set to 0.0. + /// + /// X-coordinate to set. + Vector3(double _x); + /// + /// Constructor to construct a Vector3 with the specified components with the + /// Z-component set to 0.0. + /// + /// X-coordinate to set. + /// Y-coordinate to set. + Vector3(double _x, double _y); + /// + /// Constructor to construct a Vector3 with the specified components. + /// + /// X-coordinate to set. + /// Y-coordinate to set. + /// Z-coordinate to set. + Vector3(double _x, double _y, double _z); + /// + /// Conversion constructor to construct a Vector3 using a Vector2. + /// + /// + Vector3(Vector2 vec); + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Normalises this current Vector3. This changes the data of this Vector3. + /// If you would like to get a copy, use GetNormalised() instead. + /// This function does nothing to a zero vector. + /// + void Normalise(); + /// + /// Creates a copy of this Vector3 and returns a normalized version. + /// + /// + /// Returns a normalised copy of this Vector3. + /// If this Vector3 is a zero vector, a zero vector will be returned. + /// + Vector3 GetNormalised(); + /// + /// Calculates and returns the magnitude of this Vector3. Note that this function + /// incurs a performance cost from the square root calculation. If you do not + /// need the precise magnitude, consider using GetSqrMagnitude() instead. + /// + /// Returns the length of this Vector3. + double GetMagnitude(); + /// + /// Calculates and returns the squared magnitude of this Vector3. + /// + /// Returns the squared length of this Vector3. + double GetSqrMagnitude(); + /// + /// Calculates and returns the angle of this vector from the right vector. This + /// function returns values between -Math.PI and Math.PI. + /// + /// Returns the angle of this vector from the right vector in radians. + double Angle2DFromRightRadians(); + /// + /// Calculates and returns the angle of this vector from the right vector. This + /// function returns values between -180.0 and 180.0. + /// + /// Returns the angle of this vector from the right vector in degrees. + double Angle2DFromRightDegrees(); + /// + /// Checks if a specified point is near this Vector3 that represents a point with + /// a tolerance value of PLS_EPSILON. + /// + /// The other point to check if we are near. + /// + /// True if this Vector3 representing a point and the specified point are within + /// the range of the specified tolerance. False otherwise. + /// + bool IsNearPoint(Vector3 point); + /// + /// Checks if a specified point is near this Vector3 that represents a point. + /// + /// The other point to check if we are near. + /// + /// The amount of tolerance before we consider these points as "near". + /// + /// + /// True if this Vector3 representing a point and the specified point are within + /// the range of the specified tolerance. False otherwise. + /// + bool IsNearPoint(Vector3 point, double tolerance); + + /*-----------------------------------------------------------------------------*/ + /* IEquatable */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with an object of the same type. + /// + /// The object to compare with. + /// True if both objects are the same. + virtual bool Equals(Vector3 other); + + /*-----------------------------------------------------------------------------*/ + /* Object */ + /*-----------------------------------------------------------------------------*/ + /// + /// Compares equality with another unboxed object. + /// + /// The unboxed object to compare with. + /// True if both objects are the same. + bool Equals(Object^ o) override; + /// + /// Gets a unique hash for this object. + /// + /// Unique hash for this object. + int GetHashCode() override; + + /*-----------------------------------------------------------------------------*/ + /* Static Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Checks if two specified Vector3s are near in value. + /// + /// Vector3 to check if is near in value. + /// Another Vector3 to check if is near in value. + /// + /// True if the two Vector3s are within the tolerance value specified + /// + static bool IsNear(Vector3 lhs, Vector3 rhs); + /// + /// Checks if two specified Vector3s are near in value. + /// + /// Vector3 to check if is near in value. + /// Another Vector3 to check if is near in value. + /// Amount of tolerance to do the comparison with. + /// + /// True if the two Vector3s are within the tolerance value specified + /// + static bool IsNear(Vector3 lhs, Vector3 rhs, double tolerance); + /// + /// Computes and returns the dot product of 2 specified Vector3s. + /// + /// Vector3 to calculate dot product with. + /// Another Vector3 to calculate dot product with. + /// Scalar value representing the dot product of the two Vector3s. + static double Dot(Vector3 lhs, Vector3 rhs); + /// + /// Computes and returns the cross product of 2 specified Vector3s. + /// + /// Vector3 to calculate cross product with. + /// Another Vector3 to calculate cross product with. + /// The cross product of the two Vector3s. + static Vector3 Cross(Vector3 lhs, Vector3 rhs); + /// + /// Computes and returns a Vector3 projection. + /// + /// Vector3 to project. + /// Vector3 to project onto. + /// The Vector3 that represents the projected vec onto direction. + static Vector3 Project(Vector3 vec, Vector3 direction); + /// + /// Reflects a Vector3 across another Vector3. + /// + /// A Vector3 to reflect. + /// A normal to reflect the Vector3 across. + /// The Vector3 that represents vec reflected across normal. + static Vector3 Reflect(Vector3 vec, Vector3 normal); + /// + /// Rotates a Vector3 on the Z-axis by a specified angle in an anti-clockwise + /// direction. + /// + /// A Vector3 to rotate. + /// + /// Angle to rotate the vector by in an anti-clockwise direction in radians. + /// + /// The Vector3 that represents the rotated vector. + static Vector3 RotateRadians(Vector3 vec, double radians); + /// + /// Rotates a Vector3 on the Z-axis by a specified angle in an anti-clockwise + /// direction. + /// + /// A Vector3 to rotate. + /// + /// Angle to rotate the vector by in an anti-clockwise direction in degrees. + /// + /// The Vector3 that represents the rotated vector. + static Vector3 RotateDegrees(Vector3 vec, double degrees); + /// + /// Computes and returns a Vector3 that is made from the smallest components of + /// the two specified Vector3s. + /// + /// Vector3 to calculate minimum Vector3 with. + /// Another Vector3 to calculate minimum Vector3 with. + /// + /// The Vector3 that contains the smallest components of the two specified + /// Vector3s. + /// + static Vector3 Min(Vector3 lhs, Vector3 rhs); + /// + /// Computes and returns a Vector3 that is made from the largest components of + /// the two specified Vector3s. + /// + /// Vector3 to calculate maximum Vector3 with. + /// Another Vector3 to calculate maximum Vector3 with. + /// + /// The Vector3 that contains the largest components of the two specified + /// Vector3s. + /// + static Vector3 Max(Vector3 lhs, Vector3 rhs); + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// + /// The start Vector3, returned when t = 0.0. + /// The end Vector3, returned when t = 1.0. + /// + /// Value used to interpolate between a and b which is clamped to + /// the range[0, 1]. + /// + /// The interpolated Vector3. + static Vector3 Lerp(Vector3 a, Vector3 b, double t); + /// + /// Linearly interpolates between two specified points. + /// This is most commonly used to find a point some fraction of the way along a + /// line between two endpoints. + /// Unlike Lerp(), t is not clamped to a range at all. + /// + /// The start Vector3, returned when t = 0.0. + /// The end Vector3, returned when t = 1.0. + /// Value used to interpolate between a and b. + /// The interpolated Vector3. + static Vector3 LerpUnclamped(Vector3 a, Vector3 b, double t); + /// + /// Moves a point current towards target. + /// Similar to Lerp(), however, the function will ensure that the distance never + /// exceeds maxDistanceDelta. Negative values of maxDistanceDelta pushes the + /// vector away from target + /// + /// The current position of the point. + /// The target position to move to. + /// Maximum distance moved per call. + /// Vector representing the moved point. + static Vector3 MoveTowards(Vector3 current, Vector3 target, double maxDistanceDelta); + + /*-----------------------------------------------------------------------------*/ + /* Overloaded Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Adds two Vector3s together and returns the result. + /// + /// Vector3 to add. + /// Another Vector3 to add. + /// The result of lhs added to rhs + static Vector3 operator+(Vector3 lhs, Vector3 rhs); + /// + /// Subtracts a Vector3 from another Vector3 and returns the result. + /// + /// Vector3 to subtract from. + /// Another Vector3 to subtract. + /// The result of rhs subtracted from lhs. + static Vector3 operator-(Vector3 lhs, Vector3 rhs); + /// + /// Calculates the component-wise multiplication of two Vector3s and returns the + /// result. + /// + /// Vector3 to multiply with. + /// Another Vector3 to multiply with. + /// The result of rhs subtracted from lhs. + static Vector3 operator*(Vector3 lhs, Vector3 rhs); + /// + /// Calculates the multiplication of a Vector3 with a scalar value and returns + /// the result. + /// + /// Vector3 to multiply with. + /// Scalar to multiply with. + /// The result of the scalar multiplication. + static Vector3 operator*(Vector3 lhs, double rhs); + /// + /// Calculates the division of a Vector3 with a scalar value and returns + /// the result. + /// + /// Scalar to divide with. + /// Vector3 to divide with. + /// The result of the scalar division. + static Vector3 operator/(Vector3 lhs, double rhs); + /// + /// Checks if two Vector3s are approximately equal. This is equivalent to + /// calling Vector3.IsNear() with default tolerance values. + /// + /// Vector3 to compare. + /// Another Vector3 to compare. + /// + /// True if all components are approximately equal within the default + /// tolerance value. + /// + static bool operator==(Vector3 lhs, Vector3 rhs); + /// + /// Checks if two Vector3s are not approximately equal. This is equivalent to + /// calling !Vector3.IsNear() with default tolerance values. + /// + /// Vector3 to compare. + /// Another Vector3 to compare. + /// + /// True if all components are not approximately equal within the default + /// tolerance value. + /// + static bool operator!=(Vector3 lhs, Vector3 rhs); + + /*-----------------------------------------------------------------------------*/ + /* Conversion Operators */ + /*-----------------------------------------------------------------------------*/ + /// + /// Explicit conversion operator to enable explicit casting from a Vector3 to a + /// Vector2. + /// + /// Vector3 to convert from. + static explicit operator Vector2(Vector3 vec); + /// + /// Explicit conversion operator to enable explicit casting from a Vector2 to a + /// Vector3. + /// + /// Vector2 to convert from. + static explicit operator Vector3(Vector2 vec); + }; +} // namespace PlushieAPI::Mathematics diff --git a/SHADE_Managed/src/SHpch.cpp b/SHADE_Managed/src/SHpch.cpp new file mode 100644 index 00000000..2a36c693 --- /dev/null +++ b/SHADE_Managed/src/SHpch.cpp @@ -0,0 +1,10 @@ +/**************************************************************************************** + * \file SHpch.h + * \brief Empty source file for generating SHADE Engine's precompiled header. + * + * \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. +****************************************************************************************/ + +#include "SHpch.h" \ No newline at end of file diff --git a/SHADE_Managed/src/SHpch.h b/SHADE_Managed/src/SHpch.h new file mode 100644 index 00000000..b54a8a5b --- /dev/null +++ b/SHADE_Managed/src/SHpch.h @@ -0,0 +1,31 @@ +/**************************************************************************************** + * \file SHpch.h + * \brief Precompiled header file for SHADE Engine. + * + * \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 + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files +#include +// C RunTime Header Files +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include