polygon MOI

This commit is contained in:
John Alanbrook 2023-02-27 14:50:36 +00:00
parent 4510543aaf
commit b6788e25b1
2 changed files with 12 additions and 1 deletions

View file

@ -365,7 +365,13 @@ struct phys2d_poly *Make2DPoly(int go)
float phys2d_poly_moi(struct phys2d_poly *poly, float m) float phys2d_poly_moi(struct phys2d_poly *poly, float m)
{ {
return cpMomentForPoly(m, arrlen(poly->points), poly->points, cpvzero, poly->radius); float moi = cpMomentForPoly(m, arrlen(poly->points), poly->points, cpvzero, poly->radius);
if (moi <= 0) {
YughError("Polygon MOI is negative. Returning one;");
return 1;
}
return moi;
} }
void phys2d_polydel(struct phys2d_poly *poly) void phys2d_polydel(struct phys2d_poly *poly)

View file

@ -117,6 +117,11 @@ void gameobject_apply(struct gameobject *go)
cpBodyEachShape(go->body, go_shape_apply, go); cpBodyEachShape(go->body, go_shape_apply, go);
if (go->bodytype == CP_BODY_TYPE_DYNAMIC) if (go->bodytype == CP_BODY_TYPE_DYNAMIC)
cpBodySetMass(go->body, go->mass); cpBodySetMass(go->body, go->mass);
if (cpBodyGetMoment(go->body) <= 0.f) {
YughError("Moment for object %d is zero. Setting to one.", go2id(go));
cpBodySetMoment(go->body, 1.f);
}
} }
static void gameobject_setpickcolor(struct gameobject *go) static void gameobject_setpickcolor(struct gameobject *go)