Added C# Math functions and types along with DisposableAssemblyLoadContext

This commit is contained in:
Kah Wei 2022-09-12 18:17:59 +08:00
parent 1400a25c4d
commit 2fb61609e9
12 changed files with 1683 additions and 0 deletions

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Engine">
<UniqueIdentifier>{DBC7D3B0-C769-FE86-B024-12DB9C6585D7}</UniqueIdentifier>
</Filter>
<Filter Include="Math">
<UniqueIdentifier>{AFF4887C-9B2B-8A0D-4418-7010302E060F}</UniqueIdentifier>
</Filter>
<Filter Include="Scripts">
<UniqueIdentifier>{4D6F1AE8-B94E-9983-C266-245A2EC5FFE4}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\Engine\DisposableAssemblyLoadContext.hxx">
<Filter>Engine</Filter>
</ClInclude>
<ClInclude Include="src\Math\Math.hxx">
<Filter>Math</Filter>
</ClInclude>
<ClInclude Include="src\Math\Vector2.hxx">
<Filter>Math</Filter>
</ClInclude>
<ClInclude Include="src\Math\Vector3.hxx">
<Filter>Math</Filter>
</ClInclude>
<ClInclude Include="src\SHpch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Engine\DisposableAssemblyLoadContext.cxx">
<Filter>Engine</Filter>
</ClCompile>
<ClCompile Include="src\Math\Math.cxx">
<Filter>Math</Filter>
</ClCompile>
<ClCompile Include="src\Math\Vector2.cxx">
<Filter>Math</Filter>
</ClCompile>
<ClCompile Include="src\Math\Vector3.cxx">
<Filter>Math</Filter>
</ClCompile>
<ClCompile Include="src\SHpch.cpp" />
</ItemGroup>
</Project>

View File

@ -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

View File

@ -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

View File

@ -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
{
/// <summary>
/// Custom AssemblyLoadContext marked as collectible so that it can be unloaded.
/// </summary>
private ref class DisposableAssemblyLoadContext : public System::Runtime::Loader::AssemblyLoadContext
{
public:
/*-----------------------------------------------------------------------------*/
/* Constructor */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Default Constructor
/// </summary>
DisposableAssemblyLoadContext();
protected:
/*-----------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------*/
System::Reflection::Assembly^ Load(System::Reflection::AssemblyName^ assemblyName) override;
};
} // namespace PlushieAPI

View File

@ -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);
}
}

View File

@ -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
{
/// <summary>
/// Contains utility Math functions.
/// </summary>
public ref class Math abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Static Constants */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Degrees-to-radians conversion constant
/// </summary>
static constexpr double Deg2Rad = System::Math::PI / 180.0;
/// <summary>
/// Radians-to-degrees conversion constant
/// </summary>
static constexpr double Rad2Deg = 180.0 / System::Math::PI;
/// <summary>
/// Small value used for single precision floating point comparisons.
/// </summary>
static constexpr float Epsilon = 0.001f;
/*-----------------------------------------------------------------------------*/
/* Utility Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Wraps a value if they get to low or too high.
/// </summary>
/// <param name="value">Value to wrap.</param>
/// <param name="min">Minimum value to wrap at.</param>
/// <param name="max">Maximum value to wrap at.</param>
/// <returns>Wrapped value.</returns>
static double Wrap(double value, double min, double max);
/// <summary>
/// Converts an angle from degree representation to radian representation.
/// </summary>
/// <param name="degrees">Degree-based angle to convert.</param>
/// <returns>The specified angle in radians.</returns>
static double DegreesToRadians(double degrees);
/// <summary>
/// Converts an angle from radian representation to degree representation.
/// </summary>
/// <param name="radians">Radian-based angle to convert.</param>
/// <returns>The specified angle in degrees.</returns>
static double RadiansToDegrees(double radians);
/// <summary>
/// Linearly interpolates between a and b by t.
/// The parameter t is clamped to the range [0, 1].
/// </summary>
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The interpolation value between the two double.</param>
/// <returns>The interpolated double result between the two double values.</returns>
static double Lerp(double a, double b, double t);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start value.</param>
/// <param name="b">The end value.</param>
/// <param name="t">The interpolation value between the two double.</param>
/// <returns>The interpolated double result between the two double values.</returns>
static double LerpUnclamped(double a, double b, double t);
/// <summary>
/// Calculates the linear parameter t that produces the interpolant value within the range [a, b].
/// </summary>
/// <param name="a">Start value.</param>
/// <param name="b">End value.</param>
/// <param name="value">Value between start and end.</param>
/// <returns>Percentage of value between start and end.</returns>
static double InverseLerp(double a, double b, double value);
};
}

View File

@ -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 <cmath>
#include <algorithm>
// 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<Vector2>(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

View File

@ -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 <limits>
namespace SHADE
{
///<summary>
/// CLR version of the the PlushieEngine's Vector2 class that represents a
/// 2-Dimensional Vector. Designed to closely match Unity's Vector2 struct.
/// </summary>
[StructLayout(LayoutKind::Sequential)]
public value struct Vector2 : public System::IEquatable<Vector2>
{
public:
/*-----------------------------------------------------------------------------*/
/* Constants */
/*-----------------------------------------------------------------------------*/
#pragma region Constants
///<summary>
/// Shorthand for writing Vector2(0, -1).
///</summary>
static const Vector2 Down = Vector2(0.0, -1.0);
///<summary>
/// Shorthand for writing Vector2(-1, 0).
///</summary>
static const Vector2 Left = Vector2(-1.0, 0.0);
///<summary>
/// Shorthand for writing Vector2(double.NegativeInfinity,
/// double.NegativeInfinity).
///</summary>
static const Vector2 NegativeInfinity = Vector2(std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest());
///<summary>
/// Shorthand for writing Vector2(1, 1).
///</summary>
static const Vector2 One = Vector2(1.0, 1.0);
///<summary>
/// Shorthand for writing Vector2(double.PositiveInfinity,
/// double.PositiveInfinity).
///</summary>
static const Vector2 PositiveInfinity = Vector2(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
///<summary>
/// Shorthand for writing Vector2(1, 0).
///</summary>
static const Vector2 Right = Vector2(1.0, 0.0);
///<summary>
/// Shorthand for writing Vector2(0, 1).
///</summary>
static const Vector2 Up = Vector2(0.0, 1.0);
///<summary>
/// Shorthand for writing Vector2(0, 0).
///</summary>
static const Vector2 Zero = Vector2(0.0, 0.0);
#pragma endregion
/*-----------------------------------------------------------------------------*/
/* Public Members */
/*-----------------------------------------------------------------------------*/
///<summary>
/// X-component of the Vector2.
///</summary>
double x;
///<summary>
/// Y-component of the Vector2.
///</summary>
double y;
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor to construct a Vector2 with the specified components with the
/// Y-component set to 0.0.
/// </summary>
/// <param name="_x">X-coordinate to set.</param>
Vector2(double _x);
/// <summary>
/// Constructor to construct a Vector2 with the specified components..
/// </summary>
/// <param name="_x">X-coordinate to set.</param>
/// <param name="_y">Y-coordinate to set.</param>
Vector2(double _x, double _y);
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// 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.
/// </summary>
void Normalise();
/// <summary>
/// Creates a copy of this Vector2 and returns a normalized version.
/// </summary>
/// <returns>
/// Returns a normalised copy of this Vector2.
/// If this Vector2 is a zero vector, a zero vector will be returned.
/// </returns>
Vector2 GetNormalised();
/// <summary>
/// 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.
/// </summary>
/// <returns>Returns the length of this Vector2.</returns>
double GetMagnitude();
/// <summary>
/// Calculates and returns the squared magnitude of this Vector2.
/// </summary>
/// <returns>Returns the squared length of this Vector2.</returns>
double GetSqrMagnitude();
/// <summary>
/// Calculates and returns the angle of this vector from the right vector. This
/// function returns values between -Math.PI and Math.PI.
/// </summary>
/// <returns>Returns the angle of this vector from the right vector in radians.</returns>
double AngleFromRightRadians();
/// <summary>
/// Calculates and returns the angle of this vector from the right vector. This
/// function returns values between -180.0 and 180.0.
/// </summary>
/// <returns>Returns the angle of this vector from the right vector in degrees.</returns>
double AngleFromRightDegrees();
/// <summary>
/// Checks if a specified point is near this Vector2 that represents a point with
/// a tolerance value of PLS_EPSILON.
/// </summary>
/// <param name="point">The other point to check if we are near.</param>
/// <returns>
/// True if this Vector2 representing a point and the specified point are within
/// the range of the specified tolerance. False otherwise.
/// </returns>
bool IsNearPoint(Vector2 point);
/// <summary>
/// Checks if a specified point is near this Vector2 that represents a point.
/// </summary>
/// <param name="point">The other point to check if we are near.</param>
/// <param name="tolerance">
/// The amount of tolerance before we consider these points as "near".
/// </param>
/// <returns>
/// True if this Vector2 representing a point and the specified point are within
/// the range of the specified tolerance. False otherwise.
/// </returns>
bool IsNearPoint(Vector2 point, double tolerance);
/*-----------------------------------------------------------------------------*/
/* IEquatable */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Compares equality with an object of the same type.
/// </summary>
/// <param name="other">The object to compare with.</param>
/// <returns>True if both objects are the same.</returns>
virtual bool Equals(Vector2 other);
/*-----------------------------------------------------------------------------*/
/* Object */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Compares equality with another unboxed object.
/// </summary>
/// <param name="o">The unboxed object to compare with.</param>
/// <returns>True if both objects are the same.</returns>
bool Equals(Object^ o) override;
/// <summary>
/// Gets a unique hash for this object.
/// </summary>
/// <returns>Unique hash for this object.</returns>
int GetHashCode() override;
/*-----------------------------------------------------------------------------*/
/* Static Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Checks if two specified Vector2s are near in value.
/// </summary>
/// <param name="lhs">Vector2 to check if is near in value.</param>
/// <param name="rhs">Another Vector2 to check if is near in value.</param>
/// <returns>
/// True if the two Vector2s are within the tolerance value specified
/// </returns>
static bool IsNear(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Checks if two specified Vector2s are near in value.
/// </summary>
/// <param name="lhs">Vector2 to check if is near in value.</param>
/// <param name="rhs">Another Vector2 to check if is near in value.</param>
/// <param name="tolerance">
/// Amount of tolerance to do the comparison with.
/// </param>
/// <returns>
/// True if the two Vector2s are within the tolerance value specified
/// </returns>
static bool IsNear(Vector2 lhs, Vector2 rhs, double tolerance);
/// <summary>
/// Computes and returns the dot product of 2 specified Vector2s.
/// </summary>
/// <param name="lhs">Vector2 to calculate dot product with.</param>
/// <param name="rhs">Another Vector2 to calculate dot product with.</param>
/// <returns>
/// Scalar value representing the dot product of the two Vector2s.
/// </returns>
static double Dot(Vector2 lhs, Vector2 rhs);
/// <summary>
/// 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.
/// </summary>
/// <param name="lhs">Vector2 to find a perpendicular of.</param>
/// <returns>
/// The perpendicular Vector2 relative to the specified Vector2.
/// </returns>
static Vector2 Perpendicular(Vector2 lhs);
/// <summary>
/// Computes a perpendicular Vector2 to the specified Vector2.
/// </summary>
/// <param name="lhs">Vector2 to find a perpendicular of.</param>
/// <param name="inward">
/// Whether the inward perpendicular Vector is retrieved. If true, the
/// resultant vector is rotated 90-degrees in a counter-clockwise.
/// </param>
/// <returns>The perpendicular Vector2 relative to the specified Vector2.
/// </returns>
static Vector2 Perpendicular(Vector2 lhs, bool inward);
/// <summary>
/// Computes and returns a Vector2 projection.
/// </summary>
/// <param name="vec">Vector2 to project.</param>
/// <param name="direction">Vector2 to project onto.</param>
/// <returns>The Vector2 that represents the projected vec onto direction.</returns>
static Vector2 Project(Vector2 vec, Vector2 direction);
/// <summary>
/// Reflects a Vector2 across another Vector2.
/// </summary>
/// <param name="vec">A Vector2 to reflect.</param>
/// <param name="normal">A normal to reflect the Vector2 across.</param>
/// <returns>The Vector2 that represents vec reflected across normal.</returns>
static Vector2 Reflect(Vector2 vec, Vector2 normal);
/// <summary>
/// Rotates a Vector2 on the Z-axis by a specified angle in an anti-clockwise
/// direction.
/// </summary>
/// <param name="vec">A Vector2 to rotate.</param>
/// <param name="radians">
/// Angle to rotate the vector by in an anti-clockwise direction in radians.
/// </param>
/// <returns>The Vector2 that represents the rotated vector.</returns>
static Vector2 RotateRadians(Vector2 vec, double radians);
/// <summary>
/// Rotates a Vector2 on the Z-axis by a specified angle in an anti-clockwise
/// direction.
/// </summary>
/// <param name="vec">A Vector2 to rotate.</param>
/// <param name="degrees">
/// Angle to rotate the vector by in an anti-clockwise direction in degrees.
/// </param>
/// <returns>The Vector2 that represents the rotated vector.</returns>
static Vector2 RotateDegrees(Vector2 vec, double degrees);
/// <summary>
/// Computes and returns a Vector2 that is made from the smallest components of
/// the two specified Vector2s.
/// </summary>
/// <param name="lhs">Vector2 to calculate minimum Vector2 with.</param>
/// <param name="rhs">Another Vector2 to calculate minimum Vector2 with.</param>
/// <returns>
/// The Vector2 that contains the smallest components of the two specified
/// Vector2s.
/// </returns>
static Vector2 Min(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Computes and returns a Vector2 that is made from the largest components of
/// the two specified Vector2s.
/// </summary>
/// <param name="lhs">Vector2 to calculate maximum Vector2 with.</param>
/// <param name="rhs">Another Vector2 to calculate maximum Vector2 with.</param>
/// <returns>
/// The Vector2 that contains the largest components of the two specified
/// Vector2s.
/// </returns>
static Vector2 Max(Vector2 lhs, Vector2 rhs);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start Vector2, returned when t = 0.0.</param>
/// <param name="b">The end Vector2, returned when t = 1.0.</param>
/// <param name="t">
/// Value used to interpolate between a and b which is clamped to
/// the range[0, 1].
/// </param>
/// <returns>The interpolated Vector2.</returns>
static Vector2 Lerp(Vector2 a, Vector2 b, double t);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start Vector2, returned when t = 0.0.</param>
/// <param name="b">The end Vector2, returned when t = 1.0.</param>
/// <param name="t">Value used to interpolate between a and b.</param>
/// <returns>The interpolated Vector2.</returns>
static Vector2 LerpUnclamped(Vector2 a, Vector2 b, double t);
/// <summary>
/// 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
/// </summary>
/// <param name="current">The current position of the point.</param>
/// <param name="target">The target position to move to.</param>
/// <param name="maxDistanceDelta">Maximum distance moved per call.</param>
/// <returns>Vector representing the moved point.</returns>
static Vector2 MoveTowards(Vector2 current, Vector2 target, double maxDistanceDelta);
/*-----------------------------------------------------------------------------*/
/* Overloaded Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Adds two Vector2s together and returns the result.
/// </summary>
/// <param name="lhs">Vector2 to add.</param>
/// <param name="rhs">Another Vector2 to add.</param>
/// <returns>The result of lhs added to rhs</returns>
static Vector2 operator+(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Subtracts a Vector2 from another Vector2 and returns the result.
/// </summary>
/// <param name="lhs">Vector2 to subtract from.</param>
/// <param name="rhs">Another Vector2 to subtract.</param>
/// <returns>The result of rhs subtracted from lhs.</returns>
static Vector2 operator-(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Calculates the component-wise multiplication of two Vector2s and returns the
/// result.
/// </summary>
/// <param name="lhs">Vector2 to multiply with.</param>
/// <param name="rhs">Another Vector2 to multiply with.</param>
/// <returns>The result of rhs subtracted from lhs.</returns>
static Vector2 operator*(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Calculates the multiplication of a Vector2 with a scalar value and returns
/// the result.
/// </summary>
/// <param name="lhs">Vector2 to multiply with.</param>
/// <param name="rhs">Scalar to multiply with.</param>
/// <returns>The result of the scalar multiplication.</returns>
static Vector2 operator*(Vector2 lhs, double rhs);
/// <summary>
/// Calculates the division of a Vector2 with a scalar value and returns
/// the result.
/// </summary>
/// <param name="lhs">Scalar to divide with.</param>
/// <param name="rhs">Vector2 to divide with.</param>
/// <returns>The result of the scalar division.</returns>
static Vector2 operator/(Vector2 lhs, double rhs);
/// <summary>
/// Checks if two Vector2s are approximately equal. This is equivalent to
/// calling Vector2.IsNear() with default tolerance values.
/// </summary>
/// <param name="lhs">Vector2 to compare.</param>
/// <param name="rhs">Another Vector2 to compare.</param>
/// <returns>
/// True if all components are approximately equal within the default
/// tolerance value.
/// </returns>
static bool operator==(Vector2 lhs, Vector2 rhs);
/// <summary>
/// Checks if two Vector2s are not approximately equal. This is equivalent to
/// calling !Vector2.IsNear() with default tolerance values.
/// </summary>
/// <param name="lhs">Vector2 to compare.</param>
/// <param name="rhs">Another Vector2 to compare.</param>
/// <returns>
/// True if all components are not approximately equal within the default
/// tolerance value.
/// </returns>
static bool operator!=(Vector2 lhs, Vector2 rhs);
};
}

View File

@ -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 <cmath>
#include <algorithm>
// 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<Vector3>(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

View File

@ -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 <limits>
// Project Includes
#include "Vector2.hxx"
namespace SHADE
{
///<summary>
/// CLR version of the the PlushieEngine's Vector3 class that represents a
/// 3-Dimensional Vector. Designed to closely match Unity's Vector3 struct.
/// </summary>
[StructLayout(LayoutKind::Sequential)]
public value struct Vector3 : public System::IEquatable<Vector3>
{
public:
/*-----------------------------------------------------------------------------*/
/* Constants */
/*-----------------------------------------------------------------------------*/
#pragma region Constants
///<summary>
/// Shorthand for writing Vector3(0, 0, -1).
///</summary>
static const Vector3 Back = Vector3(0.0, 0.0, -1.0);
///<summary>
/// Shorthand for writing Vector3(0, -1, 0).
///</summary>
static const Vector3 Down = Vector3(0.0, -1.0, 0.0);
///<summary>
/// Shorthand for writing Vector3(0, 0, 1).
///</summary>
static const Vector3 Forward = Vector3(0.0, 0.0, 1.0);
///<summary>
/// Shorthand for writing Vector3(-1, 0, 0).
///</summary>
static const Vector3 Left = Vector3(-1.0, 0.0, 0.0);
///<summary>
/// Shorthand for writing Vector3(double.NegativeInfinity,
/// double.NegativeInfinity, double.NegativeInfinity).
///</summary>
static const Vector3 NegativeInfinity = Vector3(std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest(),
std::numeric_limits<double>::lowest());
///<summary>
/// Shorthand for writing Vector3(1, 1, 1).
///</summary>
static const Vector3 One = Vector3(1.0, 1.0, 1.0);
///<summary>
/// Shorthand for writing Vector3(double.PositiveInfinity,
/// double.PositiveInfinity, double.PositiveInfinity).
///</summary>
static const Vector3 PositiveInfinity = Vector3(std::numeric_limits<double>::max(),
std::numeric_limits<double>::max(),
std::numeric_limits<double>::max());
///<summary>
/// Shorthand for writing Vector3(1, 0, 0).
///</summary>
static const Vector3 Right = Vector3(1.0, 0.0, 0.0);
///<summary>
/// Shorthand for writing Vector3(0, 1, 0).
///</summary>
static const Vector3 Up = Vector3(0.0, 1.0, 0.0);
///<summary>
/// Shorthand for writing Vector3(0, 0, 0).
///</summary>
static const Vector3 Zero = Vector3(0.0, 0.0, 0.0);
#pragma endregion
/*-----------------------------------------------------------------------------*/
/* Public Members */
/*-----------------------------------------------------------------------------*/
///<summary>
/// X-component of the Vector3.
///</summary>
double x;
///<summary>
/// Y-component of the Vector3.
///</summary>
double y;
///<summary>
/// Z-component of the Vector3.
///</summary>
double z;
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructor to construct a Vector3 with the specified components with the
/// Y and Z-component set to 0.0.
/// </summary>
/// <param name="_x">X-coordinate to set.</param>
Vector3(double _x);
/// <summary>
/// Constructor to construct a Vector3 with the specified components with the
/// Z-component set to 0.0.
/// </summary>
/// <param name="_x">X-coordinate to set.</param>
/// <param name="_y">Y-coordinate to set.</param>
Vector3(double _x, double _y);
/// <summary>
/// Constructor to construct a Vector3 with the specified components.
/// </summary>
/// <param name="_x">X-coordinate to set.</param>
/// <param name="_y">Y-coordinate to set.</param>
/// <param name="_z">Z-coordinate to set.</param>
Vector3(double _x, double _y, double _z);
/// <summary>
/// Conversion constructor to construct a Vector3 using a Vector2.
/// </summary>
/// <param name="vec"></param>
Vector3(Vector2 vec);
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// 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.
/// </summary>
void Normalise();
/// <summary>
/// Creates a copy of this Vector3 and returns a normalized version.
/// </summary>
/// <returns>
/// Returns a normalised copy of this Vector3.
/// If this Vector3 is a zero vector, a zero vector will be returned.
/// </returns>
Vector3 GetNormalised();
/// <summary>
/// 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.
/// </summary>
/// <returns>Returns the length of this Vector3.</returns>
double GetMagnitude();
/// <summary>
/// Calculates and returns the squared magnitude of this Vector3.
/// </summary>
/// <returns>Returns the squared length of this Vector3.</returns>
double GetSqrMagnitude();
/// <summary>
/// Calculates and returns the angle of this vector from the right vector. This
/// function returns values between -Math.PI and Math.PI.
/// </summary>
/// <returns>Returns the angle of this vector from the right vector in radians.</returns>
double Angle2DFromRightRadians();
/// <summary>
/// Calculates and returns the angle of this vector from the right vector. This
/// function returns values between -180.0 and 180.0.
/// </summary>
/// <returns>Returns the angle of this vector from the right vector in degrees.</returns>
double Angle2DFromRightDegrees();
/// <summary>
/// Checks if a specified point is near this Vector3 that represents a point with
/// a tolerance value of PLS_EPSILON.
/// </summary>
/// <param name="point">The other point to check if we are near.</param>
/// <returns>
/// True if this Vector3 representing a point and the specified point are within
/// the range of the specified tolerance. False otherwise.
/// </returns>
bool IsNearPoint(Vector3 point);
/// <summary>
/// Checks if a specified point is near this Vector3 that represents a point.
/// </summary>
/// <param name="point">The other point to check if we are near.</param>
/// <param name="tolerance">
/// The amount of tolerance before we consider these points as "near".
/// </param>
/// <returns>
/// True if this Vector3 representing a point and the specified point are within
/// the range of the specified tolerance. False otherwise.
/// </returns>
bool IsNearPoint(Vector3 point, double tolerance);
/*-----------------------------------------------------------------------------*/
/* IEquatable */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Compares equality with an object of the same type.
/// </summary>
/// <param name="other">The object to compare with.</param>
/// <returns>True if both objects are the same.</returns>
virtual bool Equals(Vector3 other);
/*-----------------------------------------------------------------------------*/
/* Object */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Compares equality with another unboxed object.
/// </summary>
/// <param name="o">The unboxed object to compare with.</param>
/// <returns>True if both objects are the same.</returns>
bool Equals(Object^ o) override;
/// <summary>
/// Gets a unique hash for this object.
/// </summary>
/// <returns>Unique hash for this object.</returns>
int GetHashCode() override;
/*-----------------------------------------------------------------------------*/
/* Static Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Checks if two specified Vector3s are near in value.
/// </summary>
/// <param name="lhs">Vector3 to check if is near in value.</param>
/// <param name="rhs">Another Vector3 to check if is near in value.</param>
/// <returns>
/// True if the two Vector3s are within the tolerance value specified
/// </returns>
static bool IsNear(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Checks if two specified Vector3s are near in value.
/// </summary>
/// <param name="lhs">Vector3 to check if is near in value.</param>
/// <param name="rhs">Another Vector3 to check if is near in value.</param>
/// <param name="tolerance">Amount of tolerance to do the comparison with.</param>
/// <returns>
/// True if the two Vector3s are within the tolerance value specified
/// </returns>
static bool IsNear(Vector3 lhs, Vector3 rhs, double tolerance);
/// <summary>
/// Computes and returns the dot product of 2 specified Vector3s.
/// </summary>
/// <param name="lhs">Vector3 to calculate dot product with.</param>
/// <param name="rhs">Another Vector3 to calculate dot product with.</param>
/// <returns>Scalar value representing the dot product of the two Vector3s.</returns>
static double Dot(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Computes and returns the cross product of 2 specified Vector3s.
/// </summary>
/// <param name="lhs">Vector3 to calculate cross product with.</param>
/// <param name="rhs">Another Vector3 to calculate cross product with.</param>
/// <returns>The cross product of the two Vector3s.</returns>
static Vector3 Cross(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Computes and returns a Vector3 projection.
/// </summary>
/// <param name="vec">Vector3 to project.</param>
/// <param name="direction">Vector3 to project onto.</param>
/// <returns>The Vector3 that represents the projected vec onto direction.</returns>
static Vector3 Project(Vector3 vec, Vector3 direction);
/// <summary>
/// Reflects a Vector3 across another Vector3.
/// </summary>
/// <param name="vec">A Vector3 to reflect.</param>
/// <param name="normal">A normal to reflect the Vector3 across.</param>
/// <returns>The Vector3 that represents vec reflected across normal.</returns>
static Vector3 Reflect(Vector3 vec, Vector3 normal);
/// <summary>
/// Rotates a Vector3 on the Z-axis by a specified angle in an anti-clockwise
/// direction.
/// </summary>
/// <param name="vec">A Vector3 to rotate.</param>
/// <param name="radians">
/// Angle to rotate the vector by in an anti-clockwise direction in radians.
/// </param>
/// <returns>The Vector3 that represents the rotated vector.</returns>
static Vector3 RotateRadians(Vector3 vec, double radians);
/// <summary>
/// Rotates a Vector3 on the Z-axis by a specified angle in an anti-clockwise
/// direction.
/// </summary>
/// <param name="vec">A Vector3 to rotate.</param>
/// <param name="degrees">
/// Angle to rotate the vector by in an anti-clockwise direction in degrees.
/// </param>
/// <returns>The Vector3 that represents the rotated vector.</returns>
static Vector3 RotateDegrees(Vector3 vec, double degrees);
/// <summary>
/// Computes and returns a Vector3 that is made from the smallest components of
/// the two specified Vector3s.
/// </summary>
/// <param name="lhs">Vector3 to calculate minimum Vector3 with.</param>
/// <param name="rhs">Another Vector3 to calculate minimum Vector3 with.</param>
/// <returns>
/// The Vector3 that contains the smallest components of the two specified
/// Vector3s.
/// </returns>
static Vector3 Min(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Computes and returns a Vector3 that is made from the largest components of
/// the two specified Vector3s.
/// </summary>
/// <param name="lhs">Vector3 to calculate maximum Vector3 with.</param>
/// <param name="rhs">Another Vector3 to calculate maximum Vector3 with.</param>
/// <returns>
/// The Vector3 that contains the largest components of the two specified
/// Vector3s.
/// </returns>
static Vector3 Max(Vector3 lhs, Vector3 rhs);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start Vector3, returned when t = 0.0.</param>
/// <param name="b">The end Vector3, returned when t = 1.0.</param>
/// <param name="t">
/// Value used to interpolate between a and b which is clamped to
/// the range[0, 1].
/// </param>
/// <returns>The interpolated Vector3.</returns>
static Vector3 Lerp(Vector3 a, Vector3 b, double t);
/// <summary>
/// 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.
/// </summary>
/// <param name="a">The start Vector3, returned when t = 0.0.</param>
/// <param name="b">The end Vector3, returned when t = 1.0.</param>
/// <param name="t">Value used to interpolate between a and b.</param>
/// <returns>The interpolated Vector3.</returns>
static Vector3 LerpUnclamped(Vector3 a, Vector3 b, double t);
/// <summary>
/// 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
/// </summary>
/// <param name="current">The current position of the point.</param>
/// <param name="target">The target position to move to.</param>
/// <param name="maxDistanceDelta">Maximum distance moved per call.</param>
/// <returns>Vector representing the moved point.</returns>
static Vector3 MoveTowards(Vector3 current, Vector3 target, double maxDistanceDelta);
/*-----------------------------------------------------------------------------*/
/* Overloaded Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Adds two Vector3s together and returns the result.
/// </summary>
/// <param name="lhs">Vector3 to add.</param>
/// <param name="rhs">Another Vector3 to add.</param>
/// <returns>The result of lhs added to rhs</returns>
static Vector3 operator+(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Subtracts a Vector3 from another Vector3 and returns the result.
/// </summary>
/// <param name="lhs">Vector3 to subtract from.</param>
/// <param name="rhs">Another Vector3 to subtract.</param>
/// <returns>The result of rhs subtracted from lhs.</returns>
static Vector3 operator-(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Calculates the component-wise multiplication of two Vector3s and returns the
/// result.
/// </summary>
/// <param name="lhs">Vector3 to multiply with.</param>
/// <param name="rhs">Another Vector3 to multiply with.</param>
/// <returns>The result of rhs subtracted from lhs.</returns>
static Vector3 operator*(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Calculates the multiplication of a Vector3 with a scalar value and returns
/// the result.
/// </summary>
/// <param name="lhs">Vector3 to multiply with.</param>
/// <param name="rhs">Scalar to multiply with.</param>
/// <returns>The result of the scalar multiplication.</returns>
static Vector3 operator*(Vector3 lhs, double rhs);
/// <summary>
/// Calculates the division of a Vector3 with a scalar value and returns
/// the result.
/// </summary>
/// <param name="lhs">Scalar to divide with.</param>
/// <param name="rhs">Vector3 to divide with.</param>
/// <returns>The result of the scalar division.</returns>
static Vector3 operator/(Vector3 lhs, double rhs);
/// <summary>
/// Checks if two Vector3s are approximately equal. This is equivalent to
/// calling Vector3.IsNear() with default tolerance values.
/// </summary>
/// <param name="lhs">Vector3 to compare.</param>
/// <param name="rhs">Another Vector3 to compare.</param>
/// <returns>
/// True if all components are approximately equal within the default
/// tolerance value.
/// </returns>
static bool operator==(Vector3 lhs, Vector3 rhs);
/// <summary>
/// Checks if two Vector3s are not approximately equal. This is equivalent to
/// calling !Vector3.IsNear() with default tolerance values.
/// </summary>
/// <param name="lhs">Vector3 to compare.</param>
/// <param name="rhs">Another Vector3 to compare.</param>
/// <returns>
/// True if all components are not approximately equal within the default
/// tolerance value.
/// </returns>
static bool operator!=(Vector3 lhs, Vector3 rhs);
/*-----------------------------------------------------------------------------*/
/* Conversion Operators */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Explicit conversion operator to enable explicit casting from a Vector3 to a
/// Vector2.
/// </summary>
/// <param name="vec">Vector3 to convert from.</param>
static explicit operator Vector2(Vector3 vec);
/// <summary>
/// Explicit conversion operator to enable explicit casting from a Vector2 to a
/// Vector3.
/// </summary>
/// <param name="vec">Vector2 to convert from.</param>
static explicit operator Vector3(Vector2 vec);
};
} // namespace PlushieAPI::Mathematics

View File

@ -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"

31
SHADE_Managed/src/SHpch.h Normal file
View File

@ -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 <Windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <unordered_map>
#include <map>
#include <tuple>
#include <functional>
#include <sstream>
#include <iomanip>