0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-21 17:14:38 -05:00

updated edge build

This commit is contained in:
liabru 2015-06-29 20:58:24 +01:00
parent b669ea0da1
commit 5b2b06046f
2 changed files with 97 additions and 36 deletions

View file

@ -1,5 +1,5 @@
/** /**
* matter.js edge-master 2015-05-22 * matter.js edge-master 2015-06-29
* http://brm.io/matter-js/ * http://brm.io/matter-js/
* License: MIT * License: MIT
*/ */
@ -64,7 +64,7 @@ var Body = {};
/** /**
* Creates a new rigid body model. The options parameter is an object that specifies any properties you wish to override the defaults. * Creates a new rigid body model. The options parameter is an object that specifies any properties you wish to override the defaults.
* All properties have default values, and many are pre-calculated automatically based on other properties. * All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @param {} options * @param {} options
* @return {body} body * @return {body} body
@ -557,7 +557,7 @@ var Body = {};
velocityPrevX = body.position.x - body.positionPrev.x, velocityPrevX = body.position.x - body.positionPrev.x,
velocityPrevY = body.position.y - body.positionPrev.y; velocityPrevY = body.position.y - body.positionPrev.y;
// update velocity with verlet integration // update velocity with Verlet integration
body.velocity.x = (velocityPrevX * frictionAir * correction) + (body.force.x / body.mass) * deltaTimeSquared; body.velocity.x = (velocityPrevX * frictionAir * correction) + (body.force.x / body.mass) * deltaTimeSquared;
body.velocity.y = (velocityPrevY * frictionAir * correction) + (body.force.y / body.mass) * deltaTimeSquared; body.velocity.y = (velocityPrevY * frictionAir * correction) + (body.force.y / body.mass) * deltaTimeSquared;
@ -566,7 +566,7 @@ var Body = {};
body.position.x += body.velocity.x; body.position.x += body.velocity.x;
body.position.y += body.velocity.y; body.position.y += body.velocity.y;
// update angular velocity with verlet integration // update angular velocity with Verlet integration
body.angularVelocity = ((body.angle - body.anglePrev) * frictionAir * correction) + (body.torque / body.inertia) * deltaTimeSquared; body.angularVelocity = ((body.angle - body.anglePrev) * frictionAir * correction) + (body.torque / body.inertia) * deltaTimeSquared;
body.anglePrev = body.angle; body.anglePrev = body.angle;
body.angle += body.angularVelocity; body.angle += body.angularVelocity;
@ -646,6 +646,32 @@ var Body = {};
return properties; return properties;
}; };
/*
*
* Events Documentation
*
*/
/**
* Fired when a body starts sleeping (where `this` is the body).
*
* @event sleepStart
* @this {body} The body that has started sleeping
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/**
* Fired when a body ends sleeping (where `this` is the body).
*
* @event sleepEnd
* @this {body} The body that has ended sleeping
* @param {} event An event object
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/
/* /*
* *
* Properties Documentation * Properties Documentation
@ -710,7 +736,7 @@ var Body = {};
* *
* [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }] * [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }]
* *
* When passed via `Body.create`, the verticies are translated relative to `body.position` (i.e. world-space, and constantly updated by `Body.update` during simulation). * When passed via `Body.create`, the vertices are translated relative to `body.position` (i.e. world-space, and constantly updated by `Body.update` during simulation).
* The `Vector` objects are also augmented with additional properties required for efficient collision detection. * The `Vector` objects are also augmented with additional properties required for efficient collision detection.
* *
* Other properties such as `inertia` and `bounds` are automatically calculated from the passed vertices (unless provided via `options`). * Other properties such as `inertia` and `bounds` are automatically calculated from the passed vertices (unless provided via `options`).
@ -1401,7 +1427,7 @@ var Composite = {};
* Removes all bodies, constraints and composites from the given composite * Removes all bodies, constraints and composites from the given composite
* Optionally clearing its children recursively * Optionally clearing its children recursively
* @method clear * @method clear
* @param {world} world * @param {composite} composite
* @param {boolean} keepStatic * @param {boolean} keepStatic
* @param {boolean} [deep=false] * @param {boolean} [deep=false]
*/ */
@ -1744,6 +1770,7 @@ var Composite = {};
})(); })();
; // End src/body/Composite.js ; // End src/body/Composite.js
@ -1769,7 +1796,7 @@ var World = {};
/** /**
* Creates a new world composite. The options parameter is an object that specifies any properties you wish to override the defaults. * Creates a new world composite. The options parameter is an object that specifies any properties you wish to override the defaults.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @constructor * @constructor
* @param {} options * @param {} options
@ -1826,6 +1853,7 @@ var World = {};
})(); })();
; // End src/body/World.js ; // End src/body/World.js
@ -2328,6 +2356,7 @@ var Pair = {};
* Description * Description
* @method create * @method create
* @param {collision} collision * @param {collision} collision
* @param {number} timestamp
* @return {pair} A new pair * @return {pair} A new pair
*/ */
Pair.create = function(collision, timestamp) { Pair.create = function(collision, timestamp) {
@ -2363,6 +2392,7 @@ var Pair = {};
* @method update * @method update
* @param {pair} pair * @param {pair} pair
* @param {collision} collision * @param {collision} collision
* @param {number} timestamp
*/ */
Pair.update = function(pair, collision, timestamp) { Pair.update = function(pair, collision, timestamp) {
var contacts = pair.contacts, var contacts = pair.contacts,
@ -2405,6 +2435,7 @@ var Pair = {};
* @method setActive * @method setActive
* @param {pair} pair * @param {pair} pair
* @param {bool} isActive * @param {bool} isActive
* @param {number} timestamp
*/ */
Pair.setActive = function(pair, isActive, timestamp) { Pair.setActive = function(pair, isActive, timestamp) {
if (isActive) { if (isActive) {
@ -2472,6 +2503,7 @@ var Pairs = {};
* @method update * @method update
* @param {object} pairs * @param {object} pairs
* @param {collision[]} collisions * @param {collision[]} collisions
* @param {number} timestamp
*/ */
Pairs.update = function(pairs, collisions, timestamp) { Pairs.update = function(pairs, collisions, timestamp) {
var pairsList = pairs.list, var pairsList = pairs.list,
@ -2537,6 +2569,7 @@ var Pairs = {};
* Description * Description
* @method removeOld * @method removeOld
* @param {object} pairs * @param {object} pairs
* @param {number} timestamp
*/ */
Pairs.removeOld = function(pairs, timestamp) { Pairs.removeOld = function(pairs, timestamp) {
var pairsList = pairs.list, var pairsList = pairs.list,
@ -2574,9 +2607,9 @@ var Pairs = {};
/** /**
* Clears the given pairs structure * Clears the given pairs structure
* @method create * @method clear
* @param {object} options
* @param {pairs} pairs * @param {pairs} pairs
* @return {pairs} pairs
*/ */
Pairs.clear = function(pairs) { Pairs.clear = function(pairs) {
pairs.table = {}; pairs.table = {};
@ -2589,6 +2622,7 @@ var Pairs = {};
})(); })();
; // End src/collision/Pairs.js ; // End src/collision/Pairs.js
@ -2920,6 +2954,7 @@ var Resolver = {};
* Description * Description
* @method solveVelocity * @method solveVelocity
* @param {pair[]} pairs * @param {pair[]} pairs
* @param {number} timeScale
*/ */
Resolver.solveVelocity = function(pairs, timeScale) { Resolver.solveVelocity = function(pairs, timeScale) {
var timeScaleSquared = timeScale * timeScale, var timeScaleSquared = timeScale * timeScale,
@ -3029,6 +3064,7 @@ var Resolver = {};
})(); })();
; // End src/collision/Resolver.js ; // End src/collision/Resolver.js
@ -3312,10 +3348,10 @@ var SAT = {};
* @class Constraint * @class Constraint
*/ */
// TODO: fix instabillity issues with torque // TODO: fix instability issues with torque
// TODO: linked constraints // TODO: linked constraints
// TODO: breakable constraints // TODO: breakable constraints
// TODO: collidable constraints // TODO: collision constraints
// TODO: allow constrained bodies to sleep // TODO: allow constrained bodies to sleep
// TODO: handle 0 length constraints properly // TODO: handle 0 length constraints properly
// TODO: impulse caching and warming // TODO: impulse caching and warming
@ -3330,7 +3366,7 @@ var Constraint = {};
/** /**
* Creates a new constraint. * Creates a new constraint.
* All properties have default values, and many are pre-calculated automatically based on other properties. * All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @param {} options * @param {} options
* @return {constraint} constraint * @return {constraint} constraint
@ -3503,8 +3539,8 @@ var Constraint = {};
Sleeping.set(bodyA, false); Sleeping.set(bodyA, false);
// clamp to prevent instabillity // clamp to prevent instability
// TODO: solve this properlly // TODO: solve this properly
torque = Common.clamp(torque, -0.01, 0.01); torque = Common.clamp(torque, -0.01, 0.01);
// keep track of applied impulses for post solving // keep track of applied impulses for post solving
@ -3523,8 +3559,8 @@ var Constraint = {};
Sleeping.set(bodyB, false); Sleeping.set(bodyB, false);
// clamp to prevent instabillity // clamp to prevent instability
// TODO: solve this properlly // TODO: solve this properly
torque = Common.clamp(torque, -0.01, 0.01); torque = Common.clamp(torque, -0.01, 0.01);
// keep track of applied impulses for post solving // keep track of applied impulses for post solving
@ -3685,7 +3721,7 @@ var Constraint = {};
/** /**
* A `Number` that specifies the target resting length of the constraint. * A `Number` that specifies the target resting length of the constraint.
* It is calculated automatically in `Constraint.create` from intial positions of the `constraint.bodyA` and `constraint.bodyB`. * It is calculated automatically in `Constraint.create` from initial positions of the `constraint.bodyA` and `constraint.bodyB`.
* *
* @property length * @property length
* @type number * @type number
@ -3693,6 +3729,7 @@ var Constraint = {};
})(); })();
; // End src/constraint/Constraint.js ; // End src/constraint/Constraint.js
@ -3715,7 +3752,7 @@ var MouseConstraint = {};
/** /**
* Creates a new mouse constraint. * Creates a new mouse constraint.
* All properties have default values, and many are pre-calculated automatically based on other properties. * All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @param {engine} engine * @param {engine} engine
* @param {} options * @param {} options
@ -3818,7 +3855,7 @@ var MouseConstraint = {};
* Triggers mouse constraint events * Triggers mouse constraint events
* @method _triggerEvents * @method _triggerEvents
* @private * @private
* @param {mouse} mouse * @param {mouse} mouseConstraint
*/ */
var _triggerEvents = function(mouseConstraint) { var _triggerEvents = function(mouseConstraint) {
var mouse = mouseConstraint.mouse, var mouse = mouseConstraint.mouse,
@ -4159,7 +4196,7 @@ var Common = {};
/** /**
* Description * Description
* @method now * @method now
* @return {number} the current timestamp (high-res if avaliable) * @return {number} the current timestamp (high-res if available)
*/ */
Common.now = function() { Common.now = function() {
// http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript // http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
@ -4268,6 +4305,7 @@ var Common = {};
})(); })();
; // End src/core/Common.js ; // End src/core/Common.js
@ -4294,7 +4332,7 @@ var Engine = {};
/** /**
* Creates a new engine. The options parameter is an object that specifies any properties you wish to override the defaults. * Creates a new engine. The options parameter is an object that specifies any properties you wish to override the defaults.
* All properties have default values, and many are pre-calculated automatically based on other properties. * All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @param {HTMLElement} element * @param {HTMLElement} element
* @param {object} [options] * @param {object} [options]
@ -4324,10 +4362,6 @@ var Engine = {};
isFixed: false, isFixed: false,
frameRequestId: 0 frameRequestId: 0
}, },
render: {
element: element,
controller: Render
},
broadphase: { broadphase: {
controller: Grid controller: Grid
} }
@ -4335,7 +4369,17 @@ var Engine = {};
var engine = Common.extend(defaults, options); var engine = Common.extend(defaults, options);
engine.render = engine.render.controller.create(engine.render); if (element && !engine.render) {
engine.render = {
element: element,
controller: Render
};
}
if (engine.render && engine.render.controller) {
engine.render = engine.render.controller.create(engine.render);
}
engine.world = World.create(engine.world); engine.world = World.create(engine.world);
engine.pairs = Pairs.create(); engine.pairs = Pairs.create();
engine.broadphase = engine.broadphase.controller.create(engine.broadphase); engine.broadphase = engine.broadphase.controller.create(engine.broadphase);
@ -4461,8 +4505,7 @@ var Engine = {};
/** /**
* Renders the world by calling its defined renderer `engine.render.controller`. Triggers `beforeRender` and `afterRender` events. * Renders the world by calling its defined renderer `engine.render.controller`. Triggers `beforeRender` and `afterRender` events.
* @method render * @method render
* @param {engine} engineA * @param {engine} engine
* @param {engine} engineB
*/ */
Engine.render = function(engine) { Engine.render = function(engine) {
// create an event object // create an event object
@ -4772,8 +4815,8 @@ var Engine = {};
/** /**
* A `Boolean` that specifies if the `Engine.run` game loop should use a fixed timestep (otherwise it is variable). * A `Boolean` that specifies if the `Engine.run` game loop should use a fixed timestep (otherwise it is variable).
* If timing is fixed, then the apparant simulation speed will change depending on the frame rate (but behaviour will be deterministic). * If timing is fixed, then the apparent simulation speed will change depending on the frame rate (but behaviour will be deterministic).
* If the timing is variable, then the apparant simulation speed will be constant (approximately, but at the cost of determininism). * If the timing is variable, then the apparent simulation speed will be constant (approximately, but at the cost of determininism).
* *
* @property timing.isFixed * @property timing.isFixed
* @type boolean * @type boolean
@ -4783,7 +4826,7 @@ var Engine = {};
/** /**
* A `Number` that specifies the time step between updates in milliseconds. * A `Number` that specifies the time step between updates in milliseconds.
* If `engine.timing.isFixed` is set to `true`, then `delta` is fixed. * If `engine.timing.isFixed` is set to `true`, then `delta` is fixed.
* If it is `false`, then `delta` can dynamically change to maintain the correct apparant simulation speed. * If it is `false`, then `delta` can dynamically change to maintain the correct apparent simulation speed.
* *
* @property timing.delta * @property timing.delta
* @type number * @type number
@ -4833,6 +4876,7 @@ var Engine = {};
})(); })();
; // End src/core/Engine.js ; // End src/core/Engine.js
@ -5097,6 +5141,7 @@ var Mouse = {};
* Sets the offset * Sets the offset
* @method setOffset * @method setOffset
* @param {mouse} mouse * @param {mouse} mouse
* @param {vector} offset
*/ */
Mouse.setOffset = function(mouse, offset) { Mouse.setOffset = function(mouse, offset) {
mouse.offset.x = offset.x; mouse.offset.x = offset.x;
@ -5109,6 +5154,7 @@ var Mouse = {};
* Sets the scale * Sets the scale
* @method setScale * @method setScale
* @param {mouse} mouse * @param {mouse} mouse
* @param {vector} scale
*/ */
Mouse.setScale = function(mouse, scale) { Mouse.setScale = function(mouse, scale) {
mouse.scale.x = scale.x; mouse.scale.x = scale.x;
@ -5171,6 +5217,11 @@ var Runner = {};
(function() { (function() {
if (typeof window === 'undefined') {
// TODO: support Runner on non-browser environments.
return;
}
var _fps = 60, var _fps = 60,
_deltaSampleSize = _fps, _deltaSampleSize = _fps,
_delta = 1000 / _fps; _delta = 1000 / _fps;
@ -5383,6 +5434,8 @@ var Sleeping = {};
* @param {boolean} isSleeping * @param {boolean} isSleeping
*/ */
Sleeping.set = function(body, isSleeping) { Sleeping.set = function(body, isSleeping) {
var wasSleeping = body.isSleeping;
if (isSleeping) { if (isSleeping) {
body.isSleeping = true; body.isSleeping = true;
body.sleepCounter = body.sleepThreshold; body.sleepCounter = body.sleepThreshold;
@ -5397,9 +5450,17 @@ var Sleeping = {};
body.speed = 0; body.speed = 0;
body.angularSpeed = 0; body.angularSpeed = 0;
body.motion = 0; body.motion = 0;
if (!wasSleeping) {
Events.trigger(body, 'sleepStart');
}
} else { } else {
body.isSleeping = false; body.isSleeping = false;
body.sleepCounter = 0; body.sleepCounter = 0;
if (wasSleeping) {
Events.trigger(body, 'sleepEnd');
}
} }
}; };
@ -7171,7 +7232,7 @@ var Render = {};
/** /**
* Creates a new renderer. The options parameter is an object that specifies any properties you wish to override the defaults. * Creates a new renderer. The options parameter is an object that specifies any properties you wish to override the defaults.
* All properties have default values, and many are pre-calculated automatically based on other properties. * All properties have default values, and many are pre-calculated automatically based on other properties.
* See the properites section below for detailed information on what you can pass via the `options` object. * See the properties section below for detailed information on what you can pass via the `options` object.
* @method create * @method create
* @param {object} [options] * @param {object} [options]
* @return {render} A new renderer * @return {render} A new renderer

8
build/matter.min.js vendored

File diff suppressed because one or more lines are too long