cpPolyShape * cpPolyShapeInitRaw(cpPolyShape *poly, cpBody *body, int count, const cpVect *verts, cpFloat radius) { cpShapeInit((cpShape *)poly, &polyClass, body, cpPolyShapeMassInfo(0.0f, count, verts, radius)); SetVerts(poly, count, verts); poly->r = radius; return poly; }
void cpPolyShapeSetVertsRaw(cpShape *shape, int count, cpVect *verts) { cpAssertHard(shape->klass == &polyClass, "Shape is not a poly shape."); cpPolyShape *poly = (cpPolyShape *)shape; cpPolyShapeDestroy(poly); SetVerts(poly, count, verts); cpFloat mass = shape->massInfo.m; shape->massInfo = cpPolyShapeMassInfo(shape->massInfo.m, count, verts, poly->r); if(mass > 0.0f) cpBodyAccumulateMassFromShapes(shape->body); }
double CompArea1(double *eqn, double *corner) { double val, area, minVal, maxVal; int i, minIndex, maxIndex; double cos_phi, top_area, bottom_area; if((corner[0] < EPS) || (corner[1] < EPS) || (corner[2] < EPS)) { return -1.0; } if(eqn[2] < 1.0) { // vertical plane return -2.0; } // cos of angle between plane perpendicular and z axis cos_phi = eqn[2]/getNorm(&(eqn[0])); maxVal = 0.0; minVal = 0.0; minIndex = maxIndex = -1; area = 0.0; SetVerts(corner[0], corner[1], corner[2]); for(i = 0; i < 8; i++) { val = applyEqn(eqn, &(vert[i][0])); vertVals[i] = val; if(val > maxVal) { maxVal = val; maxIndex = i; } if(val < minVal) { minVal = val; minIndex = i; } } /* sanity check */ if((minIndex == -1) || (maxIndex == -1)) { // all veritces below plane or all above return -3.0; } area = 0.0; // see if plane hits top of box if((vertVals[1] >= 0.0) && (vertVals[3] >= 0.0) && (vertVals[5] >= 0.0) && (vertVals[7] >= 0.0)) { /* plane does not hit top of box */ top_area = 0.0; } else { top_area = FindFaceArea(topFaceVerts); } if((vertVals[0] <= 0.0) && (vertVals[2] <= 0.0) && (vertVals[4] <= 0.0) && (vertVals[6] <= 0.0)) { /* does not hit bottom, arrea is whole base */ bottom_area = corner[0] * corner[1]; } else { bottom_area = FindFaceArea(bottomFaceVerts); } area = top_area + (bottom_area - top_area)/cos_phi; return area; }