Add setter for customizing a node's mass

This commit is contained in:
Robert Machmer 2016-01-09 12:06:26 +01:00
parent 86788b748d
commit 1681c649fb

View File

@ -23,6 +23,7 @@ function Node.new( id, x, y, anchor, ... )
local px, py = x or 0, y or 0; local px, py = x or 0, y or 0;
local ax, ay = 0, 0; local ax, ay = 0, 0;
local vx, vy = 0, 0; local vx, vy = 0, 0;
local mass = DEFAULT_MASS;
--- ---
-- Clamps a value to a certain range. -- Clamps a value to a certain range.
@ -69,7 +70,7 @@ function Node.new( id, x, y, anchor, ... )
dx = dx / distance; dx = dx / distance;
dy = dy / distance; dy = dy / distance;
local strength = FORCE_CHARGE * (DEFAULT_MASS / (distance * distance)); local strength = FORCE_CHARGE * ( mass / ( distance * distance ));
applyForce(dx * strength, dy * strength); applyForce(dx * strength, dy * strength);
end end
@ -114,6 +115,10 @@ function Node.new( id, x, y, anchor, ... )
return anchor; return anchor;
end end
function self:setMass( nmass )
mass = nmass;
end
return self; return self;
end end