planck-js
Version:
2D physics engine for JavaScript/HTML5 game development
207 lines (180 loc) • 5.22 kB
JavaScript
/*
* Copyright (c) 2016 Ali Shakiba http://shakiba.me/planck.js
* Copyright (c) 2006-2011 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
module.exports = Joint;
/**
* A joint edge is used to connect bodies and joints together in a joint graph
* where each body is a node and each joint is an edge. 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.
*
* @prop {Body} other provides quick access to the other body attached.
* @prop {Joint} joint the joint
* @prop {JointEdge} prev the previous joint edge in the body's joint list
* @prop {JointEdge} next the next joint edge in the body's joint list
*/
function JointEdge() {
this.other = null;
this.joint = null;
this.prev = null;
this.next = null;
};
/**
* Joint definitions are used to construct joints.
*
* @prop userData Use this to attach application specific data to your joints.
* void userData;
* @prop {boolean} collideConnected Set this flag to true if the attached bodies
* should collide.
*/
function JointDef() {
this.userData = null;
this.collideConnected = false;
};
/**
* The base joint class. Joints are used to constraint two bodies together in
* various fashions. Some joints also feature limits and motors.
*
* @param {JointDef} def
* @param {Body} bodyA first attached body.
* @param {Body} bodyB The second attached body.
*/
function Joint(def, bodyA, bodyB) {
bodyA = def.bodyA || bodyA;
bodyB = def.bodyB || bodyB;
Assert(bodyA);
Assert(bodyB);
Assert(bodyA != bodyB);
this.m_type = 'unknown-joint';
this.m_bodyA = bodyA;
this.m_bodyB = bodyB;
this.m_index = 0;
this.m_collideConnected = !!def.collideConnected;
this.m_prev = null;
this.m_next = null;
this.m_edgeA = new JointEdge();
this.m_edgeB = new JointEdge();
this.m_islandFlag = false;
this.m_userData = def.userData;
};
/**
* Short-cut function to determine if either body is inactive.
*
* @returns {boolean}
*/
Joint.prototype.IsActive = function() {
return this.m_bodyA.IsActive() && this.m_bodyB.IsActive();
}
/**
* Get the type of the concrete joint.
*
* @returns JointType
*/
Joint.prototype.GetType = function() {
return this.m_type;
}
/**
* Get the first body attached to this joint.
*
* @returns Body
*/
Joint.prototype.GetBodyA = function() {
return this.m_bodyA;
}
/**
* Get the second body attached to this joint.
*
* @returns Body
*/
Joint.prototype.GetBodyB = function() {
return this.m_bodyB;
}
/**
* Get the next joint the world joint list.
*
* @returns Joint
*/
Joint.prototype.GetNext = function() {
return this.m_next;
}
Joint.prototype.GetUserData = function() {
return this.m_userData;
}
Joint.prototype.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.
*
* @returns {boolean}
*/
Joint.prototype.GetCollideConnected = function() {
return this.m_collideConnected;
};
/**
* Get the anchor point on bodyA in world coordinates.
*
* @return {Vec2}
*/
Joint.prototype.GetAnchorA = function() {
};
/**
* Get the anchor point on bodyB in world coordinates.
*
* @return {Vec2}
*/
Joint.prototype.GetAnchorB = function() {
};
/**
* Get the reaction force on bodyB at the joint anchor in Newtons.
*
* @param {float} inv_dt
* @return {Vec2}
*/
Joint.prototype.GetReactionForce = function(inv_dt) {
};
/**
* Get the reaction torque on bodyB in N*m.
*
* @param {float} inv_dt
* @return {float}
*/
Joint.prototype.GetReactionTorque = function(inv_dt) {
};
/**
* Shift the origin for any points stored in world coordinates.
*
* @param {Vec2} newOrigin
*/
Joint.prototype.ShiftOrigin = function(newOrigin) {
};
/**
*/
Joint.prototype.InitVelocityConstraints = function(step) {
};
/**
*/
Joint.prototype.SolveVelocityConstraints = function(step) {
};
/**
* This returns true if the position errors are within tolerance.
*/
Joint.prototype.SolvePositionConstraints = function(step) {
};