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,11 +53,13 @@ Example.attractors = function() {
radius, radius,
{ {
mass: Common.random(10, 15), mass: Common.random(10, 15),
gravity: G,
frictionAir: 0, frictionAir: 0,
wrap: { plugin: {
min: { x: 0, y: 0 }, gravity: G,
max: { x: render.options.width, y: render.options.height } wrap: {
min: { x: 0, y: 0 },
max: { x: render.options.width, y: render.options.height }
}
} }
} }
); );

View file

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

View file

@ -72,7 +72,7 @@ Example.avalanche = function() {
// wrapping using matter-wrap plugin // wrapping using matter-wrap plugin
for (var i = 0; i < stack.bodies.length; i += 1) { 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 }, min: { x: render.bounds.min.x, y: render.bounds.min.y },
max: { x: render.bounds.max.x, y: render.bounds.max.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); var allBodies = Composite.allBodies(world);
for (var i = 0; i < allBodies.length; i += 1) { 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 }, min: { x: render.bounds.min.x - 100, y: render.bounds.min.y },
max: { x: render.bounds.max.x + 100, y: render.bounds.max.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() { (function() {
var MatterGravity = { var MatterGravity = {
@ -19,7 +21,7 @@
Body: { Body: {
init: function(body) { init: function(body) {
if (body.gravity) { if (body.plugin.gravity) {
body.attractors.push(MatterGravity.Body.applyGravity); body.attractors.push(MatterGravity.Body.applyGravity);
} }
}, },
@ -28,7 +30,7 @@
var bToA = Matter.Vector.sub(bodyB.position, bodyA.position), var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001, distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
normal = Matter.Vector.normalise(bToA), 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); force = Matter.Vector.mult(normal, magnitude);
Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force)); 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() { (function() {
var MatterWrap = { var MatterWrap = {
@ -21,8 +23,8 @@
for (var i = 0; i < bodies.length; i += 1) { for (var i = 0; i < bodies.length; i += 1) {
var body = bodies[i]; var body = bodies[i];
if (body.wrap) { if (body.plugin.wrap) {
MatterWrap.Body.wrap(body, body.wrap); MatterWrap.Body.wrap(body, body.plugin.wrap);
} }
} }
} }