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

fixed critical inertia calculation issue, a potential breaking change, so Body._inertiaScale added to try preserve previous behaviour

This commit is contained in:
liabru 2014-06-03 15:54:21 +01:00
parent 2d04389c84
commit 9a55b0c902

View file

@ -13,6 +13,8 @@ var Body = {};
(function() {
Body._inertiaScale = 4;
var _nextGroupId = 1;
/**
@ -156,12 +158,16 @@ var Body = {};
body.area = Vertices.area(body.vertices);
body.mass = body.density * body.area;
body.inverseMass = 1 / body.mass;
body.inertia = Vertices.inertia(body.vertices, body.mass);
// orient vertices around the centre of mass at origin (0, 0)
var centre = Vertices.centre(body.vertices);
Vertices.translate(body.vertices, centre, -1);
// update inertia while vertices are at origin (0, 0)
body.inertia = Body._inertiaScale * Vertices.inertia(body.vertices, body.mass);
body.inverseInertia = 1 / body.inertia;
// update geometry
var centre = Vertices.centre(body.vertices);
Vertices.translate(body.vertices, centre, -1);
Vertices.translate(body.vertices, body.position);
Vertices.rotate(body.vertices, body.angle, body.position);
Axes.rotate(body.axes, body.angle);