Skip to content

Commit

Permalink
added Demo.compound
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 31, 2015
1 parent 9c139ed commit b7bf5d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 35 deletions.
2 changes: 1 addition & 1 deletion demo/dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ <h1>Matter.js Demo (Dev. Build)</h1>
<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>
Expand Down
44 changes: 10 additions & 34 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b7bf5d6

Please sign in to comment.