mirror of
https://github.com/liabru/matter-js.git
synced 2025-03-08 23:03:36 -05:00
Merge branch 'pr/60'
[liabru] corrected some of the param types before merge Conflicts: src/body/Body.js src/collision/Resolver.js src/render/Render.js src/render/RenderPixi.js
This commit is contained in:
commit
42dc72dabe
12 changed files with 40 additions and 33 deletions
|
@ -22,7 +22,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.
|
||||
* 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
|
||||
* @param {} options
|
||||
* @return {body} body
|
||||
|
@ -515,7 +515,7 @@ var Body = {};
|
|||
velocityPrevX = body.position.x - body.positionPrev.x,
|
||||
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.y = (velocityPrevY * frictionAir * correction) + (body.force.y / body.mass) * deltaTimeSquared;
|
||||
|
||||
|
@ -524,7 +524,7 @@ var Body = {};
|
|||
body.position.x += body.velocity.x;
|
||||
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.anglePrev = body.angle;
|
||||
body.angle += body.angularVelocity;
|
||||
|
@ -668,7 +668,7 @@ var Body = {};
|
|||
*
|
||||
* [{ 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.
|
||||
*
|
||||
* Other properties such as `inertia` and `bounds` are automatically calculated from the passed vertices (unless provided via `options`).
|
||||
|
|
|
@ -308,7 +308,7 @@ var Composite = {};
|
|||
* Removes all bodies, constraints and composites from the given composite
|
||||
* Optionally clearing its children recursively
|
||||
* @method clear
|
||||
* @param {world} world
|
||||
* @param {composite} composite
|
||||
* @param {boolean} keepStatic
|
||||
* @param {boolean} [deep=false]
|
||||
*/
|
||||
|
@ -649,4 +649,4 @@ var Composite = {};
|
|||
* @default []
|
||||
*/
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -18,7 +18,7 @@ var World = {};
|
|||
|
||||
/**
|
||||
* 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
|
||||
* @constructor
|
||||
* @param {} options
|
||||
|
@ -73,4 +73,4 @@ var World = {};
|
|||
* @return {world} The original world with the constraint added
|
||||
*/
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -12,6 +12,7 @@ var Pair = {};
|
|||
* Description
|
||||
* @method create
|
||||
* @param {collision} collision
|
||||
* @param {number} timestamp
|
||||
* @return {pair} A new pair
|
||||
*/
|
||||
Pair.create = function(collision, timestamp) {
|
||||
|
@ -47,6 +48,7 @@ var Pair = {};
|
|||
* @method update
|
||||
* @param {pair} pair
|
||||
* @param {collision} collision
|
||||
* @param {number} timestamp
|
||||
*/
|
||||
Pair.update = function(pair, collision, timestamp) {
|
||||
var contacts = pair.contacts,
|
||||
|
@ -89,6 +91,7 @@ var Pair = {};
|
|||
* @method setActive
|
||||
* @param {pair} pair
|
||||
* @param {bool} isActive
|
||||
* @param {number} timestamp
|
||||
*/
|
||||
Pair.setActive = function(pair, isActive, timestamp) {
|
||||
if (isActive) {
|
||||
|
|
|
@ -31,6 +31,7 @@ var Pairs = {};
|
|||
* @method update
|
||||
* @param {object} pairs
|
||||
* @param {collision[]} collisions
|
||||
* @param {number} timestamp
|
||||
*/
|
||||
Pairs.update = function(pairs, collisions, timestamp) {
|
||||
var pairsList = pairs.list,
|
||||
|
@ -96,6 +97,7 @@ var Pairs = {};
|
|||
* Description
|
||||
* @method removeOld
|
||||
* @param {object} pairs
|
||||
* @param {number} timestamp
|
||||
*/
|
||||
Pairs.removeOld = function(pairs, timestamp) {
|
||||
var pairsList = pairs.list,
|
||||
|
@ -133,9 +135,9 @@ var Pairs = {};
|
|||
|
||||
/**
|
||||
* Clears the given pairs structure
|
||||
* @method create
|
||||
* @param {object} options
|
||||
* @method clear
|
||||
* @param {pairs} pairs
|
||||
* @return {pairs} pairs
|
||||
*/
|
||||
Pairs.clear = function(pairs) {
|
||||
pairs.table = {};
|
||||
|
@ -146,4 +148,4 @@ var Pairs = {};
|
|||
return pairs;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -216,6 +216,7 @@ var Resolver = {};
|
|||
* Description
|
||||
* @method solveVelocity
|
||||
* @param {pair[]} pairs
|
||||
* @param {number} timeScale
|
||||
*/
|
||||
Resolver.solveVelocity = function(pairs, timeScale) {
|
||||
var timeScaleSquared = timeScale * timeScale,
|
||||
|
@ -323,4 +324,4 @@ var Resolver = {};
|
|||
}
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
* @class Constraint
|
||||
*/
|
||||
|
||||
// TODO: fix instabillity issues with torque
|
||||
// TODO: fix instability issues with torque
|
||||
// TODO: linked constraints
|
||||
// TODO: breakable constraints
|
||||
// TODO: collidable constraints
|
||||
// TODO: collision constraints
|
||||
// TODO: allow constrained bodies to sleep
|
||||
// TODO: handle 0 length constraints properly
|
||||
// TODO: impulse caching and warming
|
||||
|
@ -27,7 +27,7 @@ var Constraint = {};
|
|||
/**
|
||||
* Creates a new constraint.
|
||||
* 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
|
||||
* @param {} options
|
||||
* @return {constraint} constraint
|
||||
|
@ -200,8 +200,8 @@ var Constraint = {};
|
|||
|
||||
Sleeping.set(bodyA, false);
|
||||
|
||||
// clamp to prevent instabillity
|
||||
// TODO: solve this properlly
|
||||
// clamp to prevent instability
|
||||
// TODO: solve this properly
|
||||
torque = Common.clamp(torque, -0.01, 0.01);
|
||||
|
||||
// keep track of applied impulses for post solving
|
||||
|
@ -220,8 +220,8 @@ var Constraint = {};
|
|||
|
||||
Sleeping.set(bodyB, false);
|
||||
|
||||
// clamp to prevent instabillity
|
||||
// TODO: solve this properlly
|
||||
// clamp to prevent instability
|
||||
// TODO: solve this properly
|
||||
torque = Common.clamp(torque, -0.01, 0.01);
|
||||
|
||||
// keep track of applied impulses for post solving
|
||||
|
@ -382,10 +382,10 @@ var 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
|
||||
* @type number
|
||||
*/
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -15,7 +15,7 @@ var MouseConstraint = {};
|
|||
/**
|
||||
* Creates a new mouse constraint.
|
||||
* 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
|
||||
* @param {engine} engine
|
||||
* @param {} options
|
||||
|
@ -118,7 +118,7 @@ var MouseConstraint = {};
|
|||
* Triggers mouse constraint events
|
||||
* @method _triggerEvents
|
||||
* @private
|
||||
* @param {mouse} mouse
|
||||
* @param {mouse} mouseConstraint
|
||||
*/
|
||||
var _triggerEvents = function(mouseConstraint) {
|
||||
var mouse = mouseConstraint.mouse,
|
||||
|
|
|
@ -208,7 +208,7 @@ var Common = {};
|
|||
/**
|
||||
* Description
|
||||
* @method now
|
||||
* @return {number} the current timestamp (high-res if avaliable)
|
||||
* @return {number} the current timestamp (high-res if available)
|
||||
*/
|
||||
Common.now = function() {
|
||||
// http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript
|
||||
|
@ -315,4 +315,4 @@ var Common = {};
|
|||
return Common._seed / 233280;
|
||||
};
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -19,7 +19,7 @@ var Engine = {};
|
|||
/**
|
||||
* 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.
|
||||
* 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
|
||||
* @param {HTMLElement} element
|
||||
* @param {object} [options]
|
||||
|
@ -200,8 +200,7 @@ var Engine = {};
|
|||
/**
|
||||
* Renders the world by calling its defined renderer `engine.render.controller`. Triggers `beforeRender` and `afterRender` events.
|
||||
* @method render
|
||||
* @param {engine} engineA
|
||||
* @param {engine} engineB
|
||||
* @param {engine} engine
|
||||
*/
|
||||
Engine.render = function(engine) {
|
||||
// create an event object
|
||||
|
@ -511,8 +510,8 @@ var Engine = {};
|
|||
|
||||
/**
|
||||
* 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 the timing is variable, then the apparant simulation speed will be constant (approximately, but at the cost of determininism).
|
||||
* 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 apparent simulation speed will be constant (approximately, but at the cost of determininism).
|
||||
*
|
||||
* @property timing.isFixed
|
||||
* @type boolean
|
||||
|
@ -522,7 +521,7 @@ var Engine = {};
|
|||
/**
|
||||
* A `Number` that specifies the time step between updates in milliseconds.
|
||||
* 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
|
||||
* @type number
|
||||
|
@ -570,4 +569,4 @@ var Engine = {};
|
|||
* @default a Matter.World instance
|
||||
*/
|
||||
|
||||
})();
|
||||
})();
|
||||
|
|
|
@ -141,6 +141,7 @@ var Mouse = {};
|
|||
* Sets the offset
|
||||
* @method setOffset
|
||||
* @param {mouse} mouse
|
||||
* @param {vector} offset
|
||||
*/
|
||||
Mouse.setOffset = function(mouse, offset) {
|
||||
mouse.offset.x = offset.x;
|
||||
|
@ -153,6 +154,7 @@ var Mouse = {};
|
|||
* Sets the scale
|
||||
* @method setScale
|
||||
* @param {mouse} mouse
|
||||
* @param {vector} scale
|
||||
*/
|
||||
Mouse.setScale = function(mouse, scale) {
|
||||
mouse.scale.x = scale.x;
|
||||
|
|
|
@ -17,7 +17,7 @@ var Render = {};
|
|||
/**
|
||||
* 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.
|
||||
* 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
|
||||
* @param {object} [options]
|
||||
* @return {render} A new renderer
|
||||
|
|
Loading…
Add table
Reference in a new issue