Skip to content

Commit

Permalink
fixed critical inertia calculation issue, a potential breaking change…
Browse files Browse the repository at this point in the history
…, so Body._inertiaScale added to try preserve previous behaviour
  • Loading branch information
liabru committed Jun 3, 2014
1 parent 2d04389 commit 9a55b0c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var Body = {};

(function() {

Body._inertiaScale = 4;

var _nextGroupId = 1;

/**
Expand Down Expand Up @@ -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);
body.inverseInertia = 1 / body.inertia;

// update geometry
// 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
Vertices.translate(body.vertices, body.position);
Vertices.rotate(body.vertices, body.angle, body.position);
Axes.rotate(body.axes, body.angle);
Expand Down

0 comments on commit 9a55b0c

Please sign in to comment.