Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 1, 2015
1 parent 37ccc84 commit 5888ffc
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 78 deletions.
61 changes: 10 additions & 51 deletions demo/js/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
Composites = Matter.Composites,
Common = Matter.Common,
Constraint = Matter.Constraint,
RenderPixi = Matter.RenderPixi,
Events = Matter.Events,
Bounds = Matter.Bounds,
Vector = Matter.Vector,
Vertices = Matter.Vertices,
MouseConstraint = Matter.MouseConstraint,
Mouse = Matter.Mouse,
Query = Matter.Query;
Expand Down Expand Up @@ -91,7 +89,6 @@
var sides = Math.round(Common.random(1, 8));

// triangles can be a little unstable, so avoid until fixed
// TODO: make triangles more stable
sides = (sides === 3) ? 4 : sides;

// round the edges of some bodies
Expand All @@ -117,7 +114,7 @@

World.add(_world, stack);

var renderOptions = _engine.render.options;
var renderOptions = _engine.render.options;
};

Demo.slingshot = function() {
Expand Down Expand Up @@ -160,7 +157,7 @@

World.add(_engine.world, [ground, pyramid, ground2, pyramid2, rock, elastic]);

Events.on(_engine, 'tick', function(event) {
Events.on(_engine, 'tick', function() {
if (_mouseConstraint.mouse.button === -1 && (rock.position.x > 190 || rock.position.y < 430)) {
rock = Bodies.polygon(170, 450, 7, 20, rockOptions);
World.add(_engine.world, rock);
Expand All @@ -181,51 +178,35 @@

World.add(_world, [
Bodies.rectangle(200, 200, 100, 100, {
chamfer: {
radius: 20
}
chamfer: { radius: 20 }
}),

Bodies.rectangle(300, 200, 100, 100, {
chamfer: {
radius: [90, 0, 0, 0]
}
chamfer: { radius: [90, 0, 0, 0] }
}),

Bodies.rectangle(400, 200, 200, 200, {
chamfer: {
radius: [150, 20, 40, 20]
}
chamfer: { radius: [150, 20, 40, 20] }
}),

Bodies.rectangle(200, 200, 200, 200, {
chamfer: {
radius: [150, 20, 150, 20]
}
chamfer: { radius: [150, 20, 150, 20] }
}),

Bodies.rectangle(300, 200, 200, 50, {
chamfer: {
radius: [25, 25, 0, 0]
}
chamfer: { radius: [25, 25, 0, 0] }
}),

Bodies.polygon(200, 100, 8, 80, {
chamfer: {
radius: 30
}
chamfer: { radius: 30 }
}),

Bodies.polygon(300, 100, 5, 80, {
chamfer: {
radius: [10, 40, 20, 40, 10]
}
chamfer: { radius: [10, 40, 20, 40, 10] }
}),

Bodies.polygon(400, 200, 3, 50, {
chamfer: {
radius: [20, 0, 20]
}
chamfer: { radius: [20, 0, 20] }
})
]);

Expand Down Expand Up @@ -639,8 +620,6 @@
World.add(_world, stack);

_engine.enableSleeping = true;

var renderOptions = _engine.render.options;
};

Demo.broadphase = function() {
Expand Down Expand Up @@ -694,8 +673,6 @@
});

World.add(_world, stack);

var renderOptions = _engine.render.options;
};

Demo.avalanche = function() {
Expand Down Expand Up @@ -811,8 +788,6 @@

}
}));

var renderOptions = _engine.render.options;
};

Demo.stack = function() {
Expand All @@ -825,8 +800,6 @@
});

World.add(_world, stack);

var renderOptions = _engine.render.options;
};

Demo.circleStack = function() {
Expand All @@ -839,8 +812,6 @@
});

World.add(_world, stack);

var renderOptions = _engine.render.options;
};

Demo.wreckingBall = function() {
Expand Down Expand Up @@ -887,8 +858,6 @@
Bodies.polygon(400, 560, 5, 60),
Bodies.rectangle(600, 560, 80, 80)
]);

var renderOptions = _engine.render.options;
};

Demo.stress = function() {
Expand Down Expand Up @@ -931,8 +900,6 @@
});

World.add(_world, stack);

var renderOptions = _engine.render.options;
};

Demo.restitution = function() {
Expand Down Expand Up @@ -1287,15 +1254,12 @@
context.fill();
})
);

var renderOptions = _engine.render.options;
};

Demo.collisionFiltering = function() {
var _world = _engine.world;

// define our categories (as bit fields, there are up to 32 available)

var defaultCategory = 0x0001,
redCategory = 0x0002,
greenCategory = 0x0004,
Expand All @@ -1308,7 +1272,6 @@
Demo.reset();

// create a stack with varying body categories (but these bodies can all collide with each other)

World.add(_world,
Composites.stack(275, 150, 5, 10, 10, 10, function(x, y, column, row) {
var category = redCategory,
Expand All @@ -1335,7 +1298,6 @@
);

// this body will only collide with the walls and the green bodies

World.add(_world,
Bodies.circle(310, 40, 30, {
collisionFilter: {
Expand All @@ -1349,7 +1311,6 @@
);

// this body will only collide with the walls and the red bodies

World.add(_world,
Bodies.circle(400, 40, 30, {
collisionFilter: {
Expand All @@ -1363,7 +1324,6 @@
);

// this body will only collide with the walls and the blue bodies

World.add(_world,
Bodies.circle(480, 40, 30, {
collisionFilter: {
Expand All @@ -1377,7 +1337,6 @@
);

// red category objects should not be draggable with the mouse

_mouseConstraint.collisionFilter.mask = defaultCategory | blueCategory | greenCategory;

var renderOptions = _engine.render.options;
Expand Down
1 change: 0 additions & 1 deletion src/body/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ var Body = {};
continue;

// don't update out of world bodies
// TODO: viewports
if (body.bounds.max.x < worldBounds.min.x || body.bounds.min.x > worldBounds.max.x
|| body.bounds.max.y < worldBounds.min.y || body.bounds.min.y > worldBounds.max.y)
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/collision/Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ var Contact = {};
* Description
* @method id
* @param {vertex} vertex
* @return {Number} Unique contactID
* @return {string} Unique contactID
*/
Contact.id = function(vertex) {
return vertex.body.id + '_' + vertex.index;
};

})();
})();
4 changes: 2 additions & 2 deletions src/collision/Pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ var Pair = {};
* @method id
* @param {body} bodyA
* @param {body} bodyB
* @return {number} Unique pairId
* @return {string} Unique pairId
*/
Pair.id = function(bodyA, bodyB) {
if (bodyA.id < bodyB.id) {
Expand All @@ -109,4 +109,4 @@ var Pair = {};
}
};

})();
})();
3 changes: 1 addition & 2 deletions src/collision/SAT.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ var SAT = {};
vertexToBody.y = vertex.y - bodyAPosition.y;
distance = -Vector.dot(normal, vertexToBody);
if (distance < nearestDistance) {
nearestDistance = distance;
vertexB = vertex;
}

return [vertexA, vertexB];
};

})();
})();
4 changes: 2 additions & 2 deletions src/constraint/MouseConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var MouseConstraint = {};

var mouseConstraint = Common.extend(defaults, options);

Events.on(engine, 'tick', function(event) {
Events.on(engine, 'tick', function() {
var allBodies = Composite.allBodies(engine.world);
MouseConstraint.update(mouseConstraint, allBodies);
_triggerEvents(mouseConstraint);
Expand Down Expand Up @@ -229,4 +229,4 @@ var MouseConstraint = {};
* @type object
*/

})();
})();
4 changes: 2 additions & 2 deletions src/core/Metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var Metrics = {};
Metrics.update = function(metrics, engine) {
if (metrics.extended) {
var world = engine.world,
broadphase = engine.broadphase[engine.broadphase.current],
bodies = Composite.allBodies(world);

metrics.collisions = metrics.narrowDetections;
Expand All @@ -74,9 +73,10 @@ var Metrics = {};
metrics.narrowEff = (metrics.narrowDetections / (metrics.narrowphaseTests || 1)).toFixed(2);
metrics.broadEff = (1 - (metrics.broadphaseTests / (bodies.length || 1))).toFixed(2);
metrics.narrowReuse = (metrics.narrowReuseCount / (metrics.narrowphaseTests || 1)).toFixed(2);
//var broadphase = engine.broadphase[engine.broadphase.current];
//if (broadphase.instance)
// metrics.buckets = Common.keys(broadphase.instance.buckets).length;
}
};

})();
})();
10 changes: 5 additions & 5 deletions src/factory/Bodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var Bodies = {};
/**
* Creates a new rigid body model with a rectangle hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method rectangle
* @param {number} x
* @param {number} y
Expand Down Expand Up @@ -48,7 +48,7 @@ var Bodies = {};
/**
* Creates a new rigid body model with a trapezoid hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method trapezoid
* @param {number} x
* @param {number} y
Expand Down Expand Up @@ -87,7 +87,7 @@ var Bodies = {};
/**
* Creates a new rigid body model with a circle hull.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method circle
* @param {number} x
* @param {number} y
Expand Down Expand Up @@ -118,7 +118,7 @@ var Bodies = {};
/**
* Creates a new rigid body model with a regular polygon hull with the given number of sides.
* The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properites section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* See the properties section of the `Matter.Body` module for detailed information on what you can pass via the `options` object.
* @method polygon
* @param {number} x
* @param {number} y
Expand Down Expand Up @@ -161,4 +161,4 @@ var Bodies = {};
return Body.create(Common.extend({}, polygon, options));
};

})();
})();
2 changes: 1 addition & 1 deletion src/factory/Composites.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ var Composites = {};
particleOptions = Common.extend({ inertia: Infinity }, particleOptions);
constraintOptions = Common.extend({ stiffness: 0.4 }, constraintOptions);

var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y, column, row) {
var softBody = Composites.stack(xx, yy, columns, rows, columnGap, rowGap, function(x, y) {
return Bodies.circle(x, y, particleRadius, particleOptions);
});

Expand Down
7 changes: 3 additions & 4 deletions src/geometry/Vertices.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var Vertices = {};
points = [];

path.replace(pathPattern, function(match, x, y) {
points.push({ x: parseFloat(x, 10), y: parseFloat(y, 10) });
points.push({ x: parseFloat(x), y: parseFloat(y) });
});

return Vertices.create(points, body);
Expand Down Expand Up @@ -254,8 +254,7 @@ var Vertices = {};
qualityMin = qualityMin || 2;
qualityMax = qualityMax || 14;

var centre = Vertices.centre(vertices),
newVertices = [];
var newVertices = [];

for (var i = 0; i < vertices.length; i++) {
var prevVertex = vertices[i - 1 >= 0 ? i - 1 : vertices.length - 1],
Expand Down Expand Up @@ -307,4 +306,4 @@ var Vertices = {};
return newVertices;
};

})();
})();
Loading

0 comments on commit 5888ffc

Please sign in to comment.