static cpPolyShape *push_cpPolyShape (lua_State *L) { cpPolyShape *ps = cpPolyShapeAlloc(); cpPolyShape **psp = (cpPolyShape **)lua_newuserdata(L, sizeof(cpPolyShape *)); *psp = ps; luaL_getmetatable(L, "cpPolyShape"); lua_setmetatable(L, -2); /* cpShape_ptrs.shape_pointer = shape_userdata */ lua_pushliteral(L, "cpShape_ptrs"); lua_rawget(L, LUA_REGISTRYINDEX); lua_pushlightuserdata(L, ps); /* duplicate userdata */ lua_pushvalue(L, -3); lua_rawset(L, -3); lua_pop(L, 1); return ps; }
DynamicObject::DynamicObject(float x, float y, float scale, float mass, float elast, float fric, int type, std::string gpuPath, std::string vPath, std::string fPath) { gpuDataList.push_back(gpuStore.add(gpuPath, 3.1415f)); shaderList.push_back(shaderStore.add(vPath, fPath)); transformOverrides = false; height = scale; modelScale = glm::vec3(scale); width = height*gpuDataList[0]->whRatio; /*** Set physics data ***/ body = cpBodyNew(mass, 0); cpSpaceAddBody(space, body); cpBodySetPosition(body, cpv(x, y)); ObjGPUData* gpuData = gpuDataList[0]; int vertCount = gpuData->vList.size(); cpVect vertices[vertCount]; glm::vec3 pos(x, y, 0); for(int i = 0; i < vertCount; i++) { glm::vec4 currentVert = glm::translate(glm::mat4(1.0f), pos) * glm::scale(glm::mat4(1.0f), modelScale) * gpuData->rotation * gpuData->unitScale * glm::vec4(gpuData->vList[i],0); vertices[i] = cpv(currentVert.x, currentVert.y); } shape = cpSpaceAddShape(space, (cpShape*) cpPolyShapeInitRaw(cpPolyShapeAlloc(), body, vertCount, vertices, 1.0f)); cpBodySetMoment(body, abs(cpMomentForPoly(mass, vertCount, vertices, cpvzero, 1.0f))); cpShapeSetElasticity(shape, elast); cpShapeSetFriction(shape, fric); cpShapeSetUserData(shape, this); cpShapeSetCollisionType(shape, type); draw = true; }
//cpPoly static VALUE rb_cpPolyAlloc(VALUE klass) { cpPolyShape *poly = cpPolyShapeAlloc(); return Data_Wrap_Struct(klass, NULL, cpShapeFree, poly); }
cpShape * cpPolyShapeNew(cpBody *body, int numVerts, cpVect *verts, cpVect offset) { return (cpShape *)cpPolyShapeInit(cpPolyShapeAlloc(), body, numVerts, verts, offset); }
cpShape * cpBoxShapeNew(cpBody *body, cpFloat width, cpFloat height) { return (cpShape *)cpBoxShapeInit(cpPolyShapeAlloc(), body, width, height); }
cpShape * cpBoxShapeNew2(cpBody *body, cpBB box, cpFloat radius) { return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box, radius); }
cpShape * cpPolyShapeNewRaw(cpBody *body, int count, const cpVect *verts, cpFloat radius) { return (cpShape *)cpPolyShapeInitRaw(cpPolyShapeAlloc(), body, count, verts, radius); }
cpShape * cpPolyShapeNew(cpBody *body, int count, const cpVect *verts, cpTransform transform, cpFloat radius) { return (cpShape *)cpPolyShapeInit(cpPolyShapeAlloc(), body, count, verts, transform, radius); }
cpShape * cpBoxShapeNew2(cpBody *body, cpBB box) { return (cpShape *)cpBoxShapeInit2(cpPolyShapeAlloc(), body, box); }
cpShape * cpPolyShapeNew2(cpBody *body, int numVerts, const cpVect *verts, cpVect offset, cpFloat radius) { return (cpShape *)cpPolyShapeInit2(cpPolyShapeAlloc(), body, numVerts, verts, offset, radius); }