mirror of https://github.com/bjornbytes/lovr.git
BoxShape;
This commit is contained in:
parent
995e8a2ea8
commit
e79c45ffdf
|
@ -14,6 +14,7 @@ int l_lovrPhysicsInit(lua_State* L);
|
||||||
int l_lovrTimerInit(lua_State* L);
|
int l_lovrTimerInit(lua_State* L);
|
||||||
|
|
||||||
extern const luaL_Reg lovrAudio[];
|
extern const luaL_Reg lovrAudio[];
|
||||||
|
extern const luaL_Reg lovrBoxShape[];
|
||||||
extern const luaL_Reg lovrController[];
|
extern const luaL_Reg lovrController[];
|
||||||
extern const luaL_Reg lovrBlob[];
|
extern const luaL_Reg lovrBlob[];
|
||||||
extern const luaL_Reg lovrBody[];
|
extern const luaL_Reg lovrBody[];
|
||||||
|
@ -27,6 +28,7 @@ extern const luaL_Reg lovrMesh[];
|
||||||
extern const luaL_Reg lovrModel[];
|
extern const luaL_Reg lovrModel[];
|
||||||
extern const luaL_Reg lovrPhysics[];
|
extern const luaL_Reg lovrPhysics[];
|
||||||
extern const luaL_Reg lovrShader[];
|
extern const luaL_Reg lovrShader[];
|
||||||
|
extern const luaL_Reg lovrShape[];
|
||||||
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 lovrSphereShape[];
|
||||||
|
|
|
@ -8,7 +8,8 @@ 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);
|
luax_extendtype(L, "Shape", "SphereShape", lovrShape, lovrSphereShape);
|
||||||
|
luax_extendtype(L, "Shape", "BoxShape", lovrShape, lovrBoxShape);
|
||||||
|
|
||||||
map_init(&ShapeTypes);
|
map_init(&ShapeTypes);
|
||||||
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
||||||
|
@ -37,9 +38,18 @@ int l_lovrPhysicsNewSphereShape(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrPhysicsNewBoxShape(lua_State* L) {
|
||||||
|
float x = luaL_optnumber(L, 1, 1.f);
|
||||||
|
float y = luaL_optnumber(L, 2, x);
|
||||||
|
float z = luaL_optnumber(L, 3, x);
|
||||||
|
luax_pushtype(L, BoxShape, lovrBoxShapeCreate(x, y, z));
|
||||||
|
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 },
|
{ "newSphereShape", l_lovrPhysicsNewSphereShape },
|
||||||
|
{ "newBoxShape", l_lovrPhysicsNewBoxShape },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -163,20 +163,7 @@ int l_lovrShapeSetMask(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int l_lovrSphereShapeGetRadius(lua_State* L) {
|
const luaL_Reg lovrShape[] = {
|
||||||
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 },
|
{ "getType", l_lovrShapeGetType },
|
||||||
{ "getBody", l_lovrShapeGetBody },
|
{ "getBody", l_lovrShapeGetBody },
|
||||||
{ "setBody", l_lovrShapeSetBody },
|
{ "setBody", l_lovrShapeSetBody },
|
||||||
|
@ -192,7 +179,49 @@ const luaL_Reg lovrSphereShape[] = {
|
||||||
{ "setCategory", l_lovrShapeSetCategory },
|
{ "setCategory", l_lovrShapeSetCategory },
|
||||||
{ "getMask", l_lovrShapeGetMask },
|
{ "getMask", l_lovrShapeGetMask },
|
||||||
{ "setMask", l_lovrShapeSetMask },
|
{ "setMask", l_lovrShapeSetMask },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
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[] = {
|
||||||
{ "getRadius", l_lovrSphereShapeGetRadius },
|
{ "getRadius", l_lovrSphereShapeGetRadius },
|
||||||
{ "setRadius", l_lovrSphereShapeSetRadius },
|
{ "setRadius", l_lovrSphereShapeSetRadius },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int l_lovrBoxShapeGetDimensions(lua_State* L) {
|
||||||
|
BoxShape* box = luax_checktype(L, 1, BoxShape);
|
||||||
|
float x, y, z;
|
||||||
|
lovrBoxShapeGetDimensions(box, &x, &y, &z);
|
||||||
|
lua_pushnumber(L, x);
|
||||||
|
lua_pushnumber(L, y);
|
||||||
|
lua_pushnumber(L, z);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrBoxShapeSetDimensions(lua_State* L) {
|
||||||
|
BoxShape* box = luax_checktype(L, 1, BoxShape);
|
||||||
|
float x = luaL_checknumber(L, 2);
|
||||||
|
float y = luaL_checknumber(L, 3);
|
||||||
|
float z = luaL_checknumber(L, 4);
|
||||||
|
lovrBoxShapeSetDimensions(box, x, y, z);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg lovrBoxShape[] = {
|
||||||
|
{ "getDimensions", l_lovrBoxShapeGetDimensions },
|
||||||
|
{ "setDimensions", l_lovrBoxShapeSetDimensions },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
|
@ -71,13 +71,17 @@ void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* functions) {
|
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions) {
|
||||||
luax_registertype(L, name, functions);
|
luax_registertype(L, name, functions);
|
||||||
luaL_getmetatable(L, name);
|
luaL_getmetatable(L, name);
|
||||||
|
|
||||||
lua_pushstring(L, base);
|
lua_pushstring(L, base);
|
||||||
lua_setfield(L, -2, "super");
|
lua_setfield(L, -2, "super");
|
||||||
|
|
||||||
|
if (baseFunctions) {
|
||||||
|
luaL_register(L, NULL, baseFunctions);
|
||||||
|
}
|
||||||
|
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f);
|
int luax_preloadmodule(lua_State* L, const char* key, lua_CFunction f);
|
||||||
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
void luax_registertype(lua_State* L, const char* name, const luaL_Reg* functions);
|
||||||
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* functions);
|
void luax_extendtype(lua_State* L, const char* base, const char* name, const luaL_Reg* baseFunctions, const luaL_Reg* functions);
|
||||||
int luax_releasetype(lua_State* L);
|
int luax_releasetype(lua_State* L);
|
||||||
int luax_getobject(lua_State* L, void* object);
|
int luax_getobject(lua_State* L, void* object);
|
||||||
void luax_registerobject(lua_State* L, void* object);
|
void luax_registerobject(lua_State* L, void* object);
|
||||||
|
|
|
@ -359,3 +359,25 @@ float lovrSphereShapeGetRadius(SphereShape* sphere) {
|
||||||
void lovrSphereShapeSetRadius(SphereShape* sphere, float radius) {
|
void lovrSphereShapeSetRadius(SphereShape* sphere, float radius) {
|
||||||
dGeomSphereSetRadius(sphere->id, radius);
|
dGeomSphereSetRadius(sphere->id, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoxShape* lovrBoxShapeCreate(float x, float y, float z) {
|
||||||
|
BoxShape* box = lovrAlloc(sizeof(BoxShape), lovrShapeDestroy);
|
||||||
|
if (!box) return NULL;
|
||||||
|
|
||||||
|
box->type = SHAPE_BOX;
|
||||||
|
box->id = dCreateBox(0, x, y, z);
|
||||||
|
|
||||||
|
return box;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrBoxShapeGetDimensions(BoxShape* box, float* x, float* y, float* z) {
|
||||||
|
float dimensions[3];
|
||||||
|
dGeomBoxGetLengths(box->id, dimensions);
|
||||||
|
*x = dimensions[0];
|
||||||
|
*y = dimensions[1];
|
||||||
|
*z = dimensions[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrBoxShapeSetDimensions(BoxShape* box, float x, float y, float z) {
|
||||||
|
dGeomBoxSetLengths(box->id, x, y, z);
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ typedef struct {
|
||||||
} Shape;
|
} Shape;
|
||||||
|
|
||||||
typedef Shape SphereShape;
|
typedef Shape SphereShape;
|
||||||
|
typedef Shape BoxShape;
|
||||||
|
|
||||||
void lovrPhysicsInit();
|
void lovrPhysicsInit();
|
||||||
void lovrPhysicsDestroy();
|
void lovrPhysicsDestroy();
|
||||||
|
@ -97,3 +98,7 @@ void lovrShapeSetMask(Shape* shape, uint32_t mask);
|
||||||
SphereShape* lovrSphereShapeCreate(float radius);
|
SphereShape* lovrSphereShapeCreate(float radius);
|
||||||
float lovrSphereShapeGetRadius(SphereShape* shape);
|
float lovrSphereShapeGetRadius(SphereShape* shape);
|
||||||
void lovrSphereShapeSetRadius(SphereShape* shape, float radius);
|
void lovrSphereShapeSetRadius(SphereShape* shape, float radius);
|
||||||
|
|
||||||
|
BoxShape* lovrBoxShapeCreate(float x, float y, float z);
|
||||||
|
void lovrBoxShapeGetDimensions(BoxShape* shape, float* x, float* y, float* z);
|
||||||
|
void lovrBoxShapeSetDimensions(BoxShape* shape, float x, float y, float z);
|
||||||
|
|
Loading…
Reference in New Issue