mirror of https://github.com/bjornbytes/lovr.git
SphereShape;
This commit is contained in:
parent
09db32f6b4
commit
995e8a2ea8
|
@ -29,6 +29,7 @@ extern const luaL_Reg lovrPhysics[];
|
||||||
extern const luaL_Reg lovrShader[];
|
extern const luaL_Reg lovrShader[];
|
||||||
extern const luaL_Reg lovrSkybox[];
|
extern const luaL_Reg lovrSkybox[];
|
||||||
extern const luaL_Reg lovrSource[];
|
extern const luaL_Reg lovrSource[];
|
||||||
|
extern const luaL_Reg lovrSphereShape[];
|
||||||
extern const luaL_Reg lovrTexture[];
|
extern const luaL_Reg lovrTexture[];
|
||||||
extern const luaL_Reg lovrTimer[];
|
extern const luaL_Reg lovrTimer[];
|
||||||
extern const luaL_Reg lovrTransform[];
|
extern const luaL_Reg lovrTransform[];
|
||||||
|
|
|
@ -8,6 +8,7 @@ int l_lovrPhysicsInit(lua_State* L) {
|
||||||
luaL_register(L, NULL, lovrPhysics);
|
luaL_register(L, NULL, lovrPhysics);
|
||||||
luax_registertype(L, "World", lovrWorld);
|
luax_registertype(L, "World", lovrWorld);
|
||||||
luax_registertype(L, "Body", lovrBody);
|
luax_registertype(L, "Body", lovrBody);
|
||||||
|
luax_extendtype(L, "Shape", "SphereShape", lovrSphereShape);
|
||||||
|
|
||||||
map_init(&ShapeTypes);
|
map_init(&ShapeTypes);
|
||||||
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
||||||
|
@ -30,8 +31,15 @@ int l_lovrPhysicsNewBody(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrPhysicsNewSphereShape(lua_State* L) {
|
||||||
|
float radius = luaL_optnumber(L, 1, 1.f);
|
||||||
|
luax_pushtype(L, SphereShape, lovrSphereShapeCreate(radius));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg lovrPhysics[] = {
|
const luaL_Reg lovrPhysics[] = {
|
||||||
{ "newWorld", l_lovrPhysicsNewWorld },
|
{ "newWorld", l_lovrPhysicsNewWorld },
|
||||||
{ "newBody", l_lovrPhysicsNewBody },
|
{ "newBody", l_lovrPhysicsNewBody },
|
||||||
|
{ "newSphereShape", l_lovrPhysicsNewSphereShape },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -162,3 +162,37 @@ int l_lovrShapeSetMask(lua_State* L) {
|
||||||
lovrShapeSetMask(shape, ~mask);
|
lovrShapeSetMask(shape, ~mask);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrSphereShapeGetRadius(lua_State* L) {
|
||||||
|
SphereShape* sphere = luax_checktype(L, 1, SphereShape);
|
||||||
|
lua_pushnumber(L, lovrSphereShapeGetRadius(sphere));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrSphereShapeSetRadius(lua_State* L) {
|
||||||
|
SphereShape* sphere = luax_checktype(L, 1, SphereShape);
|
||||||
|
float radius = luaL_checknumber(L, 2);
|
||||||
|
lovrSphereShapeSetRadius(sphere, radius);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg lovrSphereShape[] = {
|
||||||
|
{ "getType", l_lovrShapeGetType },
|
||||||
|
{ "getBody", l_lovrShapeGetBody },
|
||||||
|
{ "setBody", l_lovrShapeSetBody },
|
||||||
|
{ "isEnabled", l_lovrShapeIsEnabled },
|
||||||
|
{ "setEnabled", l_lovrShapeSetEnabled },
|
||||||
|
{ "getUserData", l_lovrShapeGetUserData },
|
||||||
|
{ "setUserData", l_lovrShapeSetUserData },
|
||||||
|
{ "getPosition", l_lovrShapeGetPosition },
|
||||||
|
{ "setPosition", l_lovrShapeSetPosition },
|
||||||
|
{ "getOrientation", l_lovrShapeGetOrientation },
|
||||||
|
{ "setOrientation", l_lovrShapeSetOrientation },
|
||||||
|
{ "getCategory", l_lovrShapeGetCategory },
|
||||||
|
{ "setCategory", l_lovrShapeSetCategory },
|
||||||
|
{ "getMask", l_lovrShapeGetMask },
|
||||||
|
{ "setMask", l_lovrShapeSetMask },
|
||||||
|
{ "getRadius", l_lovrSphereShapeGetRadius },
|
||||||
|
{ "setRadius", l_lovrSphereShapeSetRadius },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
|
@ -341,3 +341,21 @@ uint32_t lovrShapeGetMask(Shape* shape) {
|
||||||
void lovrShapeSetMask(Shape* shape, uint32_t mask) {
|
void lovrShapeSetMask(Shape* shape, uint32_t mask) {
|
||||||
dGeomSetCollideBits(shape->id, mask);
|
dGeomSetCollideBits(shape->id, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SphereShape* lovrSphereShapeCreate(float radius) {
|
||||||
|
SphereShape* sphere = lovrAlloc(sizeof(SphereShape), lovrShapeDestroy);
|
||||||
|
if (!sphere) return NULL;
|
||||||
|
|
||||||
|
sphere->type = SHAPE_SPHERE;
|
||||||
|
sphere->id = dCreateSphere(0, radius);
|
||||||
|
|
||||||
|
return sphere;
|
||||||
|
}
|
||||||
|
|
||||||
|
float lovrSphereShapeGetRadius(SphereShape* sphere) {
|
||||||
|
return dGeomSphereGetRadius(sphere->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrSphereShapeSetRadius(SphereShape* sphere, float radius) {
|
||||||
|
dGeomSphereSetRadius(sphere->id, radius);
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ typedef struct {
|
||||||
Body* body;
|
Body* body;
|
||||||
} Shape;
|
} Shape;
|
||||||
|
|
||||||
|
typedef Shape SphereShape;
|
||||||
|
|
||||||
void lovrPhysicsInit();
|
void lovrPhysicsInit();
|
||||||
void lovrPhysicsDestroy();
|
void lovrPhysicsDestroy();
|
||||||
|
|
||||||
|
@ -91,3 +93,7 @@ uint32_t lovrShapeGetCategory(Shape* shape);
|
||||||
void lovrShapeSetCategory(Shape* shape, uint32_t category);
|
void lovrShapeSetCategory(Shape* shape, uint32_t category);
|
||||||
uint32_t lovrShapeGetMask(Shape* shape);
|
uint32_t lovrShapeGetMask(Shape* shape);
|
||||||
void lovrShapeSetMask(Shape* shape, uint32_t mask);
|
void lovrShapeSetMask(Shape* shape, uint32_t mask);
|
||||||
|
|
||||||
|
SphereShape* lovrSphereShapeCreate(float radius);
|
||||||
|
float lovrSphereShapeGetRadius(SphereShape* shape);
|
||||||
|
void lovrSphereShapeSetRadius(SphereShape* shape, float radius);
|
||||||
|
|
Loading…
Reference in New Issue