From 9a55b0c902307e1e86a18c51fb95f2d66f877b9e Mon Sep 17 00:00:00 2001 From: liabru Date: Tue, 3 Jun 2014 15:54:21 +0100 Subject: [PATCH] fixed critical inertia calculation issue, a potential breaking change, so Body._inertiaScale added to try preserve previous behaviour --- src/body/Body.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index f50cba6..7bcb047 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -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);