2014-03-13 12:14:14 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2015-02-25 03:36:23 +00:00
|
|
|
* @copyright 2015 Photon Storm Ltd.
|
2014-03-13 12:14:14 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connects two bodies at given offset points, letting them rotate relative to each other around this point.
|
|
|
|
* The pivot points are given in world (pixel) coordinates.
|
|
|
|
*
|
|
|
|
* @class Phaser.Physics.P2.RevoluteConstraint
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
|
|
|
|
* @param {p2.Body} bodyA - First connected body.
|
|
|
|
* @param {Float32Array} pivotA - The point relative to the center of mass of bodyA which bodyA is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
|
|
|
|
* @param {p2.Body} bodyB - Second connected body.
|
|
|
|
* @param {Float32Array} pivotB - The point relative to the center of mass of bodyB which bodyB is constrained to. The value is an array with 2 elements matching x and y, i.e: [32, 32].
|
|
|
|
* @param {number} [maxForce=0] - The maximum force that should be applied to constrain the bodies.
|
2014-08-28 00:14:59 +00:00
|
|
|
* @param {Float32Array} [worldPivot=null] - A pivot point given in world coordinates. If specified, localPivotA and localPivotB are automatically computed from this value.
|
2014-03-13 12:14:14 +00:00
|
|
|
*/
|
2014-08-28 00:14:59 +00:00
|
|
|
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
|
2014-03-13 12:14:14 +00:00
|
|
|
|
|
|
|
if (typeof maxForce === 'undefined') { maxForce = Number.MAX_VALUE; }
|
2014-08-28 00:14:59 +00:00
|
|
|
if (typeof worldPivot === 'undefined') { worldPivot = null; }
|
2014-03-13 12:14:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Game} game - Local reference to game.
|
|
|
|
*/
|
|
|
|
this.game = world.game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Physics.P2} world - Local reference to P2 World.
|
|
|
|
*/
|
|
|
|
this.world = world;
|
|
|
|
|
2014-03-21 08:49:51 +00:00
|
|
|
pivotA = [ world.pxmi(pivotA[0]), world.pxmi(pivotA[1]) ];
|
|
|
|
pivotB = [ world.pxmi(pivotB[0]), world.pxmi(pivotB[1]) ];
|
2014-03-13 12:14:14 +00:00
|
|
|
|
2014-08-28 00:14:59 +00:00
|
|
|
if (worldPivot)
|
|
|
|
{
|
|
|
|
worldPivot = [ world.pxmi(worldPivot[0]), world.pxmi(worldPivot[1]) ];
|
|
|
|
}
|
|
|
|
|
2014-08-27 23:24:56 +00:00
|
|
|
var options = { worldPivot: worldPivot, localPivotA: pivotA, localPivotB: pivotB, maxForce: maxForce };
|
|
|
|
|
|
|
|
p2.RevoluteConstraint.call(this, bodyA, bodyB, options);
|
2014-03-13 12:14:14 +00:00
|
|
|
|
2014-03-23 06:31:26 +00:00
|
|
|
};
|
2014-03-13 12:14:14 +00:00
|
|
|
|
|
|
|
Phaser.Physics.P2.RevoluteConstraint.prototype = Object.create(p2.RevoluteConstraint.prototype);
|
|
|
|
Phaser.Physics.P2.RevoluteConstraint.prototype.constructor = Phaser.Physics.P2.RevoluteConstraint;
|