Merge pull request #301 from SHADE-DP/SP3-16-Math

Added rotate method with quaternions for Vector3
This commit is contained in:
XiaoQiDigipen 2023-01-07 16:18:36 +08:00 committed by GitHub
commit 83eb3fffcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View File

@ -35,7 +35,17 @@ namespace SHADE
: position { pos }
, orientation { SHQuaternion::FromEuler(rot) }
, scale { scl }
{}
{
ComputeTRS();
}
SHTransform::SHTransform(const SHVec3& pos, const SHQuaternion& quat, const SHVec3& scl) noexcept
: position { pos }
, orientation { quat }
, scale { scl }
{
ComputeTRS();
}
/*-----------------------------------------------------------------------------------*/
/* Operator Overload Definitions */

View File

@ -107,8 +107,7 @@ namespace SHADE
Vector3 Transform::Forward::get()
{
const SHVec3 DIRECTION = SHVec3::Rotate(-SHVec3::UnitZ, Convert::ToNative(GlobalRotation));
return Convert::ToCLI(DIRECTION);
return Vector3::Rotate(Vector3::Forward, GlobalRotation);
}
/*-----------------------------------------------------------------------------------*/

View File

@ -167,6 +167,10 @@ namespace SHADE
{
return Convert::ToCLI(SHVec3::Rotate(Convert::ToNative(vec), Convert::ToNative(axis), radians));
}
Vector3 Vector3::Rotate(Vector3 vec, Quaternion quat)
{
return Convert::ToCLI(SHVec3::Rotate(Convert::ToNative(vec), Convert::ToNative(quat)));
}
Vector3 Vector3::Min(Vector3 lhs, Vector3 rhs)
{
float lx = lhs.x, rx = rhs.x;

View File

@ -19,10 +19,17 @@ of DigiPen Institute of Technology is prohibited.
// Project Includes
#include "Vector2.hxx"
value struct Quaternion;
namespace SHADE
{
/*---------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-------------------------------------------------------------------------- --- */
value struct Quaternion;
/*---------------------------------------------------------------------------------*/
/* Type Definitions */
/*-------------------------------------------------------------------------- --- */
///<summary>
/// CLR version of SHADE Engine's Vector3 class that represents a 3-Dimensional Vector.
/// Designed to closely match Unity's Vector3 struct.
@ -308,6 +315,12 @@ namespace SHADE
/// <returns>The Vector3 that represents the rotated vector.</returns>
static Vector3 Rotate(Vector3 vec, Vector3 axis, float radians);
/// <summary>
/// Rotates a Vector3 using a Quaternion.
/// </summary>
/// <param name="vec">A Vector3 to rotate.</param>
/// <param name="quat">A Quaternion to rotate the vector with.</param>
static Vector3 Rotate(Vector3 vec, Quaternion quat);
/// <summary>
/// Computes and returns a Vector3 that is made from the smallest components of
/// the two specified Vector3s.
/// </summary>