mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-30 10:20:52 -05:00
removed engine.broadphase.current, removed engine.broadphase.instance, changed engine.broadphase to refer to the broadphase instance, updated matter-tools
This commit is contained in:
parent
eedd1f2a9c
commit
6dd0c05f41
3 changed files with 36 additions and 28 deletions
|
@ -1,12 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* matter-tools-dev.min.js 0.5.0-dev 2014-05-04
|
* matter-tools-dev.min.js 0.5.0-dev 2014-06-21
|
||||||
* https://github.com/liabru/matter-tools
|
* https://github.com/liabru/matter-tools
|
||||||
* License: MIT
|
* License: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var MatterTools = {};
|
var MatterTools = {};
|
||||||
var Engine = Matter.Engine, World = Matter.World, Bodies = Matter.Bodies, Body = Matter.Body, Composite = Matter.Composite, Composites = Matter.Composites, Common = Matter.Common, Constraint = Matter.Constraint, Events = Matter.Events, Bounds = Matter.Bounds, Vector = Matter.Vector, Vertices = Matter.Vertices, MouseConstraint = Matter.MouseConstraint, Render = Matter.Render, RenderPixi = Matter.RenderPixi, Mouse = Matter.Mouse, Query = Matter.Query;
|
var Engine = Matter.Engine, World = Matter.World, Bodies = Matter.Bodies, Body = Matter.Body, Composite = Matter.Composite, Composites = Matter.Composites, Common = Matter.Common, Constraint = Matter.Constraint, Events = Matter.Events, Bounds = Matter.Bounds, Vector = Matter.Vector, Vertices = Matter.Vertices, MouseConstraint = Matter.MouseConstraint, Render = Matter.Render, RenderPixi = Matter.RenderPixi, Mouse = Matter.Mouse, Query = Matter.Query, Grid = Matter.Grid, Detector = Matter.Detector;
|
||||||
var Gui = {};
|
var Gui = {};
|
||||||
(function() {
|
(function() {
|
||||||
Gui.create = function(engine, options) {
|
Gui.create = function(engine, options) {
|
||||||
|
@ -19,6 +19,13 @@
|
||||||
var gui = {
|
var gui = {
|
||||||
engine:engine,
|
engine:engine,
|
||||||
datGui:datGui,
|
datGui:datGui,
|
||||||
|
broadphase:"grid",
|
||||||
|
broadphaseCache:{
|
||||||
|
grid:engine.broadphase.controller === Grid ? engine.broadphase :Grid.create(),
|
||||||
|
bruteForce:{
|
||||||
|
detector:Detector.bruteForce
|
||||||
|
}
|
||||||
|
},
|
||||||
amount:1,
|
amount:1,
|
||||||
size:40,
|
size:40,
|
||||||
sides:4,
|
sides:4,
|
||||||
|
@ -146,7 +153,8 @@
|
||||||
gravity.open();
|
gravity.open();
|
||||||
var physics = datGui.addFolder("Engine");
|
var physics = datGui.addFolder("Engine");
|
||||||
physics.add(engine, "enableSleeping");
|
physics.add(engine, "enableSleeping");
|
||||||
physics.add(engine.broadphase, "current", [ "grid", "bruteForce" ]).onFinishChange(function(value) {
|
physics.add(gui, "broadphase", [ "grid", "bruteForce" ]).onFinishChange(function(value) {
|
||||||
|
engine.broadphase = gui.broadphaseCache[value];
|
||||||
Composite.setModified(engine.world, true, false, false);
|
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();
|
||||||
|
@ -490,10 +498,10 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var _getMousePosition = function(inspector) {
|
var _getMousePosition = function(inspector) {
|
||||||
return Vector.add(inspector.engine.input.mouse.position, inspector.offset);
|
return Vector.add(inspector.mouse.position, inspector.offset);
|
||||||
};
|
};
|
||||||
var _initEngineEvents = function(inspector) {
|
var _initEngineEvents = function(inspector) {
|
||||||
var engine = inspector.engine, mouse = engine.input.mouse, mousePosition = _getMousePosition(inspector), controls = inspector.controls;
|
var engine = inspector.engine, mouse = inspector.mouse, mousePosition = _getMousePosition(inspector), controls = inspector.controls;
|
||||||
Events.on(engine, "tick", function() {
|
Events.on(engine, "tick", function() {
|
||||||
mousePosition = _getMousePosition(inspector);
|
mousePosition = _getMousePosition(inspector);
|
||||||
var mouseDelta = mousePosition.x - inspector.mousePrevPosition.x, keyDelta = _key.isPressed("up") + _key.isPressed("right") - _key.isPressed("down") - _key.isPressed("left"), delta = mouseDelta + keyDelta;
|
var mouseDelta = mousePosition.x - inspector.mousePrevPosition.x, keyDelta = _key.isPressed("up") + _key.isPressed("right") - _key.isPressed("down") - _key.isPressed("left"), delta = mouseDelta + keyDelta;
|
||||||
|
@ -654,7 +662,7 @@
|
||||||
}, 200);
|
}, 200);
|
||||||
};
|
};
|
||||||
var _updateSelectedMouseDownOffset = function(inspector) {
|
var _updateSelectedMouseDownOffset = function(inspector) {
|
||||||
var selected = inspector.selected, mouse = inspector.engine.input.mouse, mousePosition = _getMousePosition(inspector), item, data;
|
var selected = inspector.selected, mouse = inspector.mouse, mousePosition = _getMousePosition(inspector), item, data;
|
||||||
for (var i = 0; i < selected.length; i++) {
|
for (var i = 0; i < selected.length; i++) {
|
||||||
item = selected[i];
|
item = selected[i];
|
||||||
data = item.data;
|
data = item.data;
|
||||||
|
@ -677,7 +685,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var _moveSelectedObjects = function(inspector, x, y) {
|
var _moveSelectedObjects = function(inspector, x, y) {
|
||||||
var selected = inspector.selected, mouse = inspector.engine.input.mouse, mousePosition = _getMousePosition(inspector), item, data;
|
var selected = inspector.selected, mouse = inspector.mouse, mousePosition = _getMousePosition(inspector), item, data;
|
||||||
for (var i = 0; i < selected.length; i++) {
|
for (var i = 0; i < selected.length; i++) {
|
||||||
item = selected[i];
|
item = selected[i];
|
||||||
data = item.data;
|
data = item.data;
|
||||||
|
|
|
@ -55,6 +55,9 @@ var Engine = {};
|
||||||
render: {
|
render: {
|
||||||
element: element,
|
element: element,
|
||||||
controller: Render
|
controller: Render
|
||||||
|
},
|
||||||
|
broadphase: {
|
||||||
|
controller: Grid
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,18 +67,7 @@ var Engine = {};
|
||||||
engine.world = World.create(engine.world);
|
engine.world = World.create(engine.world);
|
||||||
engine.pairs = Pairs.create();
|
engine.pairs = Pairs.create();
|
||||||
engine.metrics = engine.metrics || Metrics.create();
|
engine.metrics = engine.metrics || Metrics.create();
|
||||||
|
engine.broadphase = engine.broadphase.controller.create(engine.broadphase);
|
||||||
engine.broadphase = engine.broadphase || {
|
|
||||||
current: 'grid',
|
|
||||||
grid: {
|
|
||||||
controller: Grid,
|
|
||||||
instance: Grid.create(),
|
|
||||||
detector: Detector.collisions
|
|
||||||
},
|
|
||||||
bruteForce: {
|
|
||||||
detector: Detector.bruteForce
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return engine;
|
return engine;
|
||||||
};
|
};
|
||||||
|
@ -184,7 +176,7 @@ var Engine = {};
|
||||||
|
|
||||||
var world = engine.world,
|
var world = engine.world,
|
||||||
timing = engine.timing,
|
timing = engine.timing,
|
||||||
broadphase = engine.broadphase[engine.broadphase.current],
|
broadphase = engine.broadphase,
|
||||||
broadphasePairs = [],
|
broadphasePairs = [],
|
||||||
i;
|
i;
|
||||||
|
|
||||||
|
@ -227,11 +219,11 @@ var Engine = {};
|
||||||
|
|
||||||
// if world is dirty, we must flush the whole grid
|
// if world is dirty, we must flush the whole grid
|
||||||
if (world.isModified)
|
if (world.isModified)
|
||||||
broadphase.controller.clear(broadphase.instance);
|
broadphase.controller.clear(broadphase);
|
||||||
|
|
||||||
// update the grid buckets based on current bodies
|
// update the grid buckets based on current bodies
|
||||||
broadphase.controller.update(broadphase.instance, allBodies, engine, world.isModified);
|
broadphase.controller.update(broadphase, allBodies, engine, world.isModified);
|
||||||
broadphasePairs = broadphase.instance.pairsList;
|
broadphasePairs = broadphase.pairsList;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// if no broadphase set, we just pass all bodies
|
// if no broadphase set, we just pass all bodies
|
||||||
|
@ -329,11 +321,11 @@ var Engine = {};
|
||||||
|
|
||||||
Pairs.clear(engine.pairs);
|
Pairs.clear(engine.pairs);
|
||||||
|
|
||||||
var broadphase = engine.broadphase[engine.broadphase.current];
|
var broadphase = engine.broadphase;
|
||||||
if (broadphase.controller) {
|
if (broadphase.controller) {
|
||||||
var bodies = Composite.allBodies(world);
|
var bodies = Composite.allBodies(world);
|
||||||
broadphase.controller.clear(broadphase.instance);
|
broadphase.controller.clear(broadphase);
|
||||||
broadphase.controller.update(broadphase.instance, bodies, engine, true);
|
broadphase.controller.update(broadphase, bodies, engine, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -587,6 +579,14 @@ var Engine = {};
|
||||||
* @default a Matter.Render instance
|
* @default a Matter.Render instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An instance of a broadphase controller. The default value is a `Matter.Grid` instance created by `Engine.create`.
|
||||||
|
*
|
||||||
|
* @property broadphase
|
||||||
|
* @type grid
|
||||||
|
* @default a Matter.Grid instance
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `World` composite object that will contain all simulated bodies and constraints.
|
* A `World` composite object that will contain all simulated bodies and constraints.
|
||||||
*
|
*
|
||||||
|
|
|
@ -204,8 +204,8 @@ var Render = {};
|
||||||
|
|
||||||
Render.constraints(constraints, context);
|
Render.constraints(constraints, context);
|
||||||
|
|
||||||
if (options.showBroadphase && engine.broadphase.current === 'grid')
|
if (options.showBroadphase && engine.broadphase.controller === Grid)
|
||||||
Render.grid(engine, engine.broadphase[engine.broadphase.current].instance, context);
|
Render.grid(engine, engine.broadphase, context);
|
||||||
|
|
||||||
if (options.showDebug)
|
if (options.showDebug)
|
||||||
Render.debug(engine, context);
|
Render.debug(engine, context);
|
||||||
|
|
Loading…
Reference in a new issue