mirror of
https://github.com/rm-code/Graphoon.git
synced 2024-11-16 18:24:22 +00:00
Add setter for customizing a node's mass
This commit is contained in:
parent
86788b748d
commit
1681c649fb
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user