mirror of https://github.com/bjornbytes/lovr.git
CylinderShape;
This commit is contained in:
parent
6a166f7102
commit
bcbe6c47d4
|
@ -17,6 +17,7 @@ extern const luaL_Reg lovrAudio[];
|
|||
extern const luaL_Reg lovrBoxShape[];
|
||||
extern const luaL_Reg lovrCapsuleShape[];
|
||||
extern const luaL_Reg lovrController[];
|
||||
extern const luaL_Reg lovrCylinderShape[];
|
||||
extern const luaL_Reg lovrBlob[];
|
||||
extern const luaL_Reg lovrBody[];
|
||||
extern const luaL_Reg lovrEvent[];
|
||||
|
|
|
@ -11,6 +11,7 @@ int l_lovrPhysicsInit(lua_State* L) {
|
|||
luax_extendtype(L, "Shape", "SphereShape", lovrShape, lovrSphereShape);
|
||||
luax_extendtype(L, "Shape", "BoxShape", lovrShape, lovrBoxShape);
|
||||
luax_extendtype(L, "Shape", "CapsuleShape", lovrShape, lovrCapsuleShape);
|
||||
luax_extendtype(L, "Shape", "CylinderShape", lovrShape, lovrCylinderShape);
|
||||
|
||||
map_init(&ShapeTypes);
|
||||
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
||||
|
@ -54,11 +55,19 @@ int l_lovrPhysicsNewCapsuleShape(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrPhysicsNewCylinderShape(lua_State* L) {
|
||||
float radius = luaL_optnumber(L, 1, 1.f);
|
||||
float length = luaL_optnumber(L, 2, 1.f);
|
||||
luax_pushtype(L, CylinderShape, lovrCylinderShapeCreate(radius, length));
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrPhysics[] = {
|
||||
{ "newWorld", l_lovrPhysicsNewWorld },
|
||||
{ "newBody", l_lovrPhysicsNewBody },
|
||||
{ "newSphereShape", l_lovrPhysicsNewSphereShape },
|
||||
{ "newBoxShape", l_lovrPhysicsNewBoxShape },
|
||||
{ "newCapsuleShape", l_lovrPhysicsNewCapsuleShape },
|
||||
{ "newCylinderShape", l_lovrPhysicsNewCylinderShape },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -259,3 +259,37 @@ const luaL_Reg lovrCapsuleShape[] = {
|
|||
{ "setLength", l_lovrCapsuleShapeSetLength },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
int l_lovrCylinderShapeGetRadius(lua_State* L) {
|
||||
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
|
||||
lua_pushnumber(L, lovrCylinderShapeGetRadius(cylinder));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCylinderShapeSetRadius(lua_State* L) {
|
||||
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
|
||||
float radius = luaL_checknumber(L, 2);
|
||||
lovrCylinderShapeSetRadius(cylinder, radius);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_lovrCylinderShapeGetLength(lua_State* L) {
|
||||
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
|
||||
lua_pushnumber(L, lovrCylinderShapeGetLength(cylinder));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int l_lovrCylinderShapeSetLength(lua_State* L) {
|
||||
CylinderShape* cylinder = luax_checktype(L, 1, CylinderShape);
|
||||
float length = luaL_checknumber(L, 2);
|
||||
lovrCylinderShapeSetLength(cylinder, length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrCylinderShape[] = {
|
||||
{ "getRadius", l_lovrCylinderShapeGetRadius },
|
||||
{ "setRadius", l_lovrCylinderShapeSetRadius },
|
||||
{ "getLength", l_lovrCylinderShapeGetLength },
|
||||
{ "setLength", l_lovrCylinderShapeSetLength },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
|
|
@ -411,3 +411,33 @@ float lovrCapsuleShapeGetLength(CapsuleShape* capsule) {
|
|||
void lovrCapsuleShapeSetLength(CapsuleShape* capsule, float length) {
|
||||
dGeomCapsuleSetParams(capsule->id, lovrCapsuleShapeGetRadius(capsule), length);
|
||||
}
|
||||
|
||||
CylinderShape* lovrCylinderShapeCreate(float radius, float length) {
|
||||
CylinderShape* cylinder = lovrAlloc(sizeof(CylinderShape), lovrShapeDestroy);
|
||||
if (!cylinder) return NULL;
|
||||
|
||||
cylinder->type = SHAPE_CYLINDER;
|
||||
cylinder->id = dCreateCylinder(0, radius, length);
|
||||
|
||||
return cylinder;
|
||||
}
|
||||
|
||||
float lovrCylinderShapeGetRadius(CylinderShape* cylinder) {
|
||||
float radius, length;
|
||||
dGeomCylinderGetParams(cylinder->id, &radius, &length);
|
||||
return radius;
|
||||
}
|
||||
|
||||
void lovrCylinderShapeSetRadius(CylinderShape* cylinder, float radius) {
|
||||
dGeomCylinderSetParams(cylinder->id, radius, lovrCylinderShapeGetLength(cylinder));
|
||||
}
|
||||
|
||||
float lovrCylinderShapeGetLength(CylinderShape* cylinder) {
|
||||
float radius, length;
|
||||
dGeomCylinderGetParams(cylinder->id, &radius, &length);
|
||||
return length;
|
||||
}
|
||||
|
||||
void lovrCylinderShapeSetLength(CylinderShape* cylinder, float length) {
|
||||
dGeomCylinderSetParams(cylinder->id, lovrCylinderShapeGetRadius(cylinder), length);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct {
|
|||
typedef Shape SphereShape;
|
||||
typedef Shape BoxShape;
|
||||
typedef Shape CapsuleShape;
|
||||
typedef Shape CylinderShape;
|
||||
|
||||
void lovrPhysicsInit();
|
||||
void lovrPhysicsDestroy();
|
||||
|
@ -109,3 +110,9 @@ float lovrCapsuleShapeGetRadius(CapsuleShape* capsule);
|
|||
void lovrCapsuleShapeSetRadius(CapsuleShape* capsule, float radius);
|
||||
float lovrCapsuleShapeGetLength(CapsuleShape* capsule);
|
||||
void lovrCapsuleShapeSetLength(CapsuleShape* capsule, float length);
|
||||
|
||||
CylinderShape* lovrCylinderShapeCreate(float radius, float length);
|
||||
float lovrCylinderShapeGetRadius(CylinderShape* cylinder);
|
||||
void lovrCylinderShapeSetRadius(CylinderShape* cylinder, float radius);
|
||||
float lovrCylinderShapeGetLength(CylinderShape* cylinder);
|
||||
void lovrCylinderShapeSetLength(CylinderShape* cylinder, float length);
|
||||
|
|
Loading…
Reference in New Issue