0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

fix centroid for static compound bodies, closes #483

This commit is contained in:
liabru 2017-11-25 14:52:41 +00:00
parent 50a89d0217
commit ece66e6f16

View file

@ -672,16 +672,16 @@ var Axes = require('../geometry/Axes');
// sum the properties of all compound parts of the parent body // sum the properties of all compound parts of the parent body
for (var i = body.parts.length === 1 ? 0 : 1; i < body.parts.length; i++) { for (var i = body.parts.length === 1 ? 0 : 1; i < body.parts.length; i++) {
var part = body.parts[i]; var part = body.parts[i],
properties.mass += part.mass; mass = part.mass !== Infinity ? part.mass : 1;
properties.mass += mass;
properties.area += part.area; properties.area += part.area;
properties.inertia += part.inertia; properties.inertia += part.inertia;
properties.centre = Vector.add(properties.centre, properties.centre = Vector.add(properties.centre, Vector.mult(part.position, mass));
Vector.mult(part.position, part.mass !== Infinity ? part.mass : 1));
} }
properties.centre = Vector.div(properties.centre, properties.centre = Vector.div(properties.centre, properties.mass);
properties.mass !== Infinity ? properties.mass : body.parts.length);
return properties; return properties;
}; };