mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
cleanup
This commit is contained in:
parent
37ccc84762
commit
5888ffcaf6
11 changed files with 30 additions and 78 deletions
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -117,7 +114,7 @@
|
|||
|
||||
World.add(_world, stack);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.slingshot = function() {
|
||||
|
@ -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);
|
||||
|
@ -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] }
|
||||
})
|
||||
]);
|
||||
|
||||
|
@ -639,8 +620,6 @@
|
|||
World.add(_world, stack);
|
||||
|
||||
_engine.enableSleeping = true;
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.broadphase = function() {
|
||||
|
@ -694,8 +673,6 @@
|
|||
});
|
||||
|
||||
World.add(_world, stack);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.avalanche = function() {
|
||||
|
@ -811,8 +788,6 @@
|
|||
|
||||
}
|
||||
}));
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.stack = function() {
|
||||
|
@ -825,8 +800,6 @@
|
|||
});
|
||||
|
||||
World.add(_world, stack);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.circleStack = function() {
|
||||
|
@ -839,8 +812,6 @@
|
|||
});
|
||||
|
||||
World.add(_world, stack);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.wreckingBall = function() {
|
||||
|
@ -887,8 +858,6 @@
|
|||
Bodies.polygon(400, 560, 5, 60),
|
||||
Bodies.rectangle(600, 560, 80, 80)
|
||||
]);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.stress = function() {
|
||||
|
@ -931,8 +900,6 @@
|
|||
});
|
||||
|
||||
World.add(_world, stack);
|
||||
|
||||
var renderOptions = _engine.render.options;
|
||||
};
|
||||
|
||||
Demo.restitution = function() {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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: {
|
||||
|
@ -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: {
|
||||
|
@ -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: {
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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) {
|
||||
|
@ -109,4 +109,4 @@ var Pair = {};
|
|||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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];
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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);
|
||||
|
@ -229,4 +229,4 @@ var MouseConstraint = {};
|
|||
* @type object
|
||||
*/
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -161,4 +161,4 @@ var Bodies = {};
|
|||
return Body.create(Common.extend({}, polygon, options));
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -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],
|
||||
|
@ -307,4 +306,4 @@ var Vertices = {};
|
|||
return newVertices;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -351,8 +351,7 @@ var Render = {};
|
|||
*/
|
||||
Render.bodyShadows = function(engine, bodies, context) {
|
||||
var c = context,
|
||||
render = engine.render,
|
||||
options = render.options;
|
||||
render = engine.render;
|
||||
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
var body = bodies[i];
|
||||
|
@ -640,9 +639,7 @@ var Render = {};
|
|||
* @param {RenderingContext} context
|
||||
*/
|
||||
Render.bodyVelocity = function(engine, bodies, context) {
|
||||
var c = context,
|
||||
render = engine.render,
|
||||
options = render.options;
|
||||
var c = context;
|
||||
|
||||
c.beginPath();
|
||||
|
||||
|
@ -800,7 +797,6 @@ var Render = {};
|
|||
Render.inspector = function(inspector, context) {
|
||||
var engine = inspector.engine,
|
||||
selected = inspector.selected,
|
||||
c = context,
|
||||
render = engine.render,
|
||||
options = render.options,
|
||||
bounds;
|
||||
|
|
Loading…
Reference in a new issue