mirror of https://github.com/bjornbytes/lovr.git
Add ConvexShape methods;
This commit is contained in:
parent
91072136aa
commit
4dbcc15cef
|
@ -365,8 +365,55 @@ const luaL_Reg lovrCylinderShape[] = {
|
|||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static int l_lovrConvexShapeGetPointCount(lua_State* L) {
|
||||
ConvexShape* convex = luax_checktype(L, 1, ConvexShape);
|
||||
uint32_t count = lovrConvexShapeGetPointCount(convex);
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrConvexShapeGetPoint(lua_State* L) {
|
||||
ConvexShape* convex = luax_checktype(L, 1, ConvexShape);
|
||||
uint32_t index = luax_checku32(L, 2) - 1;
|
||||
float point[3];
|
||||
lovrConvexShapeGetPoint(convex, index, point);
|
||||
lua_pushnumber(L, point[0]);
|
||||
lua_pushnumber(L, point[1]);
|
||||
lua_pushnumber(L, point[2]);
|
||||
return 3;
|
||||
}
|
||||
|
||||
static int l_lovrConvexShapeGetFaceCount(lua_State* L) {
|
||||
ConvexShape* convex = luax_checktype(L, 1, ConvexShape);
|
||||
uint32_t count = lovrConvexShapeGetFaceCount(convex);
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_lovrConvexShapeGetFace(lua_State* L) {
|
||||
ConvexShape* convex = luax_checktype(L, 1, ConvexShape);
|
||||
uint32_t index = luax_checku32(L, 2) - 1;
|
||||
uint32_t count = lovrConvexShapeGetFace(convex, index, NULL, 0);
|
||||
lua_createtable(L, (int) count, 0);
|
||||
uint32_t stack[8];
|
||||
uint32_t* indices = count > COUNTOF(stack) ? lovrMalloc(count * sizeof(uint32_t)) : stack;
|
||||
lovrConvexShapeGetFace(convex, index, indices, count);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
lua_pushinteger(L, indices[i]);
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
if (indices != stack) {
|
||||
lovrFree(indices);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg lovrConvexShape[] = {
|
||||
lovrShape,
|
||||
{ "getPointCount", l_lovrConvexShapeGetPointCount },
|
||||
{ "getPoint", l_lovrConvexShapeGetPoint },
|
||||
{ "getFaceCount", l_lovrConvexShapeGetFaceCount },
|
||||
{ "getFace", l_lovrConvexShapeGetFace },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
|
@ -203,6 +203,10 @@ float lovrCylinderShapeGetRadius(CylinderShape* cylinder);
|
|||
float lovrCylinderShapeGetLength(CylinderShape* cylinder);
|
||||
|
||||
ConvexShape* lovrConvexShapeCreate(float points[], uint32_t count);
|
||||
uint32_t lovrConvexShapeGetPointCount(ConvexShape* convex);
|
||||
void lovrConvexShapeGetPoint(ConvexShape* shape, uint32_t index, float point[3]);
|
||||
uint32_t lovrConvexShapeGetFaceCount(ConvexShape* convex);
|
||||
uint32_t lovrConvexShapeGetFace(ConvexShape* shape, uint32_t index, uint32_t* pointIndices, uint32_t capacity);
|
||||
|
||||
MeshShape* lovrMeshShapeCreate(int vertexCount, float vertices[], int indexCount, uint32_t indices[]);
|
||||
|
||||
|
|
|
@ -950,6 +950,26 @@ ConvexShape* lovrConvexShapeCreate(float points[], uint32_t count) {
|
|||
return convex;
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetPointCount(ConvexShape* convex) {
|
||||
return JPH_ConvexHullShape_GetNumPoints(convex->shape);
|
||||
}
|
||||
|
||||
void lovrConvexShapeGetPoint(ConvexShape* convex, uint32_t index, float point[3]) {
|
||||
lovrCheck(index < lovrConvexShapeGetPointCount(convex), "Invalid point index '%d'", index + 1);
|
||||
JPH_Vec3 v;
|
||||
JPH_ConvexHullShape_GetPoint(convex->shape, index, &v);
|
||||
vec3_fromJolt(point, &v);
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetFaceCount(ConvexShape* convex) {
|
||||
return JPH_ConvexHullShape_GetNumFaces(convex->shape);
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetFace(ConvexShape* convex, uint32_t index, uint32_t* pointIndices, uint32_t capacity) {
|
||||
lovrCheck(index < lovrConvexShapeGetFaceCount(convex), "Invalid face index '%d'", index + 1);
|
||||
return JPH_ConvexHullShape_GetFaceVertices(convex->shape, index, capacity, pointIndices);
|
||||
}
|
||||
|
||||
MeshShape* lovrMeshShapeCreate(int vertexCount, float vertices[], int indexCount, uint32_t indices[]) {
|
||||
MeshShape* mesh = lovrCalloc(sizeof(MeshShape));
|
||||
mesh->ref = 1;
|
||||
|
|
|
@ -1001,6 +1001,22 @@ ConvexShape* lovrConvexShapeCreate(float positions[], uint32_t count) {
|
|||
lovrThrow("ODE does not support ConvexShape");
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetPointCount(ConvexShape* convex) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lovrConvexShapeGetPoint(ConvexShape* shape, uint32_t index, float point[3]) {
|
||||
//
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetFaceCount(ConvexShape* convex) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t lovrConvexShapeGetFace(ConvexShape* shape, uint32_t index, uint32_t* pointIndices, uint32_t capacity) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MeshShape* lovrMeshShapeCreate(int vertexCount, float* vertices, int indexCount, dTriIndex* indices) {
|
||||
MeshShape* mesh = lovrCalloc(sizeof(MeshShape));
|
||||
mesh->ref = 1;
|
||||
|
|
Loading…
Reference in New Issue