Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial support for (convex) shapes for triangle-meshes #53

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/vierkant/mesh_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace vierkant
{

DEFINE_NAMED_UUID(MeshId)

struct mesh_component_t
{
VIERKANT_ENABLE_AS_COMPONENT();
Expand Down
29 changes: 17 additions & 12 deletions include/vierkant/physics_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ struct capsule_t

struct mesh_t
{
// vierkant::MeshId mesh_id = vierkant::MeshId::nil();
vierkant::MeshId mesh_id = vierkant::MeshId::nil();
bool convex_hull = true;
};

using shape_t = std::variant<collision::sphere_t, collision::box_t, collision::cylinder_t, collision::capsule_t,
vierkant::CollisionShapeId>;
}// namespace collision

using contact_cb_t = std::function<void(uint32_t, uint32_t)>;
struct physics_component_t
{
VIERKANT_ENABLE_AS_COMPONENT();
Expand All @@ -62,13 +61,6 @@ struct physics_component_t
bool kinematic = false;
bool sensor = false;

struct callbacks_t
{
contact_cb_t collision;
contact_cb_t contact_begin;
contact_cb_t contact_end;
} callbacks;

bool need_update = false;
};

Expand All @@ -81,6 +73,15 @@ inline bool operator!=(const vierkant::physics_component_t &lhs, const vierkant:
class PhysicsContext
{
public:

struct callbacks_t
{
using contact_cb_t = std::function<void(uint32_t, uint32_t)>;
contact_cb_t collision;
contact_cb_t contact_begin;
contact_cb_t contact_end;
};

class BodyInterface
{
public:
Expand All @@ -91,6 +92,7 @@ class PhysicsContext
[[nodiscard]] virtual glm::vec3 velocity(uint32_t objectId) const = 0;
virtual void set_velocity(uint32_t objectId, const glm::vec3 &velocity) = 0;
virtual void activate(uint32_t objectId) = 0;
virtual void activate_in_aabb(const vierkant::AABB &aabb) = 0;
virtual bool is_active(uint32_t objectId) = 0;
};

Expand All @@ -109,9 +111,12 @@ class PhysicsContext
void set_gravity(const glm::vec3 &g);
[[nodiscard]] glm::vec3 gravity() const;

void add_object(const vierkant::Object3DPtr &obj);
void remove_object(const vierkant::Object3DPtr &obj);
bool contains(const vierkant::Object3DPtr &obj) const;
void add_object(uint32_t objectId, const vierkant::transform_t &transform,
const vierkant::physics_component_t &cmp);
void remove_object(uint32_t objectId);
[[nodiscard]] bool contains(uint32_t objectId) const;

void set_callbacks(uint32_t objectId, const callbacks_t &callbacks);

BodyInterface &body_interface();

Expand Down
5 changes: 0 additions & 5 deletions src/imgui/imgui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,6 @@ void draw_object_ui(const Object3DPtr &object)
change |=ImGui::Checkbox("kinematic", &phys_cmp.kinematic);
change |=ImGui::Checkbox("sensor", &phys_cmp.sensor);
phys_cmp.need_update |= change;

ImGui::Text("callbacks:");
ImGui::BulletText("collision: %s", phys_cmp.callbacks.collision ? "yes" : "-");
ImGui::BulletText("contact_begin: %s", phys_cmp.callbacks.contact_begin ? "yes" : "-");
ImGui::BulletText("contact_end: %s", phys_cmp.callbacks.contact_end ? "yes" : "-");
ImGui::TreePop();
}
}
Expand Down
Loading
Loading