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

50 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.
*
* @class Phaser.Physics.P2.PrismaticConstraint
* @constructor
* @param {Phaser.Physics.P2} world - A reference to the P2 World.
* @param {p2.Body} bodyA - First connected body.
* @param {p2.Body} bodyB - Second connected body.
* @param {boolean} [lockRotation=true] - If set to false, bodyB will be free to rotate around its anchor point.
* @param {Array} [anchorA] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {Array} [anchorB] - Body A's anchor point, defined in its own local frame. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {Array} [axis] - An axis, defined in body A frame, that body B's anchor point may slide along. The value is an array with 2 elements matching x and y, i.e: [32, 32].
* @param {number} [maxForce] - The maximum force that should be applied to constrain the bodies.
2014-03-13 12:14:14 +00:00
*/
Phaser.Physics.P2.PrismaticConstraint = function (world, bodyA, bodyB, lockRotation, anchorA, anchorB, axis, maxForce) {
2014-03-13 12:14:14 +00:00
if (lockRotation === undefined) { lockRotation = true; }
if (anchorA === undefined) { anchorA = [0, 0]; }
if (anchorB === undefined) { anchorB = [0, 0]; }
if (axis === undefined) { axis = [0, 0]; }
if (maxForce === undefined) { maxForce = Number.MAX_VALUE; }
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;
anchorA = [ world.pxmi(anchorA[0]), world.pxmi(anchorA[1]) ];
anchorB = [ world.pxmi(anchorB[0]), world.pxmi(anchorB[1]) ];
var options = { localAnchorA: anchorA, localAnchorB: anchorB, localAxisA: axis, maxForce: maxForce, disableRotationalLock: !lockRotation };
2014-03-13 12:14:14 +00:00
p2.PrismaticConstraint.call(this, bodyA, bodyB, options);
2014-03-23 06:31:26 +00:00
};
2014-03-13 12:14:14 +00:00
Phaser.Physics.P2.PrismaticConstraint.prototype = Object.create(p2.PrismaticConstraint.prototype);
Phaser.Physics.P2.PrismaticConstraint.prototype.constructor = Phaser.Physics.P2.PrismaticConstraint;