diff --git a/SHADE_Managed/src/Components/Collider.cxx b/SHADE_Managed/src/Components/Collider.cxx index 1a53f9e1..41910d66 100644 --- a/SHADE_Managed/src/Components/Collider.cxx +++ b/SHADE_Managed/src/Components/Collider.cxx @@ -20,7 +20,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { /*---------------------------------------------------------------------------------*/ - /* ColliderBound - Constructors */ + /* CollisionShape - Constructors */ /*---------------------------------------------------------------------------------*/ CollisionShape::CollisionShape(int arrayIdx, Entity attachedEntity) : arrayIndex { arrayIdx } @@ -28,102 +28,183 @@ namespace SHADE {} /*---------------------------------------------------------------------------------*/ - /* ColliderBound - Setter Functions */ + /* CollisionShape - Properties */ + /*---------------------------------------------------------------------------------*/ + + bool CollisionShape::IsTrigger::get() + { + return getNativeCollisionShape().IsTrigger(); + } + + void CollisionShape::IsTrigger::set(bool value) + { + getNativeCollisionShape().SetIsTrigger(value); + } + + Vector3 CollisionShape::PositionOffset::get() + { + return Convert::ToCLI(getNativeCollisionShape().GetPositionOffset()); + } + + void CollisionShape::PositionOffset::set(Vector3 value) + { + getNativeCollisionShape().SetPositionOffset(Convert::ToNative(value)); + } + + Vector3 CollisionShape::RotationOffset::get() + { + return Convert::ToCLI(getNativeCollisionShape().GetRotationOffset()); + } + + void CollisionShape::RotationOffset::set(Vector3 value) + { + getNativeCollisionShape().SetRotationOffset(Convert::ToNative(value)); + } + + float CollisionShape::Friction::get() + { + return getNativeCollisionShape().GetFriction(); + } + + void CollisionShape::Friction::set(float value) + { + getNativeCollisionShape().SetFriction(value); + } + + float CollisionShape::Bounciness::get() + { + return getNativeCollisionShape().GetBounciness(); + } + + void CollisionShape::Bounciness::set(float value) + { + getNativeCollisionShape().SetBounciness(value); + } + + float CollisionShape::Density::get() + { + return getNativeCollisionShape().GetDensity(); + } + + void CollisionShape::Density::set(float value) + { + getNativeCollisionShape().SetDensity(value); + } + + /*---------------------------------------------------------------------------------*/ + /* CollisionShape - helper Functions */ /*---------------------------------------------------------------------------------*/ void CollisionShape::updateArrayIndex(int index) { arrayIndex = index; } + SHCollisionShape& SHADE::CollisionShape::getNativeCollisionShape() + { + SHColliderComponent* collider = SHComponentManager::GetComponent_s(entity); + if (!collider) + throw gcnew System::InvalidOperationException("Unable to retrieve Collider component!"); + + try + { + auto& shape = collider->GetCollisionShape(arrayIndex); + return shape; + } + catch (std::invalid_argument&) + { + throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range CollisionShape!"); + } + } + /*---------------------------------------------------------------------------------*/ - /* BoxColliderBound - Constructors */ + /* BoxCollider - Constructors */ /*---------------------------------------------------------------------------------*/ BoxCollider::BoxCollider(int arrayIdx, Entity attachedEntity) : CollisionShape { arrayIndex, attachedEntity } {} /*---------------------------------------------------------------------------------*/ - /* BoxColliderBound - Properties */ + /* BoxCollider - Properties */ /*---------------------------------------------------------------------------------*/ Vector3 BoxCollider::Center::get() { - return Convert::ToCLI(getNativeBoundObject().GetCenter()); + return Convert::ToCLI(getNativeCollisionShape().GetCenter()); } void BoxCollider::Center::set(Vector3 value) { - getNativeBoundObject().SetCenter(Convert::ToNative(value)); + getNativeCollisionShape().SetCenter(Convert::ToNative(value)); } Vector3 BoxCollider::HalfExtents::get() { - return Convert::ToCLI(getNativeBoundObject().GetWorldExtents()); + return Convert::ToCLI(getNativeCollisionShape().GetWorldExtents()); } void BoxCollider::HalfExtents::set(Vector3 value) { - getNativeBoundObject().SetWorldExtents(Convert::ToNative(value)); + getNativeCollisionShape().SetWorldExtents(Convert::ToNative(value)); } Vector3 BoxCollider::Min::get() { - return Convert::ToCLI(getNativeBoundObject().GetMin()); + return Convert::ToCLI(getNativeCollisionShape().GetMin()); } void BoxCollider::Min::set(Vector3 value) { - getNativeBoundObject().SetMin(Convert::ToNative(value)); + getNativeCollisionShape().SetMin(Convert::ToNative(value)); } Vector3 BoxCollider::Max::get() { - return Convert::ToCLI(getNativeBoundObject().GetMax()); + return Convert::ToCLI(getNativeCollisionShape().GetMax()); } void BoxCollider::Max::set(Vector3 value) { - getNativeBoundObject().SetMax(Convert::ToNative(value)); + getNativeCollisionShape().SetMax(Convert::ToNative(value)); } /*---------------------------------------------------------------------------------*/ - /* BoxColliderBound - Usage Functions */ + /* BoxCollider - Usage Functions */ /*---------------------------------------------------------------------------------*/ bool BoxCollider::TestPoint(Vector3 point) { - return getNativeBoundObject().TestPoint(Convert::ToNative(point)); + return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); } bool BoxCollider::Raycast(Ray ray, float maxDistance) { - return getNativeBoundObject().Raycast(Convert::ToNative(ray), maxDistance); + return getNativeCollisionShape().Raycast(Convert::ToNative(ray), maxDistance); } /*---------------------------------------------------------------------------------*/ - /* BoxColliderBound - Properties */ + /* SphereCollider - Properties */ /*---------------------------------------------------------------------------------*/ Vector3 SphereCollider::Center::get() { - return Convert::ToCLI(getNativeBoundObject().GetCenter()); + return Convert::ToCLI(getNativeCollisionShape().GetCenter()); } void SphereCollider::Center::set(Vector3 value) { - getNativeBoundObject().SetCenter(Convert::ToNative(value)); + getNativeCollisionShape().SetCenter(Convert::ToNative(value)); } float SphereCollider::Radius::get() { - return getNativeBoundObject().GetWorldRadius(); + return getNativeCollisionShape().GetWorldRadius(); } void SphereCollider::Radius::set(float value) { - getNativeBoundObject().SetWorldRadius(value); + getNativeCollisionShape().SetWorldRadius(value); } /*---------------------------------------------------------------------------------*/ - /* SphereColliderBound - Usage Functions */ + /* SphereCollider - Usage Functions */ /*---------------------------------------------------------------------------------*/ bool SphereCollider::TestPoint(Vector3 point) { - return getNativeBoundObject().TestPoint(Convert::ToNative(point)); + return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); } bool SphereCollider::Raycast(Ray ray, float maxDistance) { - return getNativeBoundObject().Raycast(Convert::ToNative(ray), maxDistance); + return getNativeCollisionShape().Raycast(Convert::ToNative(ray), maxDistance); } /*---------------------------------------------------------------------------------*/ - /* SphereColliderBound - Constructors */ + /* SphereCollider - Constructors */ /*---------------------------------------------------------------------------------*/ SphereCollider::SphereCollider(int arrayIndex, Entity attachedEntity) : CollisionShape{ arrayIndex, attachedEntity } @@ -154,7 +235,7 @@ namespace SHADE } /*---------------------------------------------------------------------------------*/ - /* Collider - ColliderBound Functions */ + /* Collider - Collider Functions */ /*---------------------------------------------------------------------------------*/ CollisionShape^ Collider::GetCollisionShape(int index) { @@ -166,7 +247,7 @@ namespace SHADE // Check if valid if (index < 0 || index >= subColliderList->Count) - throw gcnew System::ArgumentException("[Collider] Invalid index for Collider Bound retrieval."); + throw gcnew System::ArgumentException("[Collider] Invalid index for Collision Shape retrieval."); // Return the bound return subColliderList[index]; @@ -217,7 +298,7 @@ namespace SHADE { collidersList->Remove(wr); } - SAFE_NATIVE_CALL_END("Collider.OnColliderBoundChanged") + SAFE_NATIVE_CALL_END("Collider.OnCollisionShapeChanged") } void Collider::updateSubColliderList() diff --git a/SHADE_Managed/src/Components/Collider.h++ b/SHADE_Managed/src/Components/Collider.h++ index 6e165619..8ea648aa 100644 --- a/SHADE_Managed/src/Components/Collider.h++ +++ b/SHADE_Managed/src/Components/Collider.h++ @@ -19,7 +19,7 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { template - CollisionShapeType& SHADE::CollisionShape::getNativeBoundObject() + CollisionShapeType& SHADE::CollisionShape::getNativeCollisionShape() { SHColliderComponent* collider = SHComponentManager::GetComponent_s(entity); if (!collider) @@ -29,13 +29,13 @@ namespace SHADE { auto& shape = collider->GetCollisionShape(arrayIndex); if (shape.GetType() != SHCollisionShape::Type::BOX) - throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound."); + throw gcnew System::InvalidOperationException("Attempted to retrieve invalid CollisionShape."); return reinterpret_cast(shape); } catch (std::invalid_argument&) { - throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range ColliderBound!"); + throw gcnew System::IndexOutOfRangeException("Attempted to retrieve out of range CollisionShape!"); } } } diff --git a/SHADE_Managed/src/Components/Collider.hxx b/SHADE_Managed/src/Components/Collider.hxx index 1711e8b9..a649483f 100644 --- a/SHADE_Managed/src/Components/Collider.hxx +++ b/SHADE_Managed/src/Components/Collider.hxx @@ -30,6 +30,61 @@ namespace SHADE public ref class CollisionShape abstract { public: + /*-----------------------------------------------------------------------------*/ + /* Properties */ + /*-----------------------------------------------------------------------------*/ + + /// + /// Whether or not this CollisionShape is a trigger. + /// + property bool IsTrigger + { + bool get(); + void set(bool value); + } + /// + /// The positional offset of this collision shape from the transform's position. + /// + property Vector3 PositionOffset + { + Vector3 get(); + void set(Vector3 value); + } + /// + /// The rotational offset of this collision shape from the transform's rotation. + /// + property Vector3 RotationOffset + { + Vector3 get(); + void set(Vector3 value); + } + + // TODO(Diren): Swap this to Physics Materials once asset implementation for that is done + /// + /// The frictional coefficient of the shape. Clamped between 0 and 1. + /// + property float Friction + { + float get(); + void set(float value); + } + /// + /// The bounciness factor of the shape. Clamped between 0 and 1. + /// + property float Bounciness + { + float get(); + void set(float value); + } + /// + /// The mass density of this shape. Cannot be negative. + /// + property float Density + { + float get(); + void set(float value); + } + /*-----------------------------------------------------------------------------*/ /* Usage Functions */ /*-----------------------------------------------------------------------------*/ @@ -56,20 +111,25 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Data Members */ /*-----------------------------------------------------------------------------*/ - int arrayIndex; // Index into the colliders vector on the native object - Entity entity; // Entity holding the collider component that this collider bounds is on + int arrayIndex; // Index into the colliders vector on the native object + Entity entity; // Entity holding the collider component that this collider bounds is on /*-----------------------------------------------------------------------------*/ /* Helper Functions */ /*-----------------------------------------------------------------------------*/ template - CollisionShapeType& getNativeBoundObject(); + CollisionShapeType& getNativeCollisionShape(); internal: /*-----------------------------------------------------------------------------*/ /* Setter Functions */ /*-----------------------------------------------------------------------------*/ void updateArrayIndex(int index); + + /*-----------------------------------------------------------------------------*/ + /* Helper Functions */ + /*-----------------------------------------------------------------------------*/ + SHCollisionShape& getNativeCollisionShape(); }; /// @@ -205,18 +265,18 @@ namespace SHADE /* Usage Functions */ /*-----------------------------------------------------------------------------*/ /// - /// Retrieves a ColliderBound at the specified index in the ColliderBound list. + /// Retrieves a CollisionShape at the specified index in the CollisionShapes list. /// /// Index to retrieve a ColliderBound from. /// ColliderBound for the specified index. CollisionShape^ GetCollisionShape(int index); /// - /// Retrieves a ColliderBound at the specified index in the ColliderBound list + /// Retrieves a CollisionShape at the specified index in the CollisionShapes list /// and casts it to the appropriate type. /// - /// Type of the ColliderBound to cast to. - /// Index to retrieve a ColliderBound from. - /// ColliderBound for the specified index. + /// Type of the CollisionShape to cast to. + /// Index to retrieve a CollisionShape from. + /// CollisionShape for the specified index. generic where T:CollisionShape T GetCollisionShape(int index);