From b6093eda2aac8583b540e65974e437233c840166 Mon Sep 17 00:00:00 2001 From: bjorn Date: Thu, 10 Oct 2019 15:36:28 -0700 Subject: [PATCH] Shape:isSensor; Shape:setSensor; --- src/api/l_shapes.c | 15 +++++++++++++++ src/modules/physics/physics.c | 16 +++++++++++++--- src/modules/physics/physics.h | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/api/l_shapes.c b/src/api/l_shapes.c index f297d633..9b919dad 100644 --- a/src/api/l_shapes.c +++ b/src/api/l_shapes.c @@ -50,6 +50,19 @@ static int l_lovrShapeSetEnabled(lua_State* L) { return 0; } +static int l_lovrShapeIsSensor(lua_State* L) { + Shape* shape = luax_checkshape(L, 1); + lua_pushboolean(L, lovrShapeIsSensor(shape)); + return 1; +} + +static int l_lovrShapeSetSensor(lua_State* L) { + Shape* shape = luax_checkshape(L, 1); + bool sensor = lua_toboolean(L, 2); + lovrShapeSetSensor(shape, sensor); + return 0; +} + static int l_lovrShapeGetUserData(lua_State* L) { Shape* shape = luax_checkshape(L, 1); union { int i; void* p; } ref = { .p = lovrShapeGetUserData(shape) }; @@ -148,6 +161,8 @@ static int l_lovrShapeGetAABB(lua_State* L) { { "getCollider", l_lovrShapeGetCollider }, \ { "isEnabled", l_lovrShapeIsEnabled }, \ { "setEnabled", l_lovrShapeSetEnabled }, \ + { "isSensor", l_lovrShapeIsSensor }, \ + { "setSensor", l_lovrShapeSetSensor }, \ { "getUserData", l_lovrShapeGetUserData }, \ { "setUserData", l_lovrShapeSetUserData }, \ { "getPosition", l_lovrShapeGetPosition }, \ diff --git a/src/modules/physics/physics.c b/src/modules/physics/physics.c index 992f4f1f..7efc4c75 100644 --- a/src/modules/physics/physics.c +++ b/src/modules/physics/physics.c @@ -161,9 +161,11 @@ int lovrWorldCollide(World* world, Shape* a, Shape* b, float friction, float res int contactCount = dCollide(a->id, b->id, MAX_CONTACTS, &contacts[0].geom, sizeof(dContact)); - for (int i = 0; i < contactCount; i++) { - dJointID joint = dJointCreateContact(world->id, world->contactGroup, &contacts[i]); - dJointAttach(joint, colliderA->body, colliderB->body); + if (!a->sensor && !b->sensor) { + for (int i = 0; i < contactCount; i++) { + dJointID joint = dJointCreateContact(world->id, world->contactGroup, &contacts[i]); + dJointAttach(joint, colliderA->body, colliderB->body); + } } return contactCount; @@ -695,6 +697,14 @@ void lovrShapeSetEnabled(Shape* shape, bool enabled) { } } +bool lovrShapeIsSensor(Shape* shape) { + return shape->sensor; +} + +void lovrShapeSetSensor(Shape* shape, bool sensor) { + shape->sensor = sensor; +} + void* lovrShapeGetUserData(Shape* shape) { return shape->userdata; } diff --git a/src/modules/physics/physics.h b/src/modules/physics/physics.h index 30beaa24..5f38f4fc 100644 --- a/src/modules/physics/physics.h +++ b/src/modules/physics/physics.h @@ -56,6 +56,7 @@ struct Shape { dGeomID id; Collider* collider; void* userdata; + bool sensor; }; typedef Shape SphereShape; @@ -166,6 +167,8 @@ ShapeType lovrShapeGetType(Shape* shape); Collider* lovrShapeGetCollider(Shape* shape); bool lovrShapeIsEnabled(Shape* shape); void lovrShapeSetEnabled(Shape* shape, bool enabled); +bool lovrShapeIsSensor(Shape* shape); +void lovrShapeSetSensor(Shape* shape, bool sensor); void* lovrShapeGetUserData(Shape* shape); void lovrShapeSetUserData(Shape* shape, void* data); void lovrShapeGetPosition(Shape* shape, float* x, float* y, float* z);