File:addBox2D\Dynamics\Joints\b2Joint.js
//################################################################################################//
//################################################################################################//
// //
// ██ ██████ ██ ██ ██ //
// ██ ██ ██ ██ //
// █████ ██ ██ █████ ██ █████ █████ //
// ██ ██ ██████ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// █████ ██████ █████ █████ ██ ██ ██ ████ //
// //
//################################################################################################//
//################################################################################################//
// CLASS CONSTRUCTOR
/**
* Abstract base joint class.
*
* Joints are used to constraint two bodies together in various fashions.
* Some joints also feature limits and motors.
*
* @class b2Joint
* @constructor
* @param {b2JointDef} jointDef
* @module Joints
*/
function b2Joint( jointDef ) {
if ( jointDef ) { //[optimisation] This is a constructor call not the prototype being inherited.
/*##if EXPORT_ASSERTS */
if ( b2Settings.ASSERTS_ENABLED ) {
b2Assert( jointDef.bodyA !== jointDef.bodyB );
}/*#*/
////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// ██████ ██ ██ //
// ██ ██ ██ //
// ██ ██ ████ █████ █████ █████ ████ █████ ██ █████ █████ //
// ██████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ ██ ██ ██ ██ █████ ██ ██ ██ █████ █████ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ █████ █████ █████ ██ ████ ██ █████ █████ //
// ██ //
// ██ //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////
// property DECLARATIONS
/**
* A joint edge belongs to a doubly linked list
* maintained in each attached body. Each joint has two joint
* nodes, one for each attached body.
*
* @public
* @property m_edgeA
* @type {b2JointEdge}
*/
this.m_edgeA = new b2JointEdge;
/**
* A joint edge belongs to a doubly linked list
* maintained in each attached body. Each joint has two joint
* nodes, one for each attached body.
*
* @public
* @property m_edgeB
* @type {b2JointEdge}
*/
this.m_edgeB = new b2JointEdge;
// property INITIALISATIONS
/**
* Joint type: distance, wheel (line), mouse, prismatic, pulley, revolute,
* weld, friction, gear, rope, motor, and (constant) area.
*
* @public
* @property m_type
* @type {int}
* @default b2jointDef.type
*/
this.m_type = jointDef.type;
/**
* Previous joint in the world's joint linked-list.
*
* @public
* @property m_prev
* @type {b2Joint|null}
* @default null
*/
this.m_prev = null;
/**
* Next joint in the world's joint linked-list.
* May be null if 'this' joint instance is the head of the linked-list.
*
* @public
* @property m_next
* @type {b2Joint|null}
* @default null
*/
this.m_next = null;
/**
* 'this' joint instance's body A.
*
* @public
* @property m_bodyA
* @type {b2Body}
* @default b2jointDef.bodyA
*/
this.m_bodyA = jointDef.bodyA;
/**
* 'this' joint instance's body B.
*
* @public
* @property m_bodyB
* @type {b2Body}
* @default b2jointDef.bodyB
*/
this.m_bodyB = jointDef.bodyB;
/**
* Will body A be able to collide with body B, or not?
*
* @public
* @property m_collideConnected
* @type {boolean}
* @default b2jointDef.collideConnected
*/
this.m_collideConnected = jointDef.collideConnected;
/**
* @public
* @property m_islandFlag
* @type {boolean}
* @default false
*/
this.m_islandFlag = false;
/**
* @public
* @property m_index
* @type {int}
* @default false
*/
this.m_index = 0;
/**
* Application specific data.</br></br>
*
* NOTE: Using the
* <a href=https://github.com/SmartArtsStudio/addPhysicsJS>addPhysicsJS framework</a>
* m_userData is managed for you extending either a
* <a href=http://www.createjs.com/docs/easeljs/classes/Container.html>createjs.container</a>
* or
* <a href=http://www.createjs.com/docs/easeljs/classes/MovieClip.html>createjs.movieClip</a>
* class.
*
* @public
* @property m_userData
* @type {*}
* @default b2jointDef.userData
*/
this.m_userData = jointDef.userData;
} //[optimisation] else this call is just the prototype (abstract class) being inherited.
////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// ██ ██ ██ ██ //
// ██ ██ ██ //
// ██ █████ █████ █████ ████ ██ █████ █████ █████ █████ █████ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ ██ ██ ██ █████ ██ ██ ██ █████ ██ ██ ██ █████ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ ██ ██ ██ █████ ██ ██ ████ █████ ██ ██ █████ █████ //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////
} p = b2Joint.prototype; Box2D.b2Joint = b2Joint;
// STATIC CLASS PROPERTIES
b2Joint.e_unknownJoint = 0;
b2Joint.e_revoluteJoint = 1;
b2Joint.e_prismaticJoint = 2;
b2Joint.e_distanceJoint = 3;
b2Joint.e_pulleyJoint = 4;
b2Joint.e_mouseJoint = 5;
b2Joint.e_gearJoint = 6;
b2Joint.e_wheelJoint = 7;
b2Joint.e_lineJoint = 7; // depreciated for B2WheelJoint
b2Joint.e_weldJoint = 8;
b2Joint.e_frictionJoint = 9;
b2Joint.e_ropeJoint = 10;
b2Joint.e_motorJoint = 11;
b2Joint.e_areaJoint = 12;
b2Joint.e_inactiveLimit = 0;
b2Joint.e_atLowerLimit = 1;
b2Joint.e_atUpperLimit = 2;
b2Joint.e_equalLimits = 3;
/**
* Super class constructor function reference for sub classes.
*
* NOTE: Explicit declaration to protect against sub-classes
* inheriting a prototype.constructor value other than this.
*
* @public
* @property ParentClass
* @type {constructor}
*/
p.constructor = b2Joint;
////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// ██ ██ ██ ██ ██ //
// ███ ███ ██ ██ ██ //
// ███████ █████ █████ █████ █████ █████ █████ //
// ██ █ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ █████ ██ ██ ██ ██ ██ ██ ██ █████ //
// ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ //
// ██ ██ █████ ████ ██ ██ █████ █████ █████ //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////
// STATIC CLASS METHODS
/**
* Create a joint from a joint definition.
*
* @static
* @method create
* @param {b2JointDef} b2JointDef
* @param {b2JointDef} allocator
* @return b2Joint
*/
b2Joint.create = function ( b2JointDef, allocator ) {
return b2JointFactory.create( b2JointDef, allocator );
};
/**
* Callback function called during World.step upon b2Joint destruction.
* Override this method to define your joint destruction behaviour.
*
* NOTE: b2JointFactory.destroy(joint, allocator){ b2Joint.destroy(joint, allocator); }
*
* @static
* @virtual
* @method destroy
* @param {b2Joint} b2JointDef
* @param {b2Joint} allocator
*/
b2Joint.destroy = function ( b2JointDef, allocator ) {
};
// INSTANCE METHODS
/**
* Get the type of the concrete joint.
*
* @public
* @method getType
* @return {int}
*/
p.getType = function () {
return this.m_type;
};
/**
* Get the first body attached to this joint.
*
* @public
* @method getBodyA
* @return {b2Body}
*/
p.getBodyA = function () {
return this.m_bodyA;
};
/**
* Get the second body attached to this joint.
*
* @public
* @method getBodyB
* @return {b2Body}
*/
p.getBodyB = function () {
return this.m_bodyB;
};
/**
* Get the anchor point on bodyA in world coordinates.
*
* @public
* @virtual
* @method getAnchorA
* @param {b2Vec2} out reusable object
* @return {b2Vec2} out
*/
p.getAnchorA = function ( out ) {
return out.setZero();
};
/**
* Get the anchor point on bodyB in world coordinates.
*
* @public
* @virtual
* @method getAnchorB
* @param {b2Vec2} out reusable object
* @return {b2Vec2} out
*/
p.getAnchorB = function ( out ) {
return out.setZero();
};
/**
* Get the reaction force on bodyB at the joint anchor in Newtons.
*
* @public
* @virtual
* @method getReactionForce
* @param {number} invDeltaTime
* @param {b2Vec2} out reusable object
* @return {b2Vec2}
*/
p.getReactionForce = function ( invDeltaTime, out ) {
return out.setZero();
};
/**
* Get the reaction torque on bodyB in N*m.
*
* @public
* @virtual
* @method getReactionTorque
* @return {float}
*/
p.getReactionTorque = function ( invDeltaTime ) {
return 0;
};
/**
* Get the next joint in the world joint list.
*
* @public
* @method getNext
* @return {b2Joint}
*/
p.getNext = function () {
return this.m_next;
};
/**
* Get the application specific user data reference.</br></br>
*
* NOTE: Using the
* <a href=https://github.com/SmartArtsStudio/addPhysicsJS>addPhysicsJS framework</a>
* m_userData is managed for you extending either a
* <a href=http://www.createjs.com/docs/easeljs/classes/Container.html>createjs.container</a>
* or
* <a href=http://www.createjs.com/docs/easeljs/classes/MovieClip.html>createjs.movieClip</a>
* class.
*
* @public
* @method getUserData
* @return {*}
*/
p.getUserData = function () {
return this.m_userData;
};
/**
* Set the application specific userdata reference.</br></br>
*
* NOTE: Using the
* <a href=https://github.com/SmartArtsStudio/addPhysicsJS>addPhysicsJS framework</a>
* m_userData is managed for you extending either a
* <a href=http://www.createjs.com/docs/easeljs/classes/Container.html>createjs.container</a>
* or
* <a href=http://www.createjs.com/docs/easeljs/classes/MovieClip.html>createjs.movieClip</a>
* class.
*
* @public
* @method setUserData
* @return {void}
*/
p.setUserData = function ( data ) {
this.m_userData = data;
};
/**
* Get collide connected.
*
* Note: modifying the collide connect flag won't work correctly
* because the flag is only checked when fixture AABBs begin to
* overlap.
*
* @public
* @method getCollideConnected
* @return {boolean}
*/
p.getCollideConnected = function () {
return this.m_collideConnected;
};
/**
* Short-cut function to determine if either body is inactive.
*
* @public
* @method isActive
* @return {boolean}
*/
p.isActive = function () {
return this.m_bodyA.isActive() && this.m_bodyB.isActive();
};
/**
* @public
* @virtual
* @method initVelocityConstraints
* @param {b2SolverData} data
* @return {void}
*/
p.initVelocityConstraints = function ( data ) {};
/**
* @public
* @virtual
* @method solveVelocityConstraints
* @param {b2SolverData} data
* @return {void}
*/
p.solveVelocityConstraints = function ( data ) {};
/**
* This returns true if the position errors are within tolerance.
*
* @public
* @virtual
* @method solveVelocityConstraints
* @param {b2SolverData} data
* @return {void}
*/
p.solvePositionConstraints = function ( data ) {
return false;
};
/**
* Shift the origin for any points stored in world coordinates.
*
* @public
* @virtual
* @method shiftOrigin
* @param {b2Vec2} newOrigin
* @return {void}
*/
p.shiftOrigin = function ( newOrigin ) {};