Add more collider components

This commit is contained in:
SeanOMik 2022-11-10 23:53:03 -05:00
parent 6577c6c45b
commit bac1ff4a00
Signed by: SeanOMik
GPG Key ID: 568F326C7EB33ACB
9 changed files with 123 additions and 10 deletions

View File

@ -1,5 +1,5 @@
#include "simpleengine/camera.h" #include "simpleengine/camera.h"
#include "simpleengine/ecs/component/box_collision_component.h" #include "simpleengine/ecs/component/box_collider_component.h"
#include "simpleengine/ecs/component/mesh_component.h" #include "simpleengine/ecs/component/mesh_component.h"
#include "simpleengine/ecs/component/rigid_body_component.h" #include "simpleengine/ecs/component/rigid_body_component.h"
#include "simpleengine/ecs/component/transform_component.h" #include "simpleengine/ecs/component/transform_component.h"

View File

@ -0,0 +1,23 @@
#pragma once
#include "../../physics/collision/capsule_shape.h"
#include "../../vector.h"
namespace simpleengine::ecs {
/**
* @brief A component that contains a capsule collision shape.
*
*/
class CapsuleColliderComponent {
public:
physics::collision::CapsuleShape capsule_shape;
CapsuleColliderComponent(physics::collision::CapsuleShape capsule) : capsule_shape(capsule) {
}
CapsuleColliderComponent(const float& radius, const float& height) : capsule_shape(radius, height) {
}
};
}

View File

@ -0,0 +1,23 @@
#pragma once
#include "../../physics/collision/cone_shape.h"
#include "../../vector.h"
namespace simpleengine::ecs {
/**
* @brief A component that contains a cone collision shape.
*
*/
class ConeColliderComponent {
public:
physics::collision::ConeShape cone_shape;
ConeColliderComponent(physics::collision::ConeShape cone) : cone_shape(cone) {
}
ConeColliderComponent(float radius, float height) : cone_shape(radius, height) {
}
};
}

View File

@ -0,0 +1,45 @@
#pragma once
#include "../../physics/collision/cylinder_shape.h"
#include "../../vector.h"
namespace simpleengine::ecs {
/**
* @brief A component that contains a cylinder collision shape.
*
*/
class CylinderColliderComponent {
public:
physics::collision::CylinderShape cylinder_shape;
CylinderColliderComponent(physics::collision::CylinderShape cylinder) : cylinder_shape(cylinder) {
}
/**
* @brief Create a cylinder collider with the extent of the cylinder shape.
*
* @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet).
*
* @param x_extent The extent of the cylinder shape in the x direction.
* @param y_extent The extent of the cylinder shape in the y direction.
* @param z_extent The extent of the cylinder shape in the z direction.
*
*/
CylinderColliderComponent(const float& x_extent, const float& y_extent, const float& z_extent) : cylinder_shape(x_extent, y_extent, z_extent) {
}
/**
* @brief Create a CylinderShape with the extent of the cylinder shape.
*
* @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet).
*
* @param extent The extent of the cylinder.
*
*/
CylinderColliderComponent(const simpleengine::Vectorf& extent) : cylinder_shape(extent) {
}
};
}

View File

@ -18,8 +18,22 @@ namespace simpleengine::physics::collision {
} }
btConeShape* get_inner() { /**
* @brief Get the inner bullet cone shape object as a pointer.
*
* @return btConeShape*
*/
btConeShape* get_inner_ptr() {
return &inner; return &inner;
} }
/**
* @brief Get the inner bullet cone shape object as a reference.
*
* @return btConeShape&
*/
btConeShape& get_inner() {
return inner;
}
}; };
} }

View File

@ -14,13 +14,13 @@ namespace simpleengine::physics::collision {
} }
/** /**
* @brief Create a CylinderShape with the extent of the box. * @brief Create a CylinderShape with the extent of the cylinder shape.
* *
* @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet). * @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet).
* *
* @param x_extent The extent of the box in the x direction. * @param x_extent The extent of the cylinder shape in the x direction.
* @param y_extent The extent of the box in the y direction. * @param y_extent The extent of the cylinder shape in the y direction.
* @param z_extent The extent of the box in the z direction. * @param z_extent The extent of the cylinder shape in the z direction.
* *
*/ */
CylinderShape(const float& x_extent, const float& y_extent, const float& z_extent) : inner(btVector3(btScalar(x_extent), btScalar(y_extent), btScalar(z_extent))) { CylinderShape(const float& x_extent, const float& y_extent, const float& z_extent) : inner(btVector3(btScalar(x_extent), btScalar(y_extent), btScalar(z_extent))) {
@ -28,7 +28,7 @@ namespace simpleengine::physics::collision {
} }
/** /**
* @brief Create a CylinderShape with the extent of the box. * @brief Create a CylinderShape with the extent of the cylinder shape.
* *
* @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet). * @note These extents are in half-extents since that's what the underlying Physics engine uses (Bullet).
* *

View File

@ -1,7 +1,10 @@
#include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletCollision/CollisionShapes/btCollisionShape.h"
#include "ecs/component/box_collision_component.h" #include "ecs/component/box_collider_component.h"
#include "ecs/component/sphere_collider_component.h"
#include "ecs/component/cylinder_collider_component.h"
#include "ecs/component/cone_collider_component.h"
#include "ecs/component/capsule_collider_component.h"
#include "ecs/component/rigid_body_component.h" #include "ecs/component/rigid_body_component.h"
#include "ecs/component/sphere_collision_component.h"
#include "ecs/system/system.h" #include "ecs/system/system.h"
#include "entt/entity/fwd.hpp" #include "entt/entity/fwd.hpp"
#include "physics/physics_system.h" #include "physics/physics_system.h"
@ -66,11 +69,16 @@ namespace simpleengine::physics {
} }
btCollisionShape* PhysicsSystem::try_get_collision_shape(const entt::entity& entity) { btCollisionShape* PhysicsSystem::try_get_collision_shape(const entt::entity& entity) {
btCollisionShape* collision_shape;
if (auto box_col = entity_registry->get_inner().try_get<simpleengine::ecs::BoxColliderComponent>(entity)) { if (auto box_col = entity_registry->get_inner().try_get<simpleengine::ecs::BoxColliderComponent>(entity)) {
return box_col->box_shape.get_inner_ptr(); return box_col->box_shape.get_inner_ptr();
} else if (auto sphere_col = entity_registry->get_inner().try_get<simpleengine::ecs::SphereColliderComponent>(entity)) { } else if (auto sphere_col = entity_registry->get_inner().try_get<simpleengine::ecs::SphereColliderComponent>(entity)) {
return sphere_col->sphere_shape.get_inner_ptr(); return sphere_col->sphere_shape.get_inner_ptr();
} else if (auto cylinder_col = entity_registry->get_inner().try_get<simpleengine::ecs::CylinderColliderComponent>(entity)) {
return cylinder_col->cylinder_shape.get_inner_ptr();
} else if (auto cone_col = entity_registry->get_inner().try_get<simpleengine::ecs::ConeColliderComponent>(entity)) {
return cone_col->cone_shape.get_inner_ptr();
} else if (auto capsule_col = entity_registry->get_inner().try_get<simpleengine::ecs::CapsuleColliderComponent>(entity)) {
return capsule_col->capsule_shape.get_inner_ptr();
} }
return nullptr; return nullptr;