SP3-16 Updated SHADE Managed Math & Transform #113
|
@ -1,17 +0,0 @@
|
|||
/************************************************************************************//*!
|
||||
\file Quaternion.hxx
|
||||
\author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
\par email: diren.dbharwani\@digipen.edu
|
||||
\date Oct 23, 2022
|
||||
\brief Contains the definitions of Quaternion 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
|
||||
|
||||
// TODO(Diren)
|
|
@ -21,7 +21,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Utility Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
double Math::Wrap(double value, double min, double max)
|
||||
float Math::Wrap(float value, float min, float max)
|
||||
{
|
||||
while (value < min)
|
||||
{
|
||||
|
@ -33,24 +33,24 @@ namespace SHADE
|
|||
}
|
||||
return value;
|
||||
}
|
||||
double Math::DegreesToRadians(double degrees)
|
||||
float Math::DegreesToRadians(float degrees)
|
||||
{
|
||||
return degrees * Deg2Rad;
|
||||
}
|
||||
double Math::RadiansToDegrees(double radians)
|
||||
float Math::RadiansToDegrees(float radians)
|
||||
{
|
||||
return radians * Rad2Deg;
|
||||
}
|
||||
double Math::Lerp(double a, double b, double t)
|
||||
float Math::Lerp(float a, float b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, System::Math::Clamp(t, 0.0, 1.0));
|
||||
return LerpUnclamped(a, b, System::Math::Clamp(t, 0.0f, 1.0f));
|
||||
}
|
||||
double Math::LerpUnclamped(double a, double b, double t)
|
||||
float Math::LerpUnclamped(float a, float b, float t)
|
||||
{
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
double Math::InverseLerp(double a, double b, double value)
|
||||
float Math::InverseLerp(float a, float b, float value)
|
||||
{
|
||||
return (value - a) / (b - a);
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ namespace SHADE
|
|||
/// <summary>
|
||||
/// Degrees-to-radians conversion constant
|
||||
/// </summary>
|
||||
static constexpr double Deg2Rad = System::Math::PI / 180.0;
|
||||
static constexpr float Deg2Rad = System::Math::PI / 180.0f;
|
||||
/// <summary>
|
||||
/// Radians-to-degrees conversion constant
|
||||
/// </summary>
|
||||
static constexpr double Rad2Deg = 180.0 / System::Math::PI;
|
||||
static constexpr float Rad2Deg = 180.0f / System::Math::PI;
|
||||
/// <summary>
|
||||
/// Small value used for single precision floating point comparisons.
|
||||
/// </summary>
|
||||
|
@ -47,28 +47,28 @@ namespace SHADE
|
|||
/// <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);
|
||||
static float Wrap(float value, float min, float 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);
|
||||
static float DegreesToRadians(float 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);
|
||||
static float RadiansToDegrees(float 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);
|
||||
/// <param name="t">The interpolation value between the two float.</param>
|
||||
/// <returns>The interpolated float result between the two float values.</returns>
|
||||
static float Lerp(float a, float b, float 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.
|
||||
|
@ -77,9 +77,9 @@ namespace SHADE
|
|||
/// </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);
|
||||
/// <param name="t">The interpolation value between the two float.</param>
|
||||
/// <returns>The interpolated float result between the two float values.</returns>
|
||||
static float LerpUnclamped(float a, float b, float t);
|
||||
/// <summary>
|
||||
/// Calculates the linear parameter t that produces the interpolant value within the range [a, b].
|
||||
/// </summary>
|
||||
|
@ -87,6 +87,6 @@ namespace SHADE
|
|||
/// <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);
|
||||
static float InverseLerp(float a, float b, float value);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,170 @@
|
|||
/************************************************************************************//*!
|
||||
\file Quaternion.cxx
|
||||
\author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
\par email: diren.dbharwani\@digipen.edu
|
||||
\date Oct 23, 2022
|
||||
\brief Contains the definitions of functions in the Quaternion 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 "Quaternion.hxx"
|
||||
// External Dependencies
|
||||
#include "Math/SHQuaternion.h"
|
||||
#include "Math/Vector/SHVec4.h"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
#include "Math.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
Quaternion::Quaternion(float _x, float _y, float _z, float _w)
|
||||
: x { _x }
|
||||
, y { _y }
|
||||
, z { _z }
|
||||
, w { _w }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void Quaternion::SetFromToRotation(Vector3 fromDirection, Vector3 toDirection)
|
||||
{
|
||||
const SHQuaternion R = SHQuaternion::FromToRotation(Convert::ToNative(fromDirection), Convert::ToNative(toDirection));
|
||||
*this = Convert::ToCLI(R);
|
||||
}
|
||||
|
||||
void Quaternion::SetLookRotation(Vector3 view, Vector3 up)
|
||||
{
|
||||
const SHQuaternion R = SHQuaternion::LookRotation(Convert::ToNative(view), Convert::ToNative(up));
|
||||
*this = Convert::ToCLI(R);
|
||||
}
|
||||
|
||||
void Quaternion::ToAngleAxis(float^% angle, Vector3^% axis)
|
||||
{
|
||||
const SHVec4 NATIVE_AXIS_ANGLE = Convert::ToNative(*this).GetAxisAngle();
|
||||
axis = Convert::ToCLI(NATIVE_AXIS_ANGLE.ToVec3());
|
||||
angle = NATIVE_AXIS_ANGLE.w;
|
||||
}
|
||||
|
||||
System::String^ Quaternion::ToString()
|
||||
{
|
||||
return ValueType::ToString();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool Quaternion::Equals(Quaternion other)
|
||||
{
|
||||
const float DOT = Dot(*this, other);
|
||||
return fabs(1.0f - DOT) <= Math::Epsilon;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Object Overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool Quaternion::Equals(Object^ o)
|
||||
{
|
||||
return ValueType::Equals(o);
|
||||
}
|
||||
|
||||
int Quaternion::GetHashCode()
|
||||
{
|
||||
return ValueType::GetHashCode();
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
float Quaternion::Angle(Quaternion a, Quaternion b)
|
||||
{
|
||||
return SHQuaternion::Angle(Convert::ToNative(a), Convert::ToNative(b));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::AngleAxis(float angle, Vector3 axis)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::FromAxisAngle(Convert::ToNative(axis), angle));
|
||||
}
|
||||
|
||||
float Quaternion::Dot(Quaternion a, Quaternion b)
|
||||
{
|
||||
return (a.x * b.x) + (a.y * b.y) + (a.z * b.z) + (a.w * b.w);
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Euler(float _x, float _y, float _z)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::FromPitchYawRoll(_x, _y, _z));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::FromToRotation(Vector3 fromDirection, Vector3 toDirection)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::FromToRotation(Convert::ToNative(fromDirection), Convert::ToNative(toDirection)));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Inverse(Quaternion rotation)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::Inverse(Convert::ToNative(rotation)));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Lerp(Quaternion a, Quaternion b, float t)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::ClampedLerp(Convert::ToNative(a), Convert::ToNative(b), t));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::LerpUnclamped(Quaternion a, Quaternion b, float t)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::Lerp(Convert::ToNative(a), Convert::ToNative(b), t));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::LookRotation(Vector3 forward, Vector3 upwards)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::LookRotation(Convert::ToNative(forward), Convert::ToNative(upwards)));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Normalize(Quaternion q)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::Normalise(Convert::ToNative(q)));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::RotateTowards(Convert::ToNative(from), Convert::ToNative(to), Math::DegreesToRadians(maxDegreesDelta)));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::Slerp(Quaternion a, Quaternion b, float t)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::ClampedSlerp(Convert::ToNative(a), Convert::ToNative(b), t));
|
||||
}
|
||||
|
||||
Quaternion Quaternion::SlerpUnclamped(Quaternion a, Quaternion b, float t)
|
||||
{
|
||||
return Convert::ToCLI(SHQuaternion::Slerp(Convert::ToNative(a), Convert::ToNative(b), t));
|
||||
}
|
||||
|
||||
|
||||
Quaternion Quaternion::operator*(Quaternion lhs, Quaternion rhs)
|
||||
{
|
||||
return Convert::ToCLI(Convert::ToNative(lhs) * Convert::ToNative(rhs));
|
||||
}
|
||||
|
||||
bool Quaternion::operator==(Quaternion lhs, Quaternion rhs)
|
||||
{
|
||||
return lhs.Equals(rhs);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,237 @@
|
|||
/************************************************************************************//*!
|
||||
\file Quaternion.hxx
|
||||
\author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
\par email: diren.dbharwani\@digipen.edu
|
||||
\date Oct 23, 2022
|
||||
\brief Contains the definitions of Quaternion 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 "Vector3.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
///<summary>
|
||||
/// CLR version of SHADE's Quaternion class that represents an orientation.
|
||||
/// Designed to closely match Unity's Quaternion struct.
|
||||
/// </summary>
|
||||
[System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
|
||||
public value struct Quaternion : public System::IEquatable<Quaternion>
|
||||
{
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constants */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
#pragma region Constants
|
||||
|
||||
///<summary>
|
||||
/// Shorthand for writing Quaternion(0, 0, 0, 1).
|
||||
///</summary>
|
||||
static initonly Quaternion Identity = Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Public Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
///<summary>
|
||||
/// X-component of the Quaternion.
|
||||
/// Don't modify this directly unless you know quaternions inside out.
|
||||
///</summary>
|
||||
float x;
|
||||
///<summary>
|
||||
/// Y-component of the Quaternion.
|
||||
/// Don't modify this directly unless you know quaternions inside out.
|
||||
///</summary>
|
||||
float y;
|
||||
///<summary>
|
||||
/// Z-component of the Quaternion.
|
||||
/// Don't modify this directly unless you know quaternions inside out.
|
||||
///</summary>
|
||||
float z;
|
||||
///<summary>
|
||||
/// W-component of the Quaternion. Do not directly modify quaternions.
|
||||
///</summary>
|
||||
float w;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
/// <summary>
|
||||
/// Constructor to construct a Quaternion 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>
|
||||
/// <param name="_z">W-coordinate to set.</param>
|
||||
Quaternion(float _x, float _y, float _z, float _w);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation which rotates from fromDirection to toDirection. <br/>
|
||||
/// Use this to create a rotation which starts at the first Vector (fromDirection) and rotates to the second Vector (toDirection).
|
||||
/// These Vectors must be set up in a script.
|
||||
/// </summary>
|
||||
void SetFromToRotation(Vector3 fromDirection, Vector3 toDirection);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation with the specified forward and upwards directions. <br/>
|
||||
/// The result is applied to this quaternion.
|
||||
/// If used to orient a Transform, the Z axis will be aligned with forward and the Y axis with upwards, assuming these vectors are orthogonal.
|
||||
/// Logs an error if the forward direction is zero.
|
||||
/// </summary>
|
||||
/// <param name="view">The direction to look in.</param>
|
||||
/// <param name="up">The vector that defines in which direction up is.</param>
|
||||
void SetLookRotation(Vector3 view, Vector3 up);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a rotation to angle-axis representation (angles in degrees).
|
||||
/// </summary>
|
||||
void ToAngleAxis(float^% angle, Vector3^% axis);
|
||||
|
||||
System::String^ ToString() override;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* 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(Quaternion 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>
|
||||
/// Returns the angle in degrees between two rotations a and b.<br/>
|
||||
/// </summary>
|
||||
/// <returns>The angle in degrees between the two vectors. </returns>
|
||||
static float Angle(Quaternion a, Quaternion b);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation which rotates angle degrees around axis.
|
||||
/// </summary>
|
||||
static Quaternion AngleAxis(float angle, Vector3 axis);
|
||||
|
||||
/// <summary>
|
||||
/// The dot product between two rotations.
|
||||
/// </summary>
|
||||
static float Dot(Quaternion a, Quaternion b);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a rotation that rotates y degrees around the y axis, x degrees around the x axis, and z degrees around the z axis; applied in that order.
|
||||
/// </summary>
|
||||
static Quaternion Euler(float _x, float _y, float _z);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation which rotates from fromDirection to toDirection.
|
||||
/// </summary>
|
||||
static Quaternion FromToRotation(Vector3 fromDirection, Vector3 toDirection);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Inverse of rotation.
|
||||
/// </summary>
|
||||
static Quaternion Inverse(Quaternion rotation);
|
||||
|
||||
/// <summary>
|
||||
/// Interpolates between a and b by t and normalizes the result afterwards. The parameter t is clamped to the range [0, 1].
|
||||
/// </summary>
|
||||
/// <param name="a">Start value, returned when t = 0.</param>
|
||||
/// <param name="b">End value, returned when t = 1.</param>
|
||||
/// <param name="t">Interpolation ratio.</param>
|
||||
/// <returns> A quaternion interpolated between quaternions a and b.</returns>
|
||||
static Quaternion Lerp(Quaternion a, Quaternion b, float t);
|
||||
|
||||
/// <summary>
|
||||
/// Interpolates between a and b by t and normalizes the result afterwards. The parameter t is not clamped.
|
||||
/// </summary>
|
||||
static Quaternion LerpUnclamped(Quaternion a, Quaternion b, float t);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation with the specified forward and upwards directions. <br/>
|
||||
/// Z axis will be aligned with forward, X axis aligned with cross product between forward and upwards, and Y axis aligned with cross product between Z and X.
|
||||
/// </summary>
|
||||
static Quaternion LookRotation(Vector3 forward, Vector3 upwards);
|
||||
|
||||
/// <summary>
|
||||
/// Converts this quaternion to one with the same orientation but with a magnitude of 1.
|
||||
/// </summary>
|
||||
static Quaternion Normalize(Quaternion q);
|
||||
|
||||
/// <summary>
|
||||
/// Rotates a rotation from towards to. <br/>
|
||||
/// The from quaternion is rotated towards to by an angular step of maxDegreesDelta (but note that the rotation will not overshoot).
|
||||
/// Negative values of maxDegreesDelta will move away from to until the rotation is exactly the opposite direction.
|
||||
/// </summary>
|
||||
static Quaternion RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta);
|
||||
|
||||
/// <summary>
|
||||
/// Spherically interpolates between quaternions a and b by ratio t. The parameter t is clamped to the range [0, 1].
|
||||
/// </summary>
|
||||
/// <param name="a">Start value, returned when t = 0.</param>
|
||||
/// <param name="b">End value, returned when t = 1.</param>
|
||||
/// <param name="t">Interpolation ratio.</param>
|
||||
/// <returns> A quaternion spherically interpolated between quaternions a and b.</returns>
|
||||
static Quaternion Slerp(Quaternion a, Quaternion b, float t);
|
||||
|
||||
/// <summary>
|
||||
/// Spherically interpolates between a and b by t. The parameter t is not clamped.
|
||||
/// </summary>
|
||||
static Quaternion SlerpUnclamped(Quaternion a, Quaternion b, float t);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
||||
/// <summary>
|
||||
/// Combines rotations lhs and rhs.
|
||||
/// </summary>
|
||||
/// <param name="lhs">Left-hand side quaternion.</param>
|
||||
/// <param name="rhs">Right-hand side quaternion.</param>
|
||||
static Quaternion operator*(Quaternion lhs, Quaternion rhs);
|
||||
|
||||
/// <summary>
|
||||
/// Are two quaternions equal to each other?
|
||||
/// </summary>
|
||||
/// <param name="lhs">Left-hand side quaternion.</param>
|
||||
/// <param name="rhs">Right-hand side quaternion.</param>
|
||||
static bool operator==(Quaternion lhs, Quaternion rhs);
|
||||
};
|
||||
|
||||
} // namespace SHADE
|
|
@ -26,10 +26,10 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Vector2::Vector2(double _x)
|
||||
: Vector2 { _x, 0.0 }
|
||||
Vector2::Vector2(float _x)
|
||||
: Vector2 { _x, 0.0f }
|
||||
{}
|
||||
Vector2::Vector2(double _x, double _y)
|
||||
Vector2::Vector2(float _x, float _y)
|
||||
: x { _x }
|
||||
, y { _y }
|
||||
{}
|
||||
|
@ -47,22 +47,22 @@ namespace SHADE
|
|||
return *this / GetMagnitude();
|
||||
}
|
||||
|
||||
double Vector2::GetMagnitude()
|
||||
float Vector2::GetMagnitude()
|
||||
{
|
||||
return sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
double Vector2::GetSqrMagnitude()
|
||||
float Vector2::GetSqrMagnitude()
|
||||
{
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
double Vector2::AngleFromRightRadians()
|
||||
float Vector2::AngleFromRightRadians()
|
||||
{
|
||||
return atan2(y, x);
|
||||
}
|
||||
|
||||
double Vector2::AngleFromRightDegrees()
|
||||
float Vector2::AngleFromRightDegrees()
|
||||
{
|
||||
return Math::RadiansToDegrees(AngleFromRightRadians());
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace SHADE
|
|||
return IsNearPoint(point, Math::Epsilon);
|
||||
}
|
||||
|
||||
bool Vector2::IsNearPoint(Vector2 point, double tolerance)
|
||||
bool Vector2::IsNearPoint(Vector2 point, float tolerance)
|
||||
{
|
||||
return (*this - point).GetSqrMagnitude() < (tolerance * tolerance);
|
||||
}
|
||||
|
@ -113,13 +113,13 @@ namespace SHADE
|
|||
{
|
||||
return IsNear(lhs, rhs, Math::Epsilon);
|
||||
}
|
||||
bool Vector2::IsNear(Vector2 lhs, Vector2 rhs, double tolerance)
|
||||
bool Vector2::IsNear(Vector2 lhs, Vector2 rhs, float 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)
|
||||
float Vector2::Dot(Vector2 lhs, Vector2 rhs)
|
||||
{
|
||||
return lhs.x * rhs.x + lhs.y * rhs.y;
|
||||
}
|
||||
|
@ -153,12 +153,12 @@ namespace SHADE
|
|||
}
|
||||
Vector2 Vector2::Reflect(Vector2 vec, Vector2 normal)
|
||||
{
|
||||
return vec - (Project(vec, normal.GetNormalised()) * 2.0);
|
||||
return vec - (Project(vec, normal.GetNormalised()) * 2.0f);
|
||||
}
|
||||
Vector2 Vector2::RotateRadians(Vector2 vec, double radians)
|
||||
Vector2 Vector2::RotateRadians(Vector2 vec, float radians)
|
||||
{
|
||||
const double SINE = sin(radians);
|
||||
const double COSINE = cos(radians);
|
||||
const float SINE = sin(radians);
|
||||
const float COSINE = cos(radians);
|
||||
|
||||
return Vector2
|
||||
(
|
||||
|
@ -166,35 +166,35 @@ namespace SHADE
|
|||
vec.x * SINE + vec.y * COSINE
|
||||
);
|
||||
}
|
||||
Vector2 Vector2::RotateDegrees(Vector2 vec, double degrees)
|
||||
Vector2 Vector2::RotateDegrees(Vector2 vec, float 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;
|
||||
float lx = lhs.x, rx = rhs.x;
|
||||
float 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;
|
||||
float lx = lhs.x, rx = rhs.x;
|
||||
float 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)
|
||||
Vector2 Vector2::Lerp(Vector2 a, Vector2 b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, std::clamp(t, 0.0, 1.0));
|
||||
return LerpUnclamped(a, b, std::clamp(t, 0.0f, 1.0f));
|
||||
}
|
||||
Vector2 Vector2::LerpUnclamped(Vector2 a, Vector2 b, double t)
|
||||
Vector2 Vector2::LerpUnclamped(Vector2 a, Vector2 b, float t)
|
||||
{
|
||||
return a + ((b - a) * t);
|
||||
}
|
||||
Vector2 Vector2::MoveTowards(Vector2 current, Vector2 target, double maxDistanceDelta)
|
||||
Vector2 Vector2::MoveTowards(Vector2 current, Vector2 target, float maxDistanceDelta)
|
||||
{
|
||||
// Ignore if it is exactly on the same point
|
||||
if (current == target)
|
||||
|
@ -206,7 +206,7 @@ namespace SHADE
|
|||
|
||||
// Check if check if is behind or ahead of target
|
||||
Vector2 DIFF = target - newPos;
|
||||
if (Dot(DELTA, DIFF) < 0.0)
|
||||
if (Dot(DELTA, DIFF) < 0.0f)
|
||||
{
|
||||
newPos = target;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ namespace SHADE
|
|||
lhs.y * rhs.y
|
||||
);
|
||||
}
|
||||
Vector2 Vector2::operator*(Vector2 lhs, double rhs)
|
||||
Vector2 Vector2::operator*(Vector2 lhs, float rhs)
|
||||
{
|
||||
return Vector2
|
||||
(
|
||||
|
@ -244,7 +244,7 @@ namespace SHADE
|
|||
lhs.y * rhs
|
||||
);
|
||||
}
|
||||
Vector2 Vector2::operator/(Vector2 lhs, double rhs)
|
||||
Vector2 Vector2::operator/(Vector2 lhs, float rhs)
|
||||
{
|
||||
return Vector2
|
||||
(
|
||||
|
|
|
@ -19,8 +19,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
namespace SHADE
|
||||
{
|
||||
///<summary>
|
||||
/// CLR version of the the SHADE Engine's Vector2 class that represents a
|
||||
/// 2-Dimensional Vector. Designed to closely match Unity's Vector2 struct.
|
||||
/// CLR version of SHADE Engine's Vector2 class that represents a 2-Dimensional Vector.
|
||||
/// Designed to closely match Unity's Vector2 struct.
|
||||
/// </summary>
|
||||
[System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
|
||||
public value struct Vector2 : public System::IEquatable<Vector2>
|
||||
|
@ -33,37 +33,37 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// Shorthand for writing Vector2(0, -1).
|
||||
///</summary>
|
||||
static initonly Vector2 Down = Vector2(0.0, -1.0);
|
||||
static initonly Vector2 Down = Vector2(0.0f, -1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(-1, 0).
|
||||
///</summary>
|
||||
static initonly Vector2 Left = Vector2(-1.0, 0.0);
|
||||
static initonly Vector2 Left = Vector2(-1.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(double.NegativeInfinity,
|
||||
/// double.NegativeInfinity).
|
||||
/// Shorthand for writing Vector2(float.NegativeInfinity,
|
||||
/// float.NegativeInfinity).
|
||||
///</summary>
|
||||
static initonly Vector2 NegativeInfinity = Vector2(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest());
|
||||
static initonly Vector2 NegativeInfinity = Vector2(std::numeric_limits<float>::lowest(), std::numeric_limits<float>::lowest());
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(1, 1).
|
||||
///</summary>
|
||||
static initonly Vector2 One = Vector2(1.0, 1.0);
|
||||
static initonly Vector2 One = Vector2(1.0f, 1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(double.PositiveInfinity,
|
||||
/// double.PositiveInfinity).
|
||||
/// Shorthand for writing Vector2(float.PositiveInfinity,
|
||||
/// float.PositiveInfinity).
|
||||
///</summary>
|
||||
static initonly Vector2 PositiveInfinity = Vector2(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
|
||||
static initonly Vector2 PositiveInfinity = Vector2(std::numeric_limits<float>::max(), std::numeric_limits<float>::max());
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(1, 0).
|
||||
///</summary>
|
||||
static initonly Vector2 Right = Vector2(1.0, 0.0);
|
||||
static initonly Vector2 Right = Vector2(1.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(0, 1).
|
||||
///</summary>
|
||||
static initonly Vector2 Up = Vector2(0.0, 1.0);
|
||||
static initonly Vector2 Up = Vector2(0.0f, 1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector2(0, 0).
|
||||
///</summary>
|
||||
static initonly Vector2 Zero = Vector2(0.0, 0.0);
|
||||
static initonly Vector2 Zero = Vector2(0.0f, 0.0f);
|
||||
#pragma endregion
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -72,27 +72,27 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// X-component of the Vector2.
|
||||
///</summary>
|
||||
double x;
|
||||
float x;
|
||||
///<summary>
|
||||
/// Y-component of the Vector2.
|
||||
///</summary>
|
||||
double y;
|
||||
float y;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor to construct a Vector2 with the specified components with the
|
||||
/// Y-component set to 0.0.
|
||||
/// Y-component set to 0.0f.
|
||||
/// </summary>
|
||||
/// <param name="_x">X-coordinate to set.</param>
|
||||
Vector2(double _x);
|
||||
Vector2(float _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);
|
||||
Vector2(float _x, float _y);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
|
@ -117,24 +117,24 @@ namespace SHADE
|
|||
/// need the precise magnitude, consider using GetSqrMagnitude() instead.
|
||||
/// </summary>
|
||||
/// <returns>Returns the length of this Vector2.</returns>
|
||||
double GetMagnitude();
|
||||
float GetMagnitude();
|
||||
/// <summary>
|
||||
/// Calculates and returns the squared magnitude of this Vector2.
|
||||
/// </summary>
|
||||
/// <returns>Returns the squared length of this Vector2.</returns>
|
||||
double GetSqrMagnitude();
|
||||
float 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();
|
||||
float AngleFromRightRadians();
|
||||
/// <summary>
|
||||
/// Calculates and returns the angle of this vector from the right vector. This
|
||||
/// function returns values between -180.0 and 180.0.
|
||||
/// function returns values between -180.0f and 180.0f.
|
||||
/// </summary>
|
||||
/// <returns>Returns the angle of this vector from the right vector in degrees.</returns>
|
||||
double AngleFromRightDegrees();
|
||||
float AngleFromRightDegrees();
|
||||
/// <summary>
|
||||
/// Checks if a specified point is near this Vector2 that represents a point with
|
||||
/// a tolerance value of PLS_EPSILON.
|
||||
|
@ -156,7 +156,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
bool IsNearPoint(Vector2 point, float tolerance);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
|
@ -206,7 +206,7 @@ namespace SHADE
|
|||
/// <returns>
|
||||
/// True if the two Vector2s are within the tolerance value specified
|
||||
/// </returns>
|
||||
static bool IsNear(Vector2 lhs, Vector2 rhs, double tolerance);
|
||||
static bool IsNear(Vector2 lhs, Vector2 rhs, float tolerance);
|
||||
/// <summary>
|
||||
/// Computes and returns the dot product of 2 specified Vector2s.
|
||||
/// </summary>
|
||||
|
@ -215,7 +215,7 @@ namespace SHADE
|
|||
/// <returns>
|
||||
/// Scalar value representing the dot product of the two Vector2s.
|
||||
/// </returns>
|
||||
static double Dot(Vector2 lhs, Vector2 rhs);
|
||||
static float Dot(Vector2 lhs, Vector2 rhs);
|
||||
/// <summary>
|
||||
/// Computes the inward perpendicular Vector2 to the specified Vector2.
|
||||
/// Equivalent to calling Perpendicular(lhs, true). This means, the
|
||||
|
@ -260,7 +260,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
static Vector2 RotateRadians(Vector2 vec, float radians);
|
||||
/// <summary>
|
||||
/// Rotates a Vector2 on the Z-axis by a specified angle in an anti-clockwise
|
||||
/// direction.
|
||||
|
@ -270,7 +270,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
static Vector2 RotateDegrees(Vector2 vec, float degrees);
|
||||
/// <summary>
|
||||
/// Computes and returns a Vector2 that is made from the smallest components of
|
||||
/// the two specified Vector2s.
|
||||
|
@ -298,25 +298,25 @@ namespace SHADE
|
|||
/// 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="a">The start Vector2, returned when t = 0.0f.</param>
|
||||
/// <param name="b">The end Vector2, returned when t = 1.0f.</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);
|
||||
static Vector2 Lerp(Vector2 a, Vector2 b, float 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="a">The start Vector2, returned when t = 0.0f.</param>
|
||||
/// <param name="b">The end Vector2, returned when t = 1.0f.</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);
|
||||
static Vector2 LerpUnclamped(Vector2 a, Vector2 b, float t);
|
||||
/// <summary>
|
||||
/// Moves a point current towards target.
|
||||
/// Similar to Lerp(), however, the function will ensure that the distance never
|
||||
|
@ -327,7 +327,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector2 MoveTowards(Vector2 current, Vector2 target, float maxDistanceDelta);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
|
@ -361,7 +361,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector2 operator*(Vector2 lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Calculates the division of a Vector2 with a scalar value and returns
|
||||
/// the result.
|
||||
|
@ -369,7 +369,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector2 operator/(Vector2 lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Vector2s are approximately equal. This is equivalent to
|
||||
/// calling Vector2.IsNear() with default tolerance values.
|
||||
|
|
|
@ -11,6 +11,7 @@ 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
|
||||
|
@ -26,13 +27,13 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Vector3::Vector3(double _x)
|
||||
: Vector3 {_x, 0.0, 0.0}
|
||||
Vector3::Vector3(float _x)
|
||||
: Vector3 {_x, 0.0f, 0.0f}
|
||||
{}
|
||||
Vector3::Vector3(double _x, double _y)
|
||||
: Vector3 {_x, _y, 0.0}
|
||||
Vector3::Vector3(float _x, float _y)
|
||||
: Vector3 {_x, _y, 0.0f}
|
||||
{}
|
||||
Vector3::Vector3(double _x, double _y, double _z)
|
||||
Vector3::Vector3(float _x, float _y, float _z)
|
||||
: x { _x }
|
||||
, y { _y }
|
||||
, z { _z }
|
||||
|
@ -54,22 +55,22 @@ namespace SHADE
|
|||
return *this / GetSqrMagnitude();
|
||||
}
|
||||
|
||||
double Vector3::GetMagnitude()
|
||||
float Vector3::GetMagnitude()
|
||||
{
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
double Vector3::GetSqrMagnitude()
|
||||
float Vector3::GetSqrMagnitude()
|
||||
{
|
||||
return x * x + y * y + z * z;
|
||||
}
|
||||
|
||||
double Vector3::Angle2DFromRightRadians()
|
||||
float Vector3::Angle2DFromRightRadians()
|
||||
{
|
||||
return atan2(y, x);
|
||||
}
|
||||
|
||||
double Vector3::Angle2DFromRightDegrees()
|
||||
float Vector3::Angle2DFromRightDegrees()
|
||||
{
|
||||
return Math::RadiansToDegrees(Angle2DFromRightRadians());
|
||||
}
|
||||
|
@ -79,7 +80,7 @@ namespace SHADE
|
|||
return IsNearPoint(point, Math::Epsilon);
|
||||
}
|
||||
|
||||
bool Vector3::IsNearPoint(Vector3 point, double tolerance)
|
||||
bool Vector3::IsNearPoint(Vector3 point, float tolerance)
|
||||
{
|
||||
return (*this - point).GetSqrMagnitude() < (tolerance * tolerance);
|
||||
}
|
||||
|
@ -121,7 +122,7 @@ namespace SHADE
|
|||
{
|
||||
return IsNear(lhs, rhs, Math::Epsilon);
|
||||
}
|
||||
bool Vector3::IsNear(Vector3 lhs, Vector3 rhs, double tolerance)
|
||||
bool Vector3::IsNear(Vector3 lhs, Vector3 rhs, float tolerance)
|
||||
{
|
||||
return (std::abs(lhs.x) - std::abs(rhs.x)) < tolerance
|
||||
&&
|
||||
|
@ -129,7 +130,7 @@ namespace SHADE
|
|||
&&
|
||||
(std::abs(lhs.z) - std::abs(rhs.z)) < tolerance;
|
||||
}
|
||||
double Vector3::Dot(Vector3 lhs, Vector3 rhs)
|
||||
float Vector3::Dot(Vector3 lhs, Vector3 rhs)
|
||||
{
|
||||
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
|
||||
}
|
||||
|
@ -145,12 +146,12 @@ namespace SHADE
|
|||
}
|
||||
Vector3 Vector3::Reflect(Vector3 vec, Vector3 normal)
|
||||
{
|
||||
return vec - (Project(vec, normal.GetNormalised()) * 2.0);
|
||||
return vec - (Project(vec, normal.GetNormalised()) * 2.0f);
|
||||
}
|
||||
Vector3 Vector3::RotateRadians(Vector3 vec, double radians)
|
||||
Vector3 Vector3::RotateRadians(Vector3 vec, float radians)
|
||||
{
|
||||
const double SINE = sin(radians);
|
||||
const double COSINE = cos(radians);
|
||||
const float SINE = sin(radians);
|
||||
const float COSINE = cos(radians);
|
||||
|
||||
return Vector3
|
||||
(
|
||||
|
@ -159,15 +160,15 @@ namespace SHADE
|
|||
vec.z
|
||||
);
|
||||
}
|
||||
Vector3 Vector3::RotateDegrees(Vector3 vec, double degrees)
|
||||
Vector3 Vector3::RotateDegrees(Vector3 vec, float 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;
|
||||
float lx = lhs.x, rx = rhs.x;
|
||||
float ly = lhs.y, ry = rhs.y;
|
||||
float lz = lhs.z, rz = rhs.z;
|
||||
|
||||
return Vector3(std::min(lx, rx),
|
||||
std::min(ly, ry),
|
||||
|
@ -175,23 +176,23 @@ namespace SHADE
|
|||
}
|
||||
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;
|
||||
float lx = lhs.x, rx = rhs.x;
|
||||
float ly = lhs.y, ry = rhs.y;
|
||||
float 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)
|
||||
Vector3 Vector3::Lerp(Vector3 a, Vector3 b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, std::clamp(t, 0.0, 1.0));
|
||||
return LerpUnclamped(a, b, std::clamp(t, 0.0f, 1.0f));
|
||||
}
|
||||
Vector3 Vector3::LerpUnclamped(Vector3 a, Vector3 b, double t)
|
||||
Vector3 Vector3::LerpUnclamped(Vector3 a, Vector3 b, float t)
|
||||
{
|
||||
return a + ((b - a) * t);
|
||||
}
|
||||
Vector3 Vector3::MoveTowards(Vector3 current, Vector3 target, double maxDistanceDelta)
|
||||
Vector3 Vector3::MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta)
|
||||
{
|
||||
// Ignore if it is exactly on the same point
|
||||
if (current == target)
|
||||
|
@ -203,7 +204,7 @@ namespace SHADE
|
|||
|
||||
// Check if check if is behind or ahead of target
|
||||
Vector3 DIFF = target - newPos;
|
||||
if (Dot(DELTA, DIFF) < 0.0)
|
||||
if (Dot(DELTA, DIFF) < 0.0f)
|
||||
{
|
||||
newPos = target;
|
||||
}
|
||||
|
@ -236,7 +237,7 @@ namespace SHADE
|
|||
lhs.z * rhs.z
|
||||
);
|
||||
}
|
||||
Vector3 Vector3::operator*(Vector3 lhs, double rhs)
|
||||
Vector3 Vector3::operator*(Vector3 lhs, float rhs)
|
||||
{
|
||||
return Vector3
|
||||
(
|
||||
|
@ -245,7 +246,7 @@ namespace SHADE
|
|||
lhs.z * rhs
|
||||
);
|
||||
}
|
||||
Vector3 Vector3::operator/(Vector3 lhs, double rhs)
|
||||
Vector3 Vector3::operator/(Vector3 lhs, float rhs)
|
||||
{
|
||||
return Vector3
|
||||
(
|
||||
|
|
|
@ -22,8 +22,8 @@ of DigiPen Institute of Technology is prohibited.
|
|||
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.
|
||||
/// CLR version of SHADE Engine's Vector3 class that represents a 3-Dimensional Vector.
|
||||
/// Designed to closely match Unity's Vector3 struct.
|
||||
/// </summary>
|
||||
[System::Runtime::InteropServices::StructLayout(System::Runtime::InteropServices::LayoutKind::Sequential)]
|
||||
public value struct Vector3 : public System::IEquatable<Vector3>
|
||||
|
@ -36,49 +36,49 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 0, -1).
|
||||
///</summary>
|
||||
static initonly Vector3 Back = Vector3(0.0, 0.0, -1.0);
|
||||
static initonly Vector3 Back = Vector3(0.0f, 0.0f, -1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, -1, 0).
|
||||
///</summary>
|
||||
static initonly Vector3 Down = Vector3(0.0, -1.0, 0.0);
|
||||
static initonly Vector3 Down = Vector3(0.0f, -1.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 0, 1).
|
||||
///</summary>
|
||||
static initonly Vector3 Forward = Vector3(0.0, 0.0, 1.0);
|
||||
static initonly Vector3 Forward = Vector3(0.0f, 0.0f, 1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(-1, 0, 0).
|
||||
///</summary>
|
||||
static initonly Vector3 Left = Vector3(-1.0, 0.0, 0.0);
|
||||
static initonly Vector3 Left = Vector3(-1.0f, 0.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(double.NegativeInfinity,
|
||||
/// double.NegativeInfinity, double.NegativeInfinity).
|
||||
/// Shorthand for writing Vector3(float.NegativeInfinity,
|
||||
/// float.NegativeInfinity, float.NegativeInfinity).
|
||||
///</summary>
|
||||
static initonly Vector3 NegativeInfinity = Vector3(std::numeric_limits<double>::lowest(),
|
||||
std::numeric_limits<double>::lowest(),
|
||||
std::numeric_limits<double>::lowest());
|
||||
static initonly Vector3 NegativeInfinity = Vector3(std::numeric_limits<float>::lowest(),
|
||||
std::numeric_limits<float>::lowest(),
|
||||
std::numeric_limits<float>::lowest());
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(1, 1, 1).
|
||||
///</summary>
|
||||
static initonly Vector3 One = Vector3(1.0, 1.0, 1.0);
|
||||
static initonly Vector3 One = Vector3(1.0f, 1.0f, 1.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(double.PositiveInfinity,
|
||||
/// double.PositiveInfinity, double.PositiveInfinity).
|
||||
/// Shorthand for writing Vector3(float.PositiveInfinity,
|
||||
/// float.PositiveInfinity, float.PositiveInfinity).
|
||||
///</summary>
|
||||
static initonly Vector3 PositiveInfinity = Vector3(std::numeric_limits<double>::max(),
|
||||
std::numeric_limits<double>::max(),
|
||||
std::numeric_limits<double>::max());
|
||||
static initonly Vector3 PositiveInfinity = Vector3(std::numeric_limits<float>::max(),
|
||||
std::numeric_limits<float>::max(),
|
||||
std::numeric_limits<float>::max());
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(1, 0, 0).
|
||||
///</summary>
|
||||
static initonly Vector3 Right = Vector3(1.0, 0.0, 0.0);
|
||||
static initonly Vector3 Right = Vector3(1.0f, 0.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 1, 0).
|
||||
///</summary>
|
||||
static initonly Vector3 Up = Vector3(0.0, 1.0, 0.0);
|
||||
static initonly Vector3 Up = Vector3(0.0f, 1.0f, 0.0f);
|
||||
///<summary>
|
||||
/// Shorthand for writing Vector3(0, 0, 0).
|
||||
///</summary>
|
||||
static initonly Vector3 Zero = Vector3(0.0, 0.0, 0.0);
|
||||
static initonly Vector3 Zero = Vector3(0.0f, 0.0f, 0.0f);
|
||||
#pragma endregion
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
@ -87,39 +87,39 @@ namespace SHADE
|
|||
///<summary>
|
||||
/// X-component of the Vector3.
|
||||
///</summary>
|
||||
double x;
|
||||
float x;
|
||||
///<summary>
|
||||
/// Y-component of the Vector3.
|
||||
///</summary>
|
||||
double y;
|
||||
float y;
|
||||
///<summary>
|
||||
/// Z-component of the Vector3.
|
||||
///</summary>
|
||||
double z;
|
||||
float z;
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor to construct a Vector3 with the specified components with the
|
||||
/// Y and Z-component set to 0.0.
|
||||
/// Y and Z-component set to 0.0f.
|
||||
/// </summary>
|
||||
/// <param name="_x">X-coordinate to set.</param>
|
||||
Vector3(double _x);
|
||||
Vector3(float _x);
|
||||
/// <summary>
|
||||
/// Constructor to construct a Vector3 with the specified components with the
|
||||
/// Z-component set to 0.0.
|
||||
/// Z-component set to 0.0f.
|
||||
/// </summary>
|
||||
/// <param name="_x">X-coordinate to set.</param>
|
||||
/// <param name="_y">Y-coordinate to set.</param>
|
||||
Vector3(double _x, double _y);
|
||||
Vector3(float _x, float _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);
|
||||
Vector3(float _x, float _y, float _z);
|
||||
/// <summary>
|
||||
/// Conversion constructor to construct a Vector3 using a Vector2.
|
||||
/// </summary>
|
||||
|
@ -149,24 +149,24 @@ namespace SHADE
|
|||
/// need the precise magnitude, consider using GetSqrMagnitude() instead.
|
||||
/// </summary>
|
||||
/// <returns>Returns the length of this Vector3.</returns>
|
||||
double GetMagnitude();
|
||||
float GetMagnitude();
|
||||
/// <summary>
|
||||
/// Calculates and returns the squared magnitude of this Vector3.
|
||||
/// </summary>
|
||||
/// <returns>Returns the squared length of this Vector3.</returns>
|
||||
double GetSqrMagnitude();
|
||||
float 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();
|
||||
float Angle2DFromRightRadians();
|
||||
/// <summary>
|
||||
/// Calculates and returns the angle of this vector from the right vector. This
|
||||
/// function returns values between -180.0 and 180.0.
|
||||
/// function returns values between -180.0f and 180.0f.
|
||||
/// </summary>
|
||||
/// <returns>Returns the angle of this vector from the right vector in degrees.</returns>
|
||||
double Angle2DFromRightDegrees();
|
||||
float Angle2DFromRightDegrees();
|
||||
/// <summary>
|
||||
/// Checks if a specified point is near this Vector3 that represents a point with
|
||||
/// a tolerance value of PLS_EPSILON.
|
||||
|
@ -188,7 +188,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
bool IsNearPoint(Vector3 point, float tolerance);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* IEquatable */
|
||||
|
@ -236,14 +236,14 @@ namespace SHADE
|
|||
/// <returns>
|
||||
/// True if the two Vector3s are within the tolerance value specified
|
||||
/// </returns>
|
||||
static bool IsNear(Vector3 lhs, Vector3 rhs, double tolerance);
|
||||
static bool IsNear(Vector3 lhs, Vector3 rhs, float 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);
|
||||
static float Dot(Vector3 lhs, Vector3 rhs);
|
||||
/// <summary>
|
||||
/// Computes and returns the cross product of 2 specified Vector3s.
|
||||
/// </summary>
|
||||
|
@ -274,7 +274,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
static Vector3 RotateRadians(Vector3 vec, float radians);
|
||||
/// <summary>
|
||||
/// Rotates a Vector3 on the Z-axis by a specified angle in an anti-clockwise
|
||||
/// direction.
|
||||
|
@ -284,7 +284,7 @@ namespace SHADE
|
|||
/// 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);
|
||||
static Vector3 RotateDegrees(Vector3 vec, float degrees);
|
||||
/// <summary>
|
||||
/// Computes and returns a Vector3 that is made from the smallest components of
|
||||
/// the two specified Vector3s.
|
||||
|
@ -312,25 +312,25 @@ namespace SHADE
|
|||
/// 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="a">The start Vector3, returned when t = 0.0f.</param>
|
||||
/// <param name="b">The end Vector3, returned when t = 1.0f.</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);
|
||||
static Vector3 Lerp(Vector3 a, Vector3 b, float 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="a">The start Vector3, returned when t = 0.0f.</param>
|
||||
/// <param name="b">The end Vector3, returned when t = 1.0f.</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);
|
||||
static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t);
|
||||
/// <summary>
|
||||
/// Moves a point current towards target.
|
||||
/// Similar to Lerp(), however, the function will ensure that the distance never
|
||||
|
@ -341,7 +341,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Overloaded Operators */
|
||||
|
@ -375,7 +375,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector3 operator*(Vector3 lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Calculates the division of a Vector3 with a scalar value and returns
|
||||
/// the result.
|
||||
|
@ -383,7 +383,7 @@ namespace SHADE
|
|||
/// <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);
|
||||
static Vector3 operator/(Vector3 lhs, float rhs);
|
||||
/// <summary>
|
||||
/// Checks if two Vector3s are approximately equal. This is equivalent to
|
||||
/// calling Vector3.IsNear() with default tolerance values.
|
||||
|
|
|
@ -35,10 +35,7 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
SHVec3 Convert::ToNative(Vector3 vec)
|
||||
{
|
||||
const double X = vec.x;
|
||||
const double Y = vec.y;
|
||||
const double Z = vec.z;
|
||||
return SHVec3(X, Y, Z);
|
||||
return SHVec3(vec.x, vec.y, vec.z);
|
||||
}
|
||||
Vector3 Convert::ToCLI(const SHVec3& vec)
|
||||
{
|
||||
|
@ -46,9 +43,7 @@ namespace SHADE
|
|||
}
|
||||
SHVec2 Convert::ToNative(Vector2 vec)
|
||||
{
|
||||
const double X = vec.x;
|
||||
const double Y = vec.y;
|
||||
return SHVec2(X, Y);
|
||||
return SHVec2(vec.x, vec.y);
|
||||
}
|
||||
|
||||
Vector2 Convert::ToCLI(const SHVec2& vec)
|
||||
|
@ -56,6 +51,16 @@ namespace SHADE
|
|||
return Vector2(vec.x, vec.y);
|
||||
}
|
||||
|
||||
SHQuaternion Convert::ToNative(Quaternion quat)
|
||||
{
|
||||
return SHQuaternion{ quat.x, quat.y, quat.z, quat.w };
|
||||
}
|
||||
|
||||
Quaternion Convert::ToCLI(const SHQuaternion& quat)
|
||||
{
|
||||
return Quaternion{ quat.x, quat.y, quat.z, quat.w };
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* String Conversions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -18,10 +18,12 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "ECS_Base/Entity/SHEntity.h"
|
||||
#include "Math/Vector/SHVec2.h"
|
||||
#include "Math/Vector/SHVec3.h"
|
||||
#include "Math/SHQuaternion.h"
|
||||
// Project Includes
|
||||
#include "Engine/Entity.hxx"
|
||||
#include "Math/Vector2.hxx"
|
||||
#include "Math/Vector3.hxx"
|
||||
#include "Math/Quaternion.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -74,6 +76,18 @@ namespace SHADE
|
|||
/// <param name="vec">The native Vector2 to convert from.</param>
|
||||
/// <returns>Managed copy of a native Vector2.</returns>
|
||||
static Vector2 ToCLI(const SHVec2& vec);
|
||||
/// <summary>
|
||||
/// Converts from a managed Quaternion to a native Quaternion.
|
||||
/// </summary>
|
||||
/// <param name="quat">The managed Quaternion to convert from.</param>
|
||||
/// <returns>Native copy of a managed Quaternion.</returns>
|
||||
static SHQuaternion ToNative(Quaternion quat);
|
||||
/// <summary>
|
||||
/// Converts from a native Quaternion to a managed Quaternion.
|
||||
/// </summary>
|
||||
/// <param name="quat">The native Quaternion to convert from.</param>
|
||||
/// <returns>Managed copy of a native Quaternion.</returns>
|
||||
static Quaternion ToCLI(const SHQuaternion& quat);
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* String Conversions */
|
||||
|
|
Loading…
Reference in New Issue