Added Capsule Collider to C# #409
|
@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Collider.hxx"
|
#include "Collider.hxx"
|
||||||
|
|
||||||
#include "Physics/Collision/Shapes/SHBox.h"
|
#include "Physics/Collision/Shapes/SHBox.h"
|
||||||
|
#include "Physics/Collision/Shapes/SHCapsule.h"
|
||||||
#include "Physics/Collision/Shapes/SHSphere.h"
|
#include "Physics/Collision/Shapes/SHSphere.h"
|
||||||
#include "Utility/Debug.hxx"
|
#include "Utility/Debug.hxx"
|
||||||
|
|
||||||
|
@ -118,6 +119,29 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* SphereCollider - Properties */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Vector3 SphereCollider::Center::get()
|
||||||
|
{
|
||||||
|
return Convert::ToCLI(getNativeCollisionShape<SHSphere>().GetWorldCentroid());
|
||||||
|
}
|
||||||
|
float SphereCollider::Radius::get()
|
||||||
|
{
|
||||||
|
return getNativeCollisionShape<SHSphere>().GetWorldRadius();
|
||||||
|
}
|
||||||
|
void SphereCollider::Radius::set(float value)
|
||||||
|
{
|
||||||
|
getNativeCollisionShape<SHSphere>().SetWorldRadius(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* SphereCollider - Constructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
SphereCollider::SphereCollider(int arrayIndex, Entity attachedEntity)
|
||||||
|
: CollisionShape{ arrayIndex, attachedEntity }
|
||||||
|
{}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* BoxCollider - Constructors */
|
/* BoxCollider - Constructors */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -147,53 +171,33 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* BoxCollider - Usage Functions */
|
/* CapsuleCollider - Properties */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
bool BoxCollider::TestPoint(Vector3 point)
|
Vector3 CapsuleCollider::Center::get()
|
||||||
{
|
{
|
||||||
//return getNativeCollisionShape<SHAABB>().TestPoint(Convert::ToNative(point));
|
return Convert::ToCLI(getNativeCollisionShape<SHCapsule>().GetWorldCentroid());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
bool BoxCollider::Raycast(Ray ray, float maxDistance)
|
float CapsuleCollider::Radius::get()
|
||||||
{
|
{
|
||||||
//return getNativeCollisionShape<SHAABB>().Raycast(Convert::ToNative(ray));
|
return getNativeCollisionShape<SHCapsule>().GetWorldRadius();
|
||||||
return false;
|
}
|
||||||
|
void CapsuleCollider::Radius::set(float value)
|
||||||
|
{
|
||||||
|
getNativeCollisionShape<SHCapsule>().SetWorldRadius(value);
|
||||||
|
}
|
||||||
|
float CapsuleCollider::Height::get()
|
||||||
|
{
|
||||||
|
return getNativeCollisionShape<SHCapsule>().GetWorldHeight();
|
||||||
|
}
|
||||||
|
void CapsuleCollider::Height::set(float value)
|
||||||
|
{
|
||||||
|
getNativeCollisionShape<SHCapsule>().SetWorldHeight(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* SphereCollider - Properties */
|
/* CapsuleCollider - Constructors */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
Vector3 SphereCollider::Center::get()
|
CapsuleCollider::CapsuleCollider(int arrayIndex, Entity attachedEntity)
|
||||||
{
|
|
||||||
return Convert::ToCLI(getNativeCollisionShape<SHSphere>().GetWorldCentroid());
|
|
||||||
}
|
|
||||||
float SphereCollider::Radius::get()
|
|
||||||
{
|
|
||||||
return getNativeCollisionShape<SHSphere>().GetWorldRadius();
|
|
||||||
}
|
|
||||||
void SphereCollider::Radius::set(float value)
|
|
||||||
{
|
|
||||||
getNativeCollisionShape<SHSphere>().SetWorldRadius(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* SphereCollider - Usage Functions */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
bool SphereCollider::TestPoint(Vector3 point)
|
|
||||||
{
|
|
||||||
//return getNativeCollisionShape<SHSphere>().TestPoint(Convert::ToNative(point));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool SphereCollider::Raycast(Ray ray, float maxDistance)
|
|
||||||
{
|
|
||||||
//return getNativeCollisionShape<SHSphere>().Raycast(Convert::ToNative(ray));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
/* SphereCollider - Constructors */
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
SphereCollider::SphereCollider(int arrayIndex, Entity attachedEntity)
|
|
||||||
: CollisionShape{ arrayIndex, attachedEntity }
|
: CollisionShape{ arrayIndex, attachedEntity }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -303,18 +307,18 @@ namespace SHADE
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const auto& collider : GetNativeComponent()->GetCollisionShapes())
|
for (const auto& collider : GetNativeComponent()->GetCollisionShapes())
|
||||||
{
|
{
|
||||||
CollisionShape^ bound = nullptr;
|
CollisionShape^ shape = nullptr;
|
||||||
switch (collider->GetType())
|
switch (collider->GetType())
|
||||||
{
|
{
|
||||||
case SHCollisionShape::Type::BOX:
|
|
||||||
bound = gcnew BoxCollider(i, Owner.GetEntity());
|
|
||||||
break;
|
|
||||||
case SHCollisionShape::Type::SPHERE:
|
case SHCollisionShape::Type::SPHERE:
|
||||||
bound = gcnew SphereCollider(i, Owner.GetEntity());
|
shape = gcnew SphereCollider(i, Owner.GetEntity());
|
||||||
|
break;
|
||||||
|
case SHCollisionShape::Type::BOX:
|
||||||
|
shape = gcnew BoxCollider(i, Owner.GetEntity());
|
||||||
|
break;
|
||||||
|
case SHCollisionShape::Type::CAPSULE:
|
||||||
|
shape = gcnew CapsuleCollider(i, Owner.GetEntity());
|
||||||
break;
|
break;
|
||||||
//case SHCollisionShape::Type::CAPSULE:
|
|
||||||
// // TODO
|
|
||||||
// break;
|
|
||||||
default:
|
default:
|
||||||
Debug::LogWarning("[Collider] An invalid Collider Type was detected. Skipping.");
|
Debug::LogWarning("[Collider] An invalid Collider Type was detected. Skipping.");
|
||||||
break;
|
break;
|
||||||
|
@ -322,7 +326,7 @@ namespace SHADE
|
||||||
++i;
|
++i;
|
||||||
|
|
||||||
// Add into list
|
// Add into list
|
||||||
subColliderList->Add(bound);
|
subColliderList->Add(shape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
// Primary Include
|
// Primary Include
|
||||||
#include "Component.hxx"
|
#include "Component.hxx"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
template<typename CollisionShapeType>
|
template<typename CollisionShapeType>
|
||||||
|
@ -28,7 +29,7 @@ namespace SHADE
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto& shape = collider->GetCollisionShape(arrayIndex);
|
auto& shape = collider->GetCollisionShape(arrayIndex);
|
||||||
if (shape.GetType() != SHCollisionShape::Type::BOX)
|
if (shape.GetType() == SHCollisionShape::Type::INVALID)
|
||||||
throw gcnew System::InvalidOperationException("Attempted to retrieve invalid CollisionShape.");
|
throw gcnew System::InvalidOperationException("Attempted to retrieve invalid CollisionShape.");
|
||||||
|
|
||||||
return dynamic_cast<CollisionShapeType&>(shape);
|
return dynamic_cast<CollisionShapeType&>(shape);
|
||||||
|
|
|
@ -87,23 +87,6 @@ namespace SHADE
|
||||||
void set(float value);
|
void set(float value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* Usage Functions */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <summary>
|
|
||||||
/// Checks if the specified point is within this shape's bounds.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="point">Point to test with.</param>
|
|
||||||
/// <returns>True if the point is in the shape's bounds.</returns>
|
|
||||||
virtual bool TestPoint(Vector3 point) = 0;
|
|
||||||
/// <summary>
|
|
||||||
/// Computes a Raycast and checks if there is a collision with any object.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ray">The ray to cast.</param>
|
|
||||||
/// <param name="maxDistance">Maximum distance for the raycast check.</param>
|
|
||||||
/// <returns>True if the ray intersects with an object in the scene.</returns>
|
|
||||||
virtual bool Raycast(Ray ray, float maxDistance) = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
@ -135,7 +118,39 @@ namespace SHADE
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Box-shaped Collider Bound.
|
/// A Sphere Collider
|
||||||
|
/// </summary>
|
||||||
|
public ref class SphereCollider : public CollisionShape
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Properties */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/// <summary>
|
||||||
|
/// Center of the sphere.
|
||||||
|
/// </summary>
|
||||||
|
property Vector3 Center
|
||||||
|
{
|
||||||
|
Vector3 get();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Radius of the sphere/
|
||||||
|
/// </summary>
|
||||||
|
property float Radius
|
||||||
|
{
|
||||||
|
float get();
|
||||||
|
void set(float value);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructors */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
SphereCollider(int arrayIndex, Entity attachedEntity);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A Box Collider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class BoxCollider : public CollisionShape
|
public ref class BoxCollider : public CollisionShape
|
||||||
{
|
{
|
||||||
|
@ -166,14 +181,6 @@ namespace SHADE
|
||||||
Quaternion get();
|
Quaternion get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/* ColliderBound Functions */
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
|
||||||
/// <inheritdoc/>
|
|
||||||
bool TestPoint(Vector3 point) override;
|
|
||||||
/// <inheritdoc/>
|
|
||||||
bool Raycast(Ray ray, float maxDistance) override;
|
|
||||||
|
|
||||||
internal:
|
internal:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
@ -182,45 +189,46 @@ namespace SHADE
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sphere-shaped Collider Bound.
|
/// A Capsule Collider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ref class SphereCollider : public CollisionShape
|
public ref class CapsuleCollider : public CollisionShape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Properties */
|
/* Properties */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Center of the sphere.
|
/// Center of the capsule.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
property Vector3 Center
|
property Vector3 Center
|
||||||
{
|
{
|
||||||
Vector3 get();
|
Vector3 get();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Radius of the Bounding Sphere formed by this bound.
|
/// Radius of the capsule.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
property float Radius
|
property float Radius
|
||||||
{
|
{
|
||||||
float get();
|
float get();
|
||||||
void set(float value);
|
void set(float value);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
/*-----------------------------------------------------------------------------*/
|
/// Height of the capsule.
|
||||||
/* ColliderBound Functions */
|
/// </summary>
|
||||||
/*-----------------------------------------------------------------------------*/
|
property float Height
|
||||||
/// <inheritdoc/>
|
{
|
||||||
bool TestPoint(Vector3 point) override;
|
float get();
|
||||||
/// <inheritdoc/>
|
void set(float value);
|
||||||
bool Raycast(Ray ray, float maxDistance) override;
|
}
|
||||||
|
|
||||||
internal:
|
internal:
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Constructors */
|
/* Constructors */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SphereCollider(int arrayIndex, Entity attachedEntity);
|
CapsuleCollider(int arrayIndex, Entity attachedEntity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CLR version of the the SHADE Engine's SHColliderComponent.
|
/// CLR version of the the SHADE Engine's SHColliderComponent.
|
||||||
/// A single Collider component can contain one or multiple Collider Bounds.
|
/// A single Collider component can contain one or multiple Collider Bounds.
|
||||||
|
|
Loading…
Reference in New Issue