mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
changed plugins to use body.plugin
This commit is contained in:
parent
b3533937d4
commit
3fdf343015
6 changed files with 18 additions and 10 deletions
|
@ -53,13 +53,15 @@ Example.attractors = function() {
|
||||||
radius,
|
radius,
|
||||||
{
|
{
|
||||||
mass: Common.random(10, 15),
|
mass: Common.random(10, 15),
|
||||||
gravity: G,
|
|
||||||
frictionAir: 0,
|
frictionAir: 0,
|
||||||
|
plugin: {
|
||||||
|
gravity: G,
|
||||||
wrap: {
|
wrap: {
|
||||||
min: { x: 0, y: 0 },
|
min: { x: 0, y: 0 },
|
||||||
max: { x: render.options.width, y: render.options.height }
|
max: { x: render.options.width, y: render.options.height }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var speed = 5;
|
var speed = 5;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// NOTE: this plugin will be moved to its own repo
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var MatterAttractors = {
|
var MatterAttractors = {
|
||||||
|
|
|
@ -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 }
|
||||||
};
|
};
|
||||||
|
|
|
@ -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 }
|
||||||
};
|
};
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue