mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -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:
parent
2d04389c84
commit
9a55b0c902
1 changed files with 9 additions and 3 deletions
|
@ -13,6 +13,8 @@ var Body = {};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
Body._inertiaScale = 4;
|
||||||
|
|
||||||
var _nextGroupId = 1;
|
var _nextGroupId = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,12 +158,16 @@ var Body = {};
|
||||||
body.area = Vertices.area(body.vertices);
|
body.area = Vertices.area(body.vertices);
|
||||||
body.mass = body.density * body.area;
|
body.mass = body.density * body.area;
|
||||||
body.inverseMass = 1 / body.mass;
|
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;
|
body.inverseInertia = 1 / body.inertia;
|
||||||
|
|
||||||
// update geometry
|
// update geometry
|
||||||
var centre = Vertices.centre(body.vertices);
|
|
||||||
Vertices.translate(body.vertices, centre, -1);
|
|
||||||
Vertices.translate(body.vertices, body.position);
|
Vertices.translate(body.vertices, body.position);
|
||||||
Vertices.rotate(body.vertices, body.angle, body.position);
|
Vertices.rotate(body.vertices, body.angle, body.position);
|
||||||
Axes.rotate(body.axes, body.angle);
|
Axes.rotate(body.axes, body.angle);
|
||||||
|
|
Loading…
Reference in a new issue