/*
* 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.
*
*
* Sean Lin 2012-5-8,
*
* The library is box2dweb, http://code.google.com/p/box2dweb/
*
* It is a port of Box2DFlash 2.1a to JavaScript.
* You can read the documentation for Box2dFlash, since nearly everything is
* organized the same way. http://www.box2dflash.org/docs/2.1a/reference/
*
*/
var Box2D = {};
(function (a2j, undefined) {
if(!(Object.defineProperty instanceof Function)
&& 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() {