Skip to content

Commit

Permalink
fix inertia change in Body.setMass, closes #378
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Nov 25, 2017
1 parent 894c1ef commit f7d1877
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,23 @@ var Axes = require('../geometry/Axes');
};

/**
* Sets the mass of the body. Inverse mass and density are automatically updated to reflect the change.
* Sets the mass of the body. Inverse mass, density and inertia are automatically updated to reflect the change.
* @method setMass
* @param {body} body
* @param {number} mass
*/
Body.setMass = function(body, mass) {
var moment = body.inertia / (body.mass / 6);
body.inertia = moment * (mass / 6);
body.inverseInertia = 1 / body.inertia;

body.mass = mass;
body.inverseMass = 1 / body.mass;
body.density = body.mass / body.area;
};

/**
* Sets the density of the body. Mass is automatically updated to reflect the change.
* Sets the density of the body. Mass and inertia are automatically updated to reflect the change.
* @method setDensity
* @param {body} body
* @param {number} density
Expand Down

0 comments on commit f7d1877

Please sign in to comment.