Fixed bug where rigidbody setters in the first frame causes a crash #261

Merged
direnbharwani merged 2 commits from SP3-2-Physics into main 2022-11-23 15:33:17 +08:00
7 changed files with 266 additions and 185 deletions
Showing only changes of commit ef0243c335 - Show all commits

View File

@ -23,6 +23,7 @@ public class RaccoonShowcase : Script
[Range(-5, 5)] [Range(-5, 5)]
public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 }); public List<int> intList = new List<int>(new int[] { 2, 8, 2, 6, 8, 0, 1 });
public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient }); public List<Light.Type> enumList = new List<Light.Type>(new Light.Type[] { Light.Type.Point, Light.Type.Directional, Light.Type.Ambient });
public List<int> nullList;
public FontAsset fontAsset; public FontAsset fontAsset;
public MeshAsset mesh; public MeshAsset mesh;
public MaterialAsset matAsset; public MaterialAsset matAsset;

View File

@ -61,8 +61,13 @@ namespace SHADE
SHVkInstance::Init(true, false, true); SHVkInstance::Init(true, false, true);
#endif #endif
// Get Physical Device and Construct Logical Device // Get Physical Device
physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST); physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST);
if (!physicalDevice->GetVkPhysicalDevice())
{
throw std::runtime_error("[Graphics System] No supported Vulkan 1.3 compatible GPU was detected!");
}
// Construct Logical Device
device = SHVkInstance::CreateLogicalDevice({ SHQueueParams(SH_Q_FAM::GRAPHICS, SH_QUEUE_SELECT::DEDICATED), SHQueueParams(SH_Q_FAM::TRANSFER, SH_QUEUE_SELECT::DEDICATED) }, physicalDevice); device = SHVkInstance::CreateLogicalDevice({ SHQueueParams(SH_Q_FAM::GRAPHICS, SH_QUEUE_SELECT::DEDICATED), SHQueueParams(SH_Q_FAM::TRANSFER, SH_QUEUE_SELECT::DEDICATED) }, physicalDevice);
// Construct surface // Construct surface

View File

@ -35,7 +35,7 @@ namespace SHADE
SHVec3 const SHVec3::Back { 0.0f, 0.0f, -1.0f }; SHVec3 const SHVec3::Back { 0.0f, 0.0f, -1.0f };
SHVec3 const SHVec3::UnitX { 1.0f, 0.0f, 0.0f }; SHVec3 const SHVec3::UnitX { 1.0f, 0.0f, 0.0f };
SHVec3 const SHVec3::UnitY { 0.0f, 1.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 */ /* Constructors & Destructor Definitions */
@ -411,6 +411,14 @@ namespace SHADE
return result; 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 SHVec3::RotateX(const SHVec3& v, float angleInRad) noexcept
{ {
SHVec3 result; SHVec3 result;

View File

@ -25,6 +25,8 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Forward Declarations */ /* Forward Declarations */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
class SHQuaternion;
class SHMatrix; class SHMatrix;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -136,6 +138,7 @@ namespace SHADE
[[nodiscard]] static SHVec3 Project (const SHVec3& v, const SHVec3& u) noexcept; [[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 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 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 RotateX (const SHVec3& v, float angleInRad) noexcept;
[[nodiscard]] static SHVec3 RotateY (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; [[nodiscard]] static SHVec3 RotateZ (const SHVec3& v, float angleInRad) noexcept;

View File

@ -1,16 +1,12 @@
/************************************************************************************//*! /****************************************************************************************
\file Transform.cxx * \file Transform.cxx
\author Tng Kah Wei, kahwei.tng, 390009620 * \author Diren D Bharwani, diren.dbharwani, 390002520
\par email: kahwei.tng\@digipen.edu * \brief Implementation for the managed Transform class.
\date Sep 23, 2022 *
\brief Contains the definition of the functions of 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
Note: This file is written in C++17/CLI. * of DigiPen Institute of Technology is prohibited.
****************************************************************************************/
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 // Precompiled Headers
#include "SHpch.h" #include "SHpch.h"
// Primary Header // Primary Header
@ -18,80 +14,116 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE namespace SHADE
{ {
/*---------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Properties */ /* Constructors */
/*---------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
Vector3 Transform::LocalPosition::get()
{ Transform::Transform(Entity entity)
return Convert::ToCLI(GetNativeComponent()->GetLocalPosition()); : Component(entity)
} {}
void Transform::LocalPosition::set(Vector3 val)
{ /*-----------------------------------------------------------------------------------*/
GetNativeComponent()->SetLocalPosition(Convert::ToNative(val)); /* Properties */
} /*-----------------------------------------------------------------------------------*/
Quaternion Transform::LocalRotation::get() Vector3 Transform::LocalPosition::get()
{ {
return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation()); return Convert::ToCLI(GetNativeComponent()->GetLocalPosition());
} }
void Transform::LocalRotation::set(Quaternion val)
{ void Transform::LocalPosition::set(Vector3 val)
GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val)); {
} GetNativeComponent()->SetLocalPosition(Convert::ToNative(val));
Vector3 Transform::LocalEulerAngles::get() }
{
return Convert::ToCLI(GetNativeComponent()->GetLocalRotation()); Quaternion Transform::LocalRotation::get()
} {
void Transform::LocalEulerAngles::set(Vector3 val) return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
{ }
GetNativeComponent()->SetLocalRotation(Convert::ToNative(val));
} void Transform::LocalRotation::set(Quaternion val)
Vector3 Transform::LocalScale::get() {
{ GetNativeComponent()->SetLocalOrientation(Convert::ToNative(val));
return Convert::ToCLI(GetNativeComponent()->GetLocalScale()); }
} Vector3 Transform::LocalEulerAngles::get()
void Transform::LocalScale::set(Vector3 val) {
{ return Convert::ToCLI(GetNativeComponent()->GetLocalRotation());
GetNativeComponent()->SetLocalScale(Convert::ToNative(val)); }
}
Vector3 Transform::GlobalPosition::get() void Transform::LocalEulerAngles::set(Vector3 val)
{ {
return Convert::ToCLI(GetNativeComponent()->GetWorldPosition()); GetNativeComponent()->SetLocalRotation(Convert::ToNative(val));
} }
void Transform::GlobalPosition::set(Vector3 val)
{ Vector3 Transform::LocalScale::get()
GetNativeComponent()->SetWorldPosition(Convert::ToNative(val)); {
} return Convert::ToCLI(GetNativeComponent()->GetLocalScale());
Quaternion Transform::GlobalRotation::get() }
{
return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation()); void Transform::LocalScale::set(Vector3 val)
} {
void Transform::GlobalRotation::set(Quaternion val) GetNativeComponent()->SetLocalScale(Convert::ToNative(val));
{ }
GetNativeComponent()->SetWorldOrientation(Convert::ToNative(val));
} Vector3 Transform::GlobalPosition::get()
Vector3 Transform::GlobalEulerAngles::get() {
{ return Convert::ToCLI(GetNativeComponent()->GetWorldPosition());
return Convert::ToCLI(GetNativeComponent()->GetWorldRotation()); }
}
void Transform::GlobalEulerAngles::set(Vector3 val) void Transform::GlobalPosition::set(Vector3 val)
{ {
GetNativeComponent()->SetWorldRotation(Convert::ToNative(val)); GetNativeComponent()->SetWorldPosition(Convert::ToNative(val));
} }
Vector3 Transform::GlobalScale::get()
{ Quaternion Transform::GlobalRotation::get()
return Convert::ToCLI(GetNativeComponent()->GetWorldScale()); {
return Convert::ToCLI(GetNativeComponent()->GetLocalOrientation());
} }
void Transform::GlobalScale::set(Vector3 val)
{ void Transform::GlobalRotation::set(Quaternion val)
GetNativeComponent()->SetWorldScale(Convert::ToNative(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)
{}
} }

View File

@ -1,17 +1,12 @@
/************************************************************************************//*! /****************************************************************************************
\file Transform.hxx * \file Transform.hxx
\author Tng Kah Wei, kahwei.tng, 390009620 * \author Diren D Bharwani, diren.dbharwani, 390002520
\par email: kahwei.tng\@digipen.edu * \brief Interface for the managed Transform class.
\date Sep 23, 2022 *
\brief Contains the definition of the managed Transform class with the * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
declaration of functions for working with it. * disclosure of this file or its contents without the prior written consent
* of DigiPen Institute of Technology is prohibited.
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.
*//*************************************************************************************/
#pragma once #pragma once
// Project Includes // Project Includes
@ -23,90 +18,121 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE namespace SHADE
{ {
/// <summary>
/// CLR version of the SHADE Engine's TransformComponent.
/// </summary>
public ref class Transform : public Component<SHTransformComponent>
{
public:
/*-----------------------------------------------------------------------------*/
/* Properties */
/*-----------------------------------------------------------------------------*/
/// <summary> /// <summary>
/// CLR version of the SHADE Engine's TransformComponent. /// Local position stored by this Transform.
/// </summary> /// </summary>
public ref class Transform : public Component<SHTransformComponent> property Vector3 LocalPosition
{ {
internal: Vector3 get();
/*-----------------------------------------------------------------------------*/ void set(Vector3 val);
/* Constructors */ }
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructs a Transform Component that represents a native Transform component
/// tied to the specified Entity.
/// </summary>
/// <param name="entity">Entity that this Component will be tied to.</param>
Transform(Entity entity);
public: /// <summary>
/*-----------------------------------------------------------------------------*/ /// Local rotation quaternion stored by this Transform.
/* Properties */ /// </summary>
/*-----------------------------------------------------------------------------*/ property Quaternion LocalRotation
/// <summary> {
/// Local position stored by this Transform. Quaternion get();
/// </summary> void set(Quaternion val);
property Vector3 LocalPosition }
{
Vector3 get(); /// <summary>
void set(Vector3 val); /// Local euler angle rotations stored by this Transform.
} /// </summary>
/// <summary> property Vector3 LocalEulerAngles
/// Local rotation quaternion stored by this Transform. {
/// </summary> Vector3 get();
property Quaternion LocalRotation void set(Vector3 val);
{ }
Quaternion get();
void set(Quaternion val); /// <summary>
} /// Local scale stored by this Transform.
/// <summary> /// </summary>
/// Local euler angle rotations stored by this Transform. property Vector3 LocalScale
/// </summary> {
property Vector3 LocalEulerAngles Vector3 get();
{ void set(Vector3 val);
Vector3 get(); }
void set(Vector3 val);
} /// <summary>
/// <summary> /// Global position stored by this Transform.
/// Local scale stored by this Transform. /// </summary>
/// </summary> property Vector3 GlobalPosition
property Vector3 LocalScale {
{ Vector3 get();
Vector3 get(); void set(Vector3 val);
void set(Vector3 val); }
}
/// <summary> /// <summary>
/// Global position stored by this Transform. /// Global rotation quaternion stored by this Transform.
/// </summary> /// </summary>
property Vector3 GlobalPosition property Quaternion GlobalRotation
{ {
Vector3 get(); Quaternion get();
void set(Vector3 val); void set(Quaternion val);
} }
/// <summary>
/// Global rotation quaternion stored by this Transform. /// <summary>
/// </summary> /// Global euler angle rotations stored by this Transform.
property Quaternion GlobalRotation /// </summary>
{ property Vector3 GlobalEulerAngles
Quaternion get(); {
void set(Quaternion val); Vector3 get();
} void set(Vector3 val);
/// <summary> }
/// Global euler angle rotations stored by this Transform.
/// </summary> /// <summary>
property Vector3 GlobalEulerAngles /// Global scale stored by this Transform.
{ /// </summary>
Vector3 get(); property Vector3 GlobalScale
void set(Vector3 val); {
} Vector3 get();
/// <summary> void set(Vector3 val);
/// Global scale stored by this Transform. }
/// </summary>
property Vector3 GlobalScale property Vector3 Forward
{ {
Vector3 get(); Vector3 get();
void set(Vector3 val); }
}
}; internal:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Constructs a Transform Component that represents a native Transform component
/// tied to the specified Entity.
/// </summary>
/// <param name="entity">Entity that this Component will be tied to.</param>
Transform(Entity entity);
public:
/*-----------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------*/
/// <summary>
/// Rotates the transform to look at a target.
/// This function
/// </summary>
/// <param name="target"> The target to look at. </param>
void LookAt(Vector3 target);
/// <summary>
/// Rotates the transform to look at a target.
/// </summary>
/// <param name="target"> The target to look at. </param>
/// <param name="up"> The up vector to rotate about. </param>
void LookAt(Vector3 target, Vector3 up);
};
} }

View File

@ -189,6 +189,12 @@ namespace SHADE
System::Type^ listType = field->FieldType->GenericTypeArguments[0]; System::Type^ listType = field->FieldType->GenericTypeArguments[0];
RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field); RangeAttribute^ rangeAttrib = hasAttribute<RangeAttribute^>(field);
System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object)); System::Collections::IList^ iList = safe_cast<System::Collections::IList^>(field->GetValue(object));
if (iList == nullptr)
{
// Create if the list does not exist
iList = safe_cast<System::Collections::IList^>(System::Activator::CreateInstance(field->FieldType));
field->SetValue(object, iList);
}
if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name), &isHovered)) if (SHEditorUI::CollapsingHeader(Convert::ToNative(field->Name), &isHovered))
{ {