mirror of https://github.com/bjornbytes/lovr.git
Shape:isSensor; Shape:setSensor;
This commit is contained in:
parent
8c0ae3fbb3
commit
b6093eda2a
|
@ -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 }, \
|
||||
|
|
|
@ -161,10 +161,12 @@ 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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue