mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
removed Detector.bruteForce
This commit is contained in:
parent
ce478cb3ab
commit
e04de5fb4e
2 changed files with 1 additions and 73 deletions
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* matter-tools-dev.min.js 0.5.0-dev 2015-07-27
|
* matter-tools-dev.min.js 0.5.0-dev 2015-12-05
|
||||||
* https://github.com/liabru/matter-tools
|
* https://github.com/liabru/matter-tools
|
||||||
* License: MIT
|
* License: MIT
|
||||||
*/
|
*/
|
||||||
|
@ -195,10 +195,6 @@
|
||||||
gravity.open();
|
gravity.open();
|
||||||
var physics = datGui.addFolder("Engine");
|
var physics = datGui.addFolder("Engine");
|
||||||
physics.add(engine, "enableSleeping");
|
physics.add(engine, "enableSleeping");
|
||||||
physics.add(gui, "broadphase", [ "grid", "bruteForce" ]).onFinishChange(function(value) {
|
|
||||||
engine.broadphase = gui.broadphaseCache[value];
|
|
||||||
Composite.setModified(engine.world, true, false, false);
|
|
||||||
});
|
|
||||||
physics.add(engine.timing, "timeScale", 0, 1.2).step(.05).listen();
|
physics.add(engine.timing, "timeScale", 0, 1.2).step(.05).listen();
|
||||||
physics.add(engine, "velocityIterations", 1, 10).step(1);
|
physics.add(engine, "velocityIterations", 1, 10).step(1);
|
||||||
physics.add(engine, "positionIterations", 1, 10).step(1);
|
physics.add(engine, "positionIterations", 1, 10).step(1);
|
||||||
|
|
|
@ -89,74 +89,6 @@ var Bounds = require('../geometry/Bounds');
|
||||||
return collisions;
|
return collisions;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Description
|
|
||||||
* @method bruteForce
|
|
||||||
* @param {body[]} bodies
|
|
||||||
* @param {engine} engine
|
|
||||||
* @return {array} collisions
|
|
||||||
*/
|
|
||||||
Detector.bruteForce = function(bodies, engine) {
|
|
||||||
var collisions = [],
|
|
||||||
pairsTable = engine.pairs.table;
|
|
||||||
|
|
||||||
// @if DEBUG
|
|
||||||
var metrics = engine.metrics;
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
for (var i = 0; i < bodies.length; i++) {
|
|
||||||
for (var j = i + 1; j < bodies.length; j++) {
|
|
||||||
var bodyA = bodies[i],
|
|
||||||
bodyB = bodies[j];
|
|
||||||
|
|
||||||
// NOTE: could share a function for the below, but may drop performance?
|
|
||||||
|
|
||||||
if ((bodyA.isStatic || bodyA.isSleeping) && (bodyB.isStatic || bodyB.isSleeping))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!Detector.canCollide(bodyA.collisionFilter, bodyB.collisionFilter))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// @if DEBUG
|
|
||||||
metrics.midphaseTests += 1;
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
// mid phase
|
|
||||||
if (Bounds.overlaps(bodyA.bounds, bodyB.bounds)) {
|
|
||||||
|
|
||||||
// find a previous collision we could reuse
|
|
||||||
var pairId = Pair.id(bodyA, bodyB),
|
|
||||||
pair = pairsTable[pairId],
|
|
||||||
previousCollision;
|
|
||||||
|
|
||||||
if (pair && pair.isActive) {
|
|
||||||
previousCollision = pair.collision;
|
|
||||||
} else {
|
|
||||||
previousCollision = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// narrow phase
|
|
||||||
var collision = SAT.collides(bodyA, bodyB, previousCollision);
|
|
||||||
|
|
||||||
// @if DEBUG
|
|
||||||
metrics.narrowphaseTests += 1;
|
|
||||||
if (collision.reused)
|
|
||||||
metrics.narrowReuseCount += 1;
|
|
||||||
// @endif
|
|
||||||
|
|
||||||
if (collision.collided) {
|
|
||||||
collisions.push(collision);
|
|
||||||
// @if DEBUG
|
|
||||||
metrics.narrowDetections += 1;
|
|
||||||
// @endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return collisions;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns `true` if both supplied collision filters will allow a collision to occur.
|
* Returns `true` if both supplied collision filters will allow a collision to occur.
|
||||||
* See `body.collisionFilter` for more information.
|
* See `body.collisionFilter` for more information.
|
||||||
|
|
Loading…
Reference in a new issue