diff --git a/SHADE_Engine/src/Math/Vector/SHVec3.cpp b/SHADE_Engine/src/Math/Vector/SHVec3.cpp
index a696f341..4b77636a 100644
--- a/SHADE_Engine/src/Math/Vector/SHVec3.cpp
+++ b/SHADE_Engine/src/Math/Vector/SHVec3.cpp
@@ -35,7 +35,7 @@ namespace SHADE
SHVec3 const SHVec3::Back { 0.0f, 0.0f, -1.0f };
SHVec3 const SHVec3::UnitX { 1.0f, 0.0f, 0.0f };
SHVec3 const SHVec3::UnitY { 0.0f, 1.0f, 0.0f };
- SHVec3 const SHVec3::UnitZ { 0.0f, 0.0f, 1.0f };
+ SHVec3 const SHVec3::UnitZ { 0.0f, 0.0f, -1.0f };
/*-----------------------------------------------------------------------------------*/
/* Constructors & Destructor Definitions */
@@ -411,6 +411,14 @@ namespace SHADE
return result;
}
+ SHVec3 SHVec3::Rotate(const SHVec3& v, const SHQuaternion& q) noexcept
+ {
+ SHVec3 result;
+
+ XMStoreFloat3(&result, XMVector3Rotate(v, q));
+ return result;
+ }
+
SHVec3 SHVec3::RotateX(const SHVec3& v, float angleInRad) noexcept
{
SHVec3 result;
diff --git a/SHADE_Engine/src/Math/Vector/SHVec3.h b/SHADE_Engine/src/Math/Vector/SHVec3.h
index eab96b30..de37d6a5 100644
--- a/SHADE_Engine/src/Math/Vector/SHVec3.h
+++ b/SHADE_Engine/src/Math/Vector/SHVec3.h
@@ -25,6 +25,8 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
/* Forward Declarations */
/*-----------------------------------------------------------------------------------*/
+
+ class SHQuaternion;
class SHMatrix;
/*-----------------------------------------------------------------------------------*/
@@ -136,6 +138,7 @@ namespace SHADE
[[nodiscard]] static SHVec3 Project (const SHVec3& v, const SHVec3& u) noexcept;
[[nodiscard]] static SHVec3 Reflect (const SHVec3& v, const SHVec3& normal) noexcept;
[[nodiscard]] static SHVec3 Rotate (const SHVec3& v, const SHVec3& axis, float angleInRad) noexcept;
+ [[nodiscard]] static SHVec3 Rotate (const SHVec3& v, const SHQuaternion& q) noexcept;
[[nodiscard]] static SHVec3 RotateX (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateY (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateZ (const SHVec3& v, float angleInRad) noexcept;
diff --git a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp
index 2df5c496..9eab928d 100644
--- a/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp
+++ b/SHADE_Engine/src/Physics/System/SHPhysicsSystem.cpp
@@ -185,6 +185,7 @@ namespace SHADE
objectManager.commandQueue.pop();
sceneGraph.Traverse(BUILD_NEW_SCENE_PHYSICS_OBJECT);
+ objectManager.UpdateCommands();
}
void SHPhysicsSystem::ForceUpdate()
@@ -443,6 +444,7 @@ namespace SHADE
// Build scene
SHSceneManager::GetCurrentSceneGraph().Traverse(BUILD_PHYSICS_OBJECT);
+ objectManager.UpdateCommands();
return onPlayEvent->handle;
}
diff --git a/SHADE_Managed/src/Components/Transform.cxx b/SHADE_Managed/src/Components/Transform.cxx
index 927ce87f..bd564010 100644
--- a/SHADE_Managed/src/Components/Transform.cxx
+++ b/SHADE_Managed/src/Components/Transform.cxx
@@ -1,16 +1,12 @@
-/************************************************************************************//*!
-\file Transform.cxx
-\author Tng Kah Wei, kahwei.tng, 390009620
-\par email: kahwei.tng\@digipen.edu
-\date Sep 23, 2022
-\brief Contains the definition of the functions of the managed Transform class.
-
- Note: This file is written in C++17/CLI.
-
-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.
-*//*************************************************************************************/
+/****************************************************************************************
+ * \file Transform.cxx
+ * \author Diren D Bharwani, diren.dbharwani, 390002520
+ * \brief Implementation for the managed Transform class.
+ *
+ * \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.
+****************************************************************************************/
// Precompiled Headers
#include "SHpch.h"
// Primary Header
@@ -18,80 +14,116 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE
{
- /*---------------------------------------------------------------------------------*/
- /* Properties */
- /*---------------------------------------------------------------------------------*/
- Vector3 Transform::LocalPosition::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetLocalPosition());
- }
- void Transform::LocalPosition::set(Vector3 val)
- {
- GetNativeComponent()->SetLocalPosition(Convert::ToNative(val));
- }
- Quaternion Transform::LocalRotation::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
- }
- void Transform::LocalRotation::set(Quaternion val)
- {
- GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val));
- }
- Vector3 Transform::LocalEulerAngles::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetLocalRotation());
- }
- void Transform::LocalEulerAngles::set(Vector3 val)
- {
- GetNativeComponent()->SetLocalRotation(Convert::ToNative(val));
- }
- Vector3 Transform::LocalScale::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetLocalScale());
-
- }
- void Transform::LocalScale::set(Vector3 val)
- {
- GetNativeComponent()->SetLocalScale(Convert::ToNative(val));
- }
- Vector3 Transform::GlobalPosition::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetWorldPosition());
- }
- void Transform::GlobalPosition::set(Vector3 val)
- {
- GetNativeComponent()->SetWorldPosition(Convert::ToNative(val));
- }
- Quaternion Transform::GlobalRotation::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
- }
- void Transform::GlobalRotation::set(Quaternion val)
- {
- GetNativeComponent()->SetWorldOrientation(Convert::ToNative(val));
- }
- Vector3 Transform::GlobalEulerAngles::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetWorldRotation());
- }
- void Transform::GlobalEulerAngles::set(Vector3 val)
- {
- GetNativeComponent()->SetWorldRotation(Convert::ToNative(val));
- }
- Vector3 Transform::GlobalScale::get()
- {
- return Convert::ToCLI(GetNativeComponent()->GetWorldScale());
-
- }
- void Transform::GlobalScale::set(Vector3 val)
- {
- GetNativeComponent()->SetWorldScale(Convert::ToNative(val));
- }
+ /*-----------------------------------------------------------------------------------*/
+ /* Constructors */
+ /*-----------------------------------------------------------------------------------*/
+
+ Transform::Transform(Entity entity)
+ : Component(entity)
+ {}
+
+ /*-----------------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------------*/
+ Vector3 Transform::LocalPosition::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetLocalPosition());
+ }
+
+ void Transform::LocalPosition::set(Vector3 val)
+ {
+ GetNativeComponent()->SetLocalPosition(Convert::ToNative(val));
+ }
+
+ Quaternion Transform::LocalRotation::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
+ }
+
+ void Transform::LocalRotation::set(Quaternion val)
+ {
+ GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::LocalEulerAngles::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetLocalRotation());
+ }
+
+ void Transform::LocalEulerAngles::set(Vector3 val)
+ {
+ GetNativeComponent()->SetLocalRotation(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::LocalScale::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetLocalScale());
+ }
+
+ void Transform::LocalScale::set(Vector3 val)
+ {
+ GetNativeComponent()->SetLocalScale(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::GlobalPosition::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetWorldPosition());
+ }
+
+ void Transform::GlobalPosition::set(Vector3 val)
+ {
+ GetNativeComponent()->SetWorldPosition(Convert::ToNative(val));
+ }
+
+ Quaternion Transform::GlobalRotation::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
+ }
+
+ void Transform::GlobalRotation::set(Quaternion val)
+ {
+ GetNativeComponent()->SetWorldOrientation(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::GlobalEulerAngles::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetWorldRotation());
+ }
+
+ void Transform::GlobalEulerAngles::set(Vector3 val)
+ {
+ GetNativeComponent()->SetWorldRotation(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::GlobalScale::get()
+ {
+ return Convert::ToCLI(GetNativeComponent()->GetWorldScale());
+ }
+
+ void Transform::GlobalScale::set(Vector3 val)
+ {
+ GetNativeComponent()->SetWorldScale(Convert::ToNative(val));
+ }
+
+ Vector3 Transform::Forward::get()
+ {
+ const SHVec3 DIRECTION = SHVec3::Rotate(SHVec3::UnitZ, Convert::ToNative(GlobalRotation));
+ return Convert::ToCLI(DIRECTION);
+ }
+
+ /*-----------------------------------------------------------------------------------*/
+ /* Usage Function Definitions */
+ /*-----------------------------------------------------------------------------------*/
+
+ void Transform::LookAt(Vector3 target)
+ {
+ GlobalRotation.SetLookRotation(target - GlobalPosition, Vector3::Up);
+ }
+
+ void Transform::LookAt(Vector3 target, Vector3 up)
+ {
+ GlobalRotation.SetLookRotation(target - GlobalPosition, up);
+ }
+
- /*---------------------------------------------------------------------------------*/
- /* Constructors */
- /*---------------------------------------------------------------------------------*/
- Transform::Transform(Entity entity)
- : Component(entity)
- {}
}
diff --git a/SHADE_Managed/src/Components/Transform.hxx b/SHADE_Managed/src/Components/Transform.hxx
index 942c6224..75883488 100644
--- a/SHADE_Managed/src/Components/Transform.hxx
+++ b/SHADE_Managed/src/Components/Transform.hxx
@@ -1,17 +1,12 @@
-/************************************************************************************//*!
-\file Transform.hxx
-\author Tng Kah Wei, kahwei.tng, 390009620
-\par email: kahwei.tng\@digipen.edu
-\date Sep 23, 2022
-\brief Contains the definition of the managed Transform class with the
- declaration of functions for working with it.
-
- Note: This file is written in C++17/CLI.
-
-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.
-*//*************************************************************************************/
+/****************************************************************************************
+ * \file Transform.hxx
+ * \author Diren D Bharwani, diren.dbharwani, 390002520
+ * \brief Interface for the managed Transform class.
+ *
+ * \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
// Project Includes
@@ -23,90 +18,121 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE
{
+ ///
+ /// CLR version of the SHADE Engine's TransformComponent.
+ ///
+ public ref class Transform : public Component
+ {
+ public:
+ /*-----------------------------------------------------------------------------*/
+ /* Properties */
+ /*-----------------------------------------------------------------------------*/
///
- /// CLR version of the SHADE Engine's TransformComponent.
+ /// Local position stored by this Transform.
///
- public ref class Transform : public Component
+ property Vector3 LocalPosition
{
- internal:
- /*-----------------------------------------------------------------------------*/
- /* Constructors */
- /*-----------------------------------------------------------------------------*/
- ///
- /// Constructs a Transform Component that represents a native Transform component
- /// tied to the specified Entity.
- ///
- /// Entity that this Component will be tied to.
- Transform(Entity entity);
+ Vector3 get();
+ void set(Vector3 val);
+ }
- public:
- /*-----------------------------------------------------------------------------*/
- /* Properties */
- /*-----------------------------------------------------------------------------*/
- ///
- /// Local position stored by this Transform.
- ///
- property Vector3 LocalPosition
- {
- Vector3 get();
- void set(Vector3 val);
- }
- ///
- /// Local rotation quaternion stored by this Transform.
- ///
- property Quaternion LocalRotation
- {
- Quaternion get();
- void set(Quaternion val);
- }
- ///
- /// Local euler angle rotations stored by this Transform.
- ///
- property Vector3 LocalEulerAngles
- {
- Vector3 get();
- void set(Vector3 val);
- }
- ///
- /// Local scale stored by this Transform.
- ///
- property Vector3 LocalScale
- {
- Vector3 get();
- void set(Vector3 val);
- }
- ///
- /// Global position stored by this Transform.
- ///
- property Vector3 GlobalPosition
- {
- Vector3 get();
- void set(Vector3 val);
- }
- ///
- /// Global rotation quaternion stored by this Transform.
- ///
- property Quaternion GlobalRotation
- {
- Quaternion get();
- void set(Quaternion val);
- }
- ///
- /// Global euler angle rotations stored by this Transform.
- ///
- property Vector3 GlobalEulerAngles
- {
- Vector3 get();
- void set(Vector3 val);
- }
- ///
- /// Global scale stored by this Transform.
- ///
- property Vector3 GlobalScale
- {
- Vector3 get();
- void set(Vector3 val);
- }
- };
+ ///
+ /// Local rotation quaternion stored by this Transform.
+ ///
+ property Quaternion LocalRotation
+ {
+ Quaternion get();
+ void set(Quaternion val);
+ }
+
+ ///
+ /// Local euler angle rotations stored by this Transform.
+ ///
+ property Vector3 LocalEulerAngles
+ {
+ Vector3 get();
+ void set(Vector3 val);
+ }
+
+ ///
+ /// Local scale stored by this Transform.
+ ///
+ property Vector3 LocalScale
+ {
+ Vector3 get();
+ void set(Vector3 val);
+ }
+
+ ///
+ /// Global position stored by this Transform.
+ ///
+ property Vector3 GlobalPosition
+ {
+ Vector3 get();
+ void set(Vector3 val);
+ }
+
+ ///
+ /// Global rotation quaternion stored by this Transform.
+ ///
+ property Quaternion GlobalRotation
+ {
+ Quaternion get();
+ void set(Quaternion val);
+ }
+
+ ///
+ /// Global euler angle rotations stored by this Transform.
+ ///
+ property Vector3 GlobalEulerAngles
+ {
+ Vector3 get();
+ void set(Vector3 val);
+ }
+
+ ///
+ /// Global scale stored by this Transform.
+ ///
+ property Vector3 GlobalScale
+ {
+ Vector3 get();
+ void set(Vector3 val);
+ }
+
+ property Vector3 Forward
+ {
+ Vector3 get();
+ }
+
+ internal:
+ /*-----------------------------------------------------------------------------*/
+ /* Constructors */
+ /*-----------------------------------------------------------------------------*/
+ ///
+ /// Constructs a Transform Component that represents a native Transform component
+ /// tied to the specified Entity.
+ ///
+ /// Entity that this Component will be tied to.
+ Transform(Entity entity);
+
+ public:
+ /*-----------------------------------------------------------------------------*/
+ /* Usage Functions */
+ /*-----------------------------------------------------------------------------*/
+
+ ///
+ /// Rotates the transform to look at a target.
+ /// This function
+ ///
+ /// The target to look at.
+ void LookAt(Vector3 target);
+
+ ///
+ /// Rotates the transform to look at a target.
+ ///
+ /// The target to look at.
+ /// The up vector to rotate about.
+ void LookAt(Vector3 target, Vector3 up);
+ };
}