0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00

added Demo.compound

This commit is contained in:
liabru 2015-01-31 23:57:31 +00:00
parent 9c139ed9df
commit b7bf5d6643
2 changed files with 11 additions and 35 deletions

View file

@ -30,8 +30,8 @@
<div class="controls-container">
<select id="demo-select">
<option value="mixed">Mixed Shapes</option>
<option value="concave">Concave Shapes</option>
<option value="mixedSolid">Solid Rendering</option>
<option value="compound">Compound Bodies</option>
<option value="newtonsCradle">Newton's Cradle</option>
<option value="wreckingBall">Wrecking Ball</option>
<option value="slingshot">Slingshot Game</option>

View file

@ -117,52 +117,28 @@
var renderOptions = _engine.render.options;
};
Demo.concave = function() {
Demo.compound = function() {
var _world = _engine.world;
Demo.reset();
var s = 50;
//var vertices = [{ x: 0, y: 0 }, { x: 0, y: 2 * s },
// { x: 1 * s, y: 2 * s }, { x: 1 * s, y: 1 * s },
// { x: 2 * s, y: 1 * s }, { x: 2 * s, y: 0 }];
var partA = Bodies.rectangle(200, 200, 200, 40),
partB = Bodies.rectangle(200, 200, 40, 200);
//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 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
var compound = Body.create({
parts: [partA, partB]
});
//debugger;
World.add(_world, compound);
partA.parent = parent;
partB.parent = parent;
parent.parts = [parent, partA, partB];
World.add(_world, parent);
_world.gravity.y = 0;
_world.gravity.y = 1;
var renderOptions = _engine.render.options;
renderOptions.showCollisions = true;
renderOptions.showBounds = true;
renderOptions.showAxes = true;
renderOptions.showPositions = true;
renderOptions.showConvexHulls = true;
};
Demo.slingshot = function() {