0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

changed plugins to use body.plugin

This commit is contained in:
liabru 2017-01-24 20:34:26 +00:00
parent b3533937d4
commit 3fdf343015
6 changed files with 18 additions and 10 deletions

View file

@ -53,13 +53,15 @@ Example.attractors = function() {
radius,
{
mass: Common.random(10, 15),
gravity: G,
frictionAir: 0,
plugin: {
gravity: G,
wrap: {
min: { x: 0, y: 0 },
max: { x: render.options.width, y: render.options.height }
}
}
}
);
var speed = 5;

View file

@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo
(function() {
var MatterAttractors = {

View file

@ -72,7 +72,7 @@ Example.avalanche = function() {
// wrapping using matter-wrap plugin
for (var i = 0; i < stack.bodies.length; i += 1) {
stack.bodies[i].wrap = {
stack.bodies[i].plugin.wrap = {
min: { x: render.bounds.min.x, y: render.bounds.min.y },
max: { x: render.bounds.max.x, y: render.bounds.max.y }
};

View file

@ -80,7 +80,7 @@ Example.ballPool = function() {
var allBodies = Composite.allBodies(world);
for (var i = 0; i < allBodies.length; i += 1) {
allBodies[i].wrap = {
allBodies[i].plugin.wrap = {
min: { x: render.bounds.min.x - 100, y: render.bounds.min.y },
max: { x: render.bounds.max.x + 100, y: render.bounds.max.y }
};

View file

@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo
(function() {
var MatterGravity = {
@ -19,7 +21,7 @@
Body: {
init: function(body) {
if (body.gravity) {
if (body.plugin.gravity) {
body.attractors.push(MatterGravity.Body.applyGravity);
}
},
@ -28,7 +30,7 @@
var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
normal = Matter.Vector.normalise(bToA),
magnitude = -bodyA.gravity * (bodyA.mass * bodyB.mass / distanceSq),
magnitude = -bodyA.plugin.gravity * (bodyA.mass * bodyB.mass / distanceSq),
force = Matter.Vector.mult(normal, magnitude);
Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));

View file

@ -1,3 +1,5 @@
// NOTE: this plugin will be moved to its own repo
(function() {
var MatterWrap = {
@ -21,8 +23,8 @@
for (var i = 0; i < bodies.length; i += 1) {
var body = bodies[i];
if (body.wrap) {
MatterWrap.Body.wrap(body, body.wrap);
if (body.plugin.wrap) {
MatterWrap.Body.wrap(body, body.plugin.wrap);
}
}
}