phaser/3.0.0/merge/physics/p2/RevoluteConstraint.js

52 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-03-13 12:14:14 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2016-04-04 21:15:01 +00:00
* @copyright 2016 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.
* @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
*/
Phaser.Physics.P2.RevoluteConstraint = function (world, bodyA, pivotA, bodyB, pivotB, maxForce, worldPivot) {
2014-03-13 12:14:14 +00:00
if (maxForce === undefined) { maxForce = Number.MAX_VALUE; }
if (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;
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
if (worldPivot)
{
worldPivot = [ world.pxmi(worldPivot[0]), world.pxmi(worldPivot[1]) ];
}
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;