box2dweb-commonjs
Version:
Box2dweb as a Common JS module
1,323 lines (1,211 loc) • 431 kB
JavaScript
/*
* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
*
* 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.
*/
var Box2D = {};
(function (a2j, undefined) {
if(!Object.defineProperty
&& Object.prototype.__defineGetter__ instanceof Function
&& Object.prototype.__defineSetter__ instanceof Function)
{
Object.defineProperty = function(obj, p, cfg) {
if(cfg.get instanceof Function)
obj.__defineGetter__(p, cfg.get);
if(cfg.set instanceof Function)
obj.__defineSetter__(p, cfg.set);
}
}
function emptyFn() {};
a2j.inherit = function(cls, base) {
var tmpCtr = cls;
emptyFn.prototype = base.prototype;
cls.prototype = new emptyFn;
cls.prototype.constructor = tmpCtr;
};
a2j.generateCallback = function generateCallback(context, cb) {
return function () {
cb.apply(context, arguments);
};
};
a2j.NVector = function NVector(length) {
if (length === undefined) length = 0;
var tmp = new Array(length || 0);
for (var i = 0; i < length; ++i)
tmp[i] = 0;
return tmp;
};
a2j.is = function is(o1, o2) {
if (o1 === null) return false;
if ((o2 instanceof Function) && (o1 instanceof o2)) return true;
if ((o1.constructor.__implements != undefined) && (o1.constructor.__implements[o2])) return true;
return false;
};
a2j.parseUInt = function(v) {
return Math.abs(parseInt(v));
}
})(Box2D);
//#TODO remove assignments from global namespace
var Vector = Array;
var Vector_a2j_Number = Box2D.NVector;
//package structure
if (typeof(Box2D) === "undefined") Box2D = {};
if (typeof(Box2D.Collision) === "undefined") Box2D.Collision = {};
if (typeof(Box2D.Collision.Shapes) === "undefined") Box2D.Collision.Shapes = {};
if (typeof(Box2D.Common) === "undefined") Box2D.Common = {};
if (typeof(Box2D.Common.Math) === "undefined") Box2D.Common.Math = {};
if (typeof(Box2D.Dynamics) === "undefined") Box2D.Dynamics = {};
if (typeof(Box2D.Dynamics.Contacts) === "undefined") Box2D.Dynamics.Contacts = {};
if (typeof(Box2D.Dynamics.Controllers) === "undefined") Box2D.Dynamics.Controllers = {};
if (typeof(Box2D.Dynamics.Joints) === "undefined") Box2D.Dynamics.Joints = {};
//pre-definitions
(function () {
Box2D.Collision.IBroadPhase = 'Box2D.Collision.IBroadPhase';
function b2AABB() {
b2AABB.b2AABB.apply(this, arguments);
};
Box2D.Collision.b2AABB = b2AABB;
function b2Bound() {
b2Bound.b2Bound.apply(this, arguments);
};
Box2D.Collision.b2Bound = b2Bound;
function b2BoundValues() {
b2BoundValues.b2BoundValues.apply(this, arguments);
if (this.constructor === b2BoundValues) this.b2BoundValues.apply(this, arguments);
};
Box2D.Collision.b2BoundValues = b2BoundValues;
function b2Collision() {
b2Collision.b2Collision.apply(this, arguments);
};
Box2D.Collision.b2Collision = b2Collision;
function b2ContactID() {
b2ContactID.b2ContactID.apply(this, arguments);
if (this.constructor === b2ContactID) this.b2ContactID.apply(this, arguments);
};
Box2D.Collision.b2ContactID = b2ContactID;
function b2ContactPoint() {
b2ContactPoint.b2ContactPoint.apply(this, arguments);
};
Box2D.Collision.b2ContactPoint = b2ContactPoint;
function b2Distance() {
b2Distance.b2Distance.apply(this, arguments);
};
Box2D.Collision.b2Distance = b2Distance;
function b2DistanceInput() {
b2DistanceInput.b2DistanceInput.apply(this, arguments);
};
Box2D.Collision.b2DistanceInput = b2DistanceInput;
function b2DistanceOutput() {
b2DistanceOutput.b2DistanceOutput.apply(this, arguments);
};
Box2D.Collision.b2DistanceOutput = b2DistanceOutput;
function b2DistanceProxy() {
b2DistanceProxy.b2DistanceProxy.apply(this, arguments);
};
Box2D.Collision.b2DistanceProxy = b2DistanceProxy;
function b2DynamicTree() {
b2DynamicTree.b2DynamicTree.apply(this, arguments);
if (this.constructor === b2DynamicTree) this.b2DynamicTree.apply(this, arguments);
};
Box2D.Collision.b2DynamicTree = b2DynamicTree;
function b2DynamicTreeBroadPhase() {
b2DynamicTreeBroadPhase.b2DynamicTreeBroadPhase.apply(this, arguments);
};
Box2D.Collision.b2DynamicTreeBroadPhase = b2DynamicTreeBroadPhase;
function b2DynamicTreeNode() {
b2DynamicTreeNode.b2DynamicTreeNode.apply(this, arguments);
};
Box2D.Collision.b2DynamicTreeNode = b2DynamicTreeNode;
function b2DynamicTreePair() {
b2DynamicTreePair.b2DynamicTreePair.apply(this, arguments);
};
Box2D.Collision.b2DynamicTreePair = b2DynamicTreePair;
function b2Manifold() {
b2Manifold.b2Manifold.apply(this, arguments);
if (this.constructor === b2Manifold) this.b2Manifold.apply(this, arguments);
};
Box2D.Collision.b2Manifold = b2Manifold;
function b2ManifoldPoint() {
b2ManifoldPoint.b2ManifoldPoint.apply(this, arguments);
if (this.constructor === b2ManifoldPoint) this.b2ManifoldPoint.apply(this, arguments);
};
Box2D.Collision.b2ManifoldPoint = b2ManifoldPoint;
function b2Point() {
b2Point.b2Point.apply(this, arguments);
};
Box2D.Collision.b2Point = b2Point;
function b2RayCastInput() {
b2RayCastInput.b2RayCastInput.apply(this, arguments);
if (this.constructor === b2RayCastInput) this.b2RayCastInput.apply(this, arguments);
};
Box2D.Collision.b2RayCastInput = b2RayCastInput;
function b2RayCastOutput() {
b2RayCastOutput.b2RayCastOutput.apply(this, arguments);
};
Box2D.Collision.b2RayCastOutput = b2RayCastOutput;
function b2Segment() {
b2Segment.b2Segment.apply(this, arguments);
};
Box2D.Collision.b2Segment = b2Segment;
function b2SeparationFunction() {
b2SeparationFunction.b2SeparationFunction.apply(this, arguments);
};
Box2D.Collision.b2SeparationFunction = b2SeparationFunction;
function b2Simplex() {
b2Simplex.b2Simplex.apply(this, arguments);
if (this.constructor === b2Simplex) this.b2Simplex.apply(this, arguments);
};
Box2D.Collision.b2Simplex = b2Simplex;
function b2SimplexCache() {
b2SimplexCache.b2SimplexCache.apply(this, arguments);
};
Box2D.Collision.b2SimplexCache = b2SimplexCache;
function b2SimplexVertex() {
b2SimplexVertex.b2SimplexVertex.apply(this, arguments);
};
Box2D.Collision.b2SimplexVertex = b2SimplexVertex;
function b2TimeOfImpact() {
b2TimeOfImpact.b2TimeOfImpact.apply(this, arguments);
};
Box2D.Collision.b2TimeOfImpact = b2TimeOfImpact;
function b2TOIInput() {
b2TOIInput.b2TOIInput.apply(this, arguments);
};
Box2D.Collision.b2TOIInput = b2TOIInput;
function b2WorldManifold() {
b2WorldManifold.b2WorldManifold.apply(this, arguments);
if (this.constructor === b2WorldManifold) this.b2WorldManifold.apply(this, arguments);
};
Box2D.Collision.b2WorldManifold = b2WorldManifold;
function ClipVertex() {
ClipVertex.ClipVertex.apply(this, arguments);
};
Box2D.Collision.ClipVertex = ClipVertex;
function Features() {
Features.Features.apply(this, arguments);
};
Box2D.Collision.Features = Features;
function b2CircleShape() {
b2CircleShape.b2CircleShape.apply(this, arguments);
if (this.constructor === b2CircleShape) this.b2CircleShape.apply(this, arguments);
};
Box2D.Collision.Shapes.b2CircleShape = b2CircleShape;
function b2EdgeChainDef() {
b2EdgeChainDef.b2EdgeChainDef.apply(this, arguments);
if (this.constructor === b2EdgeChainDef) this.b2EdgeChainDef.apply(this, arguments);
};
Box2D.Collision.Shapes.b2EdgeChainDef = b2EdgeChainDef;
function b2EdgeShape() {
b2EdgeShape.b2EdgeShape.apply(this, arguments);
if (this.constructor === b2EdgeShape) this.b2EdgeShape.apply(this, arguments);
};
Box2D.Collision.Shapes.b2EdgeShape = b2EdgeShape;
function b2MassData() {
b2MassData.b2MassData.apply(this, arguments);
};
Box2D.Collision.Shapes.b2MassData = b2MassData;
function b2PolygonShape() {
b2PolygonShape.b2PolygonShape.apply(this, arguments);
if (this.constructor === b2PolygonShape) this.b2PolygonShape.apply(this, arguments);
};
Box2D.Collision.Shapes.b2PolygonShape = b2PolygonShape;
function b2Shape() {
b2Shape.b2Shape.apply(this, arguments);
if (this.constructor === b2Shape) this.b2Shape.apply(this, arguments);
};
Box2D.Collision.Shapes.b2Shape = b2Shape;
Box2D.Common.b2internal = 'Box2D.Common.b2internal';
function b2Color() {
b2Color.b2Color.apply(this, arguments);
if (this.constructor === b2Color) this.b2Color.apply(this, arguments);
};
Box2D.Common.b2Color = b2Color;
function b2Settings() {
b2Settings.b2Settings.apply(this, arguments);
};
Box2D.Common.b2Settings = b2Settings;
function b2Mat22() {
b2Mat22.b2Mat22.apply(this, arguments);
if (this.constructor === b2Mat22) this.b2Mat22.apply(this, arguments);
};
Box2D.Common.Math.b2Mat22 = b2Mat22;
function b2Mat33() {
b2Mat33.b2Mat33.apply(this, arguments);
if (this.constructor === b2Mat33) this.b2Mat33.apply(this, arguments);
};
Box2D.Common.Math.b2Mat33 = b2Mat33;
function b2Math() {
b2Math.b2Math.apply(this, arguments);
};
Box2D.Common.Math.b2Math = b2Math;
function b2Sweep() {
b2Sweep.b2Sweep.apply(this, arguments);
};
Box2D.Common.Math.b2Sweep = b2Sweep;
function b2Transform() {
b2Transform.b2Transform.apply(this, arguments);
if (this.constructor === b2Transform) this.b2Transform.apply(this, arguments);
};
Box2D.Common.Math.b2Transform = b2Transform;
function b2Vec2() {
b2Vec2.b2Vec2.apply(this, arguments);
if (this.constructor === b2Vec2) this.b2Vec2.apply(this, arguments);
};
Box2D.Common.Math.b2Vec2 = b2Vec2;
function b2Vec3() {
b2Vec3.b2Vec3.apply(this, arguments);
if (this.constructor === b2Vec3) this.b2Vec3.apply(this, arguments);
};
Box2D.Common.Math.b2Vec3 = b2Vec3;
function b2Body() {
b2Body.b2Body.apply(this, arguments);
if (this.constructor === b2Body) this.b2Body.apply(this, arguments);
};
Box2D.Dynamics.b2Body = b2Body;
function b2BodyDef() {
b2BodyDef.b2BodyDef.apply(this, arguments);
if (this.constructor === b2BodyDef) this.b2BodyDef.apply(this, arguments);
};
Box2D.Dynamics.b2BodyDef = b2BodyDef;
function b2ContactFilter() {
b2ContactFilter.b2ContactFilter.apply(this, arguments);
};
Box2D.Dynamics.b2ContactFilter = b2ContactFilter;
function b2ContactImpulse() {
b2ContactImpulse.b2ContactImpulse.apply(this, arguments);
};
Box2D.Dynamics.b2ContactImpulse = b2ContactImpulse;
function b2ContactListener() {
b2ContactListener.b2ContactListener.apply(this, arguments);
};
Box2D.Dynamics.b2ContactListener = b2ContactListener;
function b2ContactManager() {
b2ContactManager.b2ContactManager.apply(this, arguments);
if (this.constructor === b2ContactManager) this.b2ContactManager.apply(this, arguments);
};
Box2D.Dynamics.b2ContactManager = b2ContactManager;
function b2DebugDraw() {
b2DebugDraw.b2DebugDraw.apply(this, arguments);
if (this.constructor === b2DebugDraw) this.b2DebugDraw.apply(this, arguments);
};
Box2D.Dynamics.b2DebugDraw = b2DebugDraw;
function b2DestructionListener() {
b2DestructionListener.b2DestructionListener.apply(this, arguments);
};
Box2D.Dynamics.b2DestructionListener = b2DestructionListener;
function b2FilterData() {
b2FilterData.b2FilterData.apply(this, arguments);
};
Box2D.Dynamics.b2FilterData = b2FilterData;
function b2Fixture() {
b2Fixture.b2Fixture.apply(this, arguments);
if (this.constructor === b2Fixture) this.b2Fixture.apply(this, arguments);
};
Box2D.Dynamics.b2Fixture = b2Fixture;
function b2FixtureDef() {
b2FixtureDef.b2FixtureDef.apply(this, arguments);
if (this.constructor === b2FixtureDef) this.b2FixtureDef.apply(this, arguments);
};
Box2D.Dynamics.b2FixtureDef = b2FixtureDef;
function b2Island() {
b2Island.b2Island.apply(this, arguments);
if (this.constructor === b2Island) this.b2Island.apply(this, arguments);
};
Box2D.Dynamics.b2Island = b2Island;
function b2TimeStep() {
b2TimeStep.b2TimeStep.apply(this, arguments);
};
Box2D.Dynamics.b2TimeStep = b2TimeStep;
function b2World() {
b2World.b2World.apply(this, arguments);
if (this.constructor === b2World) this.b2World.apply(this, arguments);
};
Box2D.Dynamics.b2World = b2World;
function b2CircleContact() {
b2CircleContact.b2CircleContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2CircleContact = b2CircleContact;
function b2Contact() {
b2Contact.b2Contact.apply(this, arguments);
if (this.constructor === b2Contact) this.b2Contact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2Contact = b2Contact;
function b2ContactConstraint() {
b2ContactConstraint.b2ContactConstraint.apply(this, arguments);
if (this.constructor === b2ContactConstraint) this.b2ContactConstraint.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactConstraint = b2ContactConstraint;
function b2ContactConstraintPoint() {
b2ContactConstraintPoint.b2ContactConstraintPoint.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactConstraintPoint = b2ContactConstraintPoint;
function b2ContactEdge() {
b2ContactEdge.b2ContactEdge.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactEdge = b2ContactEdge;
function b2ContactFactory() {
b2ContactFactory.b2ContactFactory.apply(this, arguments);
if (this.constructor === b2ContactFactory) this.b2ContactFactory.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactFactory = b2ContactFactory;
function b2ContactRegister() {
b2ContactRegister.b2ContactRegister.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactRegister = b2ContactRegister;
function b2ContactResult() {
b2ContactResult.b2ContactResult.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactResult = b2ContactResult;
function b2ContactSolver() {
b2ContactSolver.b2ContactSolver.apply(this, arguments);
if (this.constructor === b2ContactSolver) this.b2ContactSolver.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2ContactSolver = b2ContactSolver;
function b2EdgeAndCircleContact() {
b2EdgeAndCircleContact.b2EdgeAndCircleContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2EdgeAndCircleContact = b2EdgeAndCircleContact;
function b2NullContact() {
b2NullContact.b2NullContact.apply(this, arguments);
if (this.constructor === b2NullContact) this.b2NullContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2NullContact = b2NullContact;
function b2PolyAndCircleContact() {
b2PolyAndCircleContact.b2PolyAndCircleContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2PolyAndCircleContact = b2PolyAndCircleContact;
function b2PolyAndEdgeContact() {
b2PolyAndEdgeContact.b2PolyAndEdgeContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2PolyAndEdgeContact = b2PolyAndEdgeContact;
function b2PolygonContact() {
b2PolygonContact.b2PolygonContact.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2PolygonContact = b2PolygonContact;
function b2PositionSolverManifold() {
b2PositionSolverManifold.b2PositionSolverManifold.apply(this, arguments);
if (this.constructor === b2PositionSolverManifold) this.b2PositionSolverManifold.apply(this, arguments);
};
Box2D.Dynamics.Contacts.b2PositionSolverManifold = b2PositionSolverManifold;
function b2BuoyancyController() {
b2BuoyancyController.b2BuoyancyController.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2BuoyancyController = b2BuoyancyController;
function b2ConstantAccelController() {
b2ConstantAccelController.b2ConstantAccelController.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2ConstantAccelController = b2ConstantAccelController;
function b2ConstantForceController() {
b2ConstantForceController.b2ConstantForceController.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2ConstantForceController = b2ConstantForceController;
function b2Controller() {
b2Controller.b2Controller.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2Controller = b2Controller;
function b2ControllerEdge() {
b2ControllerEdge.b2ControllerEdge.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2ControllerEdge = b2ControllerEdge;
function b2GravityController() {
b2GravityController.b2GravityController.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2GravityController = b2GravityController;
function b2TensorDampingController() {
b2TensorDampingController.b2TensorDampingController.apply(this, arguments);
};
Box2D.Dynamics.Controllers.b2TensorDampingController = b2TensorDampingController;
function b2DistanceJoint() {
b2DistanceJoint.b2DistanceJoint.apply(this, arguments);
if (this.constructor === b2DistanceJoint) this.b2DistanceJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2DistanceJoint = b2DistanceJoint;
function b2DistanceJointDef() {
b2DistanceJointDef.b2DistanceJointDef.apply(this, arguments);
if (this.constructor === b2DistanceJointDef) this.b2DistanceJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2DistanceJointDef = b2DistanceJointDef;
function b2FrictionJoint() {
b2FrictionJoint.b2FrictionJoint.apply(this, arguments);
if (this.constructor === b2FrictionJoint) this.b2FrictionJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2FrictionJoint = b2FrictionJoint;
function b2FrictionJointDef() {
b2FrictionJointDef.b2FrictionJointDef.apply(this, arguments);
if (this.constructor === b2FrictionJointDef) this.b2FrictionJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2FrictionJointDef = b2FrictionJointDef;
function b2GearJoint() {
b2GearJoint.b2GearJoint.apply(this, arguments);
if (this.constructor === b2GearJoint) this.b2GearJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2GearJoint = b2GearJoint;
function b2GearJointDef() {
b2GearJointDef.b2GearJointDef.apply(this, arguments);
if (this.constructor === b2GearJointDef) this.b2GearJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2GearJointDef = b2GearJointDef;
function b2Jacobian() {
b2Jacobian.b2Jacobian.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2Jacobian = b2Jacobian;
function b2Joint() {
b2Joint.b2Joint.apply(this, arguments);
if (this.constructor === b2Joint) this.b2Joint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2Joint = b2Joint;
function b2JointDef() {
b2JointDef.b2JointDef.apply(this, arguments);
if (this.constructor === b2JointDef) this.b2JointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2JointDef = b2JointDef;
function b2JointEdge() {
b2JointEdge.b2JointEdge.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2JointEdge = b2JointEdge;
function b2LineJoint() {
b2LineJoint.b2LineJoint.apply(this, arguments);
if (this.constructor === b2LineJoint) this.b2LineJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2LineJoint = b2LineJoint;
function b2LineJointDef() {
b2LineJointDef.b2LineJointDef.apply(this, arguments);
if (this.constructor === b2LineJointDef) this.b2LineJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2LineJointDef = b2LineJointDef;
function b2MouseJoint() {
b2MouseJoint.b2MouseJoint.apply(this, arguments);
if (this.constructor === b2MouseJoint) this.b2MouseJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2MouseJoint = b2MouseJoint;
function b2MouseJointDef() {
b2MouseJointDef.b2MouseJointDef.apply(this, arguments);
if (this.constructor === b2MouseJointDef) this.b2MouseJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2MouseJointDef = b2MouseJointDef;
function b2PrismaticJoint() {
b2PrismaticJoint.b2PrismaticJoint.apply(this, arguments);
if (this.constructor === b2PrismaticJoint) this.b2PrismaticJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2PrismaticJoint = b2PrismaticJoint;
function b2PrismaticJointDef() {
b2PrismaticJointDef.b2PrismaticJointDef.apply(this, arguments);
if (this.constructor === b2PrismaticJointDef) this.b2PrismaticJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2PrismaticJointDef = b2PrismaticJointDef;
function b2PulleyJoint() {
b2PulleyJoint.b2PulleyJoint.apply(this, arguments);
if (this.constructor === b2PulleyJoint) this.b2PulleyJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2PulleyJoint = b2PulleyJoint;
function b2PulleyJointDef() {
b2PulleyJointDef.b2PulleyJointDef.apply(this, arguments);
if (this.constructor === b2PulleyJointDef) this.b2PulleyJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2PulleyJointDef = b2PulleyJointDef;
function b2RevoluteJoint() {
b2RevoluteJoint.b2RevoluteJoint.apply(this, arguments);
if (this.constructor === b2RevoluteJoint) this.b2RevoluteJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2RevoluteJoint = b2RevoluteJoint;
function b2RevoluteJointDef() {
b2RevoluteJointDef.b2RevoluteJointDef.apply(this, arguments);
if (this.constructor === b2RevoluteJointDef) this.b2RevoluteJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2RevoluteJointDef = b2RevoluteJointDef;
function b2WeldJoint() {
b2WeldJoint.b2WeldJoint.apply(this, arguments);
if (this.constructor === b2WeldJoint) this.b2WeldJoint.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2WeldJoint = b2WeldJoint;
function b2WeldJointDef() {
b2WeldJointDef.b2WeldJointDef.apply(this, arguments);
if (this.constructor === b2WeldJointDef) this.b2WeldJointDef.apply(this, arguments);
};
Box2D.Dynamics.Joints.b2WeldJointDef = b2WeldJointDef;
})(); //definitions
Box2D.postDefs = [];
(function () {
var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
b2MassData = Box2D.Collision.Shapes.b2MassData,
b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
b2Shape = Box2D.Collision.Shapes.b2Shape,
b2Color = Box2D.Common.b2Color,
b2internal = Box2D.Common.b2internal,
b2Settings = Box2D.Common.b2Settings,
b2Mat22 = Box2D.Common.Math.b2Mat22,
b2Mat33 = Box2D.Common.Math.b2Mat33,
b2Math = Box2D.Common.Math.b2Math,
b2Sweep = Box2D.Common.Math.b2Sweep,
b2Transform = Box2D.Common.Math.b2Transform,
b2Vec2 = Box2D.Common.Math.b2Vec2,
b2Vec3 = Box2D.Common.Math.b2Vec3,
b2AABB = Box2D.Collision.b2AABB,
b2Bound = Box2D.Collision.b2Bound,
b2BoundValues = Box2D.Collision.b2BoundValues,
b2Collision = Box2D.Collision.b2Collision,
b2ContactID = Box2D.Collision.b2ContactID,
b2ContactPoint = Box2D.Collision.b2ContactPoint,
b2Distance = Box2D.Collision.b2Distance,
b2DistanceInput = Box2D.Collision.b2DistanceInput,
b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
b2DynamicTree = Box2D.Collision.b2DynamicTree,
b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
b2Manifold = Box2D.Collision.b2Manifold,
b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
b2Point = Box2D.Collision.b2Point,
b2RayCastInput = Box2D.Collision.b2RayCastInput,
b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
b2Segment = Box2D.Collision.b2Segment,
b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
b2Simplex = Box2D.Collision.b2Simplex,
b2SimplexCache = Box2D.Collision.b2SimplexCache,
b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
b2TOIInput = Box2D.Collision.b2TOIInput,
b2WorldManifold = Box2D.Collision.b2WorldManifold,
ClipVertex = Box2D.Collision.ClipVertex,
Features = Box2D.Collision.Features,
IBroadPhase = Box2D.Collision.IBroadPhase;
b2AABB.b2AABB = function () {
this.lowerBound = new b2Vec2();
this.upperBound = new b2Vec2();
};
b2AABB.prototype.IsValid = function () {
var dX = this.upperBound.x - this.lowerBound.x;
var dY = this.upperBound.y - this.lowerBound.y;
var valid = dX >= 0.0 && dY >= 0.0;
valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();
return valid;
}
b2AABB.prototype.GetCenter = function () {
return new b2Vec2((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2);
}
b2AABB.prototype.GetExtents = function () {
return new b2Vec2((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2);
}
b2AABB.prototype.Contains = function (aabb) {
var result = true;
result = result && this.lowerBound.x <= aabb.lowerBound.x;
result = result && this.lowerBound.y <= aabb.lowerBound.y;
result = result && aabb.upperBound.x <= this.upperBound.x;
result = result && aabb.upperBound.y <= this.upperBound.y;
return result;
}
b2AABB.prototype.RayCast = function (output, input) {
var tmin = (-Number.MAX_VALUE);
var tmax = Number.MAX_VALUE;
var pX = input.p1.x;
var pY = input.p1.y;
var dX = input.p2.x - input.p1.x;
var dY = input.p2.y - input.p1.y;
var absDX = Math.abs(dX);
var absDY = Math.abs(dY);
var normal = output.normal;
var inv_d = 0;
var t1 = 0;
var t2 = 0;
var t3 = 0;
var s = 0; {
if (absDX < Number.MIN_VALUE) {
if (pX < this.lowerBound.x || this.upperBound.x < pX) return false;
}
else {
inv_d = 1.0 / dX;
t1 = (this.lowerBound.x - pX) * inv_d;
t2 = (this.upperBound.x - pX) * inv_d;
s = (-1.0);
if (t1 > t2) {
t3 = t1;
t1 = t2;
t2 = t3;
s = 1.0;
}
if (t1 > tmin) {
normal.x = s;
normal.y = 0;
tmin = t1;
}
tmax = Math.min(tmax, t2);
if (tmin > tmax) return false;
}
} {
if (absDY < Number.MIN_VALUE) {
if (pY < this.lowerBound.y || this.upperBound.y < pY) return false;
}
else {
inv_d = 1.0 / dY;
t1 = (this.lowerBound.y - pY) * inv_d;
t2 = (this.upperBound.y - pY) * inv_d;
s = (-1.0);
if (t1 > t2) {
t3 = t1;
t1 = t2;
t2 = t3;
s = 1.0;
}
if (t1 > tmin) {
normal.y = s;
normal.x = 0;
tmin = t1;
}
tmax = Math.min(tmax, t2);
if (tmin > tmax) return false;
}
}
output.fraction = tmin;
return true;
}
b2AABB.prototype.TestOverlap = function (other) {
var d1X = other.lowerBound.x - this.upperBound.x;
var d1Y = other.lowerBound.y - this.upperBound.y;
var d2X = this.lowerBound.x - other.upperBound.x;
var d2Y = this.lowerBound.y - other.upperBound.y;
if (d1X > 0.0 || d1Y > 0.0) return false;
if (d2X > 0.0 || d2Y > 0.0) return false;
return true;
}
b2AABB.Combine = function (aabb1, aabb2) {
var aabb = new b2AABB();
aabb.Combine(aabb1, aabb2);
return aabb;
}
b2AABB.prototype.Combine = function (aabb1, aabb2) {
this.lowerBound.x = Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x);
this.lowerBound.y = Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y);
this.upperBound.x = Math.max(aabb1.upperBound.x, aabb2.upperBound.x);
this.upperBound.y = Math.max(aabb1.upperBound.y, aabb2.upperBound.y);
}
b2Bound.b2Bound = function () {};
b2Bound.prototype.IsLower = function () {
return (this.value & 1) == 0;
}
b2Bound.prototype.IsUpper = function () {
return (this.value & 1) == 1;
}
b2Bound.prototype.Swap = function (b) {
var tempValue = this.value;
var tempProxy = this.proxy;
var tempStabbingCount = this.stabbingCount;
this.value = b.value;
this.proxy = b.proxy;
this.stabbingCount = b.stabbingCount;
b.value = tempValue;
b.proxy = tempProxy;
b.stabbingCount = tempStabbingCount;
}
b2BoundValues.b2BoundValues = function () {};
b2BoundValues.prototype.b2BoundValues = function () {
this.lowerValues = new Vector_a2j_Number();
this.lowerValues[0] = 0.0;
this.lowerValues[1] = 0.0;
this.upperValues = new Vector_a2j_Number();
this.upperValues[0] = 0.0;
this.upperValues[1] = 0.0;
}
b2Collision.b2Collision = function () {};
b2Collision.ClipSegmentToLine = function (vOut, vIn, normal, offset) {
if (offset === undefined) offset = 0;
var cv;
var numOut = 0;
cv = vIn[0];
var vIn0 = cv.v;
cv = vIn[1];
var vIn1 = cv.v;
var distance0 = normal.x * vIn0.x + normal.y * vIn0.y - offset;
var distance1 = normal.x * vIn1.x + normal.y * vIn1.y - offset;
if (distance0 <= 0.0) vOut[numOut++].Set(vIn[0]);
if (distance1 <= 0.0) vOut[numOut++].Set(vIn[1]);
if (distance0 * distance1 < 0.0) {
var interp = distance0 / (distance0 - distance1);
cv = vOut[numOut];
var tVec = cv.v;
tVec.x = vIn0.x + interp * (vIn1.x - vIn0.x);
tVec.y = vIn0.y + interp * (vIn1.y - vIn0.y);
cv = vOut[numOut];
var cv2;
if (distance0 > 0.0) {
cv2 = vIn[0];
cv.id = cv2.id;
}
else {
cv2 = vIn[1];
cv.id = cv2.id;
}++numOut;
}
return numOut;
}
b2Collision.EdgeSeparation = function (poly1, xf1, edge1, poly2, xf2) {
if (edge1 === undefined) edge1 = 0;
var count1 = parseInt(poly1.m_vertexCount);
var vertices1 = poly1.m_vertices;
var normals1 = poly1.m_normals;
var count2 = parseInt(poly2.m_vertexCount);
var vertices2 = poly2.m_vertices;
var tMat;
var tVec;
tMat = xf1.R;
tVec = normals1[edge1];
var normal1WorldX = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var normal1WorldY = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tMat = xf2.R;
var normal1X = (tMat.col1.x * normal1WorldX + tMat.col1.y * normal1WorldY);
var normal1Y = (tMat.col2.x * normal1WorldX + tMat.col2.y * normal1WorldY);
var index = 0;
var minDot = Number.MAX_VALUE;
for (var i = 0; i < count2; ++i) {
tVec = vertices2[i];
var dot = tVec.x * normal1X + tVec.y * normal1Y;
if (dot < minDot) {
minDot = dot;
index = i;
}
}
tVec = vertices1[edge1];
tMat = xf1.R;
var v1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var v1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tVec = vertices2[index];
tMat = xf2.R;
var v2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var v2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
v2X -= v1X;
v2Y -= v1Y;
var separation = v2X * normal1WorldX + v2Y * normal1WorldY;
return separation;
}
b2Collision.FindMaxSeparation = function (edgeIndex, poly1, xf1, poly2, xf2) {
var count1 = parseInt(poly1.m_vertexCount);
var normals1 = poly1.m_normals;
var tVec;
var tMat;
tMat = xf2.R;
tVec = poly2.m_centroid;
var dX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var dY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tMat = xf1.R;
tVec = poly1.m_centroid;
dX -= xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
dY -= xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
var dLocal1X = (dX * xf1.R.col1.x + dY * xf1.R.col1.y);
var dLocal1Y = (dX * xf1.R.col2.x + dY * xf1.R.col2.y);
var edge = 0;
var maxDot = (-Number.MAX_VALUE);
for (var i = 0; i < count1; ++i) {
tVec = normals1[i];
var dot = (tVec.x * dLocal1X + tVec.y * dLocal1Y);
if (dot > maxDot) {
maxDot = dot;
edge = i;
}
}
var s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);
var prevEdge = parseInt(edge - 1 >= 0 ? edge - 1 : count1 - 1);
var sPrev = b2Collision.EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);
var nextEdge = parseInt(edge + 1 < count1 ? edge + 1 : 0);
var sNext = b2Collision.EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);
var bestEdge = 0;
var bestSeparation = 0;
var increment = 0;
if (sPrev > s && sPrev > sNext) {
increment = (-1);
bestEdge = prevEdge;
bestSeparation = sPrev;
}
else if (sNext > s) {
increment = 1;
bestEdge = nextEdge;
bestSeparation = sNext;
}
else {
edgeIndex[0] = edge;
return s;
}
while (true) {
if (increment == (-1)) edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
else edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);
if (s > bestSeparation) {
bestEdge = edge;
bestSeparation = s;
}
else {
break;
}
}
edgeIndex[0] = bestEdge;
return bestSeparation;
}
b2Collision.FindIncidentEdge = function (c, poly1, xf1, edge1, poly2, xf2) {
if (edge1 === undefined) edge1 = 0;
var count1 = parseInt(poly1.m_vertexCount);
var normals1 = poly1.m_normals;
var count2 = parseInt(poly2.m_vertexCount);
var vertices2 = poly2.m_vertices;
var normals2 = poly2.m_normals;
var tMat;
var tVec;
tMat = xf1.R;
tVec = normals1[edge1];
var normal1X = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var normal1Y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tMat = xf2.R;
var tX = (tMat.col1.x * normal1X + tMat.col1.y * normal1Y);
normal1Y = (tMat.col2.x * normal1X + tMat.col2.y * normal1Y);
normal1X = tX;
var index = 0;
var minDot = Number.MAX_VALUE;
for (var i = 0; i < count2; ++i) {
tVec = normals2[i];
var dot = (normal1X * tVec.x + normal1Y * tVec.y);
if (dot < minDot) {
minDot = dot;
index = i;
}
}
var tClip;
var i1 = parseInt(index);
var i2 = parseInt(i1 + 1 < count2 ? i1 + 1 : 0);
tClip = c[0];
tVec = vertices2[i1];
tMat = xf2.R;
tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tClip.id.features.referenceEdge = edge1;
tClip.id.features.incidentEdge = i1;
tClip.id.features.incidentVertex = 0;
tClip = c[1];
tVec = vertices2[i2];
tMat = xf2.R;
tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tClip.id.features.referenceEdge = edge1;
tClip.id.features.incidentEdge = i2;
tClip.id.features.incidentVertex = 1;
}
b2Collision.MakeClipPointVector = function () {
var r = new Vector(2);
r[0] = new ClipVertex();
r[1] = new ClipVertex();
return r;
}
b2Collision.CollidePolygons = function (manifold, polyA, xfA, polyB, xfB) {
var cv;
manifold.m_pointCount = 0;
var totalRadius = polyA.m_radius + polyB.m_radius;
var edgeA = 0;
b2Collision.s_edgeAO[0] = edgeA;
var separationA = b2Collision.FindMaxSeparation(b2Collision.s_edgeAO, polyA, xfA, polyB, xfB);
edgeA = b2Collision.s_edgeAO[0];
if (separationA > totalRadius) return;
var edgeB = 0;
b2Collision.s_edgeBO[0] = edgeB;
var separationB = b2Collision.FindMaxSeparation(b2Collision.s_edgeBO, polyB, xfB, polyA, xfA);
edgeB = b2Collision.s_edgeBO[0];
if (separationB > totalRadius) return;
var poly1;
var poly2;
var xf1;
var xf2;
var edge1 = 0;
var flip = 0;
var k_relativeTol = 0.98;
var k_absoluteTol = 0.001;
var tMat;
if (separationB > k_relativeTol * separationA + k_absoluteTol) {
poly1 = polyB;
poly2 = polyA;
xf1 = xfB;
xf2 = xfA;
edge1 = edgeB;
manifold.m_type = b2Manifold.e_faceB;
flip = 1;
}
else {
poly1 = polyA;
poly2 = polyB;
xf1 = xfA;
xf2 = xfB;
edge1 = edgeA;
manifold.m_type = b2Manifold.e_faceA;
flip = 0;
}
var incidentEdge = b2Collision.s_incidentEdge;
b2Collision.FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
var count1 = parseInt(poly1.m_vertexCount);
var vertices1 = poly1.m_vertices;
var local_v11 = vertices1[edge1];
var local_v12;
if (edge1 + 1 < count1) {
local_v12 = vertices1[parseInt(edge1 + 1)];
}
else {
local_v12 = vertices1[0];
}
var localTangent = b2Collision.s_localTangent;
localTangent.Set(local_v12.x - local_v11.x, local_v12.y - local_v11.y);
localTangent.Normalize();
var localNormal = b2Collision.s_localNormal;
localNormal.x = localTangent.y;
localNormal.y = (-localTangent.x);
var planePoint = b2Collision.s_planePoint;
planePoint.Set(0.5 * (local_v11.x + local_v12.x), 0.5 * (local_v11.y + local_v12.y));
var tangent = b2Collision.s_tangent;
tMat = xf1.R;
tangent.x = (tMat.col1.x * localTangent.x + tMat.col2.x * localTangent.y);
tangent.y = (tMat.col1.y * localTangent.x + tMat.col2.y * localTangent.y);
var tangent2 = b2Collision.s_tangent2;
tangent2.x = (-tangent.x);
tangent2.y = (-tangent.y);
var normal = b2Collision.s_normal;
normal.x = tangent.y;
normal.y = (-tangent.x);
var v11 = b2Collision.s_v11;
var v12 = b2Collision.s_v12;
v11.x = xf1.position.x + (tMat.col1.x * local_v11.x + tMat.col2.x * local_v11.y);
v11.y = xf1.position.y + (tMat.col1.y * local_v11.x + tMat.col2.y * local_v11.y);
v12.x = xf1.position.x + (tMat.col1.x * local_v12.x + tMat.col2.x * local_v12.y);
v12.y = xf1.position.y + (tMat.col1.y * local_v12.x + tMat.col2.y * local_v12.y);
var frontOffset = normal.x * v11.x + normal.y * v11.y;
var sideOffset1 = (-tangent.x * v11.x) - tangent.y * v11.y + totalRadius;
var sideOffset2 = tangent.x * v12.x + tangent.y * v12.y + totalRadius;
var clipPoints1 = b2Collision.s_clipPoints1;
var clipPoints2 = b2Collision.s_clipPoints2;
var np = 0;
np = b2Collision.ClipSegmentToLine(clipPoints1, incidentEdge, tangent2, sideOffset1);
if (np < 2) return;
np = b2Collision.ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2);
if (np < 2) return;
manifold.m_localPlaneNormal.SetV(localNormal);
manifold.m_localPoint.SetV(planePoint);
var pointCount = 0;
for (var i = 0; i < b2Settings.b2_maxManifoldPoints; ++i) {
cv = clipPoints2[i];
var separation = normal.x * cv.v.x + normal.y * cv.v.y - frontOffset;
if (separation <= totalRadius) {
var cp = manifold.m_points[pointCount];
tMat = xf2.R;
var tX = cv.v.x - xf2.position.x;
var tY = cv.v.y - xf2.position.y;
cp.m_localPoint.x = (tX * tMat.col1.x + tY * tMat.col1.y);
cp.m_localPoint.y = (tX * tMat.col2.x + tY * tMat.col2.y);
cp.m_id.Set(cv.id);
cp.m_id.features.flip = flip;
++pointCount;
}
}
manifold.m_pointCount = pointCount;
}
b2Collision.CollideCircles = function (manifold, circle1, xf1, circle2, xf2) {
manifold.m_pointCount = 0;
var tMat;
var tVec;
tMat = xf1.R;
tVec = circle1.m_p;
var p1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var p1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
tMat = xf2.R;
tVec = circle2.m_p;
var p2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var p2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
var dX = p2X - p1X;
var dY = p2Y - p1Y;
var distSqr = dX * dX + dY * dY;
var radius = circle1.m_radius + circle2.m_radius;
if (distSqr > radius * radius) {
return;
}
manifold.m_type = b2Manifold.e_circles;
manifold.m_localPoint.SetV(circle1.m_p);
manifold.m_localPlaneNormal.SetZero();
manifold.m_pointCount = 1;
manifold.m_points[0].m_localPoint.SetV(circle2.m_p);
manifold.m_points[0].m_id.key = 0;
}
b2Collision.CollidePolygonAndCircle = function (manifold, polygon, xf1, circle, xf2) {
manifold.m_pointCount = 0;
var tPoint;
var dX = 0;
var dY = 0;
var positionX = 0;
var positionY = 0;
var tVec;
var tMat;
tMat = xf2.R;
tVec = circle.m_p;
var cX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);
var cY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);
dX = cX - xf1.position.x;
dY = cY - xf1.position.y;
tMat = xf1.R;
var cLocalX = (dX * tMat.col1.x + dY * tMat.col1.y);
var cLocalY = (dX * tMat.col2.x + dY * tMat.col2.y);
var dist = 0;
var normalIndex = 0;
var separation = (-Number.MAX_VALUE);
var radius = polygon.m_radius + circle.m_radius;
var vertexCount = parseInt(polygon.m_vertexCount);
var vertices = polygon.m_vertices;
var normals = polygon.m_normals;
for (var i = 0; i < vertexCount; ++i) {
tVec = vertices[i];
dX = cLocalX - tVec.x;
dY = cLocalY - tVec.y;
tVec = normals[i];
var s = tVec.x * dX + tVec.y * dY;
if (s > radius) {
return;
}
if (s > separation) {
separation = s;
normalIndex = i;
}
}
var vertIndex1 = parseInt(normalIndex);
var vertIndex2 = parseInt(vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0);
var v1 = vertices[vertIndex1];
var v2 = vertices[vertIndex2];
if (separation < Number.MIN_VALUE) {
manifold.m_pointCount = 1;
manifold.m_type = b2Manifold.e_faceA;
manifold.m_localPlaneNormal.SetV(normals[normalIndex]);
manifold.m_localPoint.x = 0.5 * (v1.x + v2.x);
manifold.m_localPoint.y = 0.5 * (v1.y + v2.y);
manifold.m_points[0].m_localPoint.SetV(circle.m_p);
manifold.m_points[0].m_id.key = 0;
return;
}
var u1 = (cLocalX - v1.x) * (v2.x - v1.x) + (cLocalY - v1.y) * (v2.y - v1.y);
var u2 = (cLocalX - v2.x) * (v1.x - v2.x) + (cLocalY - v2.y) * (v1.y - v2.y);
if (u1 <= 0.0) {
if ((cLocalX - v1.x) * (cLocalX - v1.x) + (cLocalY - v1.y) * (cLocalY - v1.y) > radius * radius) return;
manifold.m_pointCount = 1;
manifold.m_type = b2Manifold.e_faceA;
manifold.m_localPlaneNormal.x = cLocalX - v1.x;
manifold.m_localPlaneNormal.y = cLocalY - v1.y;
manifold.m_localPlaneNormal.Normalize();
manifold.m_localPoint.SetV(v1);
manifold.m_points[0].m_localPoint.SetV(circle.m_p);
manifold.m_points[0].m_id.key = 0;
}
else if (u2 <= 0) {
if ((cLocalX - v2.x) * (cLocalX - v2.x) + (cLocalY - v2.y) * (cLocalY - v2.y) > radius * radius) return;
manifold.m_pointCount = 1;
manifold.m_type = b2Manifold.e_faceA;
manifold.m_localPlaneNormal.x = cLocalX - v2.x;
manifold.m_localPlaneNormal.y = cLocalY - v2.y;
manifold.m_localPlaneNormal.Normalize();
manifold.m_localPoint.SetV(v2);
manifold.m_points[0].m_localPoint.SetV(circle.m_p);
manifold.m_points[0].m_id.key = 0;
}
else {
var faceCenterX = 0.5 * (v1.x + v2.x);
var faceCenterY = 0.5 * (v1.y + v2.y);
separation = (cLocalX - faceCenterX) * normals[vertIndex1].x + (cLocalY - faceCenterY) * normals[vertIndex1].y;
if (separation > radius) return;
manifold.m_pointCount = 1;
manifold.m_type = b2Manifold.e_faceA;
manifold.m_localPlaneNormal.x = normals[vertIndex1].x;
manifold.m_localPlaneNormal.y = normals[vertIndex1].y;
manifold.m_localPlaneNormal.Normalize();
manifold.m_localPoint.Set(faceCenterX, faceCenterY);
manifold.m_points[0].m_localPoint.SetV(circle.m_p);
manifold.m_points[0].m_id.key = 0;
}
}
b2Collision.TestOverlap = function (a, b) {
var t1 = b.lowerBound;
var t2 = a.upperBound;
var d1X = t1.x - t2.x;
var d1Y = t1.y - t2.y;
t1 = a.lowerBound;
t2 = b.upperBound;
var d2X = t1.x - t2.x;
var d2Y = t1.y - t2.y;
if (d1X > 0.0 || d1Y > 0.0) return false;
if (d2X > 0.0 || d2Y > 0.0) return false;
return true;
}
Box2D.postDefs.push(function () {
Box2D.Collision.b2Collision.s_incidentEdge = b2Collision.MakeClipPointVector();
Box2D.Collision.b2Collision.s_clipPoints1 = b2Collision.MakeClipPointVector();
Box2D.Collision.b2Collision.s_clipPoints2 = b2Collision.MakeClipPointVector();
Box2D.Collision.b2Collision.s_edgeAO = new Vector_a2j_Number(1);
Box2D.Collision.b2Collision.s_edgeBO = new Vector_a2j_Number(1);
Box2D.Collision.b2Collision.s_localTangent = new b2Vec2();
Box2D.Collision.b2Collision.s_localNormal = new b2Vec2();
Box2D.Collision.b2Collision.s_planePoint = new b2Vec2();
Box2D.Collision.b2Collision.s_normal = new b2Vec2();
Box2D.Collision.b2Collision.s_tangent = new b2Vec2();
Box2D.Collision.b2Collision.s_tangent2 = new b2Vec2();
Box2D.Collision.b2Collision.s_v11 = new b2Vec2();
Box2D.Collision.b2Collision.s_v12 = new b2Vec2();
Box2D.Collision.b2Collision.b2CollidePolyTempVec = new b2Vec2();
Box2D.Collision.b2Collision.b2_nullFeature = 0x000000ff;
});
b2ContactID.b2ContactID = function () {
this.features = new Features();
};
b2ContactID.prototype.b2ContactID = function () {
this.features._m_id = this;
}
b2ContactID.prototype.Set = function (id) {
this.key = id._key;
}
b2ContactID.prototype.Copy = function () {
var id = new b2ContactID();
id.key = this.key;
return id;
}
Object.defineProperty(b2ContactID.prototype, 'key', {
enumerable: false,
configurable: true,
get: function () {
return this._key;
}
});
Object.defineProperty(b2ContactID.prototype, 'key', {
enumerable: false,
configurable: true,
set: function (value) {
if (value === undefined) value = 0;
this._key = value;
this.features._referenceEdge = this._key & 0x000000ff;
this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
}
});
b2ContactPoint.b2ContactPoint = function () {
this.position = new b2Vec2();
this.velocity = new b2Vec2();
this.normal = new b2Vec2();
this.id = new b2ContactID();
};
b2Distance.b2Distance = function () {};
b2Distance.Distance = function (output, cache, input) {
++b2Distance.b2_gjkCalls;
var proxyA = input.proxyA;
var proxyB = input.proxyB;
var transformA = input.transformA;
var transformB = input.transformB;
var simplex = b2Distance.s_simplex;
simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB);
var vertices = simplex.m_