This commit is contained in:
bjorn 2017-05-16 12:17:01 -06:00
parent 4ac72a54d6
commit 43ac25a61d
4 changed files with 36 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);
}

View File

@ -1,6 +1,13 @@
#include "util.h"
#include <ode/ode.h>
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);