diff --git a/src/api/lovr.h b/src/api/lovr.h index 963367ca..e76a9fcd 100644 --- a/src/api/lovr.h +++ b/src/api/lovr.h @@ -48,6 +48,7 @@ extern map_int_t MeshAttributeTypes; extern map_int_t MeshDrawModes; extern map_int_t MeshUsages; extern map_int_t PolygonWindings; +extern map_int_t ShapeTypes; extern map_int_t TextureProjections; extern map_int_t TimeUnits; extern map_int_t VerticalAligns; diff --git a/src/api/physics.c b/src/api/physics.c index 8b3006d7..9d7f8be8 100644 --- a/src/api/physics.c +++ b/src/api/physics.c @@ -1,11 +1,20 @@ #include "api/lovr.h" #include "physics/physics.h" +map_int_t ShapeTypes; + int l_lovrPhysicsInit(lua_State* L) { lua_newtable(L); luaL_register(L, NULL, lovrPhysics); luax_registertype(L, "World", lovrWorld); luax_registertype(L, "Body", lovrBody); + + map_init(&ShapeTypes); + map_set(&ShapeTypes, "sphere", SHAPE_SPHERE); + map_set(&ShapeTypes, "box", SHAPE_BOX); + map_set(&ShapeTypes, "capsule", SHAPE_CAPSULE); + map_set(&ShapeTypes, "cylinder", SHAPE_CYLINDER); + lovrPhysicsInit(); return 1; } diff --git a/src/physics/physics.c b/src/physics/physics.c index 5bef3917..c8e28b92 100644 --- a/src/physics/physics.c +++ b/src/physics/physics.c @@ -264,3 +264,13 @@ void lovrBodySetUserData(Body* body, void* data) { World* lovrBodyGetWorld(Body* body) { return body->world; } + +ShapeType lovrShapeGetType(Shape* shape) { + return shape->type; +} + +void lovrShapeDestroy(const Ref* ref) { + Shape* shape = containerof(ref, Shape); + dGeomDestroy(shape->id); + free(shape); +} diff --git a/src/physics/physics.h b/src/physics/physics.h index af268873..fa7a3cdf 100644 --- a/src/physics/physics.h +++ b/src/physics/physics.h @@ -1,6 +1,13 @@ #include "util.h" #include +typedef enum { + SHAPE_SPHERE, + SHAPE_BOX, + SHAPE_CAPSULE, + SHAPE_CYLINDER +} ShapeType; + typedef struct { Ref ref; dWorldID id; @@ -12,6 +19,12 @@ typedef struct { World* world; } Body; +typedef struct { + Ref ref; + ShapeType type; + dGeomID id; +} Shape; + void lovrPhysicsInit(); void lovrPhysicsDestroy(); @@ -59,3 +72,6 @@ void lovrBodySetAwake(Body* body, int awake); void* lovrBodyGetUserData(Body* body); void lovrBodySetUserData(Body* body, void* data); World* lovrBodyGetWorld(Body* body); + +ShapeType lovrShapeGetType(Shape* shape); +void lovrShapeDestroy(const Ref* ref);