mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
added Demo.compound
This commit is contained in:
parent
9c139ed9df
commit
b7bf5d6643
2 changed files with 11 additions and 35 deletions
|
@ -30,8 +30,8 @@
|
||||||
<div class="controls-container">
|
<div class="controls-container">
|
||||||
<select id="demo-select">
|
<select id="demo-select">
|
||||||
<option value="mixed">Mixed Shapes</option>
|
<option value="mixed">Mixed Shapes</option>
|
||||||
<option value="concave">Concave Shapes</option>
|
|
||||||
<option value="mixedSolid">Solid Rendering</option>
|
<option value="mixedSolid">Solid Rendering</option>
|
||||||
|
<option value="compound">Compound Bodies</option>
|
||||||
<option value="newtonsCradle">Newton's Cradle</option>
|
<option value="newtonsCradle">Newton's Cradle</option>
|
||||||
<option value="wreckingBall">Wrecking Ball</option>
|
<option value="wreckingBall">Wrecking Ball</option>
|
||||||
<option value="slingshot">Slingshot Game</option>
|
<option value="slingshot">Slingshot Game</option>
|
||||||
|
|
|
@ -117,52 +117,28 @@
|
||||||
var renderOptions = _engine.render.options;
|
var renderOptions = _engine.render.options;
|
||||||
};
|
};
|
||||||
|
|
||||||
Demo.concave = function() {
|
Demo.compound = function() {
|
||||||
var _world = _engine.world;
|
var _world = _engine.world;
|
||||||
|
|
||||||
Demo.reset();
|
Demo.reset();
|
||||||
|
|
||||||
var s = 50;
|
var partA = Bodies.rectangle(200, 200, 200, 40),
|
||||||
//var vertices = [{ x: 0, y: 0 }, { x: 0, y: 2 * s },
|
partB = Bodies.rectangle(200, 200, 40, 200);
|
||||||
// { x: 1 * s, y: 2 * s }, { x: 1 * s, y: 1 * s },
|
|
||||||
// { x: 2 * s, y: 1 * s }, { x: 2 * s, y: 0 }];
|
|
||||||
|
|
||||||
//var vertices = Matter.Vertices.fromPath('-5 78,70 126,57 195,114 139,191 201,161 136,217 83,151 83,122 -1,82 85');
|
var compound = Body.create({
|
||||||
|
parts: [partA, partB]
|
||||||
var partA = Bodies.rectangle(200, 200, 200, 20);
|
|
||||||
var partB = Bodies.rectangle(200, 200, 20, 200);
|
|
||||||
var middle = Bodies.rectangle(200, 200, 20, 20);
|
|
||||||
//var parent = Bodies.rectangle(200, 200, 200, 200);
|
|
||||||
|
|
||||||
var vertices = Matter.Vertices.create(partA.vertices.concat(partB.vertices.concat(middle.vertices)), true);
|
|
||||||
Matter.Vertices.clockwiseSort(vertices);
|
|
||||||
|
|
||||||
//debugger;
|
|
||||||
|
|
||||||
var hull = Matter.Vertices.hull(vertices);
|
|
||||||
|
|
||||||
console.log(vertices);
|
|
||||||
console.log(hull);
|
|
||||||
|
|
||||||
var parent = Body.create({
|
|
||||||
position: { x: 200, y: 200 },
|
|
||||||
vertices: hull
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//debugger;
|
World.add(_world, compound);
|
||||||
|
|
||||||
partA.parent = parent;
|
_world.gravity.y = 1;
|
||||||
partB.parent = parent;
|
|
||||||
|
|
||||||
parent.parts = [parent, partA, partB];
|
|
||||||
|
|
||||||
World.add(_world, parent);
|
|
||||||
|
|
||||||
_world.gravity.y = 0;
|
|
||||||
|
|
||||||
var renderOptions = _engine.render.options;
|
var renderOptions = _engine.render.options;
|
||||||
renderOptions.showCollisions = true;
|
renderOptions.showCollisions = true;
|
||||||
renderOptions.showBounds = true;
|
renderOptions.showBounds = true;
|
||||||
|
renderOptions.showAxes = true;
|
||||||
|
renderOptions.showPositions = true;
|
||||||
|
renderOptions.showConvexHulls = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Demo.slingshot = function() {
|
Demo.slingshot = function() {
|
||||||
|
|
Loading…
Reference in a new issue