mirror of https://github.com/bjornbytes/lovr.git
CapsuleShape;
This commit is contained in:
parent
e79c45ffdf
commit
6a166f7102
|
@ -15,6 +15,7 @@ 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 lovrBoxShape[];
|
||||||
|
extern const luaL_Reg lovrCapsuleShape[];
|
||||||
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[];
|
||||||
|
|
|
@ -10,6 +10,7 @@ int l_lovrPhysicsInit(lua_State* L) {
|
||||||
luax_registertype(L, "Body", lovrBody);
|
luax_registertype(L, "Body", lovrBody);
|
||||||
luax_extendtype(L, "Shape", "SphereShape", lovrShape, lovrSphereShape);
|
luax_extendtype(L, "Shape", "SphereShape", lovrShape, lovrSphereShape);
|
||||||
luax_extendtype(L, "Shape", "BoxShape", lovrShape, lovrBoxShape);
|
luax_extendtype(L, "Shape", "BoxShape", lovrShape, lovrBoxShape);
|
||||||
|
luax_extendtype(L, "Shape", "CapsuleShape", lovrShape, lovrCapsuleShape);
|
||||||
|
|
||||||
map_init(&ShapeTypes);
|
map_init(&ShapeTypes);
|
||||||
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
map_set(&ShapeTypes, "sphere", SHAPE_SPHERE);
|
||||||
|
@ -46,10 +47,18 @@ int l_lovrPhysicsNewBoxShape(lua_State* L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrPhysicsNewCapsuleShape(lua_State* L) {
|
||||||
|
float radius = luaL_optnumber(L, 1, 1.f);
|
||||||
|
float length = luaL_optnumber(L, 2, 1.f);
|
||||||
|
luax_pushtype(L, CapsuleShape, lovrCapsuleShapeCreate(radius, length));
|
||||||
|
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 },
|
{ "newBoxShape", l_lovrPhysicsNewBoxShape },
|
||||||
|
{ "newCapsuleShape", l_lovrPhysicsNewCapsuleShape },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -225,3 +225,37 @@ const luaL_Reg lovrBoxShape[] = {
|
||||||
{ "setDimensions", l_lovrBoxShapeSetDimensions },
|
{ "setDimensions", l_lovrBoxShapeSetDimensions },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int l_lovrCapsuleShapeGetRadius(lua_State* L) {
|
||||||
|
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
|
||||||
|
lua_pushnumber(L, lovrCapsuleShapeGetRadius(capsule));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrCapsuleShapeSetRadius(lua_State* L) {
|
||||||
|
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
|
||||||
|
float radius = luaL_checknumber(L, 2);
|
||||||
|
lovrCapsuleShapeSetRadius(capsule, radius);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrCapsuleShapeGetLength(lua_State* L) {
|
||||||
|
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
|
||||||
|
lua_pushnumber(L, lovrCapsuleShapeGetLength(capsule));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrCapsuleShapeSetLength(lua_State* L) {
|
||||||
|
CapsuleShape* capsule = luax_checktype(L, 1, CapsuleShape);
|
||||||
|
float length = luaL_checknumber(L, 2);
|
||||||
|
lovrCapsuleShapeSetLength(capsule, length);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg lovrCapsuleShape[] = {
|
||||||
|
{ "getRadius", l_lovrCapsuleShapeGetRadius },
|
||||||
|
{ "setRadius", l_lovrCapsuleShapeSetRadius },
|
||||||
|
{ "getLength", l_lovrCapsuleShapeGetLength },
|
||||||
|
{ "setLength", l_lovrCapsuleShapeSetLength },
|
||||||
|
{ NULL, NULL }
|
||||||
|
};
|
||||||
|
|
|
@ -381,3 +381,33 @@ void lovrBoxShapeGetDimensions(BoxShape* box, float* x, float* y, float* z) {
|
||||||
void lovrBoxShapeSetDimensions(BoxShape* box, float x, float y, float z) {
|
void lovrBoxShapeSetDimensions(BoxShape* box, float x, float y, float z) {
|
||||||
dGeomBoxSetLengths(box->id, x, y, z);
|
dGeomBoxSetLengths(box->id, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CapsuleShape* lovrCapsuleShapeCreate(float radius, float length) {
|
||||||
|
CapsuleShape* capsule = lovrAlloc(sizeof(CapsuleShape), lovrShapeDestroy);
|
||||||
|
if (!capsule) return NULL;
|
||||||
|
|
||||||
|
capsule->type = SHAPE_CAPSULE;
|
||||||
|
capsule->id = dCreateCapsule(0, radius, length);
|
||||||
|
|
||||||
|
return capsule;
|
||||||
|
}
|
||||||
|
|
||||||
|
float lovrCapsuleShapeGetRadius(CapsuleShape* capsule) {
|
||||||
|
float radius, length;
|
||||||
|
dGeomCapsuleGetParams(capsule->id, &radius, &length);
|
||||||
|
return radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrCapsuleShapeSetRadius(CapsuleShape* capsule, float radius) {
|
||||||
|
dGeomCapsuleSetParams(capsule->id, radius, lovrCapsuleShapeGetLength(capsule));
|
||||||
|
}
|
||||||
|
|
||||||
|
float lovrCapsuleShapeGetLength(CapsuleShape* capsule) {
|
||||||
|
float radius, length;
|
||||||
|
dGeomCapsuleGetParams(capsule->id, &radius, &length);
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrCapsuleShapeSetLength(CapsuleShape* capsule, float length) {
|
||||||
|
dGeomCapsuleSetParams(capsule->id, lovrCapsuleShapeGetRadius(capsule), length);
|
||||||
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ typedef struct {
|
||||||
|
|
||||||
typedef Shape SphereShape;
|
typedef Shape SphereShape;
|
||||||
typedef Shape BoxShape;
|
typedef Shape BoxShape;
|
||||||
|
typedef Shape CapsuleShape;
|
||||||
|
|
||||||
void lovrPhysicsInit();
|
void lovrPhysicsInit();
|
||||||
void lovrPhysicsDestroy();
|
void lovrPhysicsDestroy();
|
||||||
|
@ -96,9 +97,15 @@ uint32_t lovrShapeGetMask(Shape* shape);
|
||||||
void lovrShapeSetMask(Shape* shape, uint32_t mask);
|
void lovrShapeSetMask(Shape* shape, uint32_t mask);
|
||||||
|
|
||||||
SphereShape* lovrSphereShapeCreate(float radius);
|
SphereShape* lovrSphereShapeCreate(float radius);
|
||||||
float lovrSphereShapeGetRadius(SphereShape* shape);
|
float lovrSphereShapeGetRadius(SphereShape* sphere);
|
||||||
void lovrSphereShapeSetRadius(SphereShape* shape, float radius);
|
void lovrSphereShapeSetRadius(SphereShape* sphere, float radius);
|
||||||
|
|
||||||
BoxShape* lovrBoxShapeCreate(float x, float y, float z);
|
BoxShape* lovrBoxShapeCreate(float x, float y, float z);
|
||||||
void lovrBoxShapeGetDimensions(BoxShape* shape, float* x, float* y, float* z);
|
void lovrBoxShapeGetDimensions(BoxShape* box, float* x, float* y, float* z);
|
||||||
void lovrBoxShapeSetDimensions(BoxShape* shape, float x, float y, float z);
|
void lovrBoxShapeSetDimensions(BoxShape* box, float x, float y, float z);
|
||||||
|
|
||||||
|
CapsuleShape* lovrCapsuleShapeCreate(float radius, float length);
|
||||||
|
float lovrCapsuleShapeGetRadius(CapsuleShape* capsule);
|
||||||
|
void lovrCapsuleShapeSetRadius(CapsuleShape* capsule, float radius);
|
||||||
|
float lovrCapsuleShapeGetLength(CapsuleShape* capsule);
|
||||||
|
void lovrCapsuleShapeSetLength(CapsuleShape* capsule, float length);
|
||||||
|
|
Loading…
Reference in New Issue