mirror of https://github.com/bjornbytes/lovr.git
Shape:getBody; Shape:setBody;
This commit is contained in:
parent
43ac25a61d
commit
c7515a1f7e
|
@ -0,0 +1,33 @@
|
|||
#include "api/lovr.h"
|
||||
#include "physics/physics.h"
|
||||
|
||||
int l_lovrShapeGetType(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
luax_pushenum(L, &ShapeTypes, lovrShapeGetType(shape));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrShapeGetBody(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
Body* body = lovrShapeGetBody(shape);
|
||||
|
||||
if (body) {
|
||||
luax_pushtype(L, Body, body);
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrShapeSetBody(lua_State* L) {
|
||||
Shape* shape = luax_checktypeof(L, 1, Shape);
|
||||
if (lua_isnoneornil(L, 2)) {
|
||||
lovrShapeSetBody(shape, NULL);
|
||||
} else {
|
||||
Body* body = luax_checktype(L, 2, Body);
|
||||
lovrShapeSetBody(shape, body);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -269,6 +269,15 @@ ShapeType lovrShapeGetType(Shape* shape) {
|
|||
return shape->type;
|
||||
}
|
||||
|
||||
Body* lovrShapeGetBody(Shape* shape) {
|
||||
return shape->body;
|
||||
}
|
||||
|
||||
void lovrShapeSetBody(Shape* shape, Body* body) {
|
||||
shape->body = body;
|
||||
dGeomSetBody(shape->id, body ? body->id : 0);
|
||||
}
|
||||
|
||||
void lovrShapeDestroy(const Ref* ref) {
|
||||
Shape* shape = containerof(ref, Shape);
|
||||
dGeomDestroy(shape->id);
|
||||
|
|
|
@ -23,6 +23,7 @@ typedef struct {
|
|||
Ref ref;
|
||||
ShapeType type;
|
||||
dGeomID id;
|
||||
Body* body;
|
||||
} Shape;
|
||||
|
||||
void lovrPhysicsInit();
|
||||
|
@ -74,4 +75,6 @@ void lovrBodySetUserData(Body* body, void* data);
|
|||
World* lovrBodyGetWorld(Body* body);
|
||||
|
||||
ShapeType lovrShapeGetType(Shape* shape);
|
||||
Body* lovrShapeGetBody(Shape* shape);
|
||||
void lovrShapeSetBody(Shape* shape, Body* body);
|
||||
void lovrShapeDestroy(const Ref* ref);
|
||||
|
|
Loading…
Reference in New Issue