Path: blob/main/public/games/files/garbage-collector/js/Box2dWeb/Box2dWeb-2.1.a.3.js
1515 views
/*1* Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com2*3* This software is provided 'as-is', without any express or implied4* warranty. In no event will the authors be held liable for any damages5* arising from the use of this software.6* Permission is granted to anyone to use this software for any purpose,7* including commercial applications, and to alter it and redistribute it8* freely, subject to the following restrictions:9* 1. The origin of this software must not be misrepresented; you must not10* claim that you wrote the original software. If you use this software11* in a product, an acknowledgment in the product documentation would be12* appreciated but is not required.13* 2. Altered source versions must be plainly marked as such, and must not be14* misrepresented as being the original software.15* 3. This notice may not be removed or altered from any source distribution.16*/17var Box2D = {};1819(function (a2j, undefined) {2021if(!(Object.prototype.defineProperty instanceof Function)22&& Object.prototype.__defineGetter__ instanceof Function23&& Object.prototype.__defineSetter__ instanceof Function)24{25Object.defineProperty = function(obj, p, cfg) {26if(cfg.get instanceof Function)27obj.__defineGetter__(p, cfg.get);28if(cfg.set instanceof Function)29obj.__defineSetter__(p, cfg.set);30}31}3233function emptyFn() {};34a2j.inherit = function(cls, base) {35var tmpCtr = cls;36emptyFn.prototype = base.prototype;37cls.prototype = new emptyFn;38cls.prototype.constructor = tmpCtr;39};4041a2j.generateCallback = function generateCallback(context, cb) {42return function () {43cb.apply(context, arguments);44};45};4647a2j.NVector = function NVector(length) {48if (length === undefined) length = 0;49var tmp = new Array(length || 0);50for (var i = 0; i < length; ++i)51tmp[i] = 0;52return tmp;53};5455a2j.is = function is(o1, o2) {56if (o1 === null) return false;57if ((o2 instanceof Function) && (o1 instanceof o2)) return true;58if ((o1.constructor.__implements != undefined) && (o1.constructor.__implements[o2])) return true;59return false;60};6162a2j.parseUInt = function(v) {63return Math.abs(parseInt(v));64}6566})(Box2D);6768//#TODO remove assignments from global namespace69var Vector = Array;70var Vector_a2j_Number = Box2D.NVector;71//package structure72if (typeof(Box2D) === "undefined") Box2D = {};73if (typeof(Box2D.Collision) === "undefined") Box2D.Collision = {};74if (typeof(Box2D.Collision.Shapes) === "undefined") Box2D.Collision.Shapes = {};75if (typeof(Box2D.Common) === "undefined") Box2D.Common = {};76if (typeof(Box2D.Common.Math) === "undefined") Box2D.Common.Math = {};77if (typeof(Box2D.Dynamics) === "undefined") Box2D.Dynamics = {};78if (typeof(Box2D.Dynamics.Contacts) === "undefined") Box2D.Dynamics.Contacts = {};79if (typeof(Box2D.Dynamics.Controllers) === "undefined") Box2D.Dynamics.Controllers = {};80if (typeof(Box2D.Dynamics.Joints) === "undefined") Box2D.Dynamics.Joints = {};81//pre-definitions82(function () {83Box2D.Collision.IBroadPhase = 'Box2D.Collision.IBroadPhase';8485function b2AABB() {86b2AABB.b2AABB.apply(this, arguments);87};88Box2D.Collision.b2AABB = b2AABB;8990function b2Bound() {91b2Bound.b2Bound.apply(this, arguments);92};93Box2D.Collision.b2Bound = b2Bound;9495function b2BoundValues() {96b2BoundValues.b2BoundValues.apply(this, arguments);97if (this.constructor === b2BoundValues) this.b2BoundValues.apply(this, arguments);98};99Box2D.Collision.b2BoundValues = b2BoundValues;100101function b2Collision() {102b2Collision.b2Collision.apply(this, arguments);103};104Box2D.Collision.b2Collision = b2Collision;105106function b2ContactID() {107b2ContactID.b2ContactID.apply(this, arguments);108if (this.constructor === b2ContactID) this.b2ContactID.apply(this, arguments);109};110Box2D.Collision.b2ContactID = b2ContactID;111112function b2ContactPoint() {113b2ContactPoint.b2ContactPoint.apply(this, arguments);114};115Box2D.Collision.b2ContactPoint = b2ContactPoint;116117function b2Distance() {118b2Distance.b2Distance.apply(this, arguments);119};120Box2D.Collision.b2Distance = b2Distance;121122function b2DistanceInput() {123b2DistanceInput.b2DistanceInput.apply(this, arguments);124};125Box2D.Collision.b2DistanceInput = b2DistanceInput;126127function b2DistanceOutput() {128b2DistanceOutput.b2DistanceOutput.apply(this, arguments);129};130Box2D.Collision.b2DistanceOutput = b2DistanceOutput;131132function b2DistanceProxy() {133b2DistanceProxy.b2DistanceProxy.apply(this, arguments);134};135Box2D.Collision.b2DistanceProxy = b2DistanceProxy;136137function b2DynamicTree() {138b2DynamicTree.b2DynamicTree.apply(this, arguments);139if (this.constructor === b2DynamicTree) this.b2DynamicTree.apply(this, arguments);140};141Box2D.Collision.b2DynamicTree = b2DynamicTree;142143function b2DynamicTreeBroadPhase() {144b2DynamicTreeBroadPhase.b2DynamicTreeBroadPhase.apply(this, arguments);145};146Box2D.Collision.b2DynamicTreeBroadPhase = b2DynamicTreeBroadPhase;147148function b2DynamicTreeNode() {149b2DynamicTreeNode.b2DynamicTreeNode.apply(this, arguments);150};151Box2D.Collision.b2DynamicTreeNode = b2DynamicTreeNode;152153function b2DynamicTreePair() {154b2DynamicTreePair.b2DynamicTreePair.apply(this, arguments);155};156Box2D.Collision.b2DynamicTreePair = b2DynamicTreePair;157158function b2Manifold() {159b2Manifold.b2Manifold.apply(this, arguments);160if (this.constructor === b2Manifold) this.b2Manifold.apply(this, arguments);161};162Box2D.Collision.b2Manifold = b2Manifold;163164function b2ManifoldPoint() {165b2ManifoldPoint.b2ManifoldPoint.apply(this, arguments);166if (this.constructor === b2ManifoldPoint) this.b2ManifoldPoint.apply(this, arguments);167};168Box2D.Collision.b2ManifoldPoint = b2ManifoldPoint;169170function b2Point() {171b2Point.b2Point.apply(this, arguments);172};173Box2D.Collision.b2Point = b2Point;174175function b2RayCastInput() {176b2RayCastInput.b2RayCastInput.apply(this, arguments);177if (this.constructor === b2RayCastInput) this.b2RayCastInput.apply(this, arguments);178};179Box2D.Collision.b2RayCastInput = b2RayCastInput;180181function b2RayCastOutput() {182b2RayCastOutput.b2RayCastOutput.apply(this, arguments);183};184Box2D.Collision.b2RayCastOutput = b2RayCastOutput;185186function b2Segment() {187b2Segment.b2Segment.apply(this, arguments);188};189Box2D.Collision.b2Segment = b2Segment;190191function b2SeparationFunction() {192b2SeparationFunction.b2SeparationFunction.apply(this, arguments);193};194Box2D.Collision.b2SeparationFunction = b2SeparationFunction;195196function b2Simplex() {197b2Simplex.b2Simplex.apply(this, arguments);198if (this.constructor === b2Simplex) this.b2Simplex.apply(this, arguments);199};200Box2D.Collision.b2Simplex = b2Simplex;201202function b2SimplexCache() {203b2SimplexCache.b2SimplexCache.apply(this, arguments);204};205Box2D.Collision.b2SimplexCache = b2SimplexCache;206207function b2SimplexVertex() {208b2SimplexVertex.b2SimplexVertex.apply(this, arguments);209};210Box2D.Collision.b2SimplexVertex = b2SimplexVertex;211212function b2TimeOfImpact() {213b2TimeOfImpact.b2TimeOfImpact.apply(this, arguments);214};215Box2D.Collision.b2TimeOfImpact = b2TimeOfImpact;216217function b2TOIInput() {218b2TOIInput.b2TOIInput.apply(this, arguments);219};220Box2D.Collision.b2TOIInput = b2TOIInput;221222function b2WorldManifold() {223b2WorldManifold.b2WorldManifold.apply(this, arguments);224if (this.constructor === b2WorldManifold) this.b2WorldManifold.apply(this, arguments);225};226Box2D.Collision.b2WorldManifold = b2WorldManifold;227228function ClipVertex() {229ClipVertex.ClipVertex.apply(this, arguments);230};231Box2D.Collision.ClipVertex = ClipVertex;232233function Features() {234Features.Features.apply(this, arguments);235};236Box2D.Collision.Features = Features;237238function b2CircleShape() {239b2CircleShape.b2CircleShape.apply(this, arguments);240if (this.constructor === b2CircleShape) this.b2CircleShape.apply(this, arguments);241};242Box2D.Collision.Shapes.b2CircleShape = b2CircleShape;243244function b2EdgeChainDef() {245b2EdgeChainDef.b2EdgeChainDef.apply(this, arguments);246if (this.constructor === b2EdgeChainDef) this.b2EdgeChainDef.apply(this, arguments);247};248Box2D.Collision.Shapes.b2EdgeChainDef = b2EdgeChainDef;249250function b2EdgeShape() {251b2EdgeShape.b2EdgeShape.apply(this, arguments);252if (this.constructor === b2EdgeShape) this.b2EdgeShape.apply(this, arguments);253};254Box2D.Collision.Shapes.b2EdgeShape = b2EdgeShape;255256function b2MassData() {257b2MassData.b2MassData.apply(this, arguments);258};259Box2D.Collision.Shapes.b2MassData = b2MassData;260261function b2PolygonShape() {262b2PolygonShape.b2PolygonShape.apply(this, arguments);263if (this.constructor === b2PolygonShape) this.b2PolygonShape.apply(this, arguments);264};265Box2D.Collision.Shapes.b2PolygonShape = b2PolygonShape;266267function b2Shape() {268b2Shape.b2Shape.apply(this, arguments);269if (this.constructor === b2Shape) this.b2Shape.apply(this, arguments);270};271Box2D.Collision.Shapes.b2Shape = b2Shape;272Box2D.Common.b2internal = 'Box2D.Common.b2internal';273274function b2Color() {275b2Color.b2Color.apply(this, arguments);276if (this.constructor === b2Color) this.b2Color.apply(this, arguments);277};278Box2D.Common.b2Color = b2Color;279280function b2Settings() {281b2Settings.b2Settings.apply(this, arguments);282};283Box2D.Common.b2Settings = b2Settings;284285function b2Mat22() {286b2Mat22.b2Mat22.apply(this, arguments);287if (this.constructor === b2Mat22) this.b2Mat22.apply(this, arguments);288};289Box2D.Common.Math.b2Mat22 = b2Mat22;290291function b2Mat33() {292b2Mat33.b2Mat33.apply(this, arguments);293if (this.constructor === b2Mat33) this.b2Mat33.apply(this, arguments);294};295Box2D.Common.Math.b2Mat33 = b2Mat33;296297function b2Math() {298b2Math.b2Math.apply(this, arguments);299};300Box2D.Common.Math.b2Math = b2Math;301302function b2Sweep() {303b2Sweep.b2Sweep.apply(this, arguments);304};305Box2D.Common.Math.b2Sweep = b2Sweep;306307function b2Transform() {308b2Transform.b2Transform.apply(this, arguments);309if (this.constructor === b2Transform) this.b2Transform.apply(this, arguments);310};311Box2D.Common.Math.b2Transform = b2Transform;312313function b2Vec2() {314b2Vec2.b2Vec2.apply(this, arguments);315if (this.constructor === b2Vec2) this.b2Vec2.apply(this, arguments);316};317Box2D.Common.Math.b2Vec2 = b2Vec2;318319function b2Vec3() {320b2Vec3.b2Vec3.apply(this, arguments);321if (this.constructor === b2Vec3) this.b2Vec3.apply(this, arguments);322};323Box2D.Common.Math.b2Vec3 = b2Vec3;324325function b2Body() {326b2Body.b2Body.apply(this, arguments);327if (this.constructor === b2Body) this.b2Body.apply(this, arguments);328};329Box2D.Dynamics.b2Body = b2Body;330331function b2BodyDef() {332b2BodyDef.b2BodyDef.apply(this, arguments);333if (this.constructor === b2BodyDef) this.b2BodyDef.apply(this, arguments);334};335Box2D.Dynamics.b2BodyDef = b2BodyDef;336337function b2ContactFilter() {338b2ContactFilter.b2ContactFilter.apply(this, arguments);339};340Box2D.Dynamics.b2ContactFilter = b2ContactFilter;341342function b2ContactImpulse() {343b2ContactImpulse.b2ContactImpulse.apply(this, arguments);344};345Box2D.Dynamics.b2ContactImpulse = b2ContactImpulse;346347function b2ContactListener() {348b2ContactListener.b2ContactListener.apply(this, arguments);349};350Box2D.Dynamics.b2ContactListener = b2ContactListener;351352function b2ContactManager() {353b2ContactManager.b2ContactManager.apply(this, arguments);354if (this.constructor === b2ContactManager) this.b2ContactManager.apply(this, arguments);355};356Box2D.Dynamics.b2ContactManager = b2ContactManager;357358function b2DebugDraw() {359b2DebugDraw.b2DebugDraw.apply(this, arguments);360if (this.constructor === b2DebugDraw) this.b2DebugDraw.apply(this, arguments);361};362Box2D.Dynamics.b2DebugDraw = b2DebugDraw;363364function b2DestructionListener() {365b2DestructionListener.b2DestructionListener.apply(this, arguments);366};367Box2D.Dynamics.b2DestructionListener = b2DestructionListener;368369function b2FilterData() {370b2FilterData.b2FilterData.apply(this, arguments);371};372Box2D.Dynamics.b2FilterData = b2FilterData;373374function b2Fixture() {375b2Fixture.b2Fixture.apply(this, arguments);376if (this.constructor === b2Fixture) this.b2Fixture.apply(this, arguments);377};378Box2D.Dynamics.b2Fixture = b2Fixture;379380function b2FixtureDef() {381b2FixtureDef.b2FixtureDef.apply(this, arguments);382if (this.constructor === b2FixtureDef) this.b2FixtureDef.apply(this, arguments);383};384Box2D.Dynamics.b2FixtureDef = b2FixtureDef;385386function b2Island() {387b2Island.b2Island.apply(this, arguments);388if (this.constructor === b2Island) this.b2Island.apply(this, arguments);389};390Box2D.Dynamics.b2Island = b2Island;391392function b2TimeStep() {393b2TimeStep.b2TimeStep.apply(this, arguments);394};395Box2D.Dynamics.b2TimeStep = b2TimeStep;396397function b2World() {398b2World.b2World.apply(this, arguments);399if (this.constructor === b2World) this.b2World.apply(this, arguments);400};401Box2D.Dynamics.b2World = b2World;402403function b2CircleContact() {404b2CircleContact.b2CircleContact.apply(this, arguments);405};406Box2D.Dynamics.Contacts.b2CircleContact = b2CircleContact;407408function b2Contact() {409b2Contact.b2Contact.apply(this, arguments);410if (this.constructor === b2Contact) this.b2Contact.apply(this, arguments);411};412Box2D.Dynamics.Contacts.b2Contact = b2Contact;413414function b2ContactConstraint() {415b2ContactConstraint.b2ContactConstraint.apply(this, arguments);416if (this.constructor === b2ContactConstraint) this.b2ContactConstraint.apply(this, arguments);417};418Box2D.Dynamics.Contacts.b2ContactConstraint = b2ContactConstraint;419420function b2ContactConstraintPoint() {421b2ContactConstraintPoint.b2ContactConstraintPoint.apply(this, arguments);422};423Box2D.Dynamics.Contacts.b2ContactConstraintPoint = b2ContactConstraintPoint;424425function b2ContactEdge() {426b2ContactEdge.b2ContactEdge.apply(this, arguments);427};428Box2D.Dynamics.Contacts.b2ContactEdge = b2ContactEdge;429430function b2ContactFactory() {431b2ContactFactory.b2ContactFactory.apply(this, arguments);432if (this.constructor === b2ContactFactory) this.b2ContactFactory.apply(this, arguments);433};434Box2D.Dynamics.Contacts.b2ContactFactory = b2ContactFactory;435436function b2ContactRegister() {437b2ContactRegister.b2ContactRegister.apply(this, arguments);438};439Box2D.Dynamics.Contacts.b2ContactRegister = b2ContactRegister;440441function b2ContactResult() {442b2ContactResult.b2ContactResult.apply(this, arguments);443};444Box2D.Dynamics.Contacts.b2ContactResult = b2ContactResult;445446function b2ContactSolver() {447b2ContactSolver.b2ContactSolver.apply(this, arguments);448if (this.constructor === b2ContactSolver) this.b2ContactSolver.apply(this, arguments);449};450Box2D.Dynamics.Contacts.b2ContactSolver = b2ContactSolver;451452function b2EdgeAndCircleContact() {453b2EdgeAndCircleContact.b2EdgeAndCircleContact.apply(this, arguments);454};455Box2D.Dynamics.Contacts.b2EdgeAndCircleContact = b2EdgeAndCircleContact;456457function b2NullContact() {458b2NullContact.b2NullContact.apply(this, arguments);459if (this.constructor === b2NullContact) this.b2NullContact.apply(this, arguments);460};461Box2D.Dynamics.Contacts.b2NullContact = b2NullContact;462463function b2PolyAndCircleContact() {464b2PolyAndCircleContact.b2PolyAndCircleContact.apply(this, arguments);465};466Box2D.Dynamics.Contacts.b2PolyAndCircleContact = b2PolyAndCircleContact;467468function b2PolyAndEdgeContact() {469b2PolyAndEdgeContact.b2PolyAndEdgeContact.apply(this, arguments);470};471Box2D.Dynamics.Contacts.b2PolyAndEdgeContact = b2PolyAndEdgeContact;472473function b2PolygonContact() {474b2PolygonContact.b2PolygonContact.apply(this, arguments);475};476Box2D.Dynamics.Contacts.b2PolygonContact = b2PolygonContact;477478function b2PositionSolverManifold() {479b2PositionSolverManifold.b2PositionSolverManifold.apply(this, arguments);480if (this.constructor === b2PositionSolverManifold) this.b2PositionSolverManifold.apply(this, arguments);481};482Box2D.Dynamics.Contacts.b2PositionSolverManifold = b2PositionSolverManifold;483484function b2BuoyancyController() {485b2BuoyancyController.b2BuoyancyController.apply(this, arguments);486};487Box2D.Dynamics.Controllers.b2BuoyancyController = b2BuoyancyController;488489function b2ConstantAccelController() {490b2ConstantAccelController.b2ConstantAccelController.apply(this, arguments);491};492Box2D.Dynamics.Controllers.b2ConstantAccelController = b2ConstantAccelController;493494function b2ConstantForceController() {495b2ConstantForceController.b2ConstantForceController.apply(this, arguments);496};497Box2D.Dynamics.Controllers.b2ConstantForceController = b2ConstantForceController;498499function b2Controller() {500b2Controller.b2Controller.apply(this, arguments);501};502Box2D.Dynamics.Controllers.b2Controller = b2Controller;503504function b2ControllerEdge() {505b2ControllerEdge.b2ControllerEdge.apply(this, arguments);506};507Box2D.Dynamics.Controllers.b2ControllerEdge = b2ControllerEdge;508509function b2GravityController() {510b2GravityController.b2GravityController.apply(this, arguments);511};512Box2D.Dynamics.Controllers.b2GravityController = b2GravityController;513514function b2TensorDampingController() {515b2TensorDampingController.b2TensorDampingController.apply(this, arguments);516};517Box2D.Dynamics.Controllers.b2TensorDampingController = b2TensorDampingController;518519function b2DistanceJoint() {520b2DistanceJoint.b2DistanceJoint.apply(this, arguments);521if (this.constructor === b2DistanceJoint) this.b2DistanceJoint.apply(this, arguments);522};523Box2D.Dynamics.Joints.b2DistanceJoint = b2DistanceJoint;524525function b2DistanceJointDef() {526b2DistanceJointDef.b2DistanceJointDef.apply(this, arguments);527if (this.constructor === b2DistanceJointDef) this.b2DistanceJointDef.apply(this, arguments);528};529Box2D.Dynamics.Joints.b2DistanceJointDef = b2DistanceJointDef;530531function b2FrictionJoint() {532b2FrictionJoint.b2FrictionJoint.apply(this, arguments);533if (this.constructor === b2FrictionJoint) this.b2FrictionJoint.apply(this, arguments);534};535Box2D.Dynamics.Joints.b2FrictionJoint = b2FrictionJoint;536537function b2FrictionJointDef() {538b2FrictionJointDef.b2FrictionJointDef.apply(this, arguments);539if (this.constructor === b2FrictionJointDef) this.b2FrictionJointDef.apply(this, arguments);540};541Box2D.Dynamics.Joints.b2FrictionJointDef = b2FrictionJointDef;542543function b2GearJoint() {544b2GearJoint.b2GearJoint.apply(this, arguments);545if (this.constructor === b2GearJoint) this.b2GearJoint.apply(this, arguments);546};547Box2D.Dynamics.Joints.b2GearJoint = b2GearJoint;548549function b2GearJointDef() {550b2GearJointDef.b2GearJointDef.apply(this, arguments);551if (this.constructor === b2GearJointDef) this.b2GearJointDef.apply(this, arguments);552};553Box2D.Dynamics.Joints.b2GearJointDef = b2GearJointDef;554555function b2Jacobian() {556b2Jacobian.b2Jacobian.apply(this, arguments);557};558Box2D.Dynamics.Joints.b2Jacobian = b2Jacobian;559560function b2Joint() {561b2Joint.b2Joint.apply(this, arguments);562if (this.constructor === b2Joint) this.b2Joint.apply(this, arguments);563};564Box2D.Dynamics.Joints.b2Joint = b2Joint;565566function b2JointDef() {567b2JointDef.b2JointDef.apply(this, arguments);568if (this.constructor === b2JointDef) this.b2JointDef.apply(this, arguments);569};570Box2D.Dynamics.Joints.b2JointDef = b2JointDef;571572function b2JointEdge() {573b2JointEdge.b2JointEdge.apply(this, arguments);574};575Box2D.Dynamics.Joints.b2JointEdge = b2JointEdge;576577function b2LineJoint() {578b2LineJoint.b2LineJoint.apply(this, arguments);579if (this.constructor === b2LineJoint) this.b2LineJoint.apply(this, arguments);580};581Box2D.Dynamics.Joints.b2LineJoint = b2LineJoint;582583function b2LineJointDef() {584b2LineJointDef.b2LineJointDef.apply(this, arguments);585if (this.constructor === b2LineJointDef) this.b2LineJointDef.apply(this, arguments);586};587Box2D.Dynamics.Joints.b2LineJointDef = b2LineJointDef;588589function b2MouseJoint() {590b2MouseJoint.b2MouseJoint.apply(this, arguments);591if (this.constructor === b2MouseJoint) this.b2MouseJoint.apply(this, arguments);592};593Box2D.Dynamics.Joints.b2MouseJoint = b2MouseJoint;594595function b2MouseJointDef() {596b2MouseJointDef.b2MouseJointDef.apply(this, arguments);597if (this.constructor === b2MouseJointDef) this.b2MouseJointDef.apply(this, arguments);598};599Box2D.Dynamics.Joints.b2MouseJointDef = b2MouseJointDef;600601function b2PrismaticJoint() {602b2PrismaticJoint.b2PrismaticJoint.apply(this, arguments);603if (this.constructor === b2PrismaticJoint) this.b2PrismaticJoint.apply(this, arguments);604};605Box2D.Dynamics.Joints.b2PrismaticJoint = b2PrismaticJoint;606607function b2PrismaticJointDef() {608b2PrismaticJointDef.b2PrismaticJointDef.apply(this, arguments);609if (this.constructor === b2PrismaticJointDef) this.b2PrismaticJointDef.apply(this, arguments);610};611Box2D.Dynamics.Joints.b2PrismaticJointDef = b2PrismaticJointDef;612613function b2PulleyJoint() {614b2PulleyJoint.b2PulleyJoint.apply(this, arguments);615if (this.constructor === b2PulleyJoint) this.b2PulleyJoint.apply(this, arguments);616};617Box2D.Dynamics.Joints.b2PulleyJoint = b2PulleyJoint;618619function b2PulleyJointDef() {620b2PulleyJointDef.b2PulleyJointDef.apply(this, arguments);621if (this.constructor === b2PulleyJointDef) this.b2PulleyJointDef.apply(this, arguments);622};623Box2D.Dynamics.Joints.b2PulleyJointDef = b2PulleyJointDef;624625function b2RevoluteJoint() {626b2RevoluteJoint.b2RevoluteJoint.apply(this, arguments);627if (this.constructor === b2RevoluteJoint) this.b2RevoluteJoint.apply(this, arguments);628};629Box2D.Dynamics.Joints.b2RevoluteJoint = b2RevoluteJoint;630631function b2RevoluteJointDef() {632b2RevoluteJointDef.b2RevoluteJointDef.apply(this, arguments);633if (this.constructor === b2RevoluteJointDef) this.b2RevoluteJointDef.apply(this, arguments);634};635Box2D.Dynamics.Joints.b2RevoluteJointDef = b2RevoluteJointDef;636637function b2WeldJoint() {638b2WeldJoint.b2WeldJoint.apply(this, arguments);639if (this.constructor === b2WeldJoint) this.b2WeldJoint.apply(this, arguments);640};641Box2D.Dynamics.Joints.b2WeldJoint = b2WeldJoint;642643function b2WeldJointDef() {644b2WeldJointDef.b2WeldJointDef.apply(this, arguments);645if (this.constructor === b2WeldJointDef) this.b2WeldJointDef.apply(this, arguments);646};647Box2D.Dynamics.Joints.b2WeldJointDef = b2WeldJointDef;648})(); //definitions649Box2D.postDefs = [];650(function () {651var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,652b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,653b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,654b2MassData = Box2D.Collision.Shapes.b2MassData,655b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,656b2Shape = Box2D.Collision.Shapes.b2Shape,657b2Color = Box2D.Common.b2Color,658b2internal = Box2D.Common.b2internal,659b2Settings = Box2D.Common.b2Settings,660b2Mat22 = Box2D.Common.Math.b2Mat22,661b2Mat33 = Box2D.Common.Math.b2Mat33,662b2Math = Box2D.Common.Math.b2Math,663b2Sweep = Box2D.Common.Math.b2Sweep,664b2Transform = Box2D.Common.Math.b2Transform,665b2Vec2 = Box2D.Common.Math.b2Vec2,666b2Vec3 = Box2D.Common.Math.b2Vec3,667b2AABB = Box2D.Collision.b2AABB,668b2Bound = Box2D.Collision.b2Bound,669b2BoundValues = Box2D.Collision.b2BoundValues,670b2Collision = Box2D.Collision.b2Collision,671b2ContactID = Box2D.Collision.b2ContactID,672b2ContactPoint = Box2D.Collision.b2ContactPoint,673b2Distance = Box2D.Collision.b2Distance,674b2DistanceInput = Box2D.Collision.b2DistanceInput,675b2DistanceOutput = Box2D.Collision.b2DistanceOutput,676b2DistanceProxy = Box2D.Collision.b2DistanceProxy,677b2DynamicTree = Box2D.Collision.b2DynamicTree,678b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,679b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,680b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,681b2Manifold = Box2D.Collision.b2Manifold,682b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,683b2Point = Box2D.Collision.b2Point,684b2RayCastInput = Box2D.Collision.b2RayCastInput,685b2RayCastOutput = Box2D.Collision.b2RayCastOutput,686b2Segment = Box2D.Collision.b2Segment,687b2SeparationFunction = Box2D.Collision.b2SeparationFunction,688b2Simplex = Box2D.Collision.b2Simplex,689b2SimplexCache = Box2D.Collision.b2SimplexCache,690b2SimplexVertex = Box2D.Collision.b2SimplexVertex,691b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,692b2TOIInput = Box2D.Collision.b2TOIInput,693b2WorldManifold = Box2D.Collision.b2WorldManifold,694ClipVertex = Box2D.Collision.ClipVertex,695Features = Box2D.Collision.Features,696IBroadPhase = Box2D.Collision.IBroadPhase;697698b2AABB.b2AABB = function () {699this.lowerBound = new b2Vec2();700this.upperBound = new b2Vec2();701};702b2AABB.prototype.IsValid = function () {703var dX = this.upperBound.x - this.lowerBound.x;704var dY = this.upperBound.y - this.lowerBound.y;705var valid = dX >= 0.0 && dY >= 0.0;706valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();707return valid;708}709b2AABB.prototype.GetCenter = function () {710return new b2Vec2((this.lowerBound.x + this.upperBound.x) / 2, (this.lowerBound.y + this.upperBound.y) / 2);711}712b2AABB.prototype.GetExtents = function () {713return new b2Vec2((this.upperBound.x - this.lowerBound.x) / 2, (this.upperBound.y - this.lowerBound.y) / 2);714}715b2AABB.prototype.Contains = function (aabb) {716var result = true;717result = result && this.lowerBound.x <= aabb.lowerBound.x;718result = result && this.lowerBound.y <= aabb.lowerBound.y;719result = result && aabb.upperBound.x <= this.upperBound.x;720result = result && aabb.upperBound.y <= this.upperBound.y;721return result;722}723b2AABB.prototype.RayCast = function (output, input) {724var tmin = (-Number.MAX_VALUE);725var tmax = Number.MAX_VALUE;726var pX = input.p1.x;727var pY = input.p1.y;728var dX = input.p2.x - input.p1.x;729var dY = input.p2.y - input.p1.y;730var absDX = Math.abs(dX);731var absDY = Math.abs(dY);732var normal = output.normal;733var inv_d = 0;734var t1 = 0;735var t2 = 0;736var t3 = 0;737var s = 0; {738if (absDX < Number.MIN_VALUE) {739if (pX < this.lowerBound.x || this.upperBound.x < pX) return false;740}741else {742inv_d = 1.0 / dX;743t1 = (this.lowerBound.x - pX) * inv_d;744t2 = (this.upperBound.x - pX) * inv_d;745s = (-1.0);746if (t1 > t2) {747t3 = t1;748t1 = t2;749t2 = t3;750s = 1.0;751}752if (t1 > tmin) {753normal.x = s;754normal.y = 0;755tmin = t1;756}757tmax = Math.min(tmax, t2);758if (tmin > tmax) return false;759}760} {761if (absDY < Number.MIN_VALUE) {762if (pY < this.lowerBound.y || this.upperBound.y < pY) return false;763}764else {765inv_d = 1.0 / dY;766t1 = (this.lowerBound.y - pY) * inv_d;767t2 = (this.upperBound.y - pY) * inv_d;768s = (-1.0);769if (t1 > t2) {770t3 = t1;771t1 = t2;772t2 = t3;773s = 1.0;774}775if (t1 > tmin) {776normal.y = s;777normal.x = 0;778tmin = t1;779}780tmax = Math.min(tmax, t2);781if (tmin > tmax) return false;782}783}784output.fraction = tmin;785return true;786}787b2AABB.prototype.TestOverlap = function (other) {788var d1X = other.lowerBound.x - this.upperBound.x;789var d1Y = other.lowerBound.y - this.upperBound.y;790var d2X = this.lowerBound.x - other.upperBound.x;791var d2Y = this.lowerBound.y - other.upperBound.y;792if (d1X > 0.0 || d1Y > 0.0) return false;793if (d2X > 0.0 || d2Y > 0.0) return false;794return true;795}796b2AABB.Combine = function (aabb1, aabb2) {797var aabb = new b2AABB();798aabb.Combine(aabb1, aabb2);799return aabb;800}801b2AABB.prototype.Combine = function (aabb1, aabb2) {802this.lowerBound.x = Math.min(aabb1.lowerBound.x, aabb2.lowerBound.x);803this.lowerBound.y = Math.min(aabb1.lowerBound.y, aabb2.lowerBound.y);804this.upperBound.x = Math.max(aabb1.upperBound.x, aabb2.upperBound.x);805this.upperBound.y = Math.max(aabb1.upperBound.y, aabb2.upperBound.y);806}807b2Bound.b2Bound = function () {};808b2Bound.prototype.IsLower = function () {809return (this.value & 1) == 0;810}811b2Bound.prototype.IsUpper = function () {812return (this.value & 1) == 1;813}814b2Bound.prototype.Swap = function (b) {815var tempValue = this.value;816var tempProxy = this.proxy;817var tempStabbingCount = this.stabbingCount;818this.value = b.value;819this.proxy = b.proxy;820this.stabbingCount = b.stabbingCount;821b.value = tempValue;822b.proxy = tempProxy;823b.stabbingCount = tempStabbingCount;824}825b2BoundValues.b2BoundValues = function () {};826b2BoundValues.prototype.b2BoundValues = function () {827this.lowerValues = new Vector_a2j_Number();828this.lowerValues[0] = 0.0;829this.lowerValues[1] = 0.0;830this.upperValues = new Vector_a2j_Number();831this.upperValues[0] = 0.0;832this.upperValues[1] = 0.0;833}834b2Collision.b2Collision = function () {};835b2Collision.ClipSegmentToLine = function (vOut, vIn, normal, offset) {836if (offset === undefined) offset = 0;837var cv;838var numOut = 0;839cv = vIn[0];840var vIn0 = cv.v;841cv = vIn[1];842var vIn1 = cv.v;843var distance0 = normal.x * vIn0.x + normal.y * vIn0.y - offset;844var distance1 = normal.x * vIn1.x + normal.y * vIn1.y - offset;845if (distance0 <= 0.0) vOut[numOut++].Set(vIn[0]);846if (distance1 <= 0.0) vOut[numOut++].Set(vIn[1]);847if (distance0 * distance1 < 0.0) {848var interp = distance0 / (distance0 - distance1);849cv = vOut[numOut];850var tVec = cv.v;851tVec.x = vIn0.x + interp * (vIn1.x - vIn0.x);852tVec.y = vIn0.y + interp * (vIn1.y - vIn0.y);853cv = vOut[numOut];854var cv2;855if (distance0 > 0.0) {856cv2 = vIn[0];857cv.id = cv2.id;858}859else {860cv2 = vIn[1];861cv.id = cv2.id;862}++numOut;863}864return numOut;865}866b2Collision.EdgeSeparation = function (poly1, xf1, edge1, poly2, xf2) {867if (edge1 === undefined) edge1 = 0;868var count1 = parseInt(poly1.m_vertexCount);869var vertices1 = poly1.m_vertices;870var normals1 = poly1.m_normals;871var count2 = parseInt(poly2.m_vertexCount);872var vertices2 = poly2.m_vertices;873var tMat;874var tVec;875tMat = xf1.R;876tVec = normals1[edge1];877var normal1WorldX = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);878var normal1WorldY = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);879tMat = xf2.R;880var normal1X = (tMat.col1.x * normal1WorldX + tMat.col1.y * normal1WorldY);881var normal1Y = (tMat.col2.x * normal1WorldX + tMat.col2.y * normal1WorldY);882var index = 0;883var minDot = Number.MAX_VALUE;884for (var i = 0; i < count2; ++i) {885tVec = vertices2[i];886var dot = tVec.x * normal1X + tVec.y * normal1Y;887if (dot < minDot) {888minDot = dot;889index = i;890}891}892tVec = vertices1[edge1];893tMat = xf1.R;894var v1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);895var v1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);896tVec = vertices2[index];897tMat = xf2.R;898var v2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);899var v2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);900v2X -= v1X;901v2Y -= v1Y;902var separation = v2X * normal1WorldX + v2Y * normal1WorldY;903return separation;904}905b2Collision.FindMaxSeparation = function (edgeIndex, poly1, xf1, poly2, xf2) {906var count1 = parseInt(poly1.m_vertexCount);907var normals1 = poly1.m_normals;908var tVec;909var tMat;910tMat = xf2.R;911tVec = poly2.m_centroid;912var dX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);913var dY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);914tMat = xf1.R;915tVec = poly1.m_centroid;916dX -= xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);917dY -= xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);918var dLocal1X = (dX * xf1.R.col1.x + dY * xf1.R.col1.y);919var dLocal1Y = (dX * xf1.R.col2.x + dY * xf1.R.col2.y);920var edge = 0;921var maxDot = (-Number.MAX_VALUE);922for (var i = 0; i < count1; ++i) {923tVec = normals1[i];924var dot = (tVec.x * dLocal1X + tVec.y * dLocal1Y);925if (dot > maxDot) {926maxDot = dot;927edge = i;928}929}930var s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);931var prevEdge = parseInt(edge - 1 >= 0 ? edge - 1 : count1 - 1);932var sPrev = b2Collision.EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);933var nextEdge = parseInt(edge + 1 < count1 ? edge + 1 : 0);934var sNext = b2Collision.EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);935var bestEdge = 0;936var bestSeparation = 0;937var increment = 0;938if (sPrev > s && sPrev > sNext) {939increment = (-1);940bestEdge = prevEdge;941bestSeparation = sPrev;942}943else if (sNext > s) {944increment = 1;945bestEdge = nextEdge;946bestSeparation = sNext;947}948else {949edgeIndex[0] = edge;950return s;951}952while (true) {953if (increment == (-1)) edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;954else edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;s = b2Collision.EdgeSeparation(poly1, xf1, edge, poly2, xf2);955if (s > bestSeparation) {956bestEdge = edge;957bestSeparation = s;958}959else {960break;961}962}963edgeIndex[0] = bestEdge;964return bestSeparation;965}966b2Collision.FindIncidentEdge = function (c, poly1, xf1, edge1, poly2, xf2) {967if (edge1 === undefined) edge1 = 0;968var count1 = parseInt(poly1.m_vertexCount);969var normals1 = poly1.m_normals;970var count2 = parseInt(poly2.m_vertexCount);971var vertices2 = poly2.m_vertices;972var normals2 = poly2.m_normals;973var tMat;974var tVec;975tMat = xf1.R;976tVec = normals1[edge1];977var normal1X = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);978var normal1Y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);979tMat = xf2.R;980var tX = (tMat.col1.x * normal1X + tMat.col1.y * normal1Y);981normal1Y = (tMat.col2.x * normal1X + tMat.col2.y * normal1Y);982normal1X = tX;983var index = 0;984var minDot = Number.MAX_VALUE;985for (var i = 0; i < count2; ++i) {986tVec = normals2[i];987var dot = (normal1X * tVec.x + normal1Y * tVec.y);988if (dot < minDot) {989minDot = dot;990index = i;991}992}993var tClip;994var i1 = parseInt(index);995var i2 = parseInt(i1 + 1 < count2 ? i1 + 1 : 0);996tClip = c[0];997tVec = vertices2[i1];998tMat = xf2.R;999tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1000tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1001tClip.id.features.referenceEdge = edge1;1002tClip.id.features.incidentEdge = i1;1003tClip.id.features.incidentVertex = 0;1004tClip = c[1];1005tVec = vertices2[i2];1006tMat = xf2.R;1007tClip.v.x = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1008tClip.v.y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1009tClip.id.features.referenceEdge = edge1;1010tClip.id.features.incidentEdge = i2;1011tClip.id.features.incidentVertex = 1;1012}1013b2Collision.MakeClipPointVector = function () {1014var r = new Vector(2);1015r[0] = new ClipVertex();1016r[1] = new ClipVertex();1017return r;1018}1019b2Collision.CollidePolygons = function (manifold, polyA, xfA, polyB, xfB) {1020var cv;1021manifold.m_pointCount = 0;1022var totalRadius = polyA.m_radius + polyB.m_radius;1023var edgeA = 0;1024b2Collision.s_edgeAO[0] = edgeA;1025var separationA = b2Collision.FindMaxSeparation(b2Collision.s_edgeAO, polyA, xfA, polyB, xfB);1026edgeA = b2Collision.s_edgeAO[0];1027if (separationA > totalRadius) return;1028var edgeB = 0;1029b2Collision.s_edgeBO[0] = edgeB;1030var separationB = b2Collision.FindMaxSeparation(b2Collision.s_edgeBO, polyB, xfB, polyA, xfA);1031edgeB = b2Collision.s_edgeBO[0];1032if (separationB > totalRadius) return;1033var poly1;1034var poly2;1035var xf1;1036var xf2;1037var edge1 = 0;1038var flip = 0;1039var k_relativeTol = 0.98;1040var k_absoluteTol = 0.001;1041var tMat;1042if (separationB > k_relativeTol * separationA + k_absoluteTol) {1043poly1 = polyB;1044poly2 = polyA;1045xf1 = xfB;1046xf2 = xfA;1047edge1 = edgeB;1048manifold.m_type = b2Manifold.e_faceB;1049flip = 1;1050}1051else {1052poly1 = polyA;1053poly2 = polyB;1054xf1 = xfA;1055xf2 = xfB;1056edge1 = edgeA;1057manifold.m_type = b2Manifold.e_faceA;1058flip = 0;1059}1060var incidentEdge = b2Collision.s_incidentEdge;1061b2Collision.FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);1062var count1 = parseInt(poly1.m_vertexCount);1063var vertices1 = poly1.m_vertices;1064var local_v11 = vertices1[edge1];1065var local_v12;1066if (edge1 + 1 < count1) {1067local_v12 = vertices1[parseInt(edge1 + 1)];1068}1069else {1070local_v12 = vertices1[0];1071}1072var localTangent = b2Collision.s_localTangent;1073localTangent.Set(local_v12.x - local_v11.x, local_v12.y - local_v11.y);1074localTangent.Normalize();1075var localNormal = b2Collision.s_localNormal;1076localNormal.x = localTangent.y;1077localNormal.y = (-localTangent.x);1078var planePoint = b2Collision.s_planePoint;1079planePoint.Set(0.5 * (local_v11.x + local_v12.x), 0.5 * (local_v11.y + local_v12.y));1080var tangent = b2Collision.s_tangent;1081tMat = xf1.R;1082tangent.x = (tMat.col1.x * localTangent.x + tMat.col2.x * localTangent.y);1083tangent.y = (tMat.col1.y * localTangent.x + tMat.col2.y * localTangent.y);1084var tangent2 = b2Collision.s_tangent2;1085tangent2.x = (-tangent.x);1086tangent2.y = (-tangent.y);1087var normal = b2Collision.s_normal;1088normal.x = tangent.y;1089normal.y = (-tangent.x);1090var v11 = b2Collision.s_v11;1091var v12 = b2Collision.s_v12;1092v11.x = xf1.position.x + (tMat.col1.x * local_v11.x + tMat.col2.x * local_v11.y);1093v11.y = xf1.position.y + (tMat.col1.y * local_v11.x + tMat.col2.y * local_v11.y);1094v12.x = xf1.position.x + (tMat.col1.x * local_v12.x + tMat.col2.x * local_v12.y);1095v12.y = xf1.position.y + (tMat.col1.y * local_v12.x + tMat.col2.y * local_v12.y);1096var frontOffset = normal.x * v11.x + normal.y * v11.y;1097var sideOffset1 = (-tangent.x * v11.x) - tangent.y * v11.y + totalRadius;1098var sideOffset2 = tangent.x * v12.x + tangent.y * v12.y + totalRadius;1099var clipPoints1 = b2Collision.s_clipPoints1;1100var clipPoints2 = b2Collision.s_clipPoints2;1101var np = 0;1102np = b2Collision.ClipSegmentToLine(clipPoints1, incidentEdge, tangent2, sideOffset1);1103if (np < 2) return;1104np = b2Collision.ClipSegmentToLine(clipPoints2, clipPoints1, tangent, sideOffset2);1105if (np < 2) return;1106manifold.m_localPlaneNormal.SetV(localNormal);1107manifold.m_localPoint.SetV(planePoint);1108var pointCount = 0;1109for (var i = 0; i < b2Settings.b2_maxManifoldPoints; ++i) {1110cv = clipPoints2[i];1111var separation = normal.x * cv.v.x + normal.y * cv.v.y - frontOffset;1112if (separation <= totalRadius) {1113var cp = manifold.m_points[pointCount];1114tMat = xf2.R;1115var tX = cv.v.x - xf2.position.x;1116var tY = cv.v.y - xf2.position.y;1117cp.m_localPoint.x = (tX * tMat.col1.x + tY * tMat.col1.y);1118cp.m_localPoint.y = (tX * tMat.col2.x + tY * tMat.col2.y);1119cp.m_id.Set(cv.id);1120cp.m_id.features.flip = flip;1121++pointCount;1122}1123}1124manifold.m_pointCount = pointCount;1125}1126b2Collision.CollideCircles = function (manifold, circle1, xf1, circle2, xf2) {1127manifold.m_pointCount = 0;1128var tMat;1129var tVec;1130tMat = xf1.R;1131tVec = circle1.m_p;1132var p1X = xf1.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1133var p1Y = xf1.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1134tMat = xf2.R;1135tVec = circle2.m_p;1136var p2X = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1137var p2Y = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1138var dX = p2X - p1X;1139var dY = p2Y - p1Y;1140var distSqr = dX * dX + dY * dY;1141var radius = circle1.m_radius + circle2.m_radius;1142if (distSqr > radius * radius) {1143return;1144}1145manifold.m_type = b2Manifold.e_circles;1146manifold.m_localPoint.SetV(circle1.m_p);1147manifold.m_localPlaneNormal.SetZero();1148manifold.m_pointCount = 1;1149manifold.m_points[0].m_localPoint.SetV(circle2.m_p);1150manifold.m_points[0].m_id.key = 0;1151}1152b2Collision.CollidePolygonAndCircle = function (manifold, polygon, xf1, circle, xf2) {1153manifold.m_pointCount = 0;1154var tPoint;1155var dX = 0;1156var dY = 0;1157var positionX = 0;1158var positionY = 0;1159var tVec;1160var tMat;1161tMat = xf2.R;1162tVec = circle.m_p;1163var cX = xf2.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1164var cY = xf2.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1165dX = cX - xf1.position.x;1166dY = cY - xf1.position.y;1167tMat = xf1.R;1168var cLocalX = (dX * tMat.col1.x + dY * tMat.col1.y);1169var cLocalY = (dX * tMat.col2.x + dY * tMat.col2.y);1170var dist = 0;1171var normalIndex = 0;1172var separation = (-Number.MAX_VALUE);1173var radius = polygon.m_radius + circle.m_radius;1174var vertexCount = parseInt(polygon.m_vertexCount);1175var vertices = polygon.m_vertices;1176var normals = polygon.m_normals;1177for (var i = 0; i < vertexCount; ++i) {1178tVec = vertices[i];1179dX = cLocalX - tVec.x;1180dY = cLocalY - tVec.y;1181tVec = normals[i];1182var s = tVec.x * dX + tVec.y * dY;1183if (s > radius) {1184return;1185}1186if (s > separation) {1187separation = s;1188normalIndex = i;1189}1190}1191var vertIndex1 = parseInt(normalIndex);1192var vertIndex2 = parseInt(vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0);1193var v1 = vertices[vertIndex1];1194var v2 = vertices[vertIndex2];1195if (separation < Number.MIN_VALUE) {1196manifold.m_pointCount = 1;1197manifold.m_type = b2Manifold.e_faceA;1198manifold.m_localPlaneNormal.SetV(normals[normalIndex]);1199manifold.m_localPoint.x = 0.5 * (v1.x + v2.x);1200manifold.m_localPoint.y = 0.5 * (v1.y + v2.y);1201manifold.m_points[0].m_localPoint.SetV(circle.m_p);1202manifold.m_points[0].m_id.key = 0;1203return;1204}1205var u1 = (cLocalX - v1.x) * (v2.x - v1.x) + (cLocalY - v1.y) * (v2.y - v1.y);1206var u2 = (cLocalX - v2.x) * (v1.x - v2.x) + (cLocalY - v2.y) * (v1.y - v2.y);1207if (u1 <= 0.0) {1208if ((cLocalX - v1.x) * (cLocalX - v1.x) + (cLocalY - v1.y) * (cLocalY - v1.y) > radius * radius) return;1209manifold.m_pointCount = 1;1210manifold.m_type = b2Manifold.e_faceA;1211manifold.m_localPlaneNormal.x = cLocalX - v1.x;1212manifold.m_localPlaneNormal.y = cLocalY - v1.y;1213manifold.m_localPlaneNormal.Normalize();1214manifold.m_localPoint.SetV(v1);1215manifold.m_points[0].m_localPoint.SetV(circle.m_p);1216manifold.m_points[0].m_id.key = 0;1217}1218else if (u2 <= 0) {1219if ((cLocalX - v2.x) * (cLocalX - v2.x) + (cLocalY - v2.y) * (cLocalY - v2.y) > radius * radius) return;1220manifold.m_pointCount = 1;1221manifold.m_type = b2Manifold.e_faceA;1222manifold.m_localPlaneNormal.x = cLocalX - v2.x;1223manifold.m_localPlaneNormal.y = cLocalY - v2.y;1224manifold.m_localPlaneNormal.Normalize();1225manifold.m_localPoint.SetV(v2);1226manifold.m_points[0].m_localPoint.SetV(circle.m_p);1227manifold.m_points[0].m_id.key = 0;1228}1229else {1230var faceCenterX = 0.5 * (v1.x + v2.x);1231var faceCenterY = 0.5 * (v1.y + v2.y);1232separation = (cLocalX - faceCenterX) * normals[vertIndex1].x + (cLocalY - faceCenterY) * normals[vertIndex1].y;1233if (separation > radius) return;1234manifold.m_pointCount = 1;1235manifold.m_type = b2Manifold.e_faceA;1236manifold.m_localPlaneNormal.x = normals[vertIndex1].x;1237manifold.m_localPlaneNormal.y = normals[vertIndex1].y;1238manifold.m_localPlaneNormal.Normalize();1239manifold.m_localPoint.Set(faceCenterX, faceCenterY);1240manifold.m_points[0].m_localPoint.SetV(circle.m_p);1241manifold.m_points[0].m_id.key = 0;1242}1243}1244b2Collision.TestOverlap = function (a, b) {1245var t1 = b.lowerBound;1246var t2 = a.upperBound;1247var d1X = t1.x - t2.x;1248var d1Y = t1.y - t2.y;1249t1 = a.lowerBound;1250t2 = b.upperBound;1251var d2X = t1.x - t2.x;1252var d2Y = t1.y - t2.y;1253if (d1X > 0.0 || d1Y > 0.0) return false;1254if (d2X > 0.0 || d2Y > 0.0) return false;1255return true;1256}1257Box2D.postDefs.push(function () {1258Box2D.Collision.b2Collision.s_incidentEdge = b2Collision.MakeClipPointVector();1259Box2D.Collision.b2Collision.s_clipPoints1 = b2Collision.MakeClipPointVector();1260Box2D.Collision.b2Collision.s_clipPoints2 = b2Collision.MakeClipPointVector();1261Box2D.Collision.b2Collision.s_edgeAO = new Vector_a2j_Number(1);1262Box2D.Collision.b2Collision.s_edgeBO = new Vector_a2j_Number(1);1263Box2D.Collision.b2Collision.s_localTangent = new b2Vec2();1264Box2D.Collision.b2Collision.s_localNormal = new b2Vec2();1265Box2D.Collision.b2Collision.s_planePoint = new b2Vec2();1266Box2D.Collision.b2Collision.s_normal = new b2Vec2();1267Box2D.Collision.b2Collision.s_tangent = new b2Vec2();1268Box2D.Collision.b2Collision.s_tangent2 = new b2Vec2();1269Box2D.Collision.b2Collision.s_v11 = new b2Vec2();1270Box2D.Collision.b2Collision.s_v12 = new b2Vec2();1271Box2D.Collision.b2Collision.b2CollidePolyTempVec = new b2Vec2();1272Box2D.Collision.b2Collision.b2_nullFeature = 0x000000ff;1273});1274b2ContactID.b2ContactID = function () {1275this.features = new Features();1276};1277b2ContactID.prototype.b2ContactID = function () {1278this.features._m_id = this;1279}1280b2ContactID.prototype.Set = function (id) {1281this.key = id._key;1282}1283b2ContactID.prototype.Copy = function () {1284var id = new b2ContactID();1285id.key = this.key;1286return id;1287}1288Object.defineProperty(b2ContactID.prototype, 'key', {1289enumerable: false,1290configurable: true,1291get: function () {1292return this._key;1293}1294});1295Object.defineProperty(b2ContactID.prototype, 'key', {1296enumerable: false,1297configurable: true,1298set: function (value) {1299if (value === undefined) value = 0;1300this._key = value;1301this.features._referenceEdge = this._key & 0x000000ff;1302this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;1303this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;1304this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;1305}1306});1307b2ContactPoint.b2ContactPoint = function () {1308this.position = new b2Vec2();1309this.velocity = new b2Vec2();1310this.normal = new b2Vec2();1311this.id = new b2ContactID();1312};1313b2Distance.b2Distance = function () {};1314b2Distance.Distance = function (output, cache, input) {1315++b2Distance.b2_gjkCalls;1316var proxyA = input.proxyA;1317var proxyB = input.proxyB;1318var transformA = input.transformA;1319var transformB = input.transformB;1320var simplex = b2Distance.s_simplex;1321simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB);1322var vertices = simplex.m_vertices;1323var k_maxIters = 20;1324var saveA = b2Distance.s_saveA;1325var saveB = b2Distance.s_saveB;1326var saveCount = 0;1327var closestPoint = simplex.GetClosestPoint();1328var distanceSqr1 = closestPoint.LengthSquared();1329var distanceSqr2 = distanceSqr1;1330var i = 0;1331var p;1332var iter = 0;1333while (iter < k_maxIters) {1334saveCount = simplex.m_count;1335for (i = 0;1336i < saveCount; i++) {1337saveA[i] = vertices[i].indexA;1338saveB[i] = vertices[i].indexB;1339}1340switch (simplex.m_count) {1341case 1:1342break;1343case 2:1344simplex.Solve2();1345break;1346case 3:1347simplex.Solve3();1348break;1349default:1350b2Settings.b2Assert(false);1351}1352if (simplex.m_count == 3) {1353break;1354}1355p = simplex.GetClosestPoint();1356distanceSqr2 = p.LengthSquared();1357if (distanceSqr2 > distanceSqr1) {}1358distanceSqr1 = distanceSqr2;1359var d = simplex.GetSearchDirection();1360if (d.LengthSquared() < Number.MIN_VALUE * Number.MIN_VALUE) {1361break;1362}1363var vertex = vertices[simplex.m_count];1364vertex.indexA = proxyA.GetSupport(b2Math.MulTMV(transformA.R, d.GetNegative()));1365vertex.wA = b2Math.MulX(transformA, proxyA.GetVertex(vertex.indexA));1366vertex.indexB = proxyB.GetSupport(b2Math.MulTMV(transformB.R, d));1367vertex.wB = b2Math.MulX(transformB, proxyB.GetVertex(vertex.indexB));1368vertex.w = b2Math.SubtractVV(vertex.wB, vertex.wA);1369++iter;1370++b2Distance.b2_gjkIters;1371var duplicate = false;1372for (i = 0;1373i < saveCount; i++) {1374if (vertex.indexA == saveA[i] && vertex.indexB == saveB[i]) {1375duplicate = true;1376break;1377}1378}1379if (duplicate) {1380break;1381}++simplex.m_count;1382}1383b2Distance.b2_gjkMaxIters = b2Math.Max(b2Distance.b2_gjkMaxIters, iter);1384simplex.GetWitnessPoints(output.pointA, output.pointB);1385output.distance = b2Math.SubtractVV(output.pointA, output.pointB).Length();1386output.iterations = iter;1387simplex.WriteCache(cache);1388if (input.useRadii) {1389var rA = proxyA.m_radius;1390var rB = proxyB.m_radius;1391if (output.distance > rA + rB && output.distance > Number.MIN_VALUE) {1392output.distance -= rA + rB;1393var normal = b2Math.SubtractVV(output.pointB, output.pointA);1394normal.Normalize();1395output.pointA.x += rA * normal.x;1396output.pointA.y += rA * normal.y;1397output.pointB.x -= rB * normal.x;1398output.pointB.y -= rB * normal.y;1399}1400else {1401p = new b2Vec2();1402p.x = .5 * (output.pointA.x + output.pointB.x);1403p.y = .5 * (output.pointA.y + output.pointB.y);1404output.pointA.x = output.pointB.x = p.x;1405output.pointA.y = output.pointB.y = p.y;1406output.distance = 0.0;1407}1408}1409}1410Box2D.postDefs.push(function () {1411Box2D.Collision.b2Distance.s_simplex = new b2Simplex();1412Box2D.Collision.b2Distance.s_saveA = new Vector_a2j_Number(3);1413Box2D.Collision.b2Distance.s_saveB = new Vector_a2j_Number(3);1414});1415b2DistanceInput.b2DistanceInput = function () {};1416b2DistanceOutput.b2DistanceOutput = function () {1417this.pointA = new b2Vec2();1418this.pointB = new b2Vec2();1419};1420b2DistanceProxy.b2DistanceProxy = function () {};1421b2DistanceProxy.prototype.Set = function (shape) {1422switch (shape.GetType()) {1423case b2Shape.e_circleShape:1424{1425var circle = (shape instanceof b2CircleShape ? shape : null);1426this.m_vertices = new Vector(1, true);1427this.m_vertices[0] = circle.m_p;1428this.m_count = 1;1429this.m_radius = circle.m_radius;1430}1431break;1432case b2Shape.e_polygonShape:1433{1434var polygon = (shape instanceof b2PolygonShape ? shape : null);1435this.m_vertices = polygon.m_vertices;1436this.m_count = polygon.m_vertexCount;1437this.m_radius = polygon.m_radius;1438}1439break;1440default:1441b2Settings.b2Assert(false);1442}1443}1444b2DistanceProxy.prototype.GetSupport = function (d) {1445var bestIndex = 0;1446var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;1447for (var i = 1; i < this.m_count; ++i) {1448var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;1449if (value > bestValue) {1450bestIndex = i;1451bestValue = value;1452}1453}1454return bestIndex;1455}1456b2DistanceProxy.prototype.GetSupportVertex = function (d) {1457var bestIndex = 0;1458var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;1459for (var i = 1; i < this.m_count; ++i) {1460var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;1461if (value > bestValue) {1462bestIndex = i;1463bestValue = value;1464}1465}1466return this.m_vertices[bestIndex];1467}1468b2DistanceProxy.prototype.GetVertexCount = function () {1469return this.m_count;1470}1471b2DistanceProxy.prototype.GetVertex = function (index) {1472if (index === undefined) index = 0;1473b2Settings.b2Assert(0 <= index && index < this.m_count);1474return this.m_vertices[index];1475}1476b2DynamicTree.b2DynamicTree = function () {};1477b2DynamicTree.prototype.b2DynamicTree = function () {1478this.m_root = null;1479this.m_freeList = null;1480this.m_path = 0;1481this.m_insertionCount = 0;1482}1483b2DynamicTree.prototype.CreateProxy = function (aabb, userData) {1484var node = this.AllocateNode();1485var extendX = b2Settings.b2_aabbExtension;1486var extendY = b2Settings.b2_aabbExtension;1487node.aabb.lowerBound.x = aabb.lowerBound.x - extendX;1488node.aabb.lowerBound.y = aabb.lowerBound.y - extendY;1489node.aabb.upperBound.x = aabb.upperBound.x + extendX;1490node.aabb.upperBound.y = aabb.upperBound.y + extendY;1491node.userData = userData;1492this.InsertLeaf(node);1493return node;1494}1495b2DynamicTree.prototype.DestroyProxy = function (proxy) {1496this.RemoveLeaf(proxy);1497this.FreeNode(proxy);1498}1499b2DynamicTree.prototype.MoveProxy = function (proxy, aabb, displacement) {1500b2Settings.b2Assert(proxy.IsLeaf());1501if (proxy.aabb.Contains(aabb)) {1502return false;1503}1504this.RemoveLeaf(proxy);1505var extendX = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.x > 0 ? displacement.x : (-displacement.x));1506var extendY = b2Settings.b2_aabbExtension + b2Settings.b2_aabbMultiplier * (displacement.y > 0 ? displacement.y : (-displacement.y));1507proxy.aabb.lowerBound.x = aabb.lowerBound.x - extendX;1508proxy.aabb.lowerBound.y = aabb.lowerBound.y - extendY;1509proxy.aabb.upperBound.x = aabb.upperBound.x + extendX;1510proxy.aabb.upperBound.y = aabb.upperBound.y + extendY;1511this.InsertLeaf(proxy);1512return true;1513}1514b2DynamicTree.prototype.Rebalance = function (iterations) {1515if (iterations === undefined) iterations = 0;1516if (this.m_root == null) return;1517for (var i = 0; i < iterations; i++) {1518var node = this.m_root;1519var bit = 0;1520while (node.IsLeaf() == false) {1521node = (this.m_path >> bit) & 1 ? node.child2 : node.child1;1522bit = (bit + 1) & 31;1523}++this.m_path;1524this.RemoveLeaf(node);1525this.InsertLeaf(node);1526}1527}1528b2DynamicTree.prototype.GetFatAABB = function (proxy) {1529return proxy.aabb;1530}1531b2DynamicTree.prototype.GetUserData = function (proxy) {1532return proxy.userData;1533}1534b2DynamicTree.prototype.Query = function (callback, aabb) {1535if (this.m_root == null) return;1536var stack = new Vector();1537var count = 0;1538stack[count++] = this.m_root;1539while (count > 0) {1540var node = stack[--count];1541if (node.aabb.TestOverlap(aabb)) {1542if (node.IsLeaf()) {1543var proceed = callback(node);1544if (!proceed) return;1545}1546else {1547stack[count++] = node.child1;1548stack[count++] = node.child2;1549}1550}1551}1552}1553b2DynamicTree.prototype.RayCast = function (callback, input) {1554if (this.m_root == null) return;1555var p1 = input.p1;1556var p2 = input.p2;1557var r = b2Math.SubtractVV(p1, p2);1558r.Normalize();1559var v = b2Math.CrossFV(1.0, r);1560var abs_v = b2Math.AbsV(v);1561var maxFraction = input.maxFraction;1562var segmentAABB = new b2AABB();1563var tX = 0;1564var tY = 0; {1565tX = p1.x + maxFraction * (p2.x - p1.x);1566tY = p1.y + maxFraction * (p2.y - p1.y);1567segmentAABB.lowerBound.x = Math.min(p1.x, tX);1568segmentAABB.lowerBound.y = Math.min(p1.y, tY);1569segmentAABB.upperBound.x = Math.max(p1.x, tX);1570segmentAABB.upperBound.y = Math.max(p1.y, tY);1571}1572var stack = new Vector();1573var count = 0;1574stack[count++] = this.m_root;1575while (count > 0) {1576var node = stack[--count];1577if (node.aabb.TestOverlap(segmentAABB) == false) {1578continue;1579}1580var c = node.aabb.GetCenter();1581var h = node.aabb.GetExtents();1582var separation = Math.abs(v.x * (p1.x - c.x) + v.y * (p1.y - c.y)) - abs_v.x * h.x - abs_v.y * h.y;1583if (separation > 0.0) continue;1584if (node.IsLeaf()) {1585var subInput = new b2RayCastInput();1586subInput.p1 = input.p1;1587subInput.p2 = input.p2;1588subInput.maxFraction = input.maxFraction;1589maxFraction = callback(subInput, node);1590if (maxFraction == 0.0) return;1591if (maxFraction > 0.0) {1592tX = p1.x + maxFraction * (p2.x - p1.x);1593tY = p1.y + maxFraction * (p2.y - p1.y);1594segmentAABB.lowerBound.x = Math.min(p1.x, tX);1595segmentAABB.lowerBound.y = Math.min(p1.y, tY);1596segmentAABB.upperBound.x = Math.max(p1.x, tX);1597segmentAABB.upperBound.y = Math.max(p1.y, tY);1598}1599}1600else {1601stack[count++] = node.child1;1602stack[count++] = node.child2;1603}1604}1605}1606b2DynamicTree.prototype.AllocateNode = function () {1607if (this.m_freeList) {1608var node = this.m_freeList;1609this.m_freeList = node.parent;1610node.parent = null;1611node.child1 = null;1612node.child2 = null;1613return node;1614}1615return new b2DynamicTreeNode();1616}1617b2DynamicTree.prototype.FreeNode = function (node) {1618node.parent = this.m_freeList;1619this.m_freeList = node;1620}1621b2DynamicTree.prototype.InsertLeaf = function (leaf) {1622++this.m_insertionCount;1623if (this.m_root == null) {1624this.m_root = leaf;1625this.m_root.parent = null;1626return;1627}1628var center = leaf.aabb.GetCenter();1629var sibling = this.m_root;1630if (sibling.IsLeaf() == false) {1631do {1632var child1 = sibling.child1;1633var child2 = sibling.child2;1634var norm1 = Math.abs((child1.aabb.lowerBound.x + child1.aabb.upperBound.x) / 2 - center.x) + Math.abs((child1.aabb.lowerBound.y + child1.aabb.upperBound.y) / 2 - center.y);1635var norm2 = Math.abs((child2.aabb.lowerBound.x + child2.aabb.upperBound.x) / 2 - center.x) + Math.abs((child2.aabb.lowerBound.y + child2.aabb.upperBound.y) / 2 - center.y);1636if (norm1 < norm2) {1637sibling = child1;1638}1639else {1640sibling = child2;1641}1642}1643while (sibling.IsLeaf() == false)1644}1645var node1 = sibling.parent;1646var node2 = this.AllocateNode();1647node2.parent = node1;1648node2.userData = null;1649node2.aabb.Combine(leaf.aabb, sibling.aabb);1650if (node1) {1651if (sibling.parent.child1 == sibling) {1652node1.child1 = node2;1653}1654else {1655node1.child2 = node2;1656}1657node2.child1 = sibling;1658node2.child2 = leaf;1659sibling.parent = node2;1660leaf.parent = node2;1661do {1662if (node1.aabb.Contains(node2.aabb)) break;1663node1.aabb.Combine(node1.child1.aabb, node1.child2.aabb);1664node2 = node1;1665node1 = node1.parent;1666}1667while (node1)1668}1669else {1670node2.child1 = sibling;1671node2.child2 = leaf;1672sibling.parent = node2;1673leaf.parent = node2;1674this.m_root = node2;1675}1676}1677b2DynamicTree.prototype.RemoveLeaf = function (leaf) {1678if (leaf == this.m_root) {1679this.m_root = null;1680return;1681}1682var node2 = leaf.parent;1683var node1 = node2.parent;1684var sibling;1685if (node2.child1 == leaf) {1686sibling = node2.child2;1687}1688else {1689sibling = node2.child1;1690}1691if (node1) {1692if (node1.child1 == node2) {1693node1.child1 = sibling;1694}1695else {1696node1.child2 = sibling;1697}1698sibling.parent = node1;1699this.FreeNode(node2);1700while (node1) {1701var oldAABB = node1.aabb;1702node1.aabb = b2AABB.Combine(node1.child1.aabb, node1.child2.aabb);1703if (oldAABB.Contains(node1.aabb)) break;1704node1 = node1.parent;1705}1706}1707else {1708this.m_root = sibling;1709sibling.parent = null;1710this.FreeNode(node2);1711}1712}1713b2DynamicTreeBroadPhase.b2DynamicTreeBroadPhase = function () {1714this.m_tree = new b2DynamicTree();1715this.m_moveBuffer = new Vector();1716this.m_pairBuffer = new Vector();1717this.m_pairCount = 0;1718};1719b2DynamicTreeBroadPhase.prototype.CreateProxy = function (aabb, userData) {1720var proxy = this.m_tree.CreateProxy(aabb, userData);1721++this.m_proxyCount;1722this.BufferMove(proxy);1723return proxy;1724}1725b2DynamicTreeBroadPhase.prototype.DestroyProxy = function (proxy) {1726this.UnBufferMove(proxy);1727--this.m_proxyCount;1728this.m_tree.DestroyProxy(proxy);1729}1730b2DynamicTreeBroadPhase.prototype.MoveProxy = function (proxy, aabb, displacement) {1731var buffer = this.m_tree.MoveProxy(proxy, aabb, displacement);1732if (buffer) {1733this.BufferMove(proxy);1734}1735}1736b2DynamicTreeBroadPhase.prototype.TestOverlap = function (proxyA, proxyB) {1737var aabbA = this.m_tree.GetFatAABB(proxyA);1738var aabbB = this.m_tree.GetFatAABB(proxyB);1739return aabbA.TestOverlap(aabbB);1740}1741b2DynamicTreeBroadPhase.prototype.GetUserData = function (proxy) {1742return this.m_tree.GetUserData(proxy);1743}1744b2DynamicTreeBroadPhase.prototype.GetFatAABB = function (proxy) {1745return this.m_tree.GetFatAABB(proxy);1746}1747b2DynamicTreeBroadPhase.prototype.GetProxyCount = function () {1748return this.m_proxyCount;1749}1750b2DynamicTreeBroadPhase.prototype.UpdatePairs = function (callback) {1751var __this = this;1752__this.m_pairCount = 0;1753var i = 0,1754queryProxy;1755for (i = 0;1756i < __this.m_moveBuffer.length; ++i) {1757queryProxy = __this.m_moveBuffer[i];17581759function QueryCallback(proxy) {1760if (proxy == queryProxy) return true;1761if (__this.m_pairCount == __this.m_pairBuffer.length) {1762__this.m_pairBuffer[__this.m_pairCount] = new b2DynamicTreePair();1763}1764var pair = __this.m_pairBuffer[__this.m_pairCount];1765pair.proxyA = proxy < queryProxy ? proxy : queryProxy;1766pair.proxyB = proxy >= queryProxy ? proxy : queryProxy;++__this.m_pairCount;1767return true;1768};1769var fatAABB = __this.m_tree.GetFatAABB(queryProxy);1770__this.m_tree.Query(QueryCallback, fatAABB);1771}1772__this.m_moveBuffer.length = 0;1773for (var i = 0; i < __this.m_pairCount;) {1774var primaryPair = __this.m_pairBuffer[i];1775var userDataA = __this.m_tree.GetUserData(primaryPair.proxyA);1776var userDataB = __this.m_tree.GetUserData(primaryPair.proxyB);1777callback(userDataA, userDataB);1778++i;1779while (i < __this.m_pairCount) {1780var pair = __this.m_pairBuffer[i];1781if (pair.proxyA != primaryPair.proxyA || pair.proxyB != primaryPair.proxyB) {1782break;1783}++i;1784}1785}1786}1787b2DynamicTreeBroadPhase.prototype.Query = function (callback, aabb) {1788this.m_tree.Query(callback, aabb);1789}1790b2DynamicTreeBroadPhase.prototype.RayCast = function (callback, input) {1791this.m_tree.RayCast(callback, input);1792}1793b2DynamicTreeBroadPhase.prototype.Validate = function () {}1794b2DynamicTreeBroadPhase.prototype.Rebalance = function (iterations) {1795if (iterations === undefined) iterations = 0;1796this.m_tree.Rebalance(iterations);1797}1798b2DynamicTreeBroadPhase.prototype.BufferMove = function (proxy) {1799this.m_moveBuffer[this.m_moveBuffer.length] = proxy;1800}1801b2DynamicTreeBroadPhase.prototype.UnBufferMove = function (proxy) {1802var i = parseInt(this.m_moveBuffer.indexOf(proxy));1803this.m_moveBuffer.splice(i, 1);1804}1805b2DynamicTreeBroadPhase.prototype.ComparePairs = function (pair1, pair2) {1806return 0;1807}1808b2DynamicTreeBroadPhase.__implements = {};1809b2DynamicTreeBroadPhase.__implements[IBroadPhase] = true;1810b2DynamicTreeNode.b2DynamicTreeNode = function () {1811this.aabb = new b2AABB();1812};1813b2DynamicTreeNode.prototype.IsLeaf = function () {1814return this.child1 == null;1815}1816b2DynamicTreePair.b2DynamicTreePair = function () {};1817b2Manifold.b2Manifold = function () {1818this.m_pointCount = 0;1819};1820b2Manifold.prototype.b2Manifold = function () {1821this.m_points = new Vector(b2Settings.b2_maxManifoldPoints);1822for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {1823this.m_points[i] = new b2ManifoldPoint();1824}1825this.m_localPlaneNormal = new b2Vec2();1826this.m_localPoint = new b2Vec2();1827}1828b2Manifold.prototype.Reset = function () {1829for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {1830((this.m_points[i] instanceof b2ManifoldPoint ? this.m_points[i] : null)).Reset();1831}1832this.m_localPlaneNormal.SetZero();1833this.m_localPoint.SetZero();1834this.m_type = 0;1835this.m_pointCount = 0;1836}1837b2Manifold.prototype.Set = function (m) {1838this.m_pointCount = m.m_pointCount;1839for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {1840((this.m_points[i] instanceof b2ManifoldPoint ? this.m_points[i] : null)).Set(m.m_points[i]);1841}1842this.m_localPlaneNormal.SetV(m.m_localPlaneNormal);1843this.m_localPoint.SetV(m.m_localPoint);1844this.m_type = m.m_type;1845}1846b2Manifold.prototype.Copy = function () {1847var copy = new b2Manifold();1848copy.Set(this);1849return copy;1850}1851Box2D.postDefs.push(function () {1852Box2D.Collision.b2Manifold.e_circles = 0x0001;1853Box2D.Collision.b2Manifold.e_faceA = 0x0002;1854Box2D.Collision.b2Manifold.e_faceB = 0x0004;1855});1856b2ManifoldPoint.b2ManifoldPoint = function () {1857this.m_localPoint = new b2Vec2();1858this.m_id = new b2ContactID();1859};1860b2ManifoldPoint.prototype.b2ManifoldPoint = function () {1861this.Reset();1862}1863b2ManifoldPoint.prototype.Reset = function () {1864this.m_localPoint.SetZero();1865this.m_normalImpulse = 0.0;1866this.m_tangentImpulse = 0.0;1867this.m_id.key = 0;1868}1869b2ManifoldPoint.prototype.Set = function (m) {1870this.m_localPoint.SetV(m.m_localPoint);1871this.m_normalImpulse = m.m_normalImpulse;1872this.m_tangentImpulse = m.m_tangentImpulse;1873this.m_id.Set(m.m_id);1874}1875b2Point.b2Point = function () {1876this.p = new b2Vec2();1877};1878b2Point.prototype.Support = function (xf, vX, vY) {1879if (vX === undefined) vX = 0;1880if (vY === undefined) vY = 0;1881return this.p;1882}1883b2Point.prototype.GetFirstVertex = function (xf) {1884return this.p;1885}1886b2RayCastInput.b2RayCastInput = function () {1887this.p1 = new b2Vec2();1888this.p2 = new b2Vec2();1889};1890b2RayCastInput.prototype.b2RayCastInput = function (p1, p2, maxFraction) {1891if (p1 === undefined) p1 = null;1892if (p2 === undefined) p2 = null;1893if (maxFraction === undefined) maxFraction = 1;1894if (p1) this.p1.SetV(p1);1895if (p2) this.p2.SetV(p2);1896this.maxFraction = maxFraction;1897}1898b2RayCastOutput.b2RayCastOutput = function () {1899this.normal = new b2Vec2();1900};1901b2Segment.b2Segment = function () {1902this.p1 = new b2Vec2();1903this.p2 = new b2Vec2();1904};1905b2Segment.prototype.TestSegment = function (lambda, normal, segment, maxLambda) {1906if (maxLambda === undefined) maxLambda = 0;1907var s = segment.p1;1908var rX = segment.p2.x - s.x;1909var rY = segment.p2.y - s.y;1910var dX = this.p2.x - this.p1.x;1911var dY = this.p2.y - this.p1.y;1912var nX = dY;1913var nY = (-dX);1914var k_slop = 100.0 * Number.MIN_VALUE;1915var denom = (-(rX * nX + rY * nY));1916if (denom > k_slop) {1917var bX = s.x - this.p1.x;1918var bY = s.y - this.p1.y;1919var a = (bX * nX + bY * nY);1920if (0.0 <= a && a <= maxLambda * denom) {1921var mu2 = (-rX * bY) + rY * bX;1922if ((-k_slop * denom) <= mu2 && mu2 <= denom * (1.0 + k_slop)) {1923a /= denom;1924var nLen = Math.sqrt(nX * nX + nY * nY);1925nX /= nLen;1926nY /= nLen;1927lambda[0] = a;1928normal.Set(nX, nY);1929return true;1930}1931}1932}1933return false;1934}1935b2Segment.prototype.Extend = function (aabb) {1936this.ExtendForward(aabb);1937this.ExtendBackward(aabb);1938}1939b2Segment.prototype.ExtendForward = function (aabb) {1940var dX = this.p2.x - this.p1.x;1941var dY = this.p2.y - this.p1.y;1942var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p1.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p1.x) / dX : Number.POSITIVE_INFINITY,1943dY > 0 ? (aabb.upperBound.y - this.p1.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p1.y) / dY : Number.POSITIVE_INFINITY);1944this.p2.x = this.p1.x + dX * lambda;1945this.p2.y = this.p1.y + dY * lambda;1946}1947b2Segment.prototype.ExtendBackward = function (aabb) {1948var dX = (-this.p2.x) + this.p1.x;1949var dY = (-this.p2.y) + this.p1.y;1950var lambda = Math.min(dX > 0 ? (aabb.upperBound.x - this.p2.x) / dX : dX < 0 ? (aabb.lowerBound.x - this.p2.x) / dX : Number.POSITIVE_INFINITY,1951dY > 0 ? (aabb.upperBound.y - this.p2.y) / dY : dY < 0 ? (aabb.lowerBound.y - this.p2.y) / dY : Number.POSITIVE_INFINITY);1952this.p1.x = this.p2.x + dX * lambda;1953this.p1.y = this.p2.y + dY * lambda;1954}1955b2SeparationFunction.b2SeparationFunction = function () {1956this.m_localPoint = new b2Vec2();1957this.m_axis = new b2Vec2();1958};1959b2SeparationFunction.prototype.Initialize = function (cache, proxyA, transformA, proxyB, transformB) {1960this.m_proxyA = proxyA;1961this.m_proxyB = proxyB;1962var count = parseInt(cache.count);1963b2Settings.b2Assert(0 < count && count < 3);1964var localPointA;1965var localPointA1;1966var localPointA2;1967var localPointB;1968var localPointB1;1969var localPointB2;1970var pointAX = 0;1971var pointAY = 0;1972var pointBX = 0;1973var pointBY = 0;1974var normalX = 0;1975var normalY = 0;1976var tMat;1977var tVec;1978var s = 0;1979var sgn = 0;1980if (count == 1) {1981this.m_type = b2SeparationFunction.e_points;1982localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);1983localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);1984tVec = localPointA;1985tMat = transformA.R;1986pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1987pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1988tVec = localPointB;1989tMat = transformB.R;1990pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);1991pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);1992this.m_axis.x = pointBX - pointAX;1993this.m_axis.y = pointBY - pointAY;1994this.m_axis.Normalize();1995}1996else if (cache.indexB[0] == cache.indexB[1]) {1997this.m_type = b2SeparationFunction.e_faceA;1998localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);1999localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);2000localPointB = this.m_proxyB.GetVertex(cache.indexB[0]);2001this.m_localPoint.x = 0.5 * (localPointA1.x + localPointA2.x);2002this.m_localPoint.y = 0.5 * (localPointA1.y + localPointA2.y);2003this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1.0);2004this.m_axis.Normalize();2005tVec = this.m_axis;2006tMat = transformA.R;2007normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2008normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2009tVec = this.m_localPoint;2010tMat = transformA.R;2011pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2012pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2013tVec = localPointB;2014tMat = transformB.R;2015pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2016pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2017s = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;2018if (s < 0.0) {2019this.m_axis.NegativeSelf();2020}2021}2022else if (cache.indexA[0] == cache.indexA[0]) {2023this.m_type = b2SeparationFunction.e_faceB;2024localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);2025localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);2026localPointA = this.m_proxyA.GetVertex(cache.indexA[0]);2027this.m_localPoint.x = 0.5 * (localPointB1.x + localPointB2.x);2028this.m_localPoint.y = 0.5 * (localPointB1.y + localPointB2.y);2029this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1.0);2030this.m_axis.Normalize();2031tVec = this.m_axis;2032tMat = transformB.R;2033normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2034normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2035tVec = this.m_localPoint;2036tMat = transformB.R;2037pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2038pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2039tVec = localPointA;2040tMat = transformA.R;2041pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2042pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2043s = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;2044if (s < 0.0) {2045this.m_axis.NegativeSelf();2046}2047}2048else {2049localPointA1 = this.m_proxyA.GetVertex(cache.indexA[0]);2050localPointA2 = this.m_proxyA.GetVertex(cache.indexA[1]);2051localPointB1 = this.m_proxyB.GetVertex(cache.indexB[0]);2052localPointB2 = this.m_proxyB.GetVertex(cache.indexB[1]);2053var pA = b2Math.MulX(transformA, localPointA);2054var dA = b2Math.MulMV(transformA.R, b2Math.SubtractVV(localPointA2, localPointA1));2055var pB = b2Math.MulX(transformB, localPointB);2056var dB = b2Math.MulMV(transformB.R, b2Math.SubtractVV(localPointB2, localPointB1));2057var a = dA.x * dA.x + dA.y * dA.y;2058var e = dB.x * dB.x + dB.y * dB.y;2059var r = b2Math.SubtractVV(dB, dA);2060var c = dA.x * r.x + dA.y * r.y;2061var f = dB.x * r.x + dB.y * r.y;2062var b = dA.x * dB.x + dA.y * dB.y;2063var denom = a * e - b * b;2064s = 0.0;2065if (denom != 0.0) {2066s = b2Math.Clamp((b * f - c * e) / denom, 0.0, 1.0);2067}2068var t = (b * s + f) / e;2069if (t < 0.0) {2070t = 0.0;2071s = b2Math.Clamp((b - c) / a, 0.0, 1.0);2072}2073localPointA = new b2Vec2();2074localPointA.x = localPointA1.x + s * (localPointA2.x - localPointA1.x);2075localPointA.y = localPointA1.y + s * (localPointA2.y - localPointA1.y);2076localPointB = new b2Vec2();2077localPointB.x = localPointB1.x + s * (localPointB2.x - localPointB1.x);2078localPointB.y = localPointB1.y + s * (localPointB2.y - localPointB1.y);2079if (s == 0.0 || s == 1.0) {2080this.m_type = b2SeparationFunction.e_faceB;2081this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointB2, localPointB1), 1.0);2082this.m_axis.Normalize();2083this.m_localPoint = localPointB;2084tVec = this.m_axis;2085tMat = transformB.R;2086normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2087normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2088tVec = this.m_localPoint;2089tMat = transformB.R;2090pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2091pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2092tVec = localPointA;2093tMat = transformA.R;2094pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2095pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2096sgn = (pointAX - pointBX) * normalX + (pointAY - pointBY) * normalY;2097if (s < 0.0) {2098this.m_axis.NegativeSelf();2099}2100}2101else {2102this.m_type = b2SeparationFunction.e_faceA;2103this.m_axis = b2Math.CrossVF(b2Math.SubtractVV(localPointA2, localPointA1), 1.0);2104this.m_localPoint = localPointA;2105tVec = this.m_axis;2106tMat = transformA.R;2107normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2108normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2109tVec = this.m_localPoint;2110tMat = transformA.R;2111pointAX = transformA.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2112pointAY = transformA.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2113tVec = localPointB;2114tMat = transformB.R;2115pointBX = transformB.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);2116pointBY = transformB.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);2117sgn = (pointBX - pointAX) * normalX + (pointBY - pointAY) * normalY;2118if (s < 0.0) {2119this.m_axis.NegativeSelf();2120}2121}2122}2123}2124b2SeparationFunction.prototype.Evaluate = function (transformA, transformB) {2125var axisA;2126var axisB;2127var localPointA;2128var localPointB;2129var pointA;2130var pointB;2131var seperation = 0;2132var normal;2133switch (this.m_type) {2134case b2SeparationFunction.e_points:2135{2136axisA = b2Math.MulTMV(transformA.R, this.m_axis);2137axisB = b2Math.MulTMV(transformB.R, this.m_axis.GetNegative());2138localPointA = this.m_proxyA.GetSupportVertex(axisA);2139localPointB = this.m_proxyB.GetSupportVertex(axisB);2140pointA = b2Math.MulX(transformA, localPointA);2141pointB = b2Math.MulX(transformB, localPointB);2142seperation = (pointB.x - pointA.x) * this.m_axis.x + (pointB.y - pointA.y) * this.m_axis.y;2143return seperation;2144}2145case b2SeparationFunction.e_faceA:2146{2147normal = b2Math.MulMV(transformA.R, this.m_axis);2148pointA = b2Math.MulX(transformA, this.m_localPoint);2149axisB = b2Math.MulTMV(transformB.R, normal.GetNegative());2150localPointB = this.m_proxyB.GetSupportVertex(axisB);2151pointB = b2Math.MulX(transformB, localPointB);2152seperation = (pointB.x - pointA.x) * normal.x + (pointB.y - pointA.y) * normal.y;2153return seperation;2154}2155case b2SeparationFunction.e_faceB:2156{2157normal = b2Math.MulMV(transformB.R, this.m_axis);2158pointB = b2Math.MulX(transformB, this.m_localPoint);2159axisA = b2Math.MulTMV(transformA.R, normal.GetNegative());2160localPointA = this.m_proxyA.GetSupportVertex(axisA);2161pointA = b2Math.MulX(transformA, localPointA);2162seperation = (pointA.x - pointB.x) * normal.x + (pointA.y - pointB.y) * normal.y;2163return seperation;2164}2165default:2166b2Settings.b2Assert(false);2167return 0.0;2168}2169}2170Box2D.postDefs.push(function () {2171Box2D.Collision.b2SeparationFunction.e_points = 0x01;2172Box2D.Collision.b2SeparationFunction.e_faceA = 0x02;2173Box2D.Collision.b2SeparationFunction.e_faceB = 0x04;2174});2175b2Simplex.b2Simplex = function () {2176this.m_v1 = new b2SimplexVertex();2177this.m_v2 = new b2SimplexVertex();2178this.m_v3 = new b2SimplexVertex();2179this.m_vertices = new Vector(3);2180};2181b2Simplex.prototype.b2Simplex = function () {2182this.m_vertices[0] = this.m_v1;2183this.m_vertices[1] = this.m_v2;2184this.m_vertices[2] = this.m_v3;2185}2186b2Simplex.prototype.ReadCache = function (cache, proxyA, transformA, proxyB, transformB) {2187b2Settings.b2Assert(0 <= cache.count && cache.count <= 3);2188var wALocal;2189var wBLocal;2190this.m_count = cache.count;2191var vertices = this.m_vertices;2192for (var i = 0; i < this.m_count; i++) {2193var v = vertices[i];2194v.indexA = cache.indexA[i];2195v.indexB = cache.indexB[i];2196wALocal = proxyA.GetVertex(v.indexA);2197wBLocal = proxyB.GetVertex(v.indexB);2198v.wA = b2Math.MulX(transformA, wALocal);2199v.wB = b2Math.MulX(transformB, wBLocal);2200v.w = b2Math.SubtractVV(v.wB, v.wA);2201v.a = 0;2202}2203if (this.m_count > 1) {2204var metric1 = cache.metric;2205var metric2 = this.GetMetric();2206if (metric2 < .5 * metric1 || 2.0 * metric1 < metric2 || metric2 < Number.MIN_VALUE) {2207this.m_count = 0;2208}2209}2210if (this.m_count == 0) {2211v = vertices[0];2212v.indexA = 0;2213v.indexB = 0;2214wALocal = proxyA.GetVertex(0);2215wBLocal = proxyB.GetVertex(0);2216v.wA = b2Math.MulX(transformA, wALocal);2217v.wB = b2Math.MulX(transformB, wBLocal);2218v.w = b2Math.SubtractVV(v.wB, v.wA);2219this.m_count = 1;2220}2221}2222b2Simplex.prototype.WriteCache = function (cache) {2223cache.metric = this.GetMetric();2224cache.count = Box2D.parseUInt(this.m_count);2225var vertices = this.m_vertices;2226for (var i = 0; i < this.m_count; i++) {2227cache.indexA[i] = Box2D.parseUInt(vertices[i].indexA);2228cache.indexB[i] = Box2D.parseUInt(vertices[i].indexB);2229}2230}2231b2Simplex.prototype.GetSearchDirection = function () {2232switch (this.m_count) {2233case 1:2234return this.m_v1.w.GetNegative();2235case 2:2236{2237var e12 = b2Math.SubtractVV(this.m_v2.w, this.m_v1.w);2238var sgn = b2Math.CrossVV(e12, this.m_v1.w.GetNegative());2239if (sgn > 0.0) {2240return b2Math.CrossFV(1.0, e12);2241}2242else {2243return b2Math.CrossVF(e12, 1.0);2244}2245}2246default:2247b2Settings.b2Assert(false);2248return new b2Vec2();2249}2250}2251b2Simplex.prototype.GetClosestPoint = function () {2252switch (this.m_count) {2253case 0:2254b2Settings.b2Assert(false);2255return new b2Vec2();2256case 1:2257return this.m_v1.w;2258case 2:2259return new b2Vec2(this.m_v1.a * this.m_v1.w.x + this.m_v2.a * this.m_v2.w.x, this.m_v1.a * this.m_v1.w.y + this.m_v2.a * this.m_v2.w.y);2260default:2261b2Settings.b2Assert(false);2262return new b2Vec2();2263}2264}2265b2Simplex.prototype.GetWitnessPoints = function (pA, pB) {2266switch (this.m_count) {2267case 0:2268b2Settings.b2Assert(false);2269break;2270case 1:2271pA.SetV(this.m_v1.wA);2272pB.SetV(this.m_v1.wB);2273break;2274case 2:2275pA.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x;2276pA.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y;2277pB.x = this.m_v1.a * this.m_v1.wB.x + this.m_v2.a * this.m_v2.wB.x;2278pB.y = this.m_v1.a * this.m_v1.wB.y + this.m_v2.a * this.m_v2.wB.y;2279break;2280case 3:2281pB.x = pA.x = this.m_v1.a * this.m_v1.wA.x + this.m_v2.a * this.m_v2.wA.x + this.m_v3.a * this.m_v3.wA.x;2282pB.y = pA.y = this.m_v1.a * this.m_v1.wA.y + this.m_v2.a * this.m_v2.wA.y + this.m_v3.a * this.m_v3.wA.y;2283break;2284default:2285b2Settings.b2Assert(false);2286break;2287}2288}2289b2Simplex.prototype.GetMetric = function () {2290switch (this.m_count) {2291case 0:2292b2Settings.b2Assert(false);2293return 0.0;2294case 1:2295return 0.0;2296case 2:2297return b2Math.SubtractVV(this.m_v1.w, this.m_v2.w).Length();2298case 3:2299return b2Math.CrossVV(b2Math.SubtractVV(this.m_v2.w, this.m_v1.w), b2Math.SubtractVV(this.m_v3.w, this.m_v1.w));2300default:2301b2Settings.b2Assert(false);2302return 0.0;2303}2304}2305b2Simplex.prototype.Solve2 = function () {2306var w1 = this.m_v1.w;2307var w2 = this.m_v2.w;2308var e12 = b2Math.SubtractVV(w2, w1);2309var d12_2 = (-(w1.x * e12.x + w1.y * e12.y));2310if (d12_2 <= 0.0) {2311this.m_v1.a = 1.0;2312this.m_count = 1;2313return;2314}2315var d12_1 = (w2.x * e12.x + w2.y * e12.y);2316if (d12_1 <= 0.0) {2317this.m_v2.a = 1.0;2318this.m_count = 1;2319this.m_v1.Set(this.m_v2);2320return;2321}2322var inv_d12 = 1.0 / (d12_1 + d12_2);2323this.m_v1.a = d12_1 * inv_d12;2324this.m_v2.a = d12_2 * inv_d12;2325this.m_count = 2;2326}2327b2Simplex.prototype.Solve3 = function () {2328var w1 = this.m_v1.w;2329var w2 = this.m_v2.w;2330var w3 = this.m_v3.w;2331var e12 = b2Math.SubtractVV(w2, w1);2332var w1e12 = b2Math.Dot(w1, e12);2333var w2e12 = b2Math.Dot(w2, e12);2334var d12_1 = w2e12;2335var d12_2 = (-w1e12);2336var e13 = b2Math.SubtractVV(w3, w1);2337var w1e13 = b2Math.Dot(w1, e13);2338var w3e13 = b2Math.Dot(w3, e13);2339var d13_1 = w3e13;2340var d13_2 = (-w1e13);2341var e23 = b2Math.SubtractVV(w3, w2);2342var w2e23 = b2Math.Dot(w2, e23);2343var w3e23 = b2Math.Dot(w3, e23);2344var d23_1 = w3e23;2345var d23_2 = (-w2e23);2346var n123 = b2Math.CrossVV(e12, e13);2347var d123_1 = n123 * b2Math.CrossVV(w2, w3);2348var d123_2 = n123 * b2Math.CrossVV(w3, w1);2349var d123_3 = n123 * b2Math.CrossVV(w1, w2);2350if (d12_2 <= 0.0 && d13_2 <= 0.0) {2351this.m_v1.a = 1.0;2352this.m_count = 1;2353return;2354}2355if (d12_1 > 0.0 && d12_2 > 0.0 && d123_3 <= 0.0) {2356var inv_d12 = 1.0 / (d12_1 + d12_2);2357this.m_v1.a = d12_1 * inv_d12;2358this.m_v2.a = d12_2 * inv_d12;2359this.m_count = 2;2360return;2361}2362if (d13_1 > 0.0 && d13_2 > 0.0 && d123_2 <= 0.0) {2363var inv_d13 = 1.0 / (d13_1 + d13_2);2364this.m_v1.a = d13_1 * inv_d13;2365this.m_v3.a = d13_2 * inv_d13;2366this.m_count = 2;2367this.m_v2.Set(this.m_v3);2368return;2369}2370if (d12_1 <= 0.0 && d23_2 <= 0.0) {2371this.m_v2.a = 1.0;2372this.m_count = 1;2373this.m_v1.Set(this.m_v2);2374return;2375}2376if (d13_1 <= 0.0 && d23_1 <= 0.0) {2377this.m_v3.a = 1.0;2378this.m_count = 1;2379this.m_v1.Set(this.m_v3);2380return;2381}2382if (d23_1 > 0.0 && d23_2 > 0.0 && d123_1 <= 0.0) {2383var inv_d23 = 1.0 / (d23_1 + d23_2);2384this.m_v2.a = d23_1 * inv_d23;2385this.m_v3.a = d23_2 * inv_d23;2386this.m_count = 2;2387this.m_v1.Set(this.m_v3);2388return;2389}2390var inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);2391this.m_v1.a = d123_1 * inv_d123;2392this.m_v2.a = d123_2 * inv_d123;2393this.m_v3.a = d123_3 * inv_d123;2394this.m_count = 3;2395}2396b2SimplexCache.b2SimplexCache = function () {2397this.indexA = new Vector_a2j_Number(3);2398this.indexB = new Vector_a2j_Number(3);2399};2400b2SimplexVertex.b2SimplexVertex = function () {};2401b2SimplexVertex.prototype.Set = function (other) {2402this.wA.SetV(other.wA);2403this.wB.SetV(other.wB);2404this.w.SetV(other.w);2405this.a = other.a;2406this.indexA = other.indexA;2407this.indexB = other.indexB;2408}2409b2TimeOfImpact.b2TimeOfImpact = function () {};2410b2TimeOfImpact.TimeOfImpact = function (input) {2411++b2TimeOfImpact.b2_toiCalls;2412var proxyA = input.proxyA;2413var proxyB = input.proxyB;2414var sweepA = input.sweepA;2415var sweepB = input.sweepB;2416b2Settings.b2Assert(sweepA.t0 == sweepB.t0);2417b2Settings.b2Assert(1.0 - sweepA.t0 > Number.MIN_VALUE);2418var radius = proxyA.m_radius + proxyB.m_radius;2419var tolerance = input.tolerance;2420var alpha = 0.0;2421var k_maxIterations = 1000;2422var iter = 0;2423var target = 0.0;2424b2TimeOfImpact.s_cache.count = 0;2425b2TimeOfImpact.s_distanceInput.useRadii = false;2426for (;;) {2427sweepA.GetTransform(b2TimeOfImpact.s_xfA, alpha);2428sweepB.GetTransform(b2TimeOfImpact.s_xfB, alpha);2429b2TimeOfImpact.s_distanceInput.proxyA = proxyA;2430b2TimeOfImpact.s_distanceInput.proxyB = proxyB;2431b2TimeOfImpact.s_distanceInput.transformA = b2TimeOfImpact.s_xfA;2432b2TimeOfImpact.s_distanceInput.transformB = b2TimeOfImpact.s_xfB;2433b2Distance.Distance(b2TimeOfImpact.s_distanceOutput, b2TimeOfImpact.s_cache, b2TimeOfImpact.s_distanceInput);2434if (b2TimeOfImpact.s_distanceOutput.distance <= 0.0) {2435alpha = 1.0;2436break;2437}2438b2TimeOfImpact.s_fcn.Initialize(b2TimeOfImpact.s_cache, proxyA, b2TimeOfImpact.s_xfA, proxyB, b2TimeOfImpact.s_xfB);2439var separation = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);2440if (separation <= 0.0) {2441alpha = 1.0;2442break;2443}2444if (iter == 0) {2445if (separation > radius) {2446target = b2Math.Max(radius - tolerance, 0.75 * radius);2447}2448else {2449target = b2Math.Max(separation - tolerance, 0.02 * radius);2450}2451}2452if (separation - target < 0.5 * tolerance) {2453if (iter == 0) {2454alpha = 1.0;2455break;2456}2457break;2458}2459var newAlpha = alpha; {2460var x1 = alpha;2461var x2 = 1.0;2462var f1 = separation;2463sweepA.GetTransform(b2TimeOfImpact.s_xfA, x2);2464sweepB.GetTransform(b2TimeOfImpact.s_xfB, x2);2465var f2 = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);2466if (f2 >= target) {2467alpha = 1.0;2468break;2469}2470var rootIterCount = 0;2471for (;;) {2472var x = 0;2473if (rootIterCount & 1) {2474x = x1 + (target - f1) * (x2 - x1) / (f2 - f1);2475}2476else {2477x = 0.5 * (x1 + x2);2478}2479sweepA.GetTransform(b2TimeOfImpact.s_xfA, x);2480sweepB.GetTransform(b2TimeOfImpact.s_xfB, x);2481var f = b2TimeOfImpact.s_fcn.Evaluate(b2TimeOfImpact.s_xfA, b2TimeOfImpact.s_xfB);2482if (b2Math.Abs(f - target) < 0.025 * tolerance) {2483newAlpha = x;2484break;2485}2486if (f > target) {2487x1 = x;2488f1 = f;2489}2490else {2491x2 = x;2492f2 = f;2493}++rootIterCount;2494++b2TimeOfImpact.b2_toiRootIters;2495if (rootIterCount == 50) {2496break;2497}2498}2499b2TimeOfImpact.b2_toiMaxRootIters = b2Math.Max(b2TimeOfImpact.b2_toiMaxRootIters, rootIterCount);2500}2501if (newAlpha < (1.0 + 100.0 * Number.MIN_VALUE) * alpha) {2502break;2503}2504alpha = newAlpha;2505iter++;2506++b2TimeOfImpact.b2_toiIters;2507if (iter == k_maxIterations) {2508break;2509}2510}2511b2TimeOfImpact.b2_toiMaxIters = b2Math.Max(b2TimeOfImpact.b2_toiMaxIters, iter);2512return alpha;2513}2514Box2D.postDefs.push(function () {2515Box2D.Collision.b2TimeOfImpact.b2_toiCalls = 0;2516Box2D.Collision.b2TimeOfImpact.b2_toiIters = 0;2517Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters = 0;2518Box2D.Collision.b2TimeOfImpact.b2_toiRootIters = 0;2519Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters = 0;2520Box2D.Collision.b2TimeOfImpact.s_cache = new b2SimplexCache();2521Box2D.Collision.b2TimeOfImpact.s_distanceInput = new b2DistanceInput();2522Box2D.Collision.b2TimeOfImpact.s_xfA = new b2Transform();2523Box2D.Collision.b2TimeOfImpact.s_xfB = new b2Transform();2524Box2D.Collision.b2TimeOfImpact.s_fcn = new b2SeparationFunction();2525Box2D.Collision.b2TimeOfImpact.s_distanceOutput = new b2DistanceOutput();2526});2527b2TOIInput.b2TOIInput = function () {2528this.proxyA = new b2DistanceProxy();2529this.proxyB = new b2DistanceProxy();2530this.sweepA = new b2Sweep();2531this.sweepB = new b2Sweep();2532};2533b2WorldManifold.b2WorldManifold = function () {2534this.m_normal = new b2Vec2();2535};2536b2WorldManifold.prototype.b2WorldManifold = function () {2537this.m_points = new Vector(b2Settings.b2_maxManifoldPoints);2538for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {2539this.m_points[i] = new b2Vec2();2540}2541}2542b2WorldManifold.prototype.Initialize = function (manifold, xfA, radiusA, xfB, radiusB) {2543if (radiusA === undefined) radiusA = 0;2544if (radiusB === undefined) radiusB = 0;2545if (manifold.m_pointCount == 0) {2546return;2547}2548var i = 0;2549var tVec;2550var tMat;2551var normalX = 0;2552var normalY = 0;2553var planePointX = 0;2554var planePointY = 0;2555var clipPointX = 0;2556var clipPointY = 0;2557switch (manifold.m_type) {2558case b2Manifold.e_circles:2559{2560tMat = xfA.R;2561tVec = manifold.m_localPoint;2562var pointAX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2563var pointAY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2564tMat = xfB.R;2565tVec = manifold.m_points[0].m_localPoint;2566var pointBX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2567var pointBY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2568var dX = pointBX - pointAX;2569var dY = pointBY - pointAY;2570var d2 = dX * dX + dY * dY;2571if (d2 > Number.MIN_VALUE * Number.MIN_VALUE) {2572var d = Math.sqrt(d2);2573this.m_normal.x = dX / d;2574this.m_normal.y = dY / d;2575}2576else {2577this.m_normal.x = 1;2578this.m_normal.y = 0;2579}2580var cAX = pointAX + radiusA * this.m_normal.x;2581var cAY = pointAY + radiusA * this.m_normal.y;2582var cBX = pointBX - radiusB * this.m_normal.x;2583var cBY = pointBY - radiusB * this.m_normal.y;2584this.m_points[0].x = 0.5 * (cAX + cBX);2585this.m_points[0].y = 0.5 * (cAY + cBY);2586}2587break;2588case b2Manifold.e_faceA:2589{2590tMat = xfA.R;2591tVec = manifold.m_localPlaneNormal;2592normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2593normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2594tMat = xfA.R;2595tVec = manifold.m_localPoint;2596planePointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2597planePointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2598this.m_normal.x = normalX;2599this.m_normal.y = normalY;2600for (i = 0;2601i < manifold.m_pointCount; i++) {2602tMat = xfB.R;2603tVec = manifold.m_points[i].m_localPoint;2604clipPointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2605clipPointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2606this.m_points[i].x = clipPointX + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalX;2607this.m_points[i].y = clipPointY + 0.5 * (radiusA - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusB) * normalY;2608}2609}2610break;2611case b2Manifold.e_faceB:2612{2613tMat = xfB.R;2614tVec = manifold.m_localPlaneNormal;2615normalX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2616normalY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2617tMat = xfB.R;2618tVec = manifold.m_localPoint;2619planePointX = xfB.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2620planePointY = xfB.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2621this.m_normal.x = (-normalX);2622this.m_normal.y = (-normalY);2623for (i = 0;2624i < manifold.m_pointCount; i++) {2625tMat = xfA.R;2626tVec = manifold.m_points[i].m_localPoint;2627clipPointX = xfA.position.x + tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;2628clipPointY = xfA.position.y + tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;2629this.m_points[i].x = clipPointX + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalX;2630this.m_points[i].y = clipPointY + 0.5 * (radiusB - (clipPointX - planePointX) * normalX - (clipPointY - planePointY) * normalY - radiusA) * normalY;2631}2632}2633break;2634}2635}2636ClipVertex.ClipVertex = function () {2637this.v = new b2Vec2();2638this.id = new b2ContactID();2639};2640ClipVertex.prototype.Set = function (other) {2641this.v.SetV(other.v);2642this.id.Set(other.id);2643}2644Features.Features = function () {};2645Object.defineProperty(Features.prototype, 'referenceEdge', {2646enumerable: false,2647configurable: true,2648get: function () {2649return this._referenceEdge;2650}2651});2652Object.defineProperty(Features.prototype, 'referenceEdge', {2653enumerable: false,2654configurable: true,2655set: function (value) {2656if (value === undefined) value = 0;2657this._referenceEdge = value;2658this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceEdge & 0x000000ff);2659}2660});2661Object.defineProperty(Features.prototype, 'incidentEdge', {2662enumerable: false,2663configurable: true,2664get: function () {2665return this._incidentEdge;2666}2667});2668Object.defineProperty(Features.prototype, 'incidentEdge', {2669enumerable: false,2670configurable: true,2671set: function (value) {2672if (value === undefined) value = 0;2673this._incidentEdge = value;2674this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);2675}2676});2677Object.defineProperty(Features.prototype, 'incidentVertex', {2678enumerable: false,2679configurable: true,2680get: function () {2681return this._incidentVertex;2682}2683});2684Object.defineProperty(Features.prototype, 'incidentVertex', {2685enumerable: false,2686configurable: true,2687set: function (value) {2688if (value === undefined) value = 0;2689this._incidentVertex = value;2690this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);2691}2692});2693Object.defineProperty(Features.prototype, 'flip', {2694enumerable: false,2695configurable: true,2696get: function () {2697return this._flip;2698}2699});2700Object.defineProperty(Features.prototype, 'flip', {2701enumerable: false,2702configurable: true,2703set: function (value) {2704if (value === undefined) value = 0;2705this._flip = value;2706this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);2707}2708});2709})();2710(function () {2711var b2Color = Box2D.Common.b2Color,2712b2internal = Box2D.Common.b2internal,2713b2Settings = Box2D.Common.b2Settings,2714b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,2715b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,2716b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,2717b2MassData = Box2D.Collision.Shapes.b2MassData,2718b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,2719b2Shape = Box2D.Collision.Shapes.b2Shape,2720b2Mat22 = Box2D.Common.Math.b2Mat22,2721b2Mat33 = Box2D.Common.Math.b2Mat33,2722b2Math = Box2D.Common.Math.b2Math,2723b2Sweep = Box2D.Common.Math.b2Sweep,2724b2Transform = Box2D.Common.Math.b2Transform,2725b2Vec2 = Box2D.Common.Math.b2Vec2,2726b2Vec3 = Box2D.Common.Math.b2Vec3,2727b2Body = Box2D.Dynamics.b2Body,2728b2BodyDef = Box2D.Dynamics.b2BodyDef,2729b2ContactFilter = Box2D.Dynamics.b2ContactFilter,2730b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,2731b2ContactListener = Box2D.Dynamics.b2ContactListener,2732b2ContactManager = Box2D.Dynamics.b2ContactManager,2733b2DebugDraw = Box2D.Dynamics.b2DebugDraw,2734b2DestructionListener = Box2D.Dynamics.b2DestructionListener,2735b2FilterData = Box2D.Dynamics.b2FilterData,2736b2Fixture = Box2D.Dynamics.b2Fixture,2737b2FixtureDef = Box2D.Dynamics.b2FixtureDef,2738b2Island = Box2D.Dynamics.b2Island,2739b2TimeStep = Box2D.Dynamics.b2TimeStep,2740b2World = Box2D.Dynamics.b2World,2741b2AABB = Box2D.Collision.b2AABB,2742b2Bound = Box2D.Collision.b2Bound,2743b2BoundValues = Box2D.Collision.b2BoundValues,2744b2Collision = Box2D.Collision.b2Collision,2745b2ContactID = Box2D.Collision.b2ContactID,2746b2ContactPoint = Box2D.Collision.b2ContactPoint,2747b2Distance = Box2D.Collision.b2Distance,2748b2DistanceInput = Box2D.Collision.b2DistanceInput,2749b2DistanceOutput = Box2D.Collision.b2DistanceOutput,2750b2DistanceProxy = Box2D.Collision.b2DistanceProxy,2751b2DynamicTree = Box2D.Collision.b2DynamicTree,2752b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,2753b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,2754b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,2755b2Manifold = Box2D.Collision.b2Manifold,2756b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,2757b2Point = Box2D.Collision.b2Point,2758b2RayCastInput = Box2D.Collision.b2RayCastInput,2759b2RayCastOutput = Box2D.Collision.b2RayCastOutput,2760b2Segment = Box2D.Collision.b2Segment,2761b2SeparationFunction = Box2D.Collision.b2SeparationFunction,2762b2Simplex = Box2D.Collision.b2Simplex,2763b2SimplexCache = Box2D.Collision.b2SimplexCache,2764b2SimplexVertex = Box2D.Collision.b2SimplexVertex,2765b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,2766b2TOIInput = Box2D.Collision.b2TOIInput,2767b2WorldManifold = Box2D.Collision.b2WorldManifold,2768ClipVertex = Box2D.Collision.ClipVertex,2769Features = Box2D.Collision.Features,2770IBroadPhase = Box2D.Collision.IBroadPhase;27712772Box2D.inherit(b2CircleShape, Box2D.Collision.Shapes.b2Shape);2773b2CircleShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;2774b2CircleShape.b2CircleShape = function () {2775Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);2776this.m_p = new b2Vec2();2777};2778b2CircleShape.prototype.Copy = function () {2779var s = new b2CircleShape();2780s.Set(this);2781return s;2782}2783b2CircleShape.prototype.Set = function (other) {2784this.__super.Set.call(this, other);2785if (Box2D.is(other, b2CircleShape)) {2786var other2 = (other instanceof b2CircleShape ? other : null);2787this.m_p.SetV(other2.m_p);2788}2789}2790b2CircleShape.prototype.TestPoint = function (transform, p) {2791var tMat = transform.R;2792var dX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);2793var dY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);2794dX = p.x - dX;2795dY = p.y - dY;2796return (dX * dX + dY * dY) <= this.m_radius * this.m_radius;2797}2798b2CircleShape.prototype.RayCast = function (output, input, transform) {2799var tMat = transform.R;2800var positionX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);2801var positionY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);2802var sX = input.p1.x - positionX;2803var sY = input.p1.y - positionY;2804var b = (sX * sX + sY * sY) - this.m_radius * this.m_radius;2805var rX = input.p2.x - input.p1.x;2806var rY = input.p2.y - input.p1.y;2807var c = (sX * rX + sY * rY);2808var rr = (rX * rX + rY * rY);2809var sigma = c * c - rr * b;2810if (sigma < 0.0 || rr < Number.MIN_VALUE) {2811return false;2812}2813var a = (-(c + Math.sqrt(sigma)));2814if (0.0 <= a && a <= input.maxFraction * rr) {2815a /= rr;2816output.fraction = a;2817output.normal.x = sX + a * rX;2818output.normal.y = sY + a * rY;2819output.normal.Normalize();2820return true;2821}2822return false;2823}2824b2CircleShape.prototype.ComputeAABB = function (aabb, transform) {2825var tMat = transform.R;2826var pX = transform.position.x + (tMat.col1.x * this.m_p.x + tMat.col2.x * this.m_p.y);2827var pY = transform.position.y + (tMat.col1.y * this.m_p.x + tMat.col2.y * this.m_p.y);2828aabb.lowerBound.Set(pX - this.m_radius, pY - this.m_radius);2829aabb.upperBound.Set(pX + this.m_radius, pY + this.m_radius);2830}2831b2CircleShape.prototype.ComputeMass = function (massData, density) {2832if (density === undefined) density = 0;2833massData.mass = density * b2Settings.b2_pi * this.m_radius * this.m_radius;2834massData.center.SetV(this.m_p);2835massData.I = massData.mass * (0.5 * this.m_radius * this.m_radius + (this.m_p.x * this.m_p.x + this.m_p.y * this.m_p.y));2836}2837b2CircleShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {2838if (offset === undefined) offset = 0;2839var p = b2Math.MulX(xf, this.m_p);2840var l = (-(b2Math.Dot(normal, p) - offset));2841if (l < (-this.m_radius) + Number.MIN_VALUE) {2842return 0;2843}2844if (l > this.m_radius) {2845c.SetV(p);2846return Math.PI * this.m_radius * this.m_radius;2847}2848var r2 = this.m_radius * this.m_radius;2849var l2 = l * l;2850var area = r2 * (Math.asin(l / this.m_radius) + Math.PI / 2) + l * Math.sqrt(r2 - l2);2851var com = (-2 / 3 * Math.pow(r2 - l2, 1.5) / area);2852c.x = p.x + normal.x * com;2853c.y = p.y + normal.y * com;2854return area;2855}2856b2CircleShape.prototype.GetLocalPosition = function () {2857return this.m_p;2858}2859b2CircleShape.prototype.SetLocalPosition = function (position) {2860this.m_p.SetV(position);2861}2862b2CircleShape.prototype.GetRadius = function () {2863return this.m_radius;2864}2865b2CircleShape.prototype.SetRadius = function (radius) {2866if (radius === undefined) radius = 0;2867this.m_radius = radius;2868}2869b2CircleShape.prototype.b2CircleShape = function (radius) {2870if (radius === undefined) radius = 0;2871this.__super.b2Shape.call(this);2872this.m_type = b2Shape.e_circleShape;2873this.m_radius = radius;2874}2875b2EdgeChainDef.b2EdgeChainDef = function () {};2876b2EdgeChainDef.prototype.b2EdgeChainDef = function () {2877this.vertexCount = 0;2878this.isALoop = true;2879this.vertices = [];2880}2881Box2D.inherit(b2EdgeShape, Box2D.Collision.Shapes.b2Shape);2882b2EdgeShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;2883b2EdgeShape.b2EdgeShape = function () {2884Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);2885this.s_supportVec = new b2Vec2();2886this.m_v1 = new b2Vec2();2887this.m_v2 = new b2Vec2();2888this.m_coreV1 = new b2Vec2();2889this.m_coreV2 = new b2Vec2();2890this.m_normal = new b2Vec2();2891this.m_direction = new b2Vec2();2892this.m_cornerDir1 = new b2Vec2();2893this.m_cornerDir2 = new b2Vec2();2894};2895b2EdgeShape.prototype.TestPoint = function (transform, p) {2896return false;2897}2898b2EdgeShape.prototype.RayCast = function (output, input, transform) {2899var tMat;2900var rX = input.p2.x - input.p1.x;2901var rY = input.p2.y - input.p1.y;2902tMat = transform.R;2903var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);2904var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);2905var nX = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y) - v1Y;2906var nY = (-(transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y) - v1X));2907var k_slop = 100.0 * Number.MIN_VALUE;2908var denom = (-(rX * nX + rY * nY));2909if (denom > k_slop) {2910var bX = input.p1.x - v1X;2911var bY = input.p1.y - v1Y;2912var a = (bX * nX + bY * nY);2913if (0.0 <= a && a <= input.maxFraction * denom) {2914var mu2 = (-rX * bY) + rY * bX;2915if ((-k_slop * denom) <= mu2 && mu2 <= denom * (1.0 + k_slop)) {2916a /= denom;2917output.fraction = a;2918var nLen = Math.sqrt(nX * nX + nY * nY);2919output.normal.x = nX / nLen;2920output.normal.y = nY / nLen;2921return true;2922}2923}2924}2925return false;2926}2927b2EdgeShape.prototype.ComputeAABB = function (aabb, transform) {2928var tMat = transform.R;2929var v1X = transform.position.x + (tMat.col1.x * this.m_v1.x + tMat.col2.x * this.m_v1.y);2930var v1Y = transform.position.y + (tMat.col1.y * this.m_v1.x + tMat.col2.y * this.m_v1.y);2931var v2X = transform.position.x + (tMat.col1.x * this.m_v2.x + tMat.col2.x * this.m_v2.y);2932var v2Y = transform.position.y + (tMat.col1.y * this.m_v2.x + tMat.col2.y * this.m_v2.y);2933if (v1X < v2X) {2934aabb.lowerBound.x = v1X;2935aabb.upperBound.x = v2X;2936}2937else {2938aabb.lowerBound.x = v2X;2939aabb.upperBound.x = v1X;2940}2941if (v1Y < v2Y) {2942aabb.lowerBound.y = v1Y;2943aabb.upperBound.y = v2Y;2944}2945else {2946aabb.lowerBound.y = v2Y;2947aabb.upperBound.y = v1Y;2948}2949}2950b2EdgeShape.prototype.ComputeMass = function (massData, density) {2951if (density === undefined) density = 0;2952massData.mass = 0;2953massData.center.SetV(this.m_v1);2954massData.I = 0;2955}2956b2EdgeShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {2957if (offset === undefined) offset = 0;2958var v0 = new b2Vec2(normal.x * offset, normal.y * offset);2959var v1 = b2Math.MulX(xf, this.m_v1);2960var v2 = b2Math.MulX(xf, this.m_v2);2961var d1 = b2Math.Dot(normal, v1) - offset;2962var d2 = b2Math.Dot(normal, v2) - offset;2963if (d1 > 0) {2964if (d2 > 0) {2965return 0;2966}2967else {2968v1.x = (-d2 / (d1 - d2) * v1.x) + d1 / (d1 - d2) * v2.x;2969v1.y = (-d2 / (d1 - d2) * v1.y) + d1 / (d1 - d2) * v2.y;2970}2971}2972else {2973if (d2 > 0) {2974v2.x = (-d2 / (d1 - d2) * v1.x) + d1 / (d1 - d2) * v2.x;2975v2.y = (-d2 / (d1 - d2) * v1.y) + d1 / (d1 - d2) * v2.y;2976}2977else {}2978}2979c.x = (v0.x + v1.x + v2.x) / 3;2980c.y = (v0.y + v1.y + v2.y) / 3;2981return 0.5 * ((v1.x - v0.x) * (v2.y - v0.y) - (v1.y - v0.y) * (v2.x - v0.x));2982}2983b2EdgeShape.prototype.GetLength = function () {2984return this.m_length;2985}2986b2EdgeShape.prototype.GetVertex1 = function () {2987return this.m_v1;2988}2989b2EdgeShape.prototype.GetVertex2 = function () {2990return this.m_v2;2991}2992b2EdgeShape.prototype.GetCoreVertex1 = function () {2993return this.m_coreV1;2994}2995b2EdgeShape.prototype.GetCoreVertex2 = function () {2996return this.m_coreV2;2997}2998b2EdgeShape.prototype.GetNormalVector = function () {2999return this.m_normal;3000}3001b2EdgeShape.prototype.GetDirectionVector = function () {3002return this.m_direction;3003}3004b2EdgeShape.prototype.GetCorner1Vector = function () {3005return this.m_cornerDir1;3006}3007b2EdgeShape.prototype.GetCorner2Vector = function () {3008return this.m_cornerDir2;3009}3010b2EdgeShape.prototype.Corner1IsConvex = function () {3011return this.m_cornerConvex1;3012}3013b2EdgeShape.prototype.Corner2IsConvex = function () {3014return this.m_cornerConvex2;3015}3016b2EdgeShape.prototype.GetFirstVertex = function (xf) {3017var tMat = xf.R;3018return new b2Vec2(xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y), xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y));3019}3020b2EdgeShape.prototype.GetNextEdge = function () {3021return this.m_nextEdge;3022}3023b2EdgeShape.prototype.GetPrevEdge = function () {3024return this.m_prevEdge;3025}3026b2EdgeShape.prototype.Support = function (xf, dX, dY) {3027if (dX === undefined) dX = 0;3028if (dY === undefined) dY = 0;3029var tMat = xf.R;3030var v1X = xf.position.x + (tMat.col1.x * this.m_coreV1.x + tMat.col2.x * this.m_coreV1.y);3031var v1Y = xf.position.y + (tMat.col1.y * this.m_coreV1.x + tMat.col2.y * this.m_coreV1.y);3032var v2X = xf.position.x + (tMat.col1.x * this.m_coreV2.x + tMat.col2.x * this.m_coreV2.y);3033var v2Y = xf.position.y + (tMat.col1.y * this.m_coreV2.x + tMat.col2.y * this.m_coreV2.y);3034if ((v1X * dX + v1Y * dY) > (v2X * dX + v2Y * dY)) {3035this.s_supportVec.x = v1X;3036this.s_supportVec.y = v1Y;3037}3038else {3039this.s_supportVec.x = v2X;3040this.s_supportVec.y = v2Y;3041}3042return this.s_supportVec;3043}3044b2EdgeShape.prototype.b2EdgeShape = function (v1, v2) {3045this.__super.b2Shape.call(this);3046this.m_type = b2Shape.e_edgeShape;3047this.m_prevEdge = null;3048this.m_nextEdge = null;3049this.m_v1 = v1;3050this.m_v2 = v2;3051this.m_direction.Set(this.m_v2.x - this.m_v1.x, this.m_v2.y - this.m_v1.y);3052this.m_length = this.m_direction.Normalize();3053this.m_normal.Set(this.m_direction.y, (-this.m_direction.x));3054this.m_coreV1.Set((-b2Settings.b2_toiSlop * (this.m_normal.x - this.m_direction.x)) + this.m_v1.x, (-b2Settings.b2_toiSlop * (this.m_normal.y - this.m_direction.y)) + this.m_v1.y);3055this.m_coreV2.Set((-b2Settings.b2_toiSlop * (this.m_normal.x + this.m_direction.x)) + this.m_v2.x, (-b2Settings.b2_toiSlop * (this.m_normal.y + this.m_direction.y)) + this.m_v2.y);3056this.m_cornerDir1 = this.m_normal;3057this.m_cornerDir2.Set((-this.m_normal.x), (-this.m_normal.y));3058}3059b2EdgeShape.prototype.SetPrevEdge = function (edge, core, cornerDir, convex) {3060this.m_prevEdge = edge;3061this.m_coreV1 = core;3062this.m_cornerDir1 = cornerDir;3063this.m_cornerConvex1 = convex;3064}3065b2EdgeShape.prototype.SetNextEdge = function (edge, core, cornerDir, convex) {3066this.m_nextEdge = edge;3067this.m_coreV2 = core;3068this.m_cornerDir2 = cornerDir;3069this.m_cornerConvex2 = convex;3070}3071b2MassData.b2MassData = function () {3072this.mass = 0.0;3073this.center = new b2Vec2(0, 0);3074this.I = 0.0;3075};3076Box2D.inherit(b2PolygonShape, Box2D.Collision.Shapes.b2Shape);3077b2PolygonShape.prototype.__super = Box2D.Collision.Shapes.b2Shape.prototype;3078b2PolygonShape.b2PolygonShape = function () {3079Box2D.Collision.Shapes.b2Shape.b2Shape.apply(this, arguments);3080};3081b2PolygonShape.prototype.Copy = function () {3082var s = new b2PolygonShape();3083s.Set(this);3084return s;3085}3086b2PolygonShape.prototype.Set = function (other) {3087this.__super.Set.call(this, other);3088if (Box2D.is(other, b2PolygonShape)) {3089var other2 = (other instanceof b2PolygonShape ? other : null);3090this.m_centroid.SetV(other2.m_centroid);3091this.m_vertexCount = other2.m_vertexCount;3092this.Reserve(this.m_vertexCount);3093for (var i = 0; i < this.m_vertexCount; i++) {3094this.m_vertices[i].SetV(other2.m_vertices[i]);3095this.m_normals[i].SetV(other2.m_normals[i]);3096}3097}3098}3099b2PolygonShape.prototype.SetAsArray = function (vertices, vertexCount) {3100if (vertexCount === undefined) vertexCount = 0;3101var v = new Vector();3102var i = 0,3103tVec;3104for (i = 0;3105i < vertices.length; ++i) {3106tVec = vertices[i];3107v.push(tVec);3108}3109this.SetAsVector(v, vertexCount);3110}3111b2PolygonShape.AsArray = function (vertices, vertexCount) {3112if (vertexCount === undefined) vertexCount = 0;3113var polygonShape = new b2PolygonShape();3114polygonShape.SetAsArray(vertices, vertexCount);3115return polygonShape;3116}3117b2PolygonShape.prototype.SetAsVector = function (vertices, vertexCount) {3118if (vertexCount === undefined) vertexCount = 0;3119if (vertexCount == 0) vertexCount = vertices.length;3120b2Settings.b2Assert(2 <= vertexCount);3121this.m_vertexCount = vertexCount;3122this.Reserve(vertexCount);3123var i = 0;3124for (i = 0;3125i < this.m_vertexCount; i++) {3126this.m_vertices[i].SetV(vertices[i]);3127}3128for (i = 0;3129i < this.m_vertexCount; ++i) {3130var i1 = parseInt(i);3131var i2 = parseInt(i + 1 < this.m_vertexCount ? i + 1 : 0);3132var edge = b2Math.SubtractVV(this.m_vertices[i2], this.m_vertices[i1]);3133b2Settings.b2Assert(edge.LengthSquared() > Number.MIN_VALUE);3134this.m_normals[i].SetV(b2Math.CrossVF(edge, 1.0));3135this.m_normals[i].Normalize();3136}3137this.m_centroid = b2PolygonShape.ComputeCentroid(this.m_vertices, this.m_vertexCount);3138}3139b2PolygonShape.AsVector = function (vertices, vertexCount) {3140if (vertexCount === undefined) vertexCount = 0;3141var polygonShape = new b2PolygonShape();3142polygonShape.SetAsVector(vertices, vertexCount);3143return polygonShape;3144}3145b2PolygonShape.prototype.SetAsBox = function (hx, hy) {3146if (hx === undefined) hx = 0;3147if (hy === undefined) hy = 0;3148this.m_vertexCount = 4;3149this.Reserve(4);3150this.m_vertices[0].Set((-hx), (-hy));3151this.m_vertices[1].Set(hx, (-hy));3152this.m_vertices[2].Set(hx, hy);3153this.m_vertices[3].Set((-hx), hy);3154this.m_normals[0].Set(0.0, (-1.0));3155this.m_normals[1].Set(1.0, 0.0);3156this.m_normals[2].Set(0.0, 1.0);3157this.m_normals[3].Set((-1.0), 0.0);3158this.m_centroid.SetZero();3159}3160b2PolygonShape.AsBox = function (hx, hy) {3161if (hx === undefined) hx = 0;3162if (hy === undefined) hy = 0;3163var polygonShape = new b2PolygonShape();3164polygonShape.SetAsBox(hx, hy);3165return polygonShape;3166}3167b2PolygonShape.prototype.SetAsOrientedBox = function (hx, hy, center, angle) {3168if (hx === undefined) hx = 0;3169if (hy === undefined) hy = 0;3170if (center === undefined) center = null;3171if (angle === undefined) angle = 0.0;3172this.m_vertexCount = 4;3173this.Reserve(4);3174this.m_vertices[0].Set((-hx), (-hy));3175this.m_vertices[1].Set(hx, (-hy));3176this.m_vertices[2].Set(hx, hy);3177this.m_vertices[3].Set((-hx), hy);3178this.m_normals[0].Set(0.0, (-1.0));3179this.m_normals[1].Set(1.0, 0.0);3180this.m_normals[2].Set(0.0, 1.0);3181this.m_normals[3].Set((-1.0), 0.0);3182this.m_centroid = center;3183var xf = new b2Transform();3184xf.position = center;3185xf.R.Set(angle);3186for (var i = 0; i < this.m_vertexCount; ++i) {3187this.m_vertices[i] = b2Math.MulX(xf, this.m_vertices[i]);3188this.m_normals[i] = b2Math.MulMV(xf.R, this.m_normals[i]);3189}3190}3191b2PolygonShape.AsOrientedBox = function (hx, hy, center, angle) {3192if (hx === undefined) hx = 0;3193if (hy === undefined) hy = 0;3194if (center === undefined) center = null;3195if (angle === undefined) angle = 0.0;3196var polygonShape = new b2PolygonShape();3197polygonShape.SetAsOrientedBox(hx, hy, center, angle);3198return polygonShape;3199}3200b2PolygonShape.prototype.SetAsEdge = function (v1, v2) {3201this.m_vertexCount = 2;3202this.Reserve(2);3203this.m_vertices[0].SetV(v1);3204this.m_vertices[1].SetV(v2);3205this.m_centroid.x = 0.5 * (v1.x + v2.x);3206this.m_centroid.y = 0.5 * (v1.y + v2.y);3207this.m_normals[0] = b2Math.CrossVF(b2Math.SubtractVV(v2, v1), 1.0);3208this.m_normals[0].Normalize();3209this.m_normals[1].x = (-this.m_normals[0].x);3210this.m_normals[1].y = (-this.m_normals[0].y);3211}3212b2PolygonShape.AsEdge = function (v1, v2) {3213var polygonShape = new b2PolygonShape();3214polygonShape.SetAsEdge(v1, v2);3215return polygonShape;3216}3217b2PolygonShape.prototype.TestPoint = function (xf, p) {3218var tVec;3219var tMat = xf.R;3220var tX = p.x - xf.position.x;3221var tY = p.y - xf.position.y;3222var pLocalX = (tX * tMat.col1.x + tY * tMat.col1.y);3223var pLocalY = (tX * tMat.col2.x + tY * tMat.col2.y);3224for (var i = 0; i < this.m_vertexCount; ++i) {3225tVec = this.m_vertices[i];3226tX = pLocalX - tVec.x;3227tY = pLocalY - tVec.y;3228tVec = this.m_normals[i];3229var dot = (tVec.x * tX + tVec.y * tY);3230if (dot > 0.0) {3231return false;3232}3233}3234return true;3235}3236b2PolygonShape.prototype.RayCast = function (output, input, transform) {3237var lower = 0.0;3238var upper = input.maxFraction;3239var tX = 0;3240var tY = 0;3241var tMat;3242var tVec;3243tX = input.p1.x - transform.position.x;3244tY = input.p1.y - transform.position.y;3245tMat = transform.R;3246var p1X = (tX * tMat.col1.x + tY * tMat.col1.y);3247var p1Y = (tX * tMat.col2.x + tY * tMat.col2.y);3248tX = input.p2.x - transform.position.x;3249tY = input.p2.y - transform.position.y;3250tMat = transform.R;3251var p2X = (tX * tMat.col1.x + tY * tMat.col1.y);3252var p2Y = (tX * tMat.col2.x + tY * tMat.col2.y);3253var dX = p2X - p1X;3254var dY = p2Y - p1Y;3255var index = parseInt((-1));3256for (var i = 0; i < this.m_vertexCount; ++i) {3257tVec = this.m_vertices[i];3258tX = tVec.x - p1X;3259tY = tVec.y - p1Y;3260tVec = this.m_normals[i];3261var numerator = (tVec.x * tX + tVec.y * tY);3262var denominator = (tVec.x * dX + tVec.y * dY);3263if (denominator == 0.0) {3264if (numerator < 0.0) {3265return false;3266}3267}3268else {3269if (denominator < 0.0 && numerator < lower * denominator) {3270lower = numerator / denominator;3271index = i;3272}3273else if (denominator > 0.0 && numerator < upper * denominator) {3274upper = numerator / denominator;3275}3276}3277if (upper < lower - Number.MIN_VALUE) {3278return false;3279}3280}3281if (index >= 0) {3282output.fraction = lower;3283tMat = transform.R;3284tVec = this.m_normals[index];3285output.normal.x = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);3286output.normal.y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);3287return true;3288}3289return false;3290}3291b2PolygonShape.prototype.ComputeAABB = function (aabb, xf) {3292var tMat = xf.R;3293var tVec = this.m_vertices[0];3294var lowerX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);3295var lowerY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);3296var upperX = lowerX;3297var upperY = lowerY;3298for (var i = 1; i < this.m_vertexCount; ++i) {3299tVec = this.m_vertices[i];3300var vX = xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);3301var vY = xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);3302lowerX = lowerX < vX ? lowerX : vX;3303lowerY = lowerY < vY ? lowerY : vY;3304upperX = upperX > vX ? upperX : vX;3305upperY = upperY > vY ? upperY : vY;3306}3307aabb.lowerBound.x = lowerX - this.m_radius;3308aabb.lowerBound.y = lowerY - this.m_radius;3309aabb.upperBound.x = upperX + this.m_radius;3310aabb.upperBound.y = upperY + this.m_radius;3311}3312b2PolygonShape.prototype.ComputeMass = function (massData, density) {3313if (density === undefined) density = 0;3314if (this.m_vertexCount == 2) {3315massData.center.x = 0.5 * (this.m_vertices[0].x + this.m_vertices[1].x);3316massData.center.y = 0.5 * (this.m_vertices[0].y + this.m_vertices[1].y);3317massData.mass = 0.0;3318massData.I = 0.0;3319return;3320}3321var centerX = 0.0;3322var centerY = 0.0;3323var area = 0.0;3324var I = 0.0;3325var p1X = 0.0;3326var p1Y = 0.0;3327var k_inv3 = 1.0 / 3.0;3328for (var i = 0; i < this.m_vertexCount; ++i) {3329var p2 = this.m_vertices[i];3330var p3 = i + 1 < this.m_vertexCount ? this.m_vertices[parseInt(i + 1)] : this.m_vertices[0];3331var e1X = p2.x - p1X;3332var e1Y = p2.y - p1Y;3333var e2X = p3.x - p1X;3334var e2Y = p3.y - p1Y;3335var D = e1X * e2Y - e1Y * e2X;3336var triangleArea = 0.5 * D;area += triangleArea;3337centerX += triangleArea * k_inv3 * (p1X + p2.x + p3.x);3338centerY += triangleArea * k_inv3 * (p1Y + p2.y + p3.y);3339var px = p1X;3340var py = p1Y;3341var ex1 = e1X;3342var ey1 = e1Y;3343var ex2 = e2X;3344var ey2 = e2Y;3345var intx2 = k_inv3 * (0.25 * (ex1 * ex1 + ex2 * ex1 + ex2 * ex2) + (px * ex1 + px * ex2)) + 0.5 * px * px;3346var inty2 = k_inv3 * (0.25 * (ey1 * ey1 + ey2 * ey1 + ey2 * ey2) + (py * ey1 + py * ey2)) + 0.5 * py * py;I += D * (intx2 + inty2);3347}3348massData.mass = density * area;3349centerX *= 1.0 / area;3350centerY *= 1.0 / area;3351massData.center.Set(centerX, centerY);3352massData.I = density * I;3353}3354b2PolygonShape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {3355if (offset === undefined) offset = 0;3356var normalL = b2Math.MulTMV(xf.R, normal);3357var offsetL = offset - b2Math.Dot(normal, xf.position);3358var depths = new Vector_a2j_Number();3359var diveCount = 0;3360var intoIndex = parseInt((-1));3361var outoIndex = parseInt((-1));3362var lastSubmerged = false;3363var i = 0;3364for (i = 0;3365i < this.m_vertexCount; ++i) {3366depths[i] = b2Math.Dot(normalL, this.m_vertices[i]) - offsetL;3367var isSubmerged = depths[i] < (-Number.MIN_VALUE);3368if (i > 0) {3369if (isSubmerged) {3370if (!lastSubmerged) {3371intoIndex = i - 1;3372diveCount++;3373}3374}3375else {3376if (lastSubmerged) {3377outoIndex = i - 1;3378diveCount++;3379}3380}3381}3382lastSubmerged = isSubmerged;3383}3384switch (diveCount) {3385case 0:3386if (lastSubmerged) {3387var md = new b2MassData();3388this.ComputeMass(md, 1);3389c.SetV(b2Math.MulX(xf, md.center));3390return md.mass;3391}3392else {3393return 0;3394}3395break;3396case 1:3397if (intoIndex == (-1)) {3398intoIndex = this.m_vertexCount - 1;3399}3400else {3401outoIndex = this.m_vertexCount - 1;3402}3403break;3404}3405var intoIndex2 = parseInt((intoIndex + 1) % this.m_vertexCount);3406var outoIndex2 = parseInt((outoIndex + 1) % this.m_vertexCount);3407var intoLamdda = (0 - depths[intoIndex]) / (depths[intoIndex2] - depths[intoIndex]);3408var outoLamdda = (0 - depths[outoIndex]) / (depths[outoIndex2] - depths[outoIndex]);3409var intoVec = new b2Vec2(this.m_vertices[intoIndex].x * (1 - intoLamdda) + this.m_vertices[intoIndex2].x * intoLamdda, this.m_vertices[intoIndex].y * (1 - intoLamdda) + this.m_vertices[intoIndex2].y * intoLamdda);3410var outoVec = new b2Vec2(this.m_vertices[outoIndex].x * (1 - outoLamdda) + this.m_vertices[outoIndex2].x * outoLamdda, this.m_vertices[outoIndex].y * (1 - outoLamdda) + this.m_vertices[outoIndex2].y * outoLamdda);3411var area = 0;3412var center = new b2Vec2();3413var p2 = this.m_vertices[intoIndex2];3414var p3;3415i = intoIndex2;3416while (i != outoIndex2) {3417i = (i + 1) % this.m_vertexCount;3418if (i == outoIndex2) p3 = outoVec;3419else p3 = this.m_vertices[i];3420var triangleArea = 0.5 * ((p2.x - intoVec.x) * (p3.y - intoVec.y) - (p2.y - intoVec.y) * (p3.x - intoVec.x));3421area += triangleArea;3422center.x += triangleArea * (intoVec.x + p2.x + p3.x) / 3;3423center.y += triangleArea * (intoVec.y + p2.y + p3.y) / 3;3424p2 = p3;3425}3426center.Multiply(1 / area);3427c.SetV(b2Math.MulX(xf, center));3428return area;3429}3430b2PolygonShape.prototype.GetVertexCount = function () {3431return this.m_vertexCount;3432}3433b2PolygonShape.prototype.GetVertices = function () {3434return this.m_vertices;3435}3436b2PolygonShape.prototype.GetNormals = function () {3437return this.m_normals;3438}3439b2PolygonShape.prototype.GetSupport = function (d) {3440var bestIndex = 0;3441var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;3442for (var i = 1; i < this.m_vertexCount; ++i) {3443var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;3444if (value > bestValue) {3445bestIndex = i;3446bestValue = value;3447}3448}3449return bestIndex;3450}3451b2PolygonShape.prototype.GetSupportVertex = function (d) {3452var bestIndex = 0;3453var bestValue = this.m_vertices[0].x * d.x + this.m_vertices[0].y * d.y;3454for (var i = 1; i < this.m_vertexCount; ++i) {3455var value = this.m_vertices[i].x * d.x + this.m_vertices[i].y * d.y;3456if (value > bestValue) {3457bestIndex = i;3458bestValue = value;3459}3460}3461return this.m_vertices[bestIndex];3462}3463b2PolygonShape.prototype.Validate = function () {3464return false;3465}3466b2PolygonShape.prototype.b2PolygonShape = function () {3467this.__super.b2Shape.call(this);3468this.m_type = b2Shape.e_polygonShape;3469this.m_centroid = new b2Vec2();3470this.m_vertices = new Vector();3471this.m_normals = new Vector();3472}3473b2PolygonShape.prototype.Reserve = function (count) {3474if (count === undefined) count = 0;3475for (var i = parseInt(this.m_vertices.length); i < count; i++) {3476this.m_vertices[i] = new b2Vec2();3477this.m_normals[i] = new b2Vec2();3478}3479}3480b2PolygonShape.ComputeCentroid = function (vs, count) {3481if (count === undefined) count = 0;3482var c = new b2Vec2();3483var area = 0.0;3484var p1X = 0.0;3485var p1Y = 0.0;3486var inv3 = 1.0 / 3.0;3487for (var i = 0; i < count; ++i) {3488var p2 = vs[i];3489var p3 = i + 1 < count ? vs[parseInt(i + 1)] : vs[0];3490var e1X = p2.x - p1X;3491var e1Y = p2.y - p1Y;3492var e2X = p3.x - p1X;3493var e2Y = p3.y - p1Y;3494var D = (e1X * e2Y - e1Y * e2X);3495var triangleArea = 0.5 * D;area += triangleArea;3496c.x += triangleArea * inv3 * (p1X + p2.x + p3.x);3497c.y += triangleArea * inv3 * (p1Y + p2.y + p3.y);3498}3499c.x *= 1.0 / area;3500c.y *= 1.0 / area;3501return c;3502}3503b2PolygonShape.ComputeOBB = function (obb, vs, count) {3504if (count === undefined) count = 0;3505var i = 0;3506var p = new Vector(count + 1);3507for (i = 0;3508i < count; ++i) {3509p[i] = vs[i];3510}3511p[count] = p[0];3512var minArea = Number.MAX_VALUE;3513for (i = 1;3514i <= count; ++i) {3515var root = p[parseInt(i - 1)];3516var uxX = p[i].x - root.x;3517var uxY = p[i].y - root.y;3518var length = Math.sqrt(uxX * uxX + uxY * uxY);3519uxX /= length;3520uxY /= length;3521var uyX = (-uxY);3522var uyY = uxX;3523var lowerX = Number.MAX_VALUE;3524var lowerY = Number.MAX_VALUE;3525var upperX = (-Number.MAX_VALUE);3526var upperY = (-Number.MAX_VALUE);3527for (var j = 0; j < count; ++j) {3528var dX = p[j].x - root.x;3529var dY = p[j].y - root.y;3530var rX = (uxX * dX + uxY * dY);3531var rY = (uyX * dX + uyY * dY);3532if (rX < lowerX) lowerX = rX;3533if (rY < lowerY) lowerY = rY;3534if (rX > upperX) upperX = rX;3535if (rY > upperY) upperY = rY;3536}3537var area = (upperX - lowerX) * (upperY - lowerY);3538if (area < 0.95 * minArea) {3539minArea = area;3540obb.R.col1.x = uxX;3541obb.R.col1.y = uxY;3542obb.R.col2.x = uyX;3543obb.R.col2.y = uyY;3544var centerX = 0.5 * (lowerX + upperX);3545var centerY = 0.5 * (lowerY + upperY);3546var tMat = obb.R;3547obb.center.x = root.x + (tMat.col1.x * centerX + tMat.col2.x * centerY);3548obb.center.y = root.y + (tMat.col1.y * centerX + tMat.col2.y * centerY);3549obb.extents.x = 0.5 * (upperX - lowerX);3550obb.extents.y = 0.5 * (upperY - lowerY);3551}3552}3553}3554Box2D.postDefs.push(function () {3555Box2D.Collision.Shapes.b2PolygonShape.s_mat = new b2Mat22();3556});3557b2Shape.b2Shape = function () {};3558b2Shape.prototype.Copy = function () {3559return null;3560}3561b2Shape.prototype.Set = function (other) {3562this.m_radius = other.m_radius;3563}3564b2Shape.prototype.GetType = function () {3565return this.m_type;3566}3567b2Shape.prototype.TestPoint = function (xf, p) {3568return false;3569}3570b2Shape.prototype.RayCast = function (output, input, transform) {3571return false;3572}3573b2Shape.prototype.ComputeAABB = function (aabb, xf) {}3574b2Shape.prototype.ComputeMass = function (massData, density) {3575if (density === undefined) density = 0;3576}3577b2Shape.prototype.ComputeSubmergedArea = function (normal, offset, xf, c) {3578if (offset === undefined) offset = 0;3579return 0;3580}3581b2Shape.TestOverlap = function (shape1, transform1, shape2, transform2) {3582var input = new b2DistanceInput();3583input.proxyA = new b2DistanceProxy();3584input.proxyA.Set(shape1);3585input.proxyB = new b2DistanceProxy();3586input.proxyB.Set(shape2);3587input.transformA = transform1;3588input.transformB = transform2;3589input.useRadii = true;3590var simplexCache = new b2SimplexCache();3591simplexCache.count = 0;3592var output = new b2DistanceOutput();3593b2Distance.Distance(output, simplexCache, input);3594return output.distance < 10.0 * Number.MIN_VALUE;3595}3596b2Shape.prototype.b2Shape = function () {3597this.m_type = b2Shape.e_unknownShape;3598this.m_radius = b2Settings.b2_linearSlop;3599}3600Box2D.postDefs.push(function () {3601Box2D.Collision.Shapes.b2Shape.e_unknownShape = parseInt((-1));3602Box2D.Collision.Shapes.b2Shape.e_circleShape = 0;3603Box2D.Collision.Shapes.b2Shape.e_polygonShape = 1;3604Box2D.Collision.Shapes.b2Shape.e_edgeShape = 2;3605Box2D.Collision.Shapes.b2Shape.e_shapeTypeCount = 3;3606Box2D.Collision.Shapes.b2Shape.e_hitCollide = 1;3607Box2D.Collision.Shapes.b2Shape.e_missCollide = 0;3608Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide = parseInt((-1));3609});3610})();3611(function () {3612var b2Color = Box2D.Common.b2Color,3613b2internal = Box2D.Common.b2internal,3614b2Settings = Box2D.Common.b2Settings,3615b2Mat22 = Box2D.Common.Math.b2Mat22,3616b2Mat33 = Box2D.Common.Math.b2Mat33,3617b2Math = Box2D.Common.Math.b2Math,3618b2Sweep = Box2D.Common.Math.b2Sweep,3619b2Transform = Box2D.Common.Math.b2Transform,3620b2Vec2 = Box2D.Common.Math.b2Vec2,3621b2Vec3 = Box2D.Common.Math.b2Vec3;36223623b2Color.b2Color = function () {3624this._r = 0;3625this._g = 0;3626this._b = 0;3627};3628b2Color.prototype.b2Color = function (rr, gg, bb) {3629if (rr === undefined) rr = 0;3630if (gg === undefined) gg = 0;3631if (bb === undefined) bb = 0;3632this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));3633this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));3634this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));3635}3636b2Color.prototype.Set = function (rr, gg, bb) {3637if (rr === undefined) rr = 0;3638if (gg === undefined) gg = 0;3639if (bb === undefined) bb = 0;3640this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));3641this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));3642this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));3643}3644Object.defineProperty(b2Color.prototype, 'r', {3645enumerable: false,3646configurable: true,3647set: function (rr) {3648if (rr === undefined) rr = 0;3649this._r = Box2D.parseUInt(255 * b2Math.Clamp(rr, 0.0, 1.0));3650}3651});3652Object.defineProperty(b2Color.prototype, 'g', {3653enumerable: false,3654configurable: true,3655set: function (gg) {3656if (gg === undefined) gg = 0;3657this._g = Box2D.parseUInt(255 * b2Math.Clamp(gg, 0.0, 1.0));3658}3659});3660Object.defineProperty(b2Color.prototype, 'b', {3661enumerable: false,3662configurable: true,3663set: function (bb) {3664if (bb === undefined) bb = 0;3665this._b = Box2D.parseUInt(255 * b2Math.Clamp(bb, 0.0, 1.0));3666}3667});3668Object.defineProperty(b2Color.prototype, 'color', {3669enumerable: false,3670configurable: true,3671get: function () {3672return (this._r << 16) | (this._g << 8) | (this._b);3673}3674});3675b2Settings.b2Settings = function () {};3676b2Settings.b2MixFriction = function (friction1, friction2) {3677if (friction1 === undefined) friction1 = 0;3678if (friction2 === undefined) friction2 = 0;3679return Math.sqrt(friction1 * friction2);3680}3681b2Settings.b2MixRestitution = function (restitution1, restitution2) {3682if (restitution1 === undefined) restitution1 = 0;3683if (restitution2 === undefined) restitution2 = 0;3684return restitution1 > restitution2 ? restitution1 : restitution2;3685}3686b2Settings.b2Assert = function (a) {3687if (!a) {3688throw "Assertion Failed";3689}3690}3691Box2D.postDefs.push(function () {3692Box2D.Common.b2Settings.VERSION = "2.1alpha";3693Box2D.Common.b2Settings.USHRT_MAX = 0x0000ffff;3694Box2D.Common.b2Settings.b2_pi = Math.PI;3695Box2D.Common.b2Settings.b2_maxManifoldPoints = 2;3696Box2D.Common.b2Settings.b2_aabbExtension = 0.1;3697Box2D.Common.b2Settings.b2_aabbMultiplier = 2.0;3698Box2D.Common.b2Settings.b2_polygonRadius = 2.0 * b2Settings.b2_linearSlop;3699Box2D.Common.b2Settings.b2_linearSlop = 0.005;3700Box2D.Common.b2Settings.b2_angularSlop = 2.0 / 180.0 * b2Settings.b2_pi;3701Box2D.Common.b2Settings.b2_toiSlop = 8.0 * b2Settings.b2_linearSlop;3702Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland = 32;3703Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland = 32;3704Box2D.Common.b2Settings.b2_velocityThreshold = 1.0;3705Box2D.Common.b2Settings.b2_maxLinearCorrection = 0.2;3706Box2D.Common.b2Settings.b2_maxAngularCorrection = 8.0 / 180.0 * b2Settings.b2_pi;3707Box2D.Common.b2Settings.b2_maxTranslation = 2.0;3708Box2D.Common.b2Settings.b2_maxTranslationSquared = b2Settings.b2_maxTranslation * b2Settings.b2_maxTranslation;3709Box2D.Common.b2Settings.b2_maxRotation = 0.5 * b2Settings.b2_pi;3710Box2D.Common.b2Settings.b2_maxRotationSquared = b2Settings.b2_maxRotation * b2Settings.b2_maxRotation;3711Box2D.Common.b2Settings.b2_contactBaumgarte = 0.2;3712Box2D.Common.b2Settings.b2_timeToSleep = 0.5;3713Box2D.Common.b2Settings.b2_linearSleepTolerance = 0.01;3714Box2D.Common.b2Settings.b2_angularSleepTolerance = 2.0 / 180.0 * b2Settings.b2_pi;3715});3716})();3717(function () {3718var b2AABB = Box2D.Collision.b2AABB,3719b2Color = Box2D.Common.b2Color,3720b2internal = Box2D.Common.b2internal,3721b2Settings = Box2D.Common.b2Settings,3722b2Mat22 = Box2D.Common.Math.b2Mat22,3723b2Mat33 = Box2D.Common.Math.b2Mat33,3724b2Math = Box2D.Common.Math.b2Math,3725b2Sweep = Box2D.Common.Math.b2Sweep,3726b2Transform = Box2D.Common.Math.b2Transform,3727b2Vec2 = Box2D.Common.Math.b2Vec2,3728b2Vec3 = Box2D.Common.Math.b2Vec3;37293730b2Mat22.b2Mat22 = function () {3731this.col1 = new b2Vec2();3732this.col2 = new b2Vec2();3733};3734b2Mat22.prototype.b2Mat22 = function () {3735this.SetIdentity();3736}3737b2Mat22.FromAngle = function (angle) {3738if (angle === undefined) angle = 0;3739var mat = new b2Mat22();3740mat.Set(angle);3741return mat;3742}3743b2Mat22.FromVV = function (c1, c2) {3744var mat = new b2Mat22();3745mat.SetVV(c1, c2);3746return mat;3747}3748b2Mat22.prototype.Set = function (angle) {3749if (angle === undefined) angle = 0;3750var c = Math.cos(angle);3751var s = Math.sin(angle);3752this.col1.x = c;3753this.col2.x = (-s);3754this.col1.y = s;3755this.col2.y = c;3756}3757b2Mat22.prototype.SetVV = function (c1, c2) {3758this.col1.SetV(c1);3759this.col2.SetV(c2);3760}3761b2Mat22.prototype.Copy = function () {3762var mat = new b2Mat22();3763mat.SetM(this);3764return mat;3765}3766b2Mat22.prototype.SetM = function (m) {3767this.col1.SetV(m.col1);3768this.col2.SetV(m.col2);3769}3770b2Mat22.prototype.AddM = function (m) {3771this.col1.x += m.col1.x;3772this.col1.y += m.col1.y;3773this.col2.x += m.col2.x;3774this.col2.y += m.col2.y;3775}3776b2Mat22.prototype.SetIdentity = function () {3777this.col1.x = 1.0;3778this.col2.x = 0.0;3779this.col1.y = 0.0;3780this.col2.y = 1.0;3781}3782b2Mat22.prototype.SetZero = function () {3783this.col1.x = 0.0;3784this.col2.x = 0.0;3785this.col1.y = 0.0;3786this.col2.y = 0.0;3787}3788b2Mat22.prototype.GetAngle = function () {3789return Math.atan2(this.col1.y, this.col1.x);3790}3791b2Mat22.prototype.GetInverse = function (out) {3792var a = this.col1.x;3793var b = this.col2.x;3794var c = this.col1.y;3795var d = this.col2.y;3796var det = a * d - b * c;3797if (det != 0.0) {3798det = 1.0 / det;3799}3800out.col1.x = det * d;3801out.col2.x = (-det * b);3802out.col1.y = (-det * c);3803out.col2.y = det * a;3804return out;3805}3806b2Mat22.prototype.Solve = function (out, bX, bY) {3807if (bX === undefined) bX = 0;3808if (bY === undefined) bY = 0;3809var a11 = this.col1.x;3810var a12 = this.col2.x;3811var a21 = this.col1.y;3812var a22 = this.col2.y;3813var det = a11 * a22 - a12 * a21;3814if (det != 0.0) {3815det = 1.0 / det;3816}3817out.x = det * (a22 * bX - a12 * bY);3818out.y = det * (a11 * bY - a21 * bX);3819return out;3820}3821b2Mat22.prototype.Abs = function () {3822this.col1.Abs();3823this.col2.Abs();3824}3825b2Mat33.b2Mat33 = function () {3826this.col1 = new b2Vec3();3827this.col2 = new b2Vec3();3828this.col3 = new b2Vec3();3829};3830b2Mat33.prototype.b2Mat33 = function (c1, c2, c3) {3831if (c1 === undefined) c1 = null;3832if (c2 === undefined) c2 = null;3833if (c3 === undefined) c3 = null;3834if (!c1 && !c2 && !c3) {3835this.col1.SetZero();3836this.col2.SetZero();3837this.col3.SetZero();3838}3839else {3840this.col1.SetV(c1);3841this.col2.SetV(c2);3842this.col3.SetV(c3);3843}3844}3845b2Mat33.prototype.SetVVV = function (c1, c2, c3) {3846this.col1.SetV(c1);3847this.col2.SetV(c2);3848this.col3.SetV(c3);3849}3850b2Mat33.prototype.Copy = function () {3851return new b2Mat33(this.col1, this.col2, this.col3);3852}3853b2Mat33.prototype.SetM = function (m) {3854this.col1.SetV(m.col1);3855this.col2.SetV(m.col2);3856this.col3.SetV(m.col3);3857}3858b2Mat33.prototype.AddM = function (m) {3859this.col1.x += m.col1.x;3860this.col1.y += m.col1.y;3861this.col1.z += m.col1.z;3862this.col2.x += m.col2.x;3863this.col2.y += m.col2.y;3864this.col2.z += m.col2.z;3865this.col3.x += m.col3.x;3866this.col3.y += m.col3.y;3867this.col3.z += m.col3.z;3868}3869b2Mat33.prototype.SetIdentity = function () {3870this.col1.x = 1.0;3871this.col2.x = 0.0;3872this.col3.x = 0.0;3873this.col1.y = 0.0;3874this.col2.y = 1.0;3875this.col3.y = 0.0;3876this.col1.z = 0.0;3877this.col2.z = 0.0;3878this.col3.z = 1.0;3879}3880b2Mat33.prototype.SetZero = function () {3881this.col1.x = 0.0;3882this.col2.x = 0.0;3883this.col3.x = 0.0;3884this.col1.y = 0.0;3885this.col2.y = 0.0;3886this.col3.y = 0.0;3887this.col1.z = 0.0;3888this.col2.z = 0.0;3889this.col3.z = 0.0;3890}3891b2Mat33.prototype.Solve22 = function (out, bX, bY) {3892if (bX === undefined) bX = 0;3893if (bY === undefined) bY = 0;3894var a11 = this.col1.x;3895var a12 = this.col2.x;3896var a21 = this.col1.y;3897var a22 = this.col2.y;3898var det = a11 * a22 - a12 * a21;3899if (det != 0.0) {3900det = 1.0 / det;3901}3902out.x = det * (a22 * bX - a12 * bY);3903out.y = det * (a11 * bY - a21 * bX);3904return out;3905}3906b2Mat33.prototype.Solve33 = function (out, bX, bY, bZ) {3907if (bX === undefined) bX = 0;3908if (bY === undefined) bY = 0;3909if (bZ === undefined) bZ = 0;3910var a11 = this.col1.x;3911var a21 = this.col1.y;3912var a31 = this.col1.z;3913var a12 = this.col2.x;3914var a22 = this.col2.y;3915var a32 = this.col2.z;3916var a13 = this.col3.x;3917var a23 = this.col3.y;3918var a33 = this.col3.z;3919var det = a11 * (a22 * a33 - a32 * a23) + a21 * (a32 * a13 - a12 * a33) + a31 * (a12 * a23 - a22 * a13);3920if (det != 0.0) {3921det = 1.0 / det;3922}3923out.x = det * (bX * (a22 * a33 - a32 * a23) + bY * (a32 * a13 - a12 * a33) + bZ * (a12 * a23 - a22 * a13));3924out.y = det * (a11 * (bY * a33 - bZ * a23) + a21 * (bZ * a13 - bX * a33) + a31 * (bX * a23 - bY * a13));3925out.z = det * (a11 * (a22 * bZ - a32 * bY) + a21 * (a32 * bX - a12 * bZ) + a31 * (a12 * bY - a22 * bX));3926return out;3927}3928b2Math.b2Math = function () {};3929b2Math.IsValid = function (x) {3930if (x === undefined) x = 0;3931return isFinite(x);3932}3933b2Math.Dot = function (a, b) {3934return a.x * b.x + a.y * b.y;3935}3936b2Math.CrossVV = function (a, b) {3937return a.x * b.y - a.y * b.x;3938}3939b2Math.CrossVF = function (a, s) {3940if (s === undefined) s = 0;3941var v = new b2Vec2(s * a.y, (-s * a.x));3942return v;3943}3944b2Math.CrossFV = function (s, a) {3945if (s === undefined) s = 0;3946var v = new b2Vec2((-s * a.y), s * a.x);3947return v;3948}3949b2Math.MulMV = function (A, v) {3950var u = new b2Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y);3951return u;3952}3953b2Math.MulTMV = function (A, v) {3954var u = new b2Vec2(b2Math.Dot(v, A.col1), b2Math.Dot(v, A.col2));3955return u;3956}3957b2Math.MulX = function (T, v) {3958var a = b2Math.MulMV(T.R, v);3959a.x += T.position.x;3960a.y += T.position.y;3961return a;3962}3963b2Math.MulXT = function (T, v) {3964var a = b2Math.SubtractVV(v, T.position);3965var tX = (a.x * T.R.col1.x + a.y * T.R.col1.y);3966a.y = (a.x * T.R.col2.x + a.y * T.R.col2.y);3967a.x = tX;3968return a;3969}3970b2Math.AddVV = function (a, b) {3971var v = new b2Vec2(a.x + b.x, a.y + b.y);3972return v;3973}3974b2Math.SubtractVV = function (a, b) {3975var v = new b2Vec2(a.x - b.x, a.y - b.y);3976return v;3977}3978b2Math.Distance = function (a, b) {3979var cX = a.x - b.x;3980var cY = a.y - b.y;3981return Math.sqrt(cX * cX + cY * cY);3982}3983b2Math.DistanceSquared = function (a, b) {3984var cX = a.x - b.x;3985var cY = a.y - b.y;3986return (cX * cX + cY * cY);3987}3988b2Math.MulFV = function (s, a) {3989if (s === undefined) s = 0;3990var v = new b2Vec2(s * a.x, s * a.y);3991return v;3992}3993b2Math.AddMM = function (A, B) {3994var C = b2Mat22.FromVV(b2Math.AddVV(A.col1, B.col1), b2Math.AddVV(A.col2, B.col2));3995return C;3996}3997b2Math.MulMM = function (A, B) {3998var C = b2Mat22.FromVV(b2Math.MulMV(A, B.col1), b2Math.MulMV(A, B.col2));3999return C;4000}4001b2Math.MulTMM = function (A, B) {4002var c1 = new b2Vec2(b2Math.Dot(A.col1, B.col1), b2Math.Dot(A.col2, B.col1));4003var c2 = new b2Vec2(b2Math.Dot(A.col1, B.col2), b2Math.Dot(A.col2, B.col2));4004var C = b2Mat22.FromVV(c1, c2);4005return C;4006}4007b2Math.Abs = function (a) {4008if (a === undefined) a = 0;4009return a > 0.0 ? a : (-a);4010}4011b2Math.AbsV = function (a) {4012var b = new b2Vec2(b2Math.Abs(a.x), b2Math.Abs(a.y));4013return b;4014}4015b2Math.AbsM = function (A) {4016var B = b2Mat22.FromVV(b2Math.AbsV(A.col1), b2Math.AbsV(A.col2));4017return B;4018}4019b2Math.Min = function (a, b) {4020if (a === undefined) a = 0;4021if (b === undefined) b = 0;4022return a < b ? a : b;4023}4024b2Math.MinV = function (a, b) {4025var c = new b2Vec2(b2Math.Min(a.x, b.x), b2Math.Min(a.y, b.y));4026return c;4027}4028b2Math.Max = function (a, b) {4029if (a === undefined) a = 0;4030if (b === undefined) b = 0;4031return a > b ? a : b;4032}4033b2Math.MaxV = function (a, b) {4034var c = new b2Vec2(b2Math.Max(a.x, b.x), b2Math.Max(a.y, b.y));4035return c;4036}4037b2Math.Clamp = function (a, low, high) {4038if (a === undefined) a = 0;4039if (low === undefined) low = 0;4040if (high === undefined) high = 0;4041return a < low ? low : a > high ? high : a;4042}4043b2Math.ClampV = function (a, low, high) {4044return b2Math.MaxV(low, b2Math.MinV(a, high));4045}4046b2Math.Swap = function (a, b) {4047var tmp = a[0];4048a[0] = b[0];4049b[0] = tmp;4050}4051b2Math.Random = function () {4052return Math.random() * 2 - 1;4053}4054b2Math.RandomRange = function (lo, hi) {4055if (lo === undefined) lo = 0;4056if (hi === undefined) hi = 0;4057var r = Math.random();4058r = (hi - lo) * r + lo;4059return r;4060}4061b2Math.NextPowerOfTwo = function (x) {4062if (x === undefined) x = 0;4063x |= (x >> 1) & 0x7FFFFFFF;4064x |= (x >> 2) & 0x3FFFFFFF;4065x |= (x >> 4) & 0x0FFFFFFF;4066x |= (x >> 8) & 0x00FFFFFF;4067x |= (x >> 16) & 0x0000FFFF;4068return x + 1;4069}4070b2Math.IsPowerOfTwo = function (x) {4071if (x === undefined) x = 0;4072var result = x > 0 && (x & (x - 1)) == 0;4073return result;4074}4075Box2D.postDefs.push(function () {4076Box2D.Common.Math.b2Math.b2Vec2_zero = new b2Vec2(0.0, 0.0);4077Box2D.Common.Math.b2Math.b2Mat22_identity = b2Mat22.FromVV(new b2Vec2(1.0, 0.0), new b2Vec2(0.0, 1.0));4078Box2D.Common.Math.b2Math.b2Transform_identity = new b2Transform(b2Math.b2Vec2_zero, b2Math.b2Mat22_identity);4079});4080b2Sweep.b2Sweep = function () {4081this.localCenter = new b2Vec2();4082this.c0 = new b2Vec2;4083this.c = new b2Vec2();4084};4085b2Sweep.prototype.Set = function (other) {4086this.localCenter.SetV(other.localCenter);4087this.c0.SetV(other.c0);4088this.c.SetV(other.c);4089this.a0 = other.a0;4090this.a = other.a;4091this.t0 = other.t0;4092}4093b2Sweep.prototype.Copy = function () {4094var copy = new b2Sweep();4095copy.localCenter.SetV(this.localCenter);4096copy.c0.SetV(this.c0);4097copy.c.SetV(this.c);4098copy.a0 = this.a0;4099copy.a = this.a;4100copy.t0 = this.t0;4101return copy;4102}4103b2Sweep.prototype.GetTransform = function (xf, alpha) {4104if (alpha === undefined) alpha = 0;4105xf.position.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;4106xf.position.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;4107var angle = (1.0 - alpha) * this.a0 + alpha * this.a;4108xf.R.Set(angle);4109var tMat = xf.R;4110xf.position.x -= (tMat.col1.x * this.localCenter.x + tMat.col2.x * this.localCenter.y);4111xf.position.y -= (tMat.col1.y * this.localCenter.x + tMat.col2.y * this.localCenter.y);4112}4113b2Sweep.prototype.Advance = function (t) {4114if (t === undefined) t = 0;4115if (this.t0 < t && 1.0 - this.t0 > Number.MIN_VALUE) {4116var alpha = (t - this.t0) / (1.0 - this.t0);4117this.c0.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;4118this.c0.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;4119this.a0 = (1.0 - alpha) * this.a0 + alpha * this.a;4120this.t0 = t;4121}4122}4123b2Transform.b2Transform = function () {4124this.position = new b2Vec2;4125this.R = new b2Mat22();4126};4127b2Transform.prototype.b2Transform = function (pos, r) {4128if (pos === undefined) pos = null;4129if (r === undefined) r = null;4130if (pos) {4131this.position.SetV(pos);4132this.R.SetM(r);4133}4134}4135b2Transform.prototype.Initialize = function (pos, r) {4136this.position.SetV(pos);4137this.R.SetM(r);4138}4139b2Transform.prototype.SetIdentity = function () {4140this.position.SetZero();4141this.R.SetIdentity();4142}4143b2Transform.prototype.Set = function (x) {4144this.position.SetV(x.position);4145this.R.SetM(x.R);4146}4147b2Transform.prototype.GetAngle = function () {4148return Math.atan2(this.R.col1.y, this.R.col1.x);4149}4150b2Vec2.b2Vec2 = function () {};4151b2Vec2.prototype.b2Vec2 = function (x_, y_) {4152if (x_ === undefined) x_ = 0;4153if (y_ === undefined) y_ = 0;4154this.x = x_;4155this.y = y_;4156}4157b2Vec2.prototype.SetZero = function () {4158this.x = 0.0;4159this.y = 0.0;4160}4161b2Vec2.prototype.Set = function (x_, y_) {4162if (x_ === undefined) x_ = 0;4163if (y_ === undefined) y_ = 0;4164this.x = x_;4165this.y = y_;4166}4167b2Vec2.prototype.SetV = function (v) {4168this.x = v.x;4169this.y = v.y;4170}4171b2Vec2.prototype.GetNegative = function () {4172return new b2Vec2((-this.x), (-this.y));4173}4174b2Vec2.prototype.NegativeSelf = function () {4175this.x = (-this.x);4176this.y = (-this.y);4177}4178b2Vec2.Make = function (x_, y_) {4179if (x_ === undefined) x_ = 0;4180if (y_ === undefined) y_ = 0;4181return new b2Vec2(x_, y_);4182}4183b2Vec2.prototype.Copy = function () {4184return new b2Vec2(this.x, this.y);4185}4186b2Vec2.prototype.Add = function (v) {4187this.x += v.x;4188this.y += v.y;4189}4190b2Vec2.prototype.Subtract = function (v) {4191this.x -= v.x;4192this.y -= v.y;4193}4194b2Vec2.prototype.Multiply = function (a) {4195if (a === undefined) a = 0;4196this.x *= a;4197this.y *= a;4198}4199b2Vec2.prototype.MulM = function (A) {4200var tX = this.x;4201this.x = A.col1.x * tX + A.col2.x * this.y;4202this.y = A.col1.y * tX + A.col2.y * this.y;4203}4204b2Vec2.prototype.MulTM = function (A) {4205var tX = b2Math.Dot(this, A.col1);4206this.y = b2Math.Dot(this, A.col2);4207this.x = tX;4208}4209b2Vec2.prototype.CrossVF = function (s) {4210if (s === undefined) s = 0;4211var tX = this.x;4212this.x = s * this.y;4213this.y = (-s * tX);4214}4215b2Vec2.prototype.CrossFV = function (s) {4216if (s === undefined) s = 0;4217var tX = this.x;4218this.x = (-s * this.y);4219this.y = s * tX;4220}4221b2Vec2.prototype.MinV = function (b) {4222this.x = this.x < b.x ? this.x : b.x;4223this.y = this.y < b.y ? this.y : b.y;4224}4225b2Vec2.prototype.MaxV = function (b) {4226this.x = this.x > b.x ? this.x : b.x;4227this.y = this.y > b.y ? this.y : b.y;4228}4229b2Vec2.prototype.Abs = function () {4230if (this.x < 0) this.x = (-this.x);4231if (this.y < 0) this.y = (-this.y);4232}4233b2Vec2.prototype.Length = function () {4234return Math.sqrt(this.x * this.x + this.y * this.y);4235}4236b2Vec2.prototype.LengthSquared = function () {4237return (this.x * this.x + this.y * this.y);4238}4239b2Vec2.prototype.Normalize = function () {4240var length = Math.sqrt(this.x * this.x + this.y * this.y);4241if (length < Number.MIN_VALUE) {4242return 0.0;4243}4244var invLength = 1.0 / length;4245this.x *= invLength;4246this.y *= invLength;4247return length;4248}4249b2Vec2.prototype.IsValid = function () {4250return b2Math.IsValid(this.x) && b2Math.IsValid(this.y);4251}4252b2Vec3.b2Vec3 = function () {};4253b2Vec3.prototype.b2Vec3 = function (x, y, z) {4254if (x === undefined) x = 0;4255if (y === undefined) y = 0;4256if (z === undefined) z = 0;4257this.x = x;4258this.y = y;4259this.z = z;4260}4261b2Vec3.prototype.SetZero = function () {4262this.x = this.y = this.z = 0.0;4263}4264b2Vec3.prototype.Set = function (x, y, z) {4265if (x === undefined) x = 0;4266if (y === undefined) y = 0;4267if (z === undefined) z = 0;4268this.x = x;4269this.y = y;4270this.z = z;4271}4272b2Vec3.prototype.SetV = function (v) {4273this.x = v.x;4274this.y = v.y;4275this.z = v.z;4276}4277b2Vec3.prototype.GetNegative = function () {4278return new b2Vec3((-this.x), (-this.y), (-this.z));4279}4280b2Vec3.prototype.NegativeSelf = function () {4281this.x = (-this.x);4282this.y = (-this.y);4283this.z = (-this.z);4284}4285b2Vec3.prototype.Copy = function () {4286return new b2Vec3(this.x, this.y, this.z);4287}4288b2Vec3.prototype.Add = function (v) {4289this.x += v.x;4290this.y += v.y;4291this.z += v.z;4292}4293b2Vec3.prototype.Subtract = function (v) {4294this.x -= v.x;4295this.y -= v.y;4296this.z -= v.z;4297}4298b2Vec3.prototype.Multiply = function (a) {4299if (a === undefined) a = 0;4300this.x *= a;4301this.y *= a;4302this.z *= a;4303}4304})();4305(function () {4306var b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge,4307b2Mat22 = Box2D.Common.Math.b2Mat22,4308b2Mat33 = Box2D.Common.Math.b2Mat33,4309b2Math = Box2D.Common.Math.b2Math,4310b2Sweep = Box2D.Common.Math.b2Sweep,4311b2Transform = Box2D.Common.Math.b2Transform,4312b2Vec2 = Box2D.Common.Math.b2Vec2,4313b2Vec3 = Box2D.Common.Math.b2Vec3,4314b2Color = Box2D.Common.b2Color,4315b2internal = Box2D.Common.b2internal,4316b2Settings = Box2D.Common.b2Settings,4317b2AABB = Box2D.Collision.b2AABB,4318b2Bound = Box2D.Collision.b2Bound,4319b2BoundValues = Box2D.Collision.b2BoundValues,4320b2Collision = Box2D.Collision.b2Collision,4321b2ContactID = Box2D.Collision.b2ContactID,4322b2ContactPoint = Box2D.Collision.b2ContactPoint,4323b2Distance = Box2D.Collision.b2Distance,4324b2DistanceInput = Box2D.Collision.b2DistanceInput,4325b2DistanceOutput = Box2D.Collision.b2DistanceOutput,4326b2DistanceProxy = Box2D.Collision.b2DistanceProxy,4327b2DynamicTree = Box2D.Collision.b2DynamicTree,4328b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,4329b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,4330b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,4331b2Manifold = Box2D.Collision.b2Manifold,4332b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,4333b2Point = Box2D.Collision.b2Point,4334b2RayCastInput = Box2D.Collision.b2RayCastInput,4335b2RayCastOutput = Box2D.Collision.b2RayCastOutput,4336b2Segment = Box2D.Collision.b2Segment,4337b2SeparationFunction = Box2D.Collision.b2SeparationFunction,4338b2Simplex = Box2D.Collision.b2Simplex,4339b2SimplexCache = Box2D.Collision.b2SimplexCache,4340b2SimplexVertex = Box2D.Collision.b2SimplexVertex,4341b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,4342b2TOIInput = Box2D.Collision.b2TOIInput,4343b2WorldManifold = Box2D.Collision.b2WorldManifold,4344ClipVertex = Box2D.Collision.ClipVertex,4345Features = Box2D.Collision.Features,4346IBroadPhase = Box2D.Collision.IBroadPhase,4347b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,4348b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,4349b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,4350b2MassData = Box2D.Collision.Shapes.b2MassData,4351b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,4352b2Shape = Box2D.Collision.Shapes.b2Shape,4353b2Body = Box2D.Dynamics.b2Body,4354b2BodyDef = Box2D.Dynamics.b2BodyDef,4355b2ContactFilter = Box2D.Dynamics.b2ContactFilter,4356b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,4357b2ContactListener = Box2D.Dynamics.b2ContactListener,4358b2ContactManager = Box2D.Dynamics.b2ContactManager,4359b2DebugDraw = Box2D.Dynamics.b2DebugDraw,4360b2DestructionListener = Box2D.Dynamics.b2DestructionListener,4361b2FilterData = Box2D.Dynamics.b2FilterData,4362b2Fixture = Box2D.Dynamics.b2Fixture,4363b2FixtureDef = Box2D.Dynamics.b2FixtureDef,4364b2Island = Box2D.Dynamics.b2Island,4365b2TimeStep = Box2D.Dynamics.b2TimeStep,4366b2World = Box2D.Dynamics.b2World,4367b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact,4368b2Contact = Box2D.Dynamics.Contacts.b2Contact,4369b2ContactConstraint = Box2D.Dynamics.Contacts.b2ContactConstraint,4370b2ContactConstraintPoint = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,4371b2ContactEdge = Box2D.Dynamics.Contacts.b2ContactEdge,4372b2ContactFactory = Box2D.Dynamics.Contacts.b2ContactFactory,4373b2ContactRegister = Box2D.Dynamics.Contacts.b2ContactRegister,4374b2ContactResult = Box2D.Dynamics.Contacts.b2ContactResult,4375b2ContactSolver = Box2D.Dynamics.Contacts.b2ContactSolver,4376b2EdgeAndCircleContact = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,4377b2NullContact = Box2D.Dynamics.Contacts.b2NullContact,4378b2PolyAndCircleContact = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,4379b2PolyAndEdgeContact = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,4380b2PolygonContact = Box2D.Dynamics.Contacts.b2PolygonContact,4381b2PositionSolverManifold = Box2D.Dynamics.Contacts.b2PositionSolverManifold,4382b2Controller = Box2D.Dynamics.Controllers.b2Controller,4383b2DistanceJoint = Box2D.Dynamics.Joints.b2DistanceJoint,4384b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef,4385b2FrictionJoint = Box2D.Dynamics.Joints.b2FrictionJoint,4386b2FrictionJointDef = Box2D.Dynamics.Joints.b2FrictionJointDef,4387b2GearJoint = Box2D.Dynamics.Joints.b2GearJoint,4388b2GearJointDef = Box2D.Dynamics.Joints.b2GearJointDef,4389b2Jacobian = Box2D.Dynamics.Joints.b2Jacobian,4390b2Joint = Box2D.Dynamics.Joints.b2Joint,4391b2JointDef = Box2D.Dynamics.Joints.b2JointDef,4392b2JointEdge = Box2D.Dynamics.Joints.b2JointEdge,4393b2LineJoint = Box2D.Dynamics.Joints.b2LineJoint,4394b2LineJointDef = Box2D.Dynamics.Joints.b2LineJointDef,4395b2MouseJoint = Box2D.Dynamics.Joints.b2MouseJoint,4396b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef,4397b2PrismaticJoint = Box2D.Dynamics.Joints.b2PrismaticJoint,4398b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef,4399b2PulleyJoint = Box2D.Dynamics.Joints.b2PulleyJoint,4400b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef,4401b2RevoluteJoint = Box2D.Dynamics.Joints.b2RevoluteJoint,4402b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef,4403b2WeldJoint = Box2D.Dynamics.Joints.b2WeldJoint,4404b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDef;44054406b2Body.b2Body = function () {4407this.m_xf = new b2Transform();4408this.m_sweep = new b2Sweep();4409this.m_linearVelocity = new b2Vec2();4410this.m_force = new b2Vec2();4411};4412b2Body.prototype.connectEdges = function (s1, s2, angle1) {4413if (angle1 === undefined) angle1 = 0;4414var angle2 = Math.atan2(s2.GetDirectionVector().y, s2.GetDirectionVector().x);4415var coreOffset = Math.tan((angle2 - angle1) * 0.5);4416var core = b2Math.MulFV(coreOffset, s2.GetDirectionVector());4417core = b2Math.SubtractVV(core, s2.GetNormalVector());4418core = b2Math.MulFV(b2Settings.b2_toiSlop, core);4419core = b2Math.AddVV(core, s2.GetVertex1());4420var cornerDir = b2Math.AddVV(s1.GetDirectionVector(), s2.GetDirectionVector());4421cornerDir.Normalize();4422var convex = b2Math.Dot(s1.GetDirectionVector(), s2.GetNormalVector()) > 0.0;4423s1.SetNextEdge(s2, core, cornerDir, convex);4424s2.SetPrevEdge(s1, core, cornerDir, convex);4425return angle2;4426}4427b2Body.prototype.CreateFixture = function (def) {4428if (this.m_world.IsLocked() == true) {4429return null;4430}4431var fixture = new b2Fixture();4432fixture.Create(this, this.m_xf, def);4433if (this.m_flags & b2Body.e_activeFlag) {4434var broadPhase = this.m_world.m_contactManager.m_broadPhase;4435fixture.CreateProxy(broadPhase, this.m_xf);4436}4437fixture.m_next = this.m_fixtureList;4438this.m_fixtureList = fixture;4439++this.m_fixtureCount;4440fixture.m_body = this;4441if (fixture.m_density > 0.0) {4442this.ResetMassData();4443}4444this.m_world.m_flags |= b2World.e_newFixture;4445return fixture;4446}4447b2Body.prototype.CreateFixture2 = function (shape, density) {4448if (density === undefined) density = 0.0;4449var def = new b2FixtureDef();4450def.shape = shape;4451def.density = density;4452return this.CreateFixture(def);4453}4454b2Body.prototype.DestroyFixture = function (fixture) {4455if (this.m_world.IsLocked() == true) {4456return;4457}4458var node = this.m_fixtureList;4459var ppF = null;4460var found = false;4461while (node != null) {4462if (node == fixture) {4463if (ppF) ppF.m_next = fixture.m_next;4464else this.m_fixtureList = fixture.m_next;4465found = true;4466break;4467}4468ppF = node;4469node = node.m_next;4470}4471var edge = this.m_contactList;4472while (edge) {4473var c = edge.contact;4474edge = edge.next;4475var fixtureA = c.GetFixtureA();4476var fixtureB = c.GetFixtureB();4477if (fixture == fixtureA || fixture == fixtureB) {4478this.m_world.m_contactManager.Destroy(c);4479}4480}4481if (this.m_flags & b2Body.e_activeFlag) {4482var broadPhase = this.m_world.m_contactManager.m_broadPhase;4483fixture.DestroyProxy(broadPhase);4484}4485else {}4486fixture.Destroy();4487fixture.m_body = null;4488fixture.m_next = null;4489--this.m_fixtureCount;4490this.ResetMassData();4491}4492b2Body.prototype.SetPositionAndAngle = function (position, angle) {4493if (angle === undefined) angle = 0;4494var f;4495if (this.m_world.IsLocked() == true) {4496return;4497}4498this.m_xf.R.Set(angle);4499this.m_xf.position.SetV(position);4500var tMat = this.m_xf.R;4501var tVec = this.m_sweep.localCenter;4502this.m_sweep.c.x = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);4503this.m_sweep.c.y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);4504this.m_sweep.c.x += this.m_xf.position.x;4505this.m_sweep.c.y += this.m_xf.position.y;4506this.m_sweep.c0.SetV(this.m_sweep.c);4507this.m_sweep.a0 = this.m_sweep.a = angle;4508var broadPhase = this.m_world.m_contactManager.m_broadPhase;4509for (f = this.m_fixtureList;4510f; f = f.m_next) {4511f.Synchronize(broadPhase, this.m_xf, this.m_xf);4512}4513this.m_world.m_contactManager.FindNewContacts();4514}4515b2Body.prototype.SetTransform = function (xf) {4516this.SetPositionAndAngle(xf.position, xf.GetAngle());4517}4518b2Body.prototype.GetTransform = function () {4519return this.m_xf;4520}4521b2Body.prototype.GetPosition = function () {4522return this.m_xf.position;4523}4524b2Body.prototype.SetPosition = function (position) {4525this.SetPositionAndAngle(position, this.GetAngle());4526}4527b2Body.prototype.GetAngle = function () {4528return this.m_sweep.a;4529}4530b2Body.prototype.SetAngle = function (angle) {4531if (angle === undefined) angle = 0;4532this.SetPositionAndAngle(this.GetPosition(), angle);4533}4534b2Body.prototype.GetWorldCenter = function () {4535return this.m_sweep.c;4536}4537b2Body.prototype.GetLocalCenter = function () {4538return this.m_sweep.localCenter;4539}4540b2Body.prototype.SetLinearVelocity = function (v) {4541if (this.m_type == b2Body.b2_staticBody) {4542return;4543}4544this.m_linearVelocity.SetV(v);4545}4546b2Body.prototype.GetLinearVelocity = function () {4547return this.m_linearVelocity;4548}4549b2Body.prototype.SetAngularVelocity = function (omega) {4550if (omega === undefined) omega = 0;4551if (this.m_type == b2Body.b2_staticBody) {4552return;4553}4554this.m_angularVelocity = omega;4555}4556b2Body.prototype.GetAngularVelocity = function () {4557return this.m_angularVelocity;4558}4559b2Body.prototype.GetDefinition = function () {4560var bd = new b2BodyDef();4561bd.type = this.GetType();4562bd.allowSleep = (this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag;4563bd.angle = this.GetAngle();4564bd.angularDamping = this.m_angularDamping;4565bd.angularVelocity = this.m_angularVelocity;4566bd.fixedRotation = (this.m_flags & b2Body.e_fixedRotationFlag) == b2Body.e_fixedRotationFlag;4567bd.bullet = (this.m_flags & b2Body.e_bulletFlag) == b2Body.e_bulletFlag;4568bd.awake = (this.m_flags & b2Body.e_awakeFlag) == b2Body.e_awakeFlag;4569bd.linearDamping = this.m_linearDamping;4570bd.linearVelocity.SetV(this.GetLinearVelocity());4571bd.position = this.GetPosition();4572bd.userData = this.GetUserData();4573return bd;4574}4575b2Body.prototype.ApplyForce = function (force, point) {4576if (this.m_type != b2Body.b2_dynamicBody) {4577return;4578}4579if (this.IsAwake() == false) {4580this.SetAwake(true);4581}4582this.m_force.x += force.x;4583this.m_force.y += force.y;4584this.m_torque += ((point.x - this.m_sweep.c.x) * force.y - (point.y - this.m_sweep.c.y) * force.x);4585}4586b2Body.prototype.ApplyTorque = function (torque) {4587if (torque === undefined) torque = 0;4588if (this.m_type != b2Body.b2_dynamicBody) {4589return;4590}4591if (this.IsAwake() == false) {4592this.SetAwake(true);4593}4594this.m_torque += torque;4595}4596b2Body.prototype.ApplyImpulse = function (impulse, point) {4597if (this.m_type != b2Body.b2_dynamicBody) {4598return;4599}4600if (this.IsAwake() == false) {4601this.SetAwake(true);4602}4603this.m_linearVelocity.x += this.m_invMass * impulse.x;4604this.m_linearVelocity.y += this.m_invMass * impulse.y;4605this.m_angularVelocity += this.m_invI * ((point.x - this.m_sweep.c.x) * impulse.y - (point.y - this.m_sweep.c.y) * impulse.x);4606}4607b2Body.prototype.Split = function (callback) {4608var linearVelocity = this.GetLinearVelocity().Copy();4609var angularVelocity = this.GetAngularVelocity();4610var center = this.GetWorldCenter();4611var body1 = this;4612var body2 = this.m_world.CreateBody(this.GetDefinition());4613var prev;4614for (var f = body1.m_fixtureList; f;) {4615if (callback(f)) {4616var next = f.m_next;4617if (prev) {4618prev.m_next = next;4619}4620else {4621body1.m_fixtureList = next;4622}4623body1.m_fixtureCount--;4624f.m_next = body2.m_fixtureList;4625body2.m_fixtureList = f;4626body2.m_fixtureCount++;4627f.m_body = body2;4628f = next;4629}4630else {4631prev = f;4632f = f.m_next;4633}4634}4635body1.ResetMassData();4636body2.ResetMassData();4637var center1 = body1.GetWorldCenter();4638var center2 = body2.GetWorldCenter();4639var velocity1 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center1, center)));4640var velocity2 = b2Math.AddVV(linearVelocity, b2Math.CrossFV(angularVelocity, b2Math.SubtractVV(center2, center)));4641body1.SetLinearVelocity(velocity1);4642body2.SetLinearVelocity(velocity2);4643body1.SetAngularVelocity(angularVelocity);4644body2.SetAngularVelocity(angularVelocity);4645body1.SynchronizeFixtures();4646body2.SynchronizeFixtures();4647return body2;4648}4649b2Body.prototype.Merge = function (other) {4650var f;4651for (f = other.m_fixtureList;4652f;) {4653var next = f.m_next;4654other.m_fixtureCount--;4655f.m_next = this.m_fixtureList;4656this.m_fixtureList = f;4657this.m_fixtureCount++;4658f.m_body = body2;4659f = next;4660}4661body1.m_fixtureCount = 0;4662var body1 = this;4663var body2 = other;4664var center1 = body1.GetWorldCenter();4665var center2 = body2.GetWorldCenter();4666var velocity1 = body1.GetLinearVelocity().Copy();4667var velocity2 = body2.GetLinearVelocity().Copy();4668var angular1 = body1.GetAngularVelocity();4669var angular = body2.GetAngularVelocity();4670body1.ResetMassData();4671this.SynchronizeFixtures();4672}4673b2Body.prototype.GetMass = function () {4674return this.m_mass;4675}4676b2Body.prototype.GetInertia = function () {4677return this.m_I;4678}4679b2Body.prototype.GetMassData = function (data) {4680data.mass = this.m_mass;4681data.I = this.m_I;4682data.center.SetV(this.m_sweep.localCenter);4683}4684b2Body.prototype.SetMassData = function (massData) {4685b2Settings.b2Assert(this.m_world.IsLocked() == false);4686if (this.m_world.IsLocked() == true) {4687return;4688}4689if (this.m_type != b2Body.b2_dynamicBody) {4690return;4691}4692this.m_invMass = 0.0;4693this.m_I = 0.0;4694this.m_invI = 0.0;4695this.m_mass = massData.mass;4696if (this.m_mass <= 0.0) {4697this.m_mass = 1.0;4698}4699this.m_invMass = 1.0 / this.m_mass;4700if (massData.I > 0.0 && (this.m_flags & b2Body.e_fixedRotationFlag) == 0) {4701this.m_I = massData.I - this.m_mass * (massData.center.x * massData.center.x + massData.center.y * massData.center.y);4702this.m_invI = 1.0 / this.m_I;4703}4704var oldCenter = this.m_sweep.c.Copy();4705this.m_sweep.localCenter.SetV(massData.center);4706this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));4707this.m_sweep.c.SetV(this.m_sweep.c0);4708this.m_linearVelocity.x += this.m_angularVelocity * (-(this.m_sweep.c.y - oldCenter.y));4709this.m_linearVelocity.y += this.m_angularVelocity * (+(this.m_sweep.c.x - oldCenter.x));4710}4711b2Body.prototype.ResetMassData = function () {4712this.m_mass = 0.0;4713this.m_invMass = 0.0;4714this.m_I = 0.0;4715this.m_invI = 0.0;4716this.m_sweep.localCenter.SetZero();4717if (this.m_type == b2Body.b2_staticBody || this.m_type == b2Body.b2_kinematicBody) {4718return;4719}4720var center = b2Vec2.Make(0, 0);4721for (var f = this.m_fixtureList; f; f = f.m_next) {4722if (f.m_density == 0.0) {4723continue;4724}4725var massData = f.GetMassData();4726this.m_mass += massData.mass;4727center.x += massData.center.x * massData.mass;4728center.y += massData.center.y * massData.mass;4729this.m_I += massData.I;4730}4731if (this.m_mass > 0.0) {4732this.m_invMass = 1.0 / this.m_mass;4733center.x *= this.m_invMass;4734center.y *= this.m_invMass;4735}4736else {4737this.m_mass = 1.0;4738this.m_invMass = 1.0;4739}4740if (this.m_I > 0.0 && (this.m_flags & b2Body.e_fixedRotationFlag) == 0) {4741this.m_I -= this.m_mass * (center.x * center.x + center.y * center.y);4742this.m_I *= this.m_inertiaScale;4743b2Settings.b2Assert(this.m_I > 0);4744this.m_invI = 1.0 / this.m_I;4745}4746else {4747this.m_I = 0.0;4748this.m_invI = 0.0;4749}4750var oldCenter = this.m_sweep.c.Copy();4751this.m_sweep.localCenter.SetV(center);4752this.m_sweep.c0.SetV(b2Math.MulX(this.m_xf, this.m_sweep.localCenter));4753this.m_sweep.c.SetV(this.m_sweep.c0);4754this.m_linearVelocity.x += this.m_angularVelocity * (-(this.m_sweep.c.y - oldCenter.y));4755this.m_linearVelocity.y += this.m_angularVelocity * (+(this.m_sweep.c.x - oldCenter.x));4756}4757b2Body.prototype.GetWorldPoint = function (localPoint) {4758var A = this.m_xf.R;4759var u = new b2Vec2(A.col1.x * localPoint.x + A.col2.x * localPoint.y, A.col1.y * localPoint.x + A.col2.y * localPoint.y);4760u.x += this.m_xf.position.x;4761u.y += this.m_xf.position.y;4762return u;4763}4764b2Body.prototype.GetWorldVector = function (localVector) {4765return b2Math.MulMV(this.m_xf.R, localVector);4766}4767b2Body.prototype.GetLocalPoint = function (worldPoint) {4768return b2Math.MulXT(this.m_xf, worldPoint);4769}4770b2Body.prototype.GetLocalVector = function (worldVector) {4771return b2Math.MulTMV(this.m_xf.R, worldVector);4772}4773b2Body.prototype.GetLinearVelocityFromWorldPoint = function (worldPoint) {4774return new b2Vec2(this.m_linearVelocity.x - this.m_angularVelocity * (worldPoint.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (worldPoint.x - this.m_sweep.c.x));4775}4776b2Body.prototype.GetLinearVelocityFromLocalPoint = function (localPoint) {4777var A = this.m_xf.R;4778var worldPoint = new b2Vec2(A.col1.x * localPoint.x + A.col2.x * localPoint.y, A.col1.y * localPoint.x + A.col2.y * localPoint.y);4779worldPoint.x += this.m_xf.position.x;4780worldPoint.y += this.m_xf.position.y;4781return new b2Vec2(this.m_linearVelocity.x - this.m_angularVelocity * (worldPoint.y - this.m_sweep.c.y), this.m_linearVelocity.y + this.m_angularVelocity * (worldPoint.x - this.m_sweep.c.x));4782}4783b2Body.prototype.GetLinearDamping = function () {4784return this.m_linearDamping;4785}4786b2Body.prototype.SetLinearDamping = function (linearDamping) {4787if (linearDamping === undefined) linearDamping = 0;4788this.m_linearDamping = linearDamping;4789}4790b2Body.prototype.GetAngularDamping = function () {4791return this.m_angularDamping;4792}4793b2Body.prototype.SetAngularDamping = function (angularDamping) {4794if (angularDamping === undefined) angularDamping = 0;4795this.m_angularDamping = angularDamping;4796}4797b2Body.prototype.SetType = function (type) {4798if (type === undefined) type = 0;4799if (this.m_type == type) {4800return;4801}4802this.m_type = type;4803this.ResetMassData();4804if (this.m_type == b2Body.b2_staticBody) {4805this.m_linearVelocity.SetZero();4806this.m_angularVelocity = 0.0;4807}4808this.SetAwake(true);4809this.m_force.SetZero();4810this.m_torque = 0.0;4811for (var ce = this.m_contactList; ce; ce = ce.next) {4812ce.contact.FlagForFiltering();4813}4814}4815b2Body.prototype.GetType = function () {4816return this.m_type;4817}4818b2Body.prototype.SetBullet = function (flag) {4819if (flag) {4820this.m_flags |= b2Body.e_bulletFlag;4821}4822else {4823this.m_flags &= ~b2Body.e_bulletFlag;4824}4825}4826b2Body.prototype.IsBullet = function () {4827return (this.m_flags & b2Body.e_bulletFlag) == b2Body.e_bulletFlag;4828}4829b2Body.prototype.SetSleepingAllowed = function (flag) {4830if (flag) {4831this.m_flags |= b2Body.e_allowSleepFlag;4832}4833else {4834this.m_flags &= ~b2Body.e_allowSleepFlag;4835this.SetAwake(true);4836}4837}4838b2Body.prototype.SetAwake = function (flag) {4839if (flag) {4840this.m_flags |= b2Body.e_awakeFlag;4841this.m_sleepTime = 0.0;4842}4843else {4844this.m_flags &= ~b2Body.e_awakeFlag;4845this.m_sleepTime = 0.0;4846this.m_linearVelocity.SetZero();4847this.m_angularVelocity = 0.0;4848this.m_force.SetZero();4849this.m_torque = 0.0;4850}4851}4852b2Body.prototype.IsAwake = function () {4853return (this.m_flags & b2Body.e_awakeFlag) == b2Body.e_awakeFlag;4854}4855b2Body.prototype.SetFixedRotation = function (fixed) {4856if (fixed) {4857this.m_flags |= b2Body.e_fixedRotationFlag;4858}4859else {4860this.m_flags &= ~b2Body.e_fixedRotationFlag;4861}4862this.ResetMassData();4863}4864b2Body.prototype.IsFixedRotation = function () {4865return (this.m_flags & b2Body.e_fixedRotationFlag) == b2Body.e_fixedRotationFlag;4866}4867b2Body.prototype.SetActive = function (flag) {4868if (flag == this.IsActive()) {4869return;4870}4871var broadPhase;4872var f;4873if (flag) {4874this.m_flags |= b2Body.e_activeFlag;4875broadPhase = this.m_world.m_contactManager.m_broadPhase;4876for (f = this.m_fixtureList;4877f; f = f.m_next) {4878f.CreateProxy(broadPhase, this.m_xf);4879}4880}4881else {4882this.m_flags &= ~b2Body.e_activeFlag;4883broadPhase = this.m_world.m_contactManager.m_broadPhase;4884for (f = this.m_fixtureList;4885f; f = f.m_next) {4886f.DestroyProxy(broadPhase);4887}4888var ce = this.m_contactList;4889while (ce) {4890var ce0 = ce;4891ce = ce.next;4892this.m_world.m_contactManager.Destroy(ce0.contact);4893}4894this.m_contactList = null;4895}4896}4897b2Body.prototype.IsActive = function () {4898return (this.m_flags & b2Body.e_activeFlag) == b2Body.e_activeFlag;4899}4900b2Body.prototype.IsSleepingAllowed = function () {4901return (this.m_flags & b2Body.e_allowSleepFlag) == b2Body.e_allowSleepFlag;4902}4903b2Body.prototype.GetFixtureList = function () {4904return this.m_fixtureList;4905}4906b2Body.prototype.GetJointList = function () {4907return this.m_jointList;4908}4909b2Body.prototype.GetControllerList = function () {4910return this.m_controllerList;4911}4912b2Body.prototype.GetContactList = function () {4913return this.m_contactList;4914}4915b2Body.prototype.GetNext = function () {4916return this.m_next;4917}4918b2Body.prototype.GetUserData = function () {4919return this.m_userData;4920}4921b2Body.prototype.SetUserData = function (data) {4922this.m_userData = data;4923}4924b2Body.prototype.GetWorld = function () {4925return this.m_world;4926}4927b2Body.prototype.b2Body = function (bd, world) {4928this.m_flags = 0;4929if (bd.bullet) {4930this.m_flags |= b2Body.e_bulletFlag;4931}4932if (bd.fixedRotation) {4933this.m_flags |= b2Body.e_fixedRotationFlag;4934}4935if (bd.allowSleep) {4936this.m_flags |= b2Body.e_allowSleepFlag;4937}4938if (bd.awake) {4939this.m_flags |= b2Body.e_awakeFlag;4940}4941if (bd.active) {4942this.m_flags |= b2Body.e_activeFlag;4943}4944this.m_world = world;4945this.m_xf.position.SetV(bd.position);4946this.m_xf.R.Set(bd.angle);4947this.m_sweep.localCenter.SetZero();4948this.m_sweep.t0 = 1.0;4949this.m_sweep.a0 = this.m_sweep.a = bd.angle;4950var tMat = this.m_xf.R;4951var tVec = this.m_sweep.localCenter;4952this.m_sweep.c.x = (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);4953this.m_sweep.c.y = (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);4954this.m_sweep.c.x += this.m_xf.position.x;4955this.m_sweep.c.y += this.m_xf.position.y;4956this.m_sweep.c0.SetV(this.m_sweep.c);4957this.m_jointList = null;4958this.m_controllerList = null;4959this.m_contactList = null;4960this.m_controllerCount = 0;4961this.m_prev = null;4962this.m_next = null;4963this.m_linearVelocity.SetV(bd.linearVelocity);4964this.m_angularVelocity = bd.angularVelocity;4965this.m_linearDamping = bd.linearDamping;4966this.m_angularDamping = bd.angularDamping;4967this.m_force.Set(0.0, 0.0);4968this.m_torque = 0.0;4969this.m_sleepTime = 0.0;4970this.m_type = bd.type;4971if (this.m_type == b2Body.b2_dynamicBody) {4972this.m_mass = 1.0;4973this.m_invMass = 1.0;4974}4975else {4976this.m_mass = 0.0;4977this.m_invMass = 0.0;4978}4979this.m_I = 0.0;4980this.m_invI = 0.0;4981this.m_inertiaScale = bd.inertiaScale;4982this.m_userData = bd.userData;4983this.m_fixtureList = null;4984this.m_fixtureCount = 0;4985}4986b2Body.prototype.SynchronizeFixtures = function () {4987var xf1 = b2Body.s_xf1;4988xf1.R.Set(this.m_sweep.a0);4989var tMat = xf1.R;4990var tVec = this.m_sweep.localCenter;4991xf1.position.x = this.m_sweep.c0.x - (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);4992xf1.position.y = this.m_sweep.c0.y - (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);4993var f;4994var broadPhase = this.m_world.m_contactManager.m_broadPhase;4995for (f = this.m_fixtureList;4996f; f = f.m_next) {4997f.Synchronize(broadPhase, xf1, this.m_xf);4998}4999}5000b2Body.prototype.SynchronizeTransform = function () {5001this.m_xf.R.Set(this.m_sweep.a);5002var tMat = this.m_xf.R;5003var tVec = this.m_sweep.localCenter;5004this.m_xf.position.x = this.m_sweep.c.x - (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);5005this.m_xf.position.y = this.m_sweep.c.y - (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);5006}5007b2Body.prototype.ShouldCollide = function (other) {5008if (this.m_type != b2Body.b2_dynamicBody && other.m_type != b2Body.b2_dynamicBody) {5009return false;5010}5011for (var jn = this.m_jointList; jn; jn = jn.next) {5012if (jn.other == other) if (jn.joint.m_collideConnected == false) {5013return false;5014}5015}5016return true;5017}5018b2Body.prototype.Advance = function (t) {5019if (t === undefined) t = 0;5020this.m_sweep.Advance(t);5021this.m_sweep.c.SetV(this.m_sweep.c0);5022this.m_sweep.a = this.m_sweep.a0;5023this.SynchronizeTransform();5024}5025Box2D.postDefs.push(function () {5026Box2D.Dynamics.b2Body.s_xf1 = new b2Transform();5027Box2D.Dynamics.b2Body.e_islandFlag = 0x0001;5028Box2D.Dynamics.b2Body.e_awakeFlag = 0x0002;5029Box2D.Dynamics.b2Body.e_allowSleepFlag = 0x0004;5030Box2D.Dynamics.b2Body.e_bulletFlag = 0x0008;5031Box2D.Dynamics.b2Body.e_fixedRotationFlag = 0x0010;5032Box2D.Dynamics.b2Body.e_activeFlag = 0x0020;5033Box2D.Dynamics.b2Body.b2_staticBody = 0;5034Box2D.Dynamics.b2Body.b2_kinematicBody = 1;5035Box2D.Dynamics.b2Body.b2_dynamicBody = 2;5036});5037b2BodyDef.b2BodyDef = function () {5038this.position = new b2Vec2();5039this.linearVelocity = new b2Vec2();5040};5041b2BodyDef.prototype.b2BodyDef = function () {5042this.userData = null;5043this.position.Set(0.0, 0.0);5044this.angle = 0.0;5045this.linearVelocity.Set(0, 0);5046this.angularVelocity = 0.0;5047this.linearDamping = 0.0;5048this.angularDamping = 0.0;5049this.allowSleep = true;5050this.awake = true;5051this.fixedRotation = false;5052this.bullet = false;5053this.type = b2Body.b2_staticBody;5054this.active = true;5055this.inertiaScale = 1.0;5056}5057b2ContactFilter.b2ContactFilter = function () {};5058b2ContactFilter.prototype.ShouldCollide = function (fixtureA, fixtureB) {5059var filter1 = fixtureA.GetFilterData();5060var filter2 = fixtureB.GetFilterData();5061if (filter1.groupIndex == filter2.groupIndex && filter1.groupIndex != 0) {5062return filter1.groupIndex > 0;5063}5064var collide = (filter1.maskBits & filter2.categoryBits) != 0 && (filter1.categoryBits & filter2.maskBits) != 0;5065return collide;5066}5067b2ContactFilter.prototype.RayCollide = function (userData, fixture) {5068if (!userData) return true;5069return this.ShouldCollide((userData instanceof b2Fixture ? userData : null), fixture);5070}5071Box2D.postDefs.push(function () {5072Box2D.Dynamics.b2ContactFilter.b2_defaultFilter = new b2ContactFilter();5073});5074b2ContactImpulse.b2ContactImpulse = function () {5075this.normalImpulses = new Vector_a2j_Number(b2Settings.b2_maxManifoldPoints);5076this.tangentImpulses = new Vector_a2j_Number(b2Settings.b2_maxManifoldPoints);5077};5078b2ContactListener.b2ContactListener = function () {};5079b2ContactListener.prototype.BeginContact = function (contact) {}5080b2ContactListener.prototype.EndContact = function (contact) {}5081b2ContactListener.prototype.PreSolve = function (contact, oldManifold) {}5082b2ContactListener.prototype.PostSolve = function (contact, impulse) {}5083Box2D.postDefs.push(function () {5084Box2D.Dynamics.b2ContactListener.b2_defaultListener = new b2ContactListener();5085});5086b2ContactManager.b2ContactManager = function () {};5087b2ContactManager.prototype.b2ContactManager = function () {5088this.m_world = null;5089this.m_contactCount = 0;5090this.m_contactFilter = b2ContactFilter.b2_defaultFilter;5091this.m_contactListener = b2ContactListener.b2_defaultListener;5092this.m_contactFactory = new b2ContactFactory(this.m_allocator);5093this.m_broadPhase = new b2DynamicTreeBroadPhase();5094}5095b2ContactManager.prototype.AddPair = function (proxyUserDataA, proxyUserDataB) {5096var fixtureA = (proxyUserDataA instanceof b2Fixture ? proxyUserDataA : null);5097var fixtureB = (proxyUserDataB instanceof b2Fixture ? proxyUserDataB : null);5098var bodyA = fixtureA.GetBody();5099var bodyB = fixtureB.GetBody();5100if (bodyA == bodyB) return;5101var edge = bodyB.GetContactList();5102while (edge) {5103if (edge.other == bodyA) {5104var fA = edge.contact.GetFixtureA();5105var fB = edge.contact.GetFixtureB();5106if (fA == fixtureA && fB == fixtureB) return;5107if (fA == fixtureB && fB == fixtureA) return;5108}5109edge = edge.next;5110}5111if (bodyB.ShouldCollide(bodyA) == false) {5112return;5113}5114if (this.m_contactFilter.ShouldCollide(fixtureA, fixtureB) == false) {5115return;5116}5117var c = this.m_contactFactory.Create(fixtureA, fixtureB);5118fixtureA = c.GetFixtureA();5119fixtureB = c.GetFixtureB();5120bodyA = fixtureA.m_body;5121bodyB = fixtureB.m_body;5122c.m_prev = null;5123c.m_next = this.m_world.m_contactList;5124if (this.m_world.m_contactList != null) {5125this.m_world.m_contactList.m_prev = c;5126}5127this.m_world.m_contactList = c;5128c.m_nodeA.contact = c;5129c.m_nodeA.other = bodyB;5130c.m_nodeA.prev = null;5131c.m_nodeA.next = bodyA.m_contactList;5132if (bodyA.m_contactList != null) {5133bodyA.m_contactList.prev = c.m_nodeA;5134}5135bodyA.m_contactList = c.m_nodeA;5136c.m_nodeB.contact = c;5137c.m_nodeB.other = bodyA;5138c.m_nodeB.prev = null;5139c.m_nodeB.next = bodyB.m_contactList;5140if (bodyB.m_contactList != null) {5141bodyB.m_contactList.prev = c.m_nodeB;5142}5143bodyB.m_contactList = c.m_nodeB;5144++this.m_world.m_contactCount;5145return;5146}5147b2ContactManager.prototype.FindNewContacts = function () {5148this.m_broadPhase.UpdatePairs(Box2D.generateCallback(this, this.AddPair));5149}5150b2ContactManager.prototype.Destroy = function (c) {5151var fixtureA = c.GetFixtureA();5152var fixtureB = c.GetFixtureB();5153var bodyA = fixtureA.GetBody();5154var bodyB = fixtureB.GetBody();5155if (c.IsTouching()) {5156this.m_contactListener.EndContact(c);5157}5158if (c.m_prev) {5159c.m_prev.m_next = c.m_next;5160}5161if (c.m_next) {5162c.m_next.m_prev = c.m_prev;5163}5164if (c == this.m_world.m_contactList) {5165this.m_world.m_contactList = c.m_next;5166}5167if (c.m_nodeA.prev) {5168c.m_nodeA.prev.next = c.m_nodeA.next;5169}5170if (c.m_nodeA.next) {5171c.m_nodeA.next.prev = c.m_nodeA.prev;5172}5173if (c.m_nodeA == bodyA.m_contactList) {5174bodyA.m_contactList = c.m_nodeA.next;5175}5176if (c.m_nodeB.prev) {5177c.m_nodeB.prev.next = c.m_nodeB.next;5178}5179if (c.m_nodeB.next) {5180c.m_nodeB.next.prev = c.m_nodeB.prev;5181}5182if (c.m_nodeB == bodyB.m_contactList) {5183bodyB.m_contactList = c.m_nodeB.next;5184}5185this.m_contactFactory.Destroy(c);5186--this.m_contactCount;5187}5188b2ContactManager.prototype.Collide = function () {5189var c = this.m_world.m_contactList;5190while (c) {5191var fixtureA = c.GetFixtureA();5192var fixtureB = c.GetFixtureB();5193var bodyA = fixtureA.GetBody();5194var bodyB = fixtureB.GetBody();5195if (bodyA.IsAwake() == false && bodyB.IsAwake() == false) {5196c = c.GetNext();5197continue;5198}5199if (c.m_flags & b2Contact.e_filterFlag) {5200if (bodyB.ShouldCollide(bodyA) == false) {5201var cNuke = c;5202c = cNuke.GetNext();5203this.Destroy(cNuke);5204continue;5205}5206if (this.m_contactFilter.ShouldCollide(fixtureA, fixtureB) == false) {5207cNuke = c;5208c = cNuke.GetNext();5209this.Destroy(cNuke);5210continue;5211}5212c.m_flags &= ~b2Contact.e_filterFlag;5213}5214var proxyA = fixtureA.m_proxy;5215var proxyB = fixtureB.m_proxy;5216var overlap = this.m_broadPhase.TestOverlap(proxyA, proxyB);5217if (overlap == false) {5218cNuke = c;5219c = cNuke.GetNext();5220this.Destroy(cNuke);5221continue;5222}5223c.Update(this.m_contactListener);5224c = c.GetNext();5225}5226}5227Box2D.postDefs.push(function () {5228Box2D.Dynamics.b2ContactManager.s_evalCP = new b2ContactPoint();5229});5230b2DebugDraw.b2DebugDraw = function () {};5231b2DebugDraw.prototype.b2DebugDraw = function () {}5232b2DebugDraw.prototype.SetFlags = function (flags) {5233if (flags === undefined) flags = 0;5234}5235b2DebugDraw.prototype.GetFlags = function () {}5236b2DebugDraw.prototype.AppendFlags = function (flags) {5237if (flags === undefined) flags = 0;5238}5239b2DebugDraw.prototype.ClearFlags = function (flags) {5240if (flags === undefined) flags = 0;5241}5242b2DebugDraw.prototype.SetSprite = function (sprite) {}5243b2DebugDraw.prototype.GetSprite = function () {}5244b2DebugDraw.prototype.SetDrawScale = function (drawScale) {5245if (drawScale === undefined) drawScale = 0;5246}5247b2DebugDraw.prototype.GetDrawScale = function () {}5248b2DebugDraw.prototype.SetLineThickness = function (lineThickness) {5249if (lineThickness === undefined) lineThickness = 0;5250}5251b2DebugDraw.prototype.GetLineThickness = function () {}5252b2DebugDraw.prototype.SetAlpha = function (alpha) {5253if (alpha === undefined) alpha = 0;5254}5255b2DebugDraw.prototype.GetAlpha = function () {}5256b2DebugDraw.prototype.SetFillAlpha = function (alpha) {5257if (alpha === undefined) alpha = 0;5258}5259b2DebugDraw.prototype.GetFillAlpha = function () {}5260b2DebugDraw.prototype.SetXFormScale = function (xformScale) {5261if (xformScale === undefined) xformScale = 0;5262}5263b2DebugDraw.prototype.GetXFormScale = function () {}5264b2DebugDraw.prototype.DrawPolygon = function (vertices, vertexCount, color) {5265if (vertexCount === undefined) vertexCount = 0;5266}5267b2DebugDraw.prototype.DrawSolidPolygon = function (vertices, vertexCount, color) {5268if (vertexCount === undefined) vertexCount = 0;5269}5270b2DebugDraw.prototype.DrawCircle = function (center, radius, color) {5271if (radius === undefined) radius = 0;5272}5273b2DebugDraw.prototype.DrawSolidCircle = function (center, radius, axis, color) {5274if (radius === undefined) radius = 0;5275}5276b2DebugDraw.prototype.DrawSegment = function (p1, p2, color) {}5277b2DebugDraw.prototype.DrawTransform = function (xf) {}5278Box2D.postDefs.push(function () {5279Box2D.Dynamics.b2DebugDraw.e_shapeBit = 0x0001;5280Box2D.Dynamics.b2DebugDraw.e_jointBit = 0x0002;5281Box2D.Dynamics.b2DebugDraw.e_aabbBit = 0x0004;5282Box2D.Dynamics.b2DebugDraw.e_pairBit = 0x0008;5283Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit = 0x0010;5284Box2D.Dynamics.b2DebugDraw.e_controllerBit = 0x0020;5285});5286b2DestructionListener.b2DestructionListener = function () {};5287b2DestructionListener.prototype.SayGoodbyeJoint = function (joint) {}5288b2DestructionListener.prototype.SayGoodbyeFixture = function (fixture) {}5289b2FilterData.b2FilterData = function () {5290this.categoryBits = 0x0001;5291this.maskBits = 0xFFFF;5292this.groupIndex = 0;5293};5294b2FilterData.prototype.Copy = function () {5295var copy = new b2FilterData();5296copy.categoryBits = this.categoryBits;5297copy.maskBits = this.maskBits;5298copy.groupIndex = this.groupIndex;5299return copy;5300}5301b2Fixture.b2Fixture = function () {5302this.m_filter = new b2FilterData();5303};5304b2Fixture.prototype.GetType = function () {5305return this.m_shape.GetType();5306}5307b2Fixture.prototype.GetShape = function () {5308return this.m_shape;5309}5310b2Fixture.prototype.SetSensor = function (sensor) {5311if (this.m_isSensor == sensor) return;5312this.m_isSensor = sensor;5313if (this.m_body == null) return;5314var edge = this.m_body.GetContactList();5315while (edge) {5316var contact = edge.contact;5317var fixtureA = contact.GetFixtureA();5318var fixtureB = contact.GetFixtureB();5319if (fixtureA == this || fixtureB == this) contact.SetSensor(fixtureA.IsSensor() || fixtureB.IsSensor());5320edge = edge.next;5321}5322}5323b2Fixture.prototype.IsSensor = function () {5324return this.m_isSensor;5325}5326b2Fixture.prototype.SetFilterData = function (filter) {5327this.m_filter = filter.Copy();5328if (this.m_body) return;5329var edge = this.m_body.GetContactList();5330while (edge) {5331var contact = edge.contact;5332var fixtureA = contact.GetFixtureA();5333var fixtureB = contact.GetFixtureB();5334if (fixtureA == this || fixtureB == this) contact.FlagForFiltering();5335edge = edge.next;5336}5337}5338b2Fixture.prototype.GetFilterData = function () {5339return this.m_filter.Copy();5340}5341b2Fixture.prototype.GetBody = function () {5342return this.m_body;5343}5344b2Fixture.prototype.GetNext = function () {5345return this.m_next;5346}5347b2Fixture.prototype.GetUserData = function () {5348return this.m_userData;5349}5350b2Fixture.prototype.SetUserData = function (data) {5351this.m_userData = data;5352}5353b2Fixture.prototype.TestPoint = function (p) {5354return this.m_shape.TestPoint(this.m_body.GetTransform(), p);5355}5356b2Fixture.prototype.RayCast = function (output, input) {5357return this.m_shape.RayCast(output, input, this.m_body.GetTransform());5358}5359b2Fixture.prototype.GetMassData = function (massData) {5360if (massData === undefined) massData = null;5361if (massData == null) {5362massData = new b2MassData();5363}5364this.m_shape.ComputeMass(massData, this.m_density);5365return massData;5366}5367b2Fixture.prototype.SetDensity = function (density) {5368if (density === undefined) density = 0;5369this.m_density = density;5370}5371b2Fixture.prototype.GetDensity = function () {5372return this.m_density;5373}5374b2Fixture.prototype.GetFriction = function () {5375return this.m_friction;5376}5377b2Fixture.prototype.SetFriction = function (friction) {5378if (friction === undefined) friction = 0;5379this.m_friction = friction;5380}5381b2Fixture.prototype.GetRestitution = function () {5382return this.m_restitution;5383}5384b2Fixture.prototype.SetRestitution = function (restitution) {5385if (restitution === undefined) restitution = 0;5386this.m_restitution = restitution;5387}5388b2Fixture.prototype.GetAABB = function () {5389return this.m_aabb;5390}5391b2Fixture.prototype.b2Fixture = function () {5392this.m_aabb = new b2AABB();5393this.m_userData = null;5394this.m_body = null;5395this.m_next = null;5396this.m_shape = null;5397this.m_density = 0.0;5398this.m_friction = 0.0;5399this.m_restitution = 0.0;5400}5401b2Fixture.prototype.Create = function (body, xf, def) {5402this.m_userData = def.userData;5403this.m_friction = def.friction;5404this.m_restitution = def.restitution;5405this.m_body = body;5406this.m_next = null;5407this.m_filter = def.filter.Copy();5408this.m_isSensor = def.isSensor;5409this.m_shape = def.shape.Copy();5410this.m_density = def.density;5411}5412b2Fixture.prototype.Destroy = function () {5413this.m_shape = null;5414}5415b2Fixture.prototype.CreateProxy = function (broadPhase, xf) {5416this.m_shape.ComputeAABB(this.m_aabb, xf);5417this.m_proxy = broadPhase.CreateProxy(this.m_aabb, this);5418}5419b2Fixture.prototype.DestroyProxy = function (broadPhase) {5420if (this.m_proxy == null) {5421return;5422}5423broadPhase.DestroyProxy(this.m_proxy);5424this.m_proxy = null;5425}5426b2Fixture.prototype.Synchronize = function (broadPhase, transform1, transform2) {5427if (!this.m_proxy) return;5428var aabb1 = new b2AABB();5429var aabb2 = new b2AABB();5430this.m_shape.ComputeAABB(aabb1, transform1);5431this.m_shape.ComputeAABB(aabb2, transform2);5432this.m_aabb.Combine(aabb1, aabb2);5433var displacement = b2Math.SubtractVV(transform2.position, transform1.position);5434broadPhase.MoveProxy(this.m_proxy, this.m_aabb, displacement);5435}5436b2FixtureDef.b2FixtureDef = function () {5437this.filter = new b2FilterData();5438};5439b2FixtureDef.prototype.b2FixtureDef = function () {5440this.shape = null;5441this.userData = null;5442this.friction = 0.2;5443this.restitution = 0.0;5444this.density = 0.0;5445this.filter.categoryBits = 0x0001;5446this.filter.maskBits = 0xFFFF;5447this.filter.groupIndex = 0;5448this.isSensor = false;5449}5450b2Island.b2Island = function () {};5451b2Island.prototype.b2Island = function () {5452this.m_bodies = new Vector();5453this.m_contacts = new Vector();5454this.m_joints = new Vector();5455}5456b2Island.prototype.Initialize = function (bodyCapacity, contactCapacity, jointCapacity, allocator, listener, contactSolver) {5457if (bodyCapacity === undefined) bodyCapacity = 0;5458if (contactCapacity === undefined) contactCapacity = 0;5459if (jointCapacity === undefined) jointCapacity = 0;5460var i = 0;5461this.m_bodyCapacity = bodyCapacity;5462this.m_contactCapacity = contactCapacity;5463this.m_jointCapacity = jointCapacity;5464this.m_bodyCount = 0;5465this.m_contactCount = 0;5466this.m_jointCount = 0;5467this.m_allocator = allocator;5468this.m_listener = listener;5469this.m_contactSolver = contactSolver;5470for (i = this.m_bodies.length;5471i < bodyCapacity; i++)5472this.m_bodies[i] = null;5473for (i = this.m_contacts.length;5474i < contactCapacity; i++)5475this.m_contacts[i] = null;5476for (i = this.m_joints.length;5477i < jointCapacity; i++)5478this.m_joints[i] = null;5479}5480b2Island.prototype.Clear = function () {5481this.m_bodyCount = 0;5482this.m_contactCount = 0;5483this.m_jointCount = 0;5484}5485b2Island.prototype.Solve = function (step, gravity, allowSleep) {5486var i = 0;5487var j = 0;5488var b;5489var joint;5490for (i = 0;5491i < this.m_bodyCount; ++i) {5492b = this.m_bodies[i];5493if (b.GetType() != b2Body.b2_dynamicBody) continue;5494b.m_linearVelocity.x += step.dt * (gravity.x + b.m_invMass * b.m_force.x);5495b.m_linearVelocity.y += step.dt * (gravity.y + b.m_invMass * b.m_force.y);5496b.m_angularVelocity += step.dt * b.m_invI * b.m_torque;5497b.m_linearVelocity.Multiply(b2Math.Clamp(1.0 - step.dt * b.m_linearDamping, 0.0, 1.0));5498b.m_angularVelocity *= b2Math.Clamp(1.0 - step.dt * b.m_angularDamping, 0.0, 1.0);5499}5500this.m_contactSolver.Initialize(step, this.m_contacts, this.m_contactCount, this.m_allocator);5501var contactSolver = this.m_contactSolver;5502contactSolver.InitVelocityConstraints(step);5503for (i = 0;5504i < this.m_jointCount; ++i) {5505joint = this.m_joints[i];5506joint.InitVelocityConstraints(step);5507}5508for (i = 0;5509i < step.velocityIterations; ++i) {5510for (j = 0;5511j < this.m_jointCount; ++j) {5512joint = this.m_joints[j];5513joint.SolveVelocityConstraints(step);5514}5515contactSolver.SolveVelocityConstraints();5516}5517for (i = 0;5518i < this.m_jointCount; ++i) {5519joint = this.m_joints[i];5520joint.FinalizeVelocityConstraints();5521}5522contactSolver.FinalizeVelocityConstraints();5523for (i = 0;5524i < this.m_bodyCount; ++i) {5525b = this.m_bodies[i];5526if (b.GetType() == b2Body.b2_staticBody) continue;5527var translationX = step.dt * b.m_linearVelocity.x;5528var translationY = step.dt * b.m_linearVelocity.y;5529if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) {5530b.m_linearVelocity.Normalize();5531b.m_linearVelocity.x *= b2Settings.b2_maxTranslation * step.inv_dt;5532b.m_linearVelocity.y *= b2Settings.b2_maxTranslation * step.inv_dt;5533}5534var rotation = step.dt * b.m_angularVelocity;5535if (rotation * rotation > b2Settings.b2_maxRotationSquared) {5536if (b.m_angularVelocity < 0.0) {5537b.m_angularVelocity = (-b2Settings.b2_maxRotation * step.inv_dt);5538}5539else {5540b.m_angularVelocity = b2Settings.b2_maxRotation * step.inv_dt;5541}5542}5543b.m_sweep.c0.SetV(b.m_sweep.c);5544b.m_sweep.a0 = b.m_sweep.a;5545b.m_sweep.c.x += step.dt * b.m_linearVelocity.x;5546b.m_sweep.c.y += step.dt * b.m_linearVelocity.y;5547b.m_sweep.a += step.dt * b.m_angularVelocity;5548b.SynchronizeTransform();5549}5550for (i = 0;5551i < step.positionIterations; ++i) {5552var contactsOkay = contactSolver.SolvePositionConstraints(b2Settings.b2_contactBaumgarte);5553var jointsOkay = true;5554for (j = 0;5555j < this.m_jointCount; ++j) {5556joint = this.m_joints[j];5557var jointOkay = joint.SolvePositionConstraints(b2Settings.b2_contactBaumgarte);5558jointsOkay = jointsOkay && jointOkay;5559}5560if (contactsOkay && jointsOkay) {5561break;5562}5563}5564this.Report(contactSolver.m_constraints);5565if (allowSleep) {5566var minSleepTime = Number.MAX_VALUE;5567var linTolSqr = b2Settings.b2_linearSleepTolerance * b2Settings.b2_linearSleepTolerance;5568var angTolSqr = b2Settings.b2_angularSleepTolerance * b2Settings.b2_angularSleepTolerance;5569for (i = 0;5570i < this.m_bodyCount; ++i) {5571b = this.m_bodies[i];5572if (b.GetType() == b2Body.b2_staticBody) {5573continue;5574}5575if ((b.m_flags & b2Body.e_allowSleepFlag) == 0) {5576b.m_sleepTime = 0.0;5577minSleepTime = 0.0;5578}5579if ((b.m_flags & b2Body.e_allowSleepFlag) == 0 || b.m_angularVelocity * b.m_angularVelocity > angTolSqr || b2Math.Dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr) {5580b.m_sleepTime = 0.0;5581minSleepTime = 0.0;5582}5583else {5584b.m_sleepTime += step.dt;5585minSleepTime = b2Math.Min(minSleepTime, b.m_sleepTime);5586}5587}5588if (minSleepTime >= b2Settings.b2_timeToSleep) {5589for (i = 0;5590i < this.m_bodyCount; ++i) {5591b = this.m_bodies[i];5592b.SetAwake(false);5593}5594}5595}5596}5597b2Island.prototype.SolveTOI = function (subStep) {5598var i = 0;5599var j = 0;5600this.m_contactSolver.Initialize(subStep, this.m_contacts, this.m_contactCount, this.m_allocator);5601var contactSolver = this.m_contactSolver;5602for (i = 0;5603i < this.m_jointCount; ++i) {5604this.m_joints[i].InitVelocityConstraints(subStep);5605}5606for (i = 0;5607i < subStep.velocityIterations; ++i) {5608contactSolver.SolveVelocityConstraints();5609for (j = 0;5610j < this.m_jointCount; ++j) {5611this.m_joints[j].SolveVelocityConstraints(subStep);5612}5613}5614for (i = 0;5615i < this.m_bodyCount; ++i) {5616var b = this.m_bodies[i];5617if (b.GetType() == b2Body.b2_staticBody) continue;5618var translationX = subStep.dt * b.m_linearVelocity.x;5619var translationY = subStep.dt * b.m_linearVelocity.y;5620if ((translationX * translationX + translationY * translationY) > b2Settings.b2_maxTranslationSquared) {5621b.m_linearVelocity.Normalize();5622b.m_linearVelocity.x *= b2Settings.b2_maxTranslation * subStep.inv_dt;5623b.m_linearVelocity.y *= b2Settings.b2_maxTranslation * subStep.inv_dt;5624}5625var rotation = subStep.dt * b.m_angularVelocity;5626if (rotation * rotation > b2Settings.b2_maxRotationSquared) {5627if (b.m_angularVelocity < 0.0) {5628b.m_angularVelocity = (-b2Settings.b2_maxRotation * subStep.inv_dt);5629}5630else {5631b.m_angularVelocity = b2Settings.b2_maxRotation * subStep.inv_dt;5632}5633}5634b.m_sweep.c0.SetV(b.m_sweep.c);5635b.m_sweep.a0 = b.m_sweep.a;5636b.m_sweep.c.x += subStep.dt * b.m_linearVelocity.x;5637b.m_sweep.c.y += subStep.dt * b.m_linearVelocity.y;5638b.m_sweep.a += subStep.dt * b.m_angularVelocity;5639b.SynchronizeTransform();5640}5641var k_toiBaumgarte = 0.75;5642for (i = 0;5643i < subStep.positionIterations; ++i) {5644var contactsOkay = contactSolver.SolvePositionConstraints(k_toiBaumgarte);5645var jointsOkay = true;5646for (j = 0;5647j < this.m_jointCount; ++j) {5648var jointOkay = this.m_joints[j].SolvePositionConstraints(b2Settings.b2_contactBaumgarte);5649jointsOkay = jointsOkay && jointOkay;5650}5651if (contactsOkay && jointsOkay) {5652break;5653}5654}5655this.Report(contactSolver.m_constraints);5656}5657b2Island.prototype.Report = function (constraints) {5658if (this.m_listener == null) {5659return;5660}5661for (var i = 0; i < this.m_contactCount; ++i) {5662var c = this.m_contacts[i];5663var cc = constraints[i];5664for (var j = 0; j < cc.pointCount; ++j) {5665b2Island.s_impulse.normalImpulses[j] = cc.points[j].normalImpulse;5666b2Island.s_impulse.tangentImpulses[j] = cc.points[j].tangentImpulse;5667}5668this.m_listener.PostSolve(c, b2Island.s_impulse);5669}5670}5671b2Island.prototype.AddBody = function (body) {5672body.m_islandIndex = this.m_bodyCount;5673this.m_bodies[this.m_bodyCount++] = body;5674}5675b2Island.prototype.AddContact = function (contact) {5676this.m_contacts[this.m_contactCount++] = contact;5677}5678b2Island.prototype.AddJoint = function (joint) {5679this.m_joints[this.m_jointCount++] = joint;5680}5681Box2D.postDefs.push(function () {5682Box2D.Dynamics.b2Island.s_impulse = new b2ContactImpulse();5683});5684b2TimeStep.b2TimeStep = function () {};5685b2TimeStep.prototype.Set = function (step) {5686this.dt = step.dt;5687this.inv_dt = step.inv_dt;5688this.positionIterations = step.positionIterations;5689this.velocityIterations = step.velocityIterations;5690this.warmStarting = step.warmStarting;5691}5692b2World.b2World = function () {5693this.s_stack = new Vector();5694this.m_contactManager = new b2ContactManager();5695this.m_contactSolver = new b2ContactSolver();5696this.m_island = new b2Island();5697};5698b2World.prototype.b2World = function (gravity, doSleep) {5699this.m_destructionListener = null;5700this.m_debugDraw = null;5701this.m_bodyList = null;5702this.m_contactList = null;5703this.m_jointList = null;5704this.m_controllerList = null;5705this.m_bodyCount = 0;5706this.m_contactCount = 0;5707this.m_jointCount = 0;5708this.m_controllerCount = 0;5709b2World.m_warmStarting = true;5710b2World.m_continuousPhysics = true;5711this.m_allowSleep = doSleep;5712this.m_gravity = gravity;5713this.m_inv_dt0 = 0.0;5714this.m_contactManager.m_world = this;5715var bd = new b2BodyDef();5716this.m_groundBody = this.CreateBody(bd);5717}5718b2World.prototype.SetDestructionListener = function (listener) {5719this.m_destructionListener = listener;5720}5721b2World.prototype.SetContactFilter = function (filter) {5722this.m_contactManager.m_contactFilter = filter;5723}5724b2World.prototype.SetContactListener = function (listener) {5725this.m_contactManager.m_contactListener = listener;5726}5727b2World.prototype.SetDebugDraw = function (debugDraw) {5728this.m_debugDraw = debugDraw;5729}5730b2World.prototype.SetBroadPhase = function (broadPhase) {5731var oldBroadPhase = this.m_contactManager.m_broadPhase;5732this.m_contactManager.m_broadPhase = broadPhase;5733for (var b = this.m_bodyList; b; b = b.m_next) {5734for (var f = b.m_fixtureList; f; f = f.m_next) {5735f.m_proxy = broadPhase.CreateProxy(oldBroadPhase.GetFatAABB(f.m_proxy), f);5736}5737}5738}5739b2World.prototype.Validate = function () {5740this.m_contactManager.m_broadPhase.Validate();5741}5742b2World.prototype.GetProxyCount = function () {5743return this.m_contactManager.m_broadPhase.GetProxyCount();5744}5745b2World.prototype.CreateBody = function (def) {5746if (this.IsLocked() == true) {5747return null;5748}5749var b = new b2Body(def, this);5750b.m_prev = null;5751b.m_next = this.m_bodyList;5752if (this.m_bodyList) {5753this.m_bodyList.m_prev = b;5754}5755this.m_bodyList = b;5756++this.m_bodyCount;5757return b;5758}5759b2World.prototype.DestroyBody = function (b) {5760if (this.IsLocked() == true) {5761return;5762}5763var jn = b.m_jointList;5764while (jn) {5765var jn0 = jn;5766jn = jn.next;5767if (this.m_destructionListener) {5768this.m_destructionListener.SayGoodbyeJoint(jn0.joint);5769}5770this.DestroyJoint(jn0.joint);5771}5772var coe = b.m_controllerList;5773while (coe) {5774var coe0 = coe;5775coe = coe.nextController;5776coe0.controller.RemoveBody(b);5777}5778var ce = b.m_contactList;5779while (ce) {5780var ce0 = ce;5781ce = ce.next;5782this.m_contactManager.Destroy(ce0.contact);5783}5784b.m_contactList = null;5785var f = b.m_fixtureList;5786while (f) {5787var f0 = f;5788f = f.m_next;5789if (this.m_destructionListener) {5790this.m_destructionListener.SayGoodbyeFixture(f0);5791}5792f0.DestroyProxy(this.m_contactManager.m_broadPhase);5793f0.Destroy();5794}5795b.m_fixtureList = null;5796b.m_fixtureCount = 0;5797if (b.m_prev) {5798b.m_prev.m_next = b.m_next;5799}5800if (b.m_next) {5801b.m_next.m_prev = b.m_prev;5802}5803if (b == this.m_bodyList) {5804this.m_bodyList = b.m_next;5805}--this.m_bodyCount;5806}5807b2World.prototype.CreateJoint = function (def) {5808var j = b2Joint.Create(def, null);5809j.m_prev = null;5810j.m_next = this.m_jointList;5811if (this.m_jointList) {5812this.m_jointList.m_prev = j;5813}5814this.m_jointList = j;5815++this.m_jointCount;5816j.m_edgeA.joint = j;5817j.m_edgeA.other = j.m_bodyB;5818j.m_edgeA.prev = null;5819j.m_edgeA.next = j.m_bodyA.m_jointList;5820if (j.m_bodyA.m_jointList) j.m_bodyA.m_jointList.prev = j.m_edgeA;5821j.m_bodyA.m_jointList = j.m_edgeA;5822j.m_edgeB.joint = j;5823j.m_edgeB.other = j.m_bodyA;5824j.m_edgeB.prev = null;5825j.m_edgeB.next = j.m_bodyB.m_jointList;5826if (j.m_bodyB.m_jointList) j.m_bodyB.m_jointList.prev = j.m_edgeB;5827j.m_bodyB.m_jointList = j.m_edgeB;5828var bodyA = def.bodyA;5829var bodyB = def.bodyB;5830if (def.collideConnected == false) {5831var edge = bodyB.GetContactList();5832while (edge) {5833if (edge.other == bodyA) {5834edge.contact.FlagForFiltering();5835}5836edge = edge.next;5837}5838}5839return j;5840}5841b2World.prototype.DestroyJoint = function (j) {5842var collideConnected = j.m_collideConnected;5843if (j.m_prev) {5844j.m_prev.m_next = j.m_next;5845}5846if (j.m_next) {5847j.m_next.m_prev = j.m_prev;5848}5849if (j == this.m_jointList) {5850this.m_jointList = j.m_next;5851}5852var bodyA = j.m_bodyA;5853var bodyB = j.m_bodyB;5854bodyA.SetAwake(true);5855bodyB.SetAwake(true);5856if (j.m_edgeA.prev) {5857j.m_edgeA.prev.next = j.m_edgeA.next;5858}5859if (j.m_edgeA.next) {5860j.m_edgeA.next.prev = j.m_edgeA.prev;5861}5862if (j.m_edgeA == bodyA.m_jointList) {5863bodyA.m_jointList = j.m_edgeA.next;5864}5865j.m_edgeA.prev = null;5866j.m_edgeA.next = null;5867if (j.m_edgeB.prev) {5868j.m_edgeB.prev.next = j.m_edgeB.next;5869}5870if (j.m_edgeB.next) {5871j.m_edgeB.next.prev = j.m_edgeB.prev;5872}5873if (j.m_edgeB == bodyB.m_jointList) {5874bodyB.m_jointList = j.m_edgeB.next;5875}5876j.m_edgeB.prev = null;5877j.m_edgeB.next = null;5878b2Joint.Destroy(j, null);5879--this.m_jointCount;5880if (collideConnected == false) {5881var edge = bodyB.GetContactList();5882while (edge) {5883if (edge.other == bodyA) {5884edge.contact.FlagForFiltering();5885}5886edge = edge.next;5887}5888}5889}5890b2World.prototype.AddController = function (c) {5891c.m_next = this.m_controllerList;5892c.m_prev = null;5893this.m_controllerList = c;5894c.m_world = this;5895this.m_controllerCount++;5896return c;5897}5898b2World.prototype.RemoveController = function (c) {5899if (c.m_prev) c.m_prev.m_next = c.m_next;5900if (c.m_next) c.m_next.m_prev = c.m_prev;5901if (this.m_controllerList == c) this.m_controllerList = c.m_next;5902this.m_controllerCount--;5903}5904b2World.prototype.CreateController = function (controller) {5905if (controller.m_world != this) throw new Error("Controller can only be a member of one world");5906controller.m_next = this.m_controllerList;5907controller.m_prev = null;5908if (this.m_controllerList) this.m_controllerList.m_prev = controller;5909this.m_controllerList = controller;5910++this.m_controllerCount;5911controller.m_world = this;5912return controller;5913}5914b2World.prototype.DestroyController = function (controller) {5915controller.Clear();5916if (controller.m_next) controller.m_next.m_prev = controller.m_prev;5917if (controller.m_prev) controller.m_prev.m_next = controller.m_next;5918if (controller == this.m_controllerList) this.m_controllerList = controller.m_next;5919--this.m_controllerCount;5920}5921b2World.prototype.SetWarmStarting = function (flag) {5922b2World.m_warmStarting = flag;5923}5924b2World.prototype.SetContinuousPhysics = function (flag) {5925b2World.m_continuousPhysics = flag;5926}5927b2World.prototype.GetBodyCount = function () {5928return this.m_bodyCount;5929}5930b2World.prototype.GetJointCount = function () {5931return this.m_jointCount;5932}5933b2World.prototype.GetContactCount = function () {5934return this.m_contactCount;5935}5936b2World.prototype.SetGravity = function (gravity) {5937this.m_gravity = gravity;5938}5939b2World.prototype.GetGravity = function () {5940return this.m_gravity;5941}5942b2World.prototype.GetGroundBody = function () {5943return this.m_groundBody;5944}5945b2World.prototype.Step = function (dt, velocityIterations, positionIterations) {5946if (dt === undefined) dt = 0;5947if (velocityIterations === undefined) velocityIterations = 0;5948if (positionIterations === undefined) positionIterations = 0;5949if (this.m_flags & b2World.e_newFixture) {5950this.m_contactManager.FindNewContacts();5951this.m_flags &= ~b2World.e_newFixture;5952}5953this.m_flags |= b2World.e_locked;5954var step = b2World.s_timestep2;5955step.dt = dt;5956step.velocityIterations = velocityIterations;5957step.positionIterations = positionIterations;5958if (dt > 0.0) {5959step.inv_dt = 1.0 / dt;5960}5961else {5962step.inv_dt = 0.0;5963}5964step.dtRatio = this.m_inv_dt0 * dt;5965step.warmStarting = b2World.m_warmStarting;5966this.m_contactManager.Collide();5967if (step.dt > 0.0) {5968this.Solve(step);5969}5970if (b2World.m_continuousPhysics && step.dt > 0.0) {5971this.SolveTOI(step);5972}5973if (step.dt > 0.0) {5974this.m_inv_dt0 = step.inv_dt;5975}5976this.m_flags &= ~b2World.e_locked;5977}5978b2World.prototype.ClearForces = function () {5979for (var body = this.m_bodyList; body; body = body.m_next) {5980body.m_force.SetZero();5981body.m_torque = 0.0;5982}5983}5984b2World.prototype.DrawDebugData = function () {5985if (this.m_debugDraw == null) {5986return;5987}5988this.m_debugDraw.m_sprite.graphics.clear();5989var flags = this.m_debugDraw.GetFlags();5990var i = 0;5991var b;5992var f;5993var s;5994var j;5995var bp;5996var invQ = new b2Vec2;5997var x1 = new b2Vec2;5998var x2 = new b2Vec2;5999var xf;6000var b1 = new b2AABB();6001var b2 = new b2AABB();6002var vs = [new b2Vec2(), new b2Vec2(), new b2Vec2(), new b2Vec2()];6003var color = new b2Color(0, 0, 0);6004if (flags & b2DebugDraw.e_shapeBit) {6005for (b = this.m_bodyList;6006b; b = b.m_next) {6007xf = b.m_xf;6008for (f = b.GetFixtureList();6009f; f = f.m_next) {6010s = f.GetShape();6011if (b.IsActive() == false) {6012color.Set(0.5, 0.5, 0.3);6013this.DrawShape(s, xf, color);6014}6015else if (b.GetType() == b2Body.b2_staticBody) {6016color.Set(0.5, 0.9, 0.5);6017this.DrawShape(s, xf, color);6018}6019else if (b.GetType() == b2Body.b2_kinematicBody) {6020color.Set(0.5, 0.5, 0.9);6021this.DrawShape(s, xf, color);6022}6023else if (b.IsAwake() == false) {6024color.Set(0.6, 0.6, 0.6);6025this.DrawShape(s, xf, color);6026}6027else {6028color.Set(0.9, 0.7, 0.7);6029this.DrawShape(s, xf, color);6030}6031}6032}6033}6034if (flags & b2DebugDraw.e_jointBit) {6035for (j = this.m_jointList;6036j; j = j.m_next) {6037this.DrawJoint(j);6038}6039}6040if (flags & b2DebugDraw.e_controllerBit) {6041for (var c = this.m_controllerList; c; c = c.m_next) {6042c.Draw(this.m_debugDraw);6043}6044}6045if (flags & b2DebugDraw.e_pairBit) {6046color.Set(0.3, 0.9, 0.9);6047for (var contact = this.m_contactManager.m_contactList; contact; contact = contact.GetNext()) {6048var fixtureA = contact.GetFixtureA();6049var fixtureB = contact.GetFixtureB();6050var cA = fixtureA.GetAABB().GetCenter();6051var cB = fixtureB.GetAABB().GetCenter();6052this.m_debugDraw.DrawSegment(cA, cB, color);6053}6054}6055if (flags & b2DebugDraw.e_aabbBit) {6056bp = this.m_contactManager.m_broadPhase;6057vs = [new b2Vec2(), new b2Vec2(), new b2Vec2(), new b2Vec2()];6058for (b = this.m_bodyList;6059b; b = b.GetNext()) {6060if (b.IsActive() == false) {6061continue;6062}6063for (f = b.GetFixtureList();6064f; f = f.GetNext()) {6065var aabb = bp.GetFatAABB(f.m_proxy);6066vs[0].Set(aabb.lowerBound.x, aabb.lowerBound.y);6067vs[1].Set(aabb.upperBound.x, aabb.lowerBound.y);6068vs[2].Set(aabb.upperBound.x, aabb.upperBound.y);6069vs[3].Set(aabb.lowerBound.x, aabb.upperBound.y);6070this.m_debugDraw.DrawPolygon(vs, 4, color);6071}6072}6073}6074if (flags & b2DebugDraw.e_centerOfMassBit) {6075for (b = this.m_bodyList;6076b; b = b.m_next) {6077xf = b2World.s_xf;6078xf.R = b.m_xf.R;6079xf.position = b.GetWorldCenter();6080this.m_debugDraw.DrawTransform(xf);6081}6082}6083}6084b2World.prototype.QueryAABB = function (callback, aabb) {6085var __this = this;6086var broadPhase = __this.m_contactManager.m_broadPhase;60876088function WorldQueryWrapper(proxy) {6089return callback(broadPhase.GetUserData(proxy));6090};6091broadPhase.Query(WorldQueryWrapper, aabb);6092}6093b2World.prototype.QueryShape = function (callback, shape, transform) {6094var __this = this;6095if (transform === undefined) transform = null;6096if (transform == null) {6097transform = new b2Transform();6098transform.SetIdentity();6099}6100var broadPhase = __this.m_contactManager.m_broadPhase;61016102function WorldQueryWrapper(proxy) {6103var fixture = (broadPhase.GetUserData(proxy) instanceof b2Fixture ? broadPhase.GetUserData(proxy) : null);6104if (b2Shape.TestOverlap(shape, transform, fixture.GetShape(), fixture.GetBody().GetTransform())) return callback(fixture);6105return true;6106};6107var aabb = new b2AABB();6108shape.ComputeAABB(aabb, transform);6109broadPhase.Query(WorldQueryWrapper, aabb);6110}6111b2World.prototype.QueryPoint = function (callback, p) {6112var __this = this;6113var broadPhase = __this.m_contactManager.m_broadPhase;61146115function WorldQueryWrapper(proxy) {6116var fixture = (broadPhase.GetUserData(proxy) instanceof b2Fixture ? broadPhase.GetUserData(proxy) : null);6117if (fixture.TestPoint(p)) return callback(fixture);6118return true;6119};6120var aabb = new b2AABB();6121aabb.lowerBound.Set(p.x - b2Settings.b2_linearSlop, p.y - b2Settings.b2_linearSlop);6122aabb.upperBound.Set(p.x + b2Settings.b2_linearSlop, p.y + b2Settings.b2_linearSlop);6123broadPhase.Query(WorldQueryWrapper, aabb);6124}6125b2World.prototype.RayCast = function (callback, point1, point2) {6126var __this = this;6127var broadPhase = __this.m_contactManager.m_broadPhase;6128var output = new b2RayCastOutput;61296130function RayCastWrapper(input, proxy) {6131var userData = broadPhase.GetUserData(proxy);6132var fixture = (userData instanceof b2Fixture ? userData : null);6133var hit = fixture.RayCast(output, input);6134if (hit) {6135var fraction = output.fraction;6136var point = new b2Vec2((1.0 - fraction) * point1.x + fraction * point2.x, (1.0 - fraction) * point1.y + fraction * point2.y);6137return callback(fixture, point, output.normal, fraction);6138}6139return input.maxFraction;6140};6141var input = new b2RayCastInput(point1, point2);6142broadPhase.RayCast(RayCastWrapper, input);6143}6144b2World.prototype.RayCastOne = function (point1, point2) {6145var __this = this;6146var result;61476148function RayCastOneWrapper(fixture, point, normal, fraction) {6149if (fraction === undefined) fraction = 0;6150result = fixture;6151return fraction;6152};6153__this.RayCast(RayCastOneWrapper, point1, point2);6154return result;6155}6156b2World.prototype.RayCastAll = function (point1, point2) {6157var __this = this;6158var result = new Vector();61596160function RayCastAllWrapper(fixture, point, normal, fraction) {6161if (fraction === undefined) fraction = 0;6162result[result.length] = fixture;6163return 1;6164};6165__this.RayCast(RayCastAllWrapper, point1, point2);6166return result;6167}6168b2World.prototype.GetBodyList = function () {6169return this.m_bodyList;6170}6171b2World.prototype.GetJointList = function () {6172return this.m_jointList;6173}6174b2World.prototype.GetContactList = function () {6175return this.m_contactList;6176}6177b2World.prototype.IsLocked = function () {6178return (this.m_flags & b2World.e_locked) > 0;6179}6180b2World.prototype.Solve = function (step) {6181var b;6182for (var controller = this.m_controllerList; controller; controller = controller.m_next) {6183controller.Step(step);6184}6185var island = this.m_island;6186island.Initialize(this.m_bodyCount, this.m_contactCount, this.m_jointCount, null, this.m_contactManager.m_contactListener, this.m_contactSolver);6187for (b = this.m_bodyList;6188b; b = b.m_next) {6189b.m_flags &= ~b2Body.e_islandFlag;6190}6191for (var c = this.m_contactList; c; c = c.m_next) {6192c.m_flags &= ~b2Contact.e_islandFlag;6193}6194for (var j = this.m_jointList; j; j = j.m_next) {6195j.m_islandFlag = false;6196}6197var stackSize = parseInt(this.m_bodyCount);6198var stack = this.s_stack;6199for (var seed = this.m_bodyList; seed; seed = seed.m_next) {6200if (seed.m_flags & b2Body.e_islandFlag) {6201continue;6202}6203if (seed.IsAwake() == false || seed.IsActive() == false) {6204continue;6205}6206if (seed.GetType() == b2Body.b2_staticBody) {6207continue;6208}6209island.Clear();6210var stackCount = 0;6211stack[stackCount++] = seed;6212seed.m_flags |= b2Body.e_islandFlag;6213while (stackCount > 0) {6214b = stack[--stackCount];6215island.AddBody(b);6216if (b.IsAwake() == false) {6217b.SetAwake(true);6218}6219if (b.GetType() == b2Body.b2_staticBody) {6220continue;6221}6222var other;6223for (var ce = b.m_contactList; ce; ce = ce.next) {6224if (ce.contact.m_flags & b2Contact.e_islandFlag) {6225continue;6226}6227if (ce.contact.IsSensor() == true || ce.contact.IsEnabled() == false || ce.contact.IsTouching() == false) {6228continue;6229}6230island.AddContact(ce.contact);6231ce.contact.m_flags |= b2Contact.e_islandFlag;6232other = ce.other;6233if (other.m_flags & b2Body.e_islandFlag) {6234continue;6235}6236stack[stackCount++] = other;6237other.m_flags |= b2Body.e_islandFlag;6238}6239for (var jn = b.m_jointList; jn; jn = jn.next) {6240if (jn.joint.m_islandFlag == true) {6241continue;6242}6243other = jn.other;6244if (other.IsActive() == false) {6245continue;6246}6247island.AddJoint(jn.joint);6248jn.joint.m_islandFlag = true;6249if (other.m_flags & b2Body.e_islandFlag) {6250continue;6251}6252stack[stackCount++] = other;6253other.m_flags |= b2Body.e_islandFlag;6254}6255}6256island.Solve(step, this.m_gravity, this.m_allowSleep);6257for (var i = 0; i < island.m_bodyCount; ++i) {6258b = island.m_bodies[i];6259if (b.GetType() == b2Body.b2_staticBody) {6260b.m_flags &= ~b2Body.e_islandFlag;6261}6262}6263}6264for (i = 0;6265i < stack.length; ++i) {6266if (!stack[i]) break;6267stack[i] = null;6268}6269for (b = this.m_bodyList;6270b; b = b.m_next) {6271if (b.IsAwake() == false || b.IsActive() == false) {6272continue;6273}6274if (b.GetType() == b2Body.b2_staticBody) {6275continue;6276}6277b.SynchronizeFixtures();6278}6279this.m_contactManager.FindNewContacts();6280}6281b2World.prototype.SolveTOI = function (step) {6282var b;6283var fA;6284var fB;6285var bA;6286var bB;6287var cEdge;6288var j;6289var island = this.m_island;6290island.Initialize(this.m_bodyCount, b2Settings.b2_maxTOIContactsPerIsland, b2Settings.b2_maxTOIJointsPerIsland, null, this.m_contactManager.m_contactListener, this.m_contactSolver);6291var queue = b2World.s_queue;6292for (b = this.m_bodyList;6293b; b = b.m_next) {6294b.m_flags &= ~b2Body.e_islandFlag;6295b.m_sweep.t0 = 0.0;6296}6297var c;6298for (c = this.m_contactList;6299c; c = c.m_next) {6300c.m_flags &= ~ (b2Contact.e_toiFlag | b2Contact.e_islandFlag);6301}6302for (j = this.m_jointList;6303j; j = j.m_next) {6304j.m_islandFlag = false;6305}6306for (;;) {6307var minContact = null;6308var minTOI = 1.0;6309for (c = this.m_contactList;6310c; c = c.m_next) {6311if (c.IsSensor() == true || c.IsEnabled() == false || c.IsContinuous() == false) {6312continue;6313}6314var toi = 1.0;6315if (c.m_flags & b2Contact.e_toiFlag) {6316toi = c.m_toi;6317}6318else {6319fA = c.m_fixtureA;6320fB = c.m_fixtureB;6321bA = fA.m_body;6322bB = fB.m_body;6323if ((bA.GetType() != b2Body.b2_dynamicBody || bA.IsAwake() == false) && (bB.GetType() != b2Body.b2_dynamicBody || bB.IsAwake() == false)) {6324continue;6325}6326var t0 = bA.m_sweep.t0;6327if (bA.m_sweep.t0 < bB.m_sweep.t0) {6328t0 = bB.m_sweep.t0;6329bA.m_sweep.Advance(t0);6330}6331else if (bB.m_sweep.t0 < bA.m_sweep.t0) {6332t0 = bA.m_sweep.t0;6333bB.m_sweep.Advance(t0);6334}6335toi = c.ComputeTOI(bA.m_sweep, bB.m_sweep);6336b2Settings.b2Assert(0.0 <= toi && toi <= 1.0);6337if (toi > 0.0 && toi < 1.0) {6338toi = (1.0 - toi) * t0 + toi;6339if (toi > 1) toi = 1;6340}6341c.m_toi = toi;6342c.m_flags |= b2Contact.e_toiFlag;6343}6344if (Number.MIN_VALUE < toi && toi < minTOI) {6345minContact = c;6346minTOI = toi;6347}6348}6349if (minContact == null || 1.0 - 100.0 * Number.MIN_VALUE < minTOI) {6350break;6351}6352fA = minContact.m_fixtureA;6353fB = minContact.m_fixtureB;6354bA = fA.m_body;6355bB = fB.m_body;6356b2World.s_backupA.Set(bA.m_sweep);6357b2World.s_backupB.Set(bB.m_sweep);6358bA.Advance(minTOI);6359bB.Advance(minTOI);6360minContact.Update(this.m_contactManager.m_contactListener);6361minContact.m_flags &= ~b2Contact.e_toiFlag;6362if (minContact.IsSensor() == true || minContact.IsEnabled() == false) {6363bA.m_sweep.Set(b2World.s_backupA);6364bB.m_sweep.Set(b2World.s_backupB);6365bA.SynchronizeTransform();6366bB.SynchronizeTransform();6367continue;6368}6369if (minContact.IsTouching() == false) {6370continue;6371}6372var seed = bA;6373if (seed.GetType() != b2Body.b2_dynamicBody) {6374seed = bB;6375}6376island.Clear();6377var queueStart = 0;6378var queueSize = 0;6379queue[queueStart + queueSize++] = seed;6380seed.m_flags |= b2Body.e_islandFlag;6381while (queueSize > 0) {6382b = queue[queueStart++];6383--queueSize;6384island.AddBody(b);6385if (b.IsAwake() == false) {6386b.SetAwake(true);6387}6388if (b.GetType() != b2Body.b2_dynamicBody) {6389continue;6390}6391for (cEdge = b.m_contactList;6392cEdge; cEdge = cEdge.next) {6393if (island.m_contactCount == island.m_contactCapacity) {6394break;6395}6396if (cEdge.contact.m_flags & b2Contact.e_islandFlag) {6397continue;6398}6399if (cEdge.contact.IsSensor() == true || cEdge.contact.IsEnabled() == false || cEdge.contact.IsTouching() == false) {6400continue;6401}6402island.AddContact(cEdge.contact);6403cEdge.contact.m_flags |= b2Contact.e_islandFlag;6404var other = cEdge.other;6405if (other.m_flags & b2Body.e_islandFlag) {6406continue;6407}6408if (other.GetType() != b2Body.b2_staticBody) {6409other.Advance(minTOI);6410other.SetAwake(true);6411}6412queue[queueStart + queueSize] = other;6413++queueSize;6414other.m_flags |= b2Body.e_islandFlag;6415}6416for (var jEdge = b.m_jointList; jEdge; jEdge = jEdge.next) {6417if (island.m_jointCount == island.m_jointCapacity) continue;6418if (jEdge.joint.m_islandFlag == true) continue;6419other = jEdge.other;6420if (other.IsActive() == false) {6421continue;6422}6423island.AddJoint(jEdge.joint);6424jEdge.joint.m_islandFlag = true;6425if (other.m_flags & b2Body.e_islandFlag) continue;6426if (other.GetType() != b2Body.b2_staticBody) {6427other.Advance(minTOI);6428other.SetAwake(true);6429}6430queue[queueStart + queueSize] = other;6431++queueSize;6432other.m_flags |= b2Body.e_islandFlag;6433}6434}6435var subStep = b2World.s_timestep;6436subStep.warmStarting = false;6437subStep.dt = (1.0 - minTOI) * step.dt;6438subStep.inv_dt = 1.0 / subStep.dt;6439subStep.dtRatio = 0.0;6440subStep.velocityIterations = step.velocityIterations;6441subStep.positionIterations = step.positionIterations;6442island.SolveTOI(subStep);6443var i = 0;6444for (i = 0;6445i < island.m_bodyCount; ++i) {6446b = island.m_bodies[i];6447b.m_flags &= ~b2Body.e_islandFlag;6448if (b.IsAwake() == false) {6449continue;6450}6451if (b.GetType() != b2Body.b2_dynamicBody) {6452continue;6453}6454b.SynchronizeFixtures();6455for (cEdge = b.m_contactList;6456cEdge; cEdge = cEdge.next) {6457cEdge.contact.m_flags &= ~b2Contact.e_toiFlag;6458}6459}6460for (i = 0;6461i < island.m_contactCount; ++i) {6462c = island.m_contacts[i];6463c.m_flags &= ~ (b2Contact.e_toiFlag | b2Contact.e_islandFlag);6464}6465for (i = 0;6466i < island.m_jointCount; ++i) {6467j = island.m_joints[i];6468j.m_islandFlag = false;6469}6470this.m_contactManager.FindNewContacts();6471}6472}6473b2World.prototype.DrawJoint = function (joint) {6474var b1 = joint.GetBodyA();6475var b2 = joint.GetBodyB();6476var xf1 = b1.m_xf;6477var xf2 = b2.m_xf;6478var x1 = xf1.position;6479var x2 = xf2.position;6480var p1 = joint.GetAnchorA();6481var p2 = joint.GetAnchorB();6482var color = b2World.s_jointColor;6483switch (joint.m_type) {6484case b2Joint.e_distanceJoint:6485this.m_debugDraw.DrawSegment(p1, p2, color);6486break;6487case b2Joint.e_pulleyJoint:6488{6489var pulley = ((joint instanceof b2PulleyJoint ? joint : null));6490var s1 = pulley.GetGroundAnchorA();6491var s2 = pulley.GetGroundAnchorB();6492this.m_debugDraw.DrawSegment(s1, p1, color);6493this.m_debugDraw.DrawSegment(s2, p2, color);6494this.m_debugDraw.DrawSegment(s1, s2, color);6495}6496break;6497case b2Joint.e_mouseJoint:6498this.m_debugDraw.DrawSegment(p1, p2, color);6499break;6500default:6501if (b1 != this.m_groundBody) this.m_debugDraw.DrawSegment(x1, p1, color);6502this.m_debugDraw.DrawSegment(p1, p2, color);6503if (b2 != this.m_groundBody) this.m_debugDraw.DrawSegment(x2, p2, color);6504}6505}6506b2World.prototype.DrawShape = function (shape, xf, color) {6507switch (shape.m_type) {6508case b2Shape.e_circleShape:6509{6510var circle = ((shape instanceof b2CircleShape ? shape : null));6511var center = b2Math.MulX(xf, circle.m_p);6512var radius = circle.m_radius;6513var axis = xf.R.col1;6514this.m_debugDraw.DrawSolidCircle(center, radius, axis, color);6515}6516break;6517case b2Shape.e_polygonShape:6518{6519var i = 0;6520var poly = ((shape instanceof b2PolygonShape ? shape : null));6521var vertexCount = parseInt(poly.GetVertexCount());6522var localVertices = poly.GetVertices();6523var vertices = new Vector(vertexCount);6524for (i = 0;6525i < vertexCount; ++i) {6526vertices[i] = b2Math.MulX(xf, localVertices[i]);6527}6528this.m_debugDraw.DrawSolidPolygon(vertices, vertexCount, color);6529}6530break;6531case b2Shape.e_edgeShape:6532{6533var edge = (shape instanceof b2EdgeShape ? shape : null);6534this.m_debugDraw.DrawSegment(b2Math.MulX(xf, edge.GetVertex1()), b2Math.MulX(xf, edge.GetVertex2()), color);6535}6536break;6537}6538}6539Box2D.postDefs.push(function () {6540Box2D.Dynamics.b2World.s_timestep2 = new b2TimeStep();6541Box2D.Dynamics.b2World.s_xf = new b2Transform();6542Box2D.Dynamics.b2World.s_backupA = new b2Sweep();6543Box2D.Dynamics.b2World.s_backupB = new b2Sweep();6544Box2D.Dynamics.b2World.s_timestep = new b2TimeStep();6545Box2D.Dynamics.b2World.s_queue = new Vector();6546Box2D.Dynamics.b2World.s_jointColor = new b2Color(0.5, 0.8, 0.8);6547Box2D.Dynamics.b2World.e_newFixture = 0x0001;6548Box2D.Dynamics.b2World.e_locked = 0x0002;6549});6550})();6551(function () {6552var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,6553b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,6554b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,6555b2MassData = Box2D.Collision.Shapes.b2MassData,6556b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,6557b2Shape = Box2D.Collision.Shapes.b2Shape,6558b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact,6559b2Contact = Box2D.Dynamics.Contacts.b2Contact,6560b2ContactConstraint = Box2D.Dynamics.Contacts.b2ContactConstraint,6561b2ContactConstraintPoint = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,6562b2ContactEdge = Box2D.Dynamics.Contacts.b2ContactEdge,6563b2ContactFactory = Box2D.Dynamics.Contacts.b2ContactFactory,6564b2ContactRegister = Box2D.Dynamics.Contacts.b2ContactRegister,6565b2ContactResult = Box2D.Dynamics.Contacts.b2ContactResult,6566b2ContactSolver = Box2D.Dynamics.Contacts.b2ContactSolver,6567b2EdgeAndCircleContact = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,6568b2NullContact = Box2D.Dynamics.Contacts.b2NullContact,6569b2PolyAndCircleContact = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,6570b2PolyAndEdgeContact = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,6571b2PolygonContact = Box2D.Dynamics.Contacts.b2PolygonContact,6572b2PositionSolverManifold = Box2D.Dynamics.Contacts.b2PositionSolverManifold,6573b2Body = Box2D.Dynamics.b2Body,6574b2BodyDef = Box2D.Dynamics.b2BodyDef,6575b2ContactFilter = Box2D.Dynamics.b2ContactFilter,6576b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,6577b2ContactListener = Box2D.Dynamics.b2ContactListener,6578b2ContactManager = Box2D.Dynamics.b2ContactManager,6579b2DebugDraw = Box2D.Dynamics.b2DebugDraw,6580b2DestructionListener = Box2D.Dynamics.b2DestructionListener,6581b2FilterData = Box2D.Dynamics.b2FilterData,6582b2Fixture = Box2D.Dynamics.b2Fixture,6583b2FixtureDef = Box2D.Dynamics.b2FixtureDef,6584b2Island = Box2D.Dynamics.b2Island,6585b2TimeStep = Box2D.Dynamics.b2TimeStep,6586b2World = Box2D.Dynamics.b2World,6587b2Color = Box2D.Common.b2Color,6588b2internal = Box2D.Common.b2internal,6589b2Settings = Box2D.Common.b2Settings,6590b2Mat22 = Box2D.Common.Math.b2Mat22,6591b2Mat33 = Box2D.Common.Math.b2Mat33,6592b2Math = Box2D.Common.Math.b2Math,6593b2Sweep = Box2D.Common.Math.b2Sweep,6594b2Transform = Box2D.Common.Math.b2Transform,6595b2Vec2 = Box2D.Common.Math.b2Vec2,6596b2Vec3 = Box2D.Common.Math.b2Vec3,6597b2AABB = Box2D.Collision.b2AABB,6598b2Bound = Box2D.Collision.b2Bound,6599b2BoundValues = Box2D.Collision.b2BoundValues,6600b2Collision = Box2D.Collision.b2Collision,6601b2ContactID = Box2D.Collision.b2ContactID,6602b2ContactPoint = Box2D.Collision.b2ContactPoint,6603b2Distance = Box2D.Collision.b2Distance,6604b2DistanceInput = Box2D.Collision.b2DistanceInput,6605b2DistanceOutput = Box2D.Collision.b2DistanceOutput,6606b2DistanceProxy = Box2D.Collision.b2DistanceProxy,6607b2DynamicTree = Box2D.Collision.b2DynamicTree,6608b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,6609b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,6610b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,6611b2Manifold = Box2D.Collision.b2Manifold,6612b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,6613b2Point = Box2D.Collision.b2Point,6614b2RayCastInput = Box2D.Collision.b2RayCastInput,6615b2RayCastOutput = Box2D.Collision.b2RayCastOutput,6616b2Segment = Box2D.Collision.b2Segment,6617b2SeparationFunction = Box2D.Collision.b2SeparationFunction,6618b2Simplex = Box2D.Collision.b2Simplex,6619b2SimplexCache = Box2D.Collision.b2SimplexCache,6620b2SimplexVertex = Box2D.Collision.b2SimplexVertex,6621b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,6622b2TOIInput = Box2D.Collision.b2TOIInput,6623b2WorldManifold = Box2D.Collision.b2WorldManifold,6624ClipVertex = Box2D.Collision.ClipVertex,6625Features = Box2D.Collision.Features,6626IBroadPhase = Box2D.Collision.IBroadPhase;66276628Box2D.inherit(b2CircleContact, Box2D.Dynamics.Contacts.b2Contact);6629b2CircleContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;6630b2CircleContact.b2CircleContact = function () {6631Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);6632};6633b2CircleContact.Create = function (allocator) {6634return new b2CircleContact();6635}6636b2CircleContact.Destroy = function (contact, allocator) {}6637b2CircleContact.prototype.Reset = function (fixtureA, fixtureB) {6638this.__super.Reset.call(this, fixtureA, fixtureB);6639}6640b2CircleContact.prototype.Evaluate = function () {6641var bA = this.m_fixtureA.GetBody();6642var bB = this.m_fixtureB.GetBody();6643b2Collision.CollideCircles(this.m_manifold, (this.m_fixtureA.GetShape() instanceof b2CircleShape ? this.m_fixtureA.GetShape() : null), bA.m_xf, (this.m_fixtureB.GetShape() instanceof b2CircleShape ? this.m_fixtureB.GetShape() : null), bB.m_xf);6644}6645b2Contact.b2Contact = function () {6646this.m_nodeA = new b2ContactEdge();6647this.m_nodeB = new b2ContactEdge();6648this.m_manifold = new b2Manifold();6649this.m_oldManifold = new b2Manifold();6650};6651b2Contact.prototype.GetManifold = function () {6652return this.m_manifold;6653}6654b2Contact.prototype.GetWorldManifold = function (worldManifold) {6655var bodyA = this.m_fixtureA.GetBody();6656var bodyB = this.m_fixtureB.GetBody();6657var shapeA = this.m_fixtureA.GetShape();6658var shapeB = this.m_fixtureB.GetShape();6659worldManifold.Initialize(this.m_manifold, bodyA.GetTransform(), shapeA.m_radius, bodyB.GetTransform(), shapeB.m_radius);6660}6661b2Contact.prototype.IsTouching = function () {6662return (this.m_flags & b2Contact.e_touchingFlag) == b2Contact.e_touchingFlag;6663}6664b2Contact.prototype.IsContinuous = function () {6665return (this.m_flags & b2Contact.e_continuousFlag) == b2Contact.e_continuousFlag;6666}6667b2Contact.prototype.SetSensor = function (sensor) {6668if (sensor) {6669this.m_flags |= b2Contact.e_sensorFlag;6670}6671else {6672this.m_flags &= ~b2Contact.e_sensorFlag;6673}6674}6675b2Contact.prototype.IsSensor = function () {6676return (this.m_flags & b2Contact.e_sensorFlag) == b2Contact.e_sensorFlag;6677}6678b2Contact.prototype.SetEnabled = function (flag) {6679if (flag) {6680this.m_flags |= b2Contact.e_enabledFlag;6681}6682else {6683this.m_flags &= ~b2Contact.e_enabledFlag;6684}6685}6686b2Contact.prototype.IsEnabled = function () {6687return (this.m_flags & b2Contact.e_enabledFlag) == b2Contact.e_enabledFlag;6688}6689b2Contact.prototype.GetNext = function () {6690return this.m_next;6691}6692b2Contact.prototype.GetFixtureA = function () {6693return this.m_fixtureA;6694}6695b2Contact.prototype.GetFixtureB = function () {6696return this.m_fixtureB;6697}6698b2Contact.prototype.FlagForFiltering = function () {6699this.m_flags |= b2Contact.e_filterFlag;6700}6701b2Contact.prototype.b2Contact = function () {}6702b2Contact.prototype.Reset = function (fixtureA, fixtureB) {6703if (fixtureA === undefined) fixtureA = null;6704if (fixtureB === undefined) fixtureB = null;6705this.m_flags = b2Contact.e_enabledFlag;6706if (!fixtureA || !fixtureB) {6707this.m_fixtureA = null;6708this.m_fixtureB = null;6709return;6710}6711if (fixtureA.IsSensor() || fixtureB.IsSensor()) {6712this.m_flags |= b2Contact.e_sensorFlag;6713}6714var bodyA = fixtureA.GetBody();6715var bodyB = fixtureB.GetBody();6716if (bodyA.GetType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.GetType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) {6717this.m_flags |= b2Contact.e_continuousFlag;6718}6719this.m_fixtureA = fixtureA;6720this.m_fixtureB = fixtureB;6721this.m_manifold.m_pointCount = 0;6722this.m_prev = null;6723this.m_next = null;6724this.m_nodeA.contact = null;6725this.m_nodeA.prev = null;6726this.m_nodeA.next = null;6727this.m_nodeA.other = null;6728this.m_nodeB.contact = null;6729this.m_nodeB.prev = null;6730this.m_nodeB.next = null;6731this.m_nodeB.other = null;6732}6733b2Contact.prototype.Update = function (listener) {6734var tManifold = this.m_oldManifold;6735this.m_oldManifold = this.m_manifold;6736this.m_manifold = tManifold;6737this.m_flags |= b2Contact.e_enabledFlag;6738var touching = false;6739var wasTouching = (this.m_flags & b2Contact.e_touchingFlag) == b2Contact.e_touchingFlag;6740var bodyA = this.m_fixtureA.m_body;6741var bodyB = this.m_fixtureB.m_body;6742var aabbOverlap = this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);6743if (this.m_flags & b2Contact.e_sensorFlag) {6744if (aabbOverlap) {6745var shapeA = this.m_fixtureA.GetShape();6746var shapeB = this.m_fixtureB.GetShape();6747var xfA = bodyA.GetTransform();6748var xfB = bodyB.GetTransform();6749touching = b2Shape.TestOverlap(shapeA, xfA, shapeB, xfB);6750}6751this.m_manifold.m_pointCount = 0;6752}6753else {6754if (bodyA.GetType() != b2Body.b2_dynamicBody || bodyA.IsBullet() || bodyB.GetType() != b2Body.b2_dynamicBody || bodyB.IsBullet()) {6755this.m_flags |= b2Contact.e_continuousFlag;6756}6757else {6758this.m_flags &= ~b2Contact.e_continuousFlag;6759}6760if (aabbOverlap) {6761this.Evaluate();6762touching = this.m_manifold.m_pointCount > 0;6763for (var i = 0; i < this.m_manifold.m_pointCount; ++i) {6764var mp2 = this.m_manifold.m_points[i];6765mp2.m_normalImpulse = 0.0;6766mp2.m_tangentImpulse = 0.0;6767var id2 = mp2.m_id;6768for (var j = 0; j < this.m_oldManifold.m_pointCount; ++j) {6769var mp1 = this.m_oldManifold.m_points[j];6770if (mp1.m_id.key == id2.key) {6771mp2.m_normalImpulse = mp1.m_normalImpulse;6772mp2.m_tangentImpulse = mp1.m_tangentImpulse;6773break;6774}6775}6776}6777}6778else {6779this.m_manifold.m_pointCount = 0;6780}6781if (touching != wasTouching) {6782bodyA.SetAwake(true);6783bodyB.SetAwake(true);6784}6785}6786if (touching) {6787this.m_flags |= b2Contact.e_touchingFlag;6788}6789else {6790this.m_flags &= ~b2Contact.e_touchingFlag;6791}6792if (wasTouching == false && touching == true) {6793listener.BeginContact(this);6794}6795if (wasTouching == true && touching == false) {6796listener.EndContact(this);6797}6798if ((this.m_flags & b2Contact.e_sensorFlag) == 0) {6799listener.PreSolve(this, this.m_oldManifold);6800}6801}6802b2Contact.prototype.Evaluate = function () {}6803b2Contact.prototype.ComputeTOI = function (sweepA, sweepB) {6804b2Contact.s_input.proxyA.Set(this.m_fixtureA.GetShape());6805b2Contact.s_input.proxyB.Set(this.m_fixtureB.GetShape());6806b2Contact.s_input.sweepA = sweepA;6807b2Contact.s_input.sweepB = sweepB;6808b2Contact.s_input.tolerance = b2Settings.b2_linearSlop;6809return b2TimeOfImpact.TimeOfImpact(b2Contact.s_input);6810}6811Box2D.postDefs.push(function () {6812Box2D.Dynamics.Contacts.b2Contact.e_sensorFlag = 0x0001;6813Box2D.Dynamics.Contacts.b2Contact.e_continuousFlag = 0x0002;6814Box2D.Dynamics.Contacts.b2Contact.e_islandFlag = 0x0004;6815Box2D.Dynamics.Contacts.b2Contact.e_toiFlag = 0x0008;6816Box2D.Dynamics.Contacts.b2Contact.e_touchingFlag = 0x0010;6817Box2D.Dynamics.Contacts.b2Contact.e_enabledFlag = 0x0020;6818Box2D.Dynamics.Contacts.b2Contact.e_filterFlag = 0x0040;6819Box2D.Dynamics.Contacts.b2Contact.s_input = new b2TOIInput();6820});6821b2ContactConstraint.b2ContactConstraint = function () {6822this.localPlaneNormal = new b2Vec2();6823this.localPoint = new b2Vec2();6824this.normal = new b2Vec2();6825this.normalMass = new b2Mat22();6826this.K = new b2Mat22();6827};6828b2ContactConstraint.prototype.b2ContactConstraint = function () {6829this.points = new Vector(b2Settings.b2_maxManifoldPoints);6830for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {6831this.points[i] = new b2ContactConstraintPoint();6832}6833}6834b2ContactConstraintPoint.b2ContactConstraintPoint = function () {6835this.localPoint = new b2Vec2();6836this.rA = new b2Vec2();6837this.rB = new b2Vec2();6838};6839b2ContactEdge.b2ContactEdge = function () {};6840b2ContactFactory.b2ContactFactory = function () {};6841b2ContactFactory.prototype.b2ContactFactory = function (allocator) {6842this.m_allocator = allocator;6843this.InitializeRegisters();6844}6845b2ContactFactory.prototype.AddType = function (createFcn, destroyFcn, type1, type2) {6846if (type1 === undefined) type1 = 0;6847if (type2 === undefined) type2 = 0;6848this.m_registers[type1][type2].createFcn = createFcn;6849this.m_registers[type1][type2].destroyFcn = destroyFcn;6850this.m_registers[type1][type2].primary = true;6851if (type1 != type2) {6852this.m_registers[type2][type1].createFcn = createFcn;6853this.m_registers[type2][type1].destroyFcn = destroyFcn;6854this.m_registers[type2][type1].primary = false;6855}6856}6857b2ContactFactory.prototype.InitializeRegisters = function () {6858this.m_registers = new Vector(b2Shape.e_shapeTypeCount);6859for (var i = 0; i < b2Shape.e_shapeTypeCount; i++) {6860this.m_registers[i] = new Vector(b2Shape.e_shapeTypeCount);6861for (var j = 0; j < b2Shape.e_shapeTypeCount; j++) {6862this.m_registers[i][j] = new b2ContactRegister();6863}6864}6865this.AddType(b2CircleContact.Create, b2CircleContact.Destroy, b2Shape.e_circleShape, b2Shape.e_circleShape);6866this.AddType(b2PolyAndCircleContact.Create, b2PolyAndCircleContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_circleShape);6867this.AddType(b2PolygonContact.Create, b2PolygonContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_polygonShape);6868this.AddType(b2EdgeAndCircleContact.Create, b2EdgeAndCircleContact.Destroy, b2Shape.e_edgeShape, b2Shape.e_circleShape);6869this.AddType(b2PolyAndEdgeContact.Create, b2PolyAndEdgeContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_edgeShape);6870}6871b2ContactFactory.prototype.Create = function (fixtureA, fixtureB) {6872var type1 = parseInt(fixtureA.GetType());6873var type2 = parseInt(fixtureB.GetType());6874var reg = this.m_registers[type1][type2];6875var c;6876if (reg.pool) {6877c = reg.pool;6878reg.pool = c.m_next;6879reg.poolCount--;6880c.Reset(fixtureA, fixtureB);6881return c;6882}6883var createFcn = reg.createFcn;6884if (createFcn != null) {6885if (reg.primary) {6886c = createFcn(this.m_allocator);6887c.Reset(fixtureA, fixtureB);6888return c;6889}6890else {6891c = createFcn(this.m_allocator);6892c.Reset(fixtureB, fixtureA);6893return c;6894}6895}6896else {6897return null;6898}6899}6900b2ContactFactory.prototype.Destroy = function (contact) {6901if (contact.m_manifold.m_pointCount > 0) {6902contact.m_fixtureA.m_body.SetAwake(true);6903contact.m_fixtureB.m_body.SetAwake(true);6904}6905var type1 = parseInt(contact.m_fixtureA.GetType());6906var type2 = parseInt(contact.m_fixtureB.GetType());6907var reg = this.m_registers[type1][type2];6908if (true) {6909reg.poolCount++;6910contact.m_next = reg.pool;6911reg.pool = contact;6912}6913var destroyFcn = reg.destroyFcn;6914destroyFcn(contact, this.m_allocator);6915}6916b2ContactRegister.b2ContactRegister = function () {};6917b2ContactResult.b2ContactResult = function () {6918this.position = new b2Vec2();6919this.normal = new b2Vec2();6920this.id = new b2ContactID();6921};6922b2ContactSolver.b2ContactSolver = function () {6923this.m_step = new b2TimeStep();6924this.m_constraints = new Vector();6925};6926b2ContactSolver.prototype.b2ContactSolver = function () {}6927b2ContactSolver.prototype.Initialize = function (step, contacts, contactCount, allocator) {6928if (contactCount === undefined) contactCount = 0;6929var contact;6930this.m_step.Set(step);6931this.m_allocator = allocator;6932var i = 0;6933var tVec;6934var tMat;6935this.m_constraintCount = contactCount;6936while (this.m_constraints.length < this.m_constraintCount) {6937this.m_constraints[this.m_constraints.length] = new b2ContactConstraint();6938}6939for (i = 0;6940i < contactCount; ++i) {6941contact = contacts[i];6942var fixtureA = contact.m_fixtureA;6943var fixtureB = contact.m_fixtureB;6944var shapeA = fixtureA.m_shape;6945var shapeB = fixtureB.m_shape;6946var radiusA = shapeA.m_radius;6947var radiusB = shapeB.m_radius;6948var bodyA = fixtureA.m_body;6949var bodyB = fixtureB.m_body;6950var manifold = contact.GetManifold();6951var friction = b2Settings.b2MixFriction(fixtureA.GetFriction(), fixtureB.GetFriction());6952var restitution = b2Settings.b2MixRestitution(fixtureA.GetRestitution(), fixtureB.GetRestitution());6953var vAX = bodyA.m_linearVelocity.x;6954var vAY = bodyA.m_linearVelocity.y;6955var vBX = bodyB.m_linearVelocity.x;6956var vBY = bodyB.m_linearVelocity.y;6957var wA = bodyA.m_angularVelocity;6958var wB = bodyB.m_angularVelocity;6959b2Settings.b2Assert(manifold.m_pointCount > 0);6960b2ContactSolver.s_worldManifold.Initialize(manifold, bodyA.m_xf, radiusA, bodyB.m_xf, radiusB);6961var normalX = b2ContactSolver.s_worldManifold.m_normal.x;6962var normalY = b2ContactSolver.s_worldManifold.m_normal.y;6963var cc = this.m_constraints[i];6964cc.bodyA = bodyA;6965cc.bodyB = bodyB;6966cc.manifold = manifold;6967cc.normal.x = normalX;6968cc.normal.y = normalY;6969cc.pointCount = manifold.m_pointCount;6970cc.friction = friction;6971cc.restitution = restitution;6972cc.localPlaneNormal.x = manifold.m_localPlaneNormal.x;6973cc.localPlaneNormal.y = manifold.m_localPlaneNormal.y;6974cc.localPoint.x = manifold.m_localPoint.x;6975cc.localPoint.y = manifold.m_localPoint.y;6976cc.radius = radiusA + radiusB;6977cc.type = manifold.m_type;6978for (var k = 0; k < cc.pointCount; ++k) {6979var cp = manifold.m_points[k];6980var ccp = cc.points[k];6981ccp.normalImpulse = cp.m_normalImpulse;6982ccp.tangentImpulse = cp.m_tangentImpulse;6983ccp.localPoint.SetV(cp.m_localPoint);6984var rAX = ccp.rA.x = b2ContactSolver.s_worldManifold.m_points[k].x - bodyA.m_sweep.c.x;6985var rAY = ccp.rA.y = b2ContactSolver.s_worldManifold.m_points[k].y - bodyA.m_sweep.c.y;6986var rBX = ccp.rB.x = b2ContactSolver.s_worldManifold.m_points[k].x - bodyB.m_sweep.c.x;6987var rBY = ccp.rB.y = b2ContactSolver.s_worldManifold.m_points[k].y - bodyB.m_sweep.c.y;6988var rnA = rAX * normalY - rAY * normalX;6989var rnB = rBX * normalY - rBY * normalX;6990rnA *= rnA;6991rnB *= rnB;6992var kNormal = bodyA.m_invMass + bodyB.m_invMass + bodyA.m_invI * rnA + bodyB.m_invI * rnB;6993ccp.normalMass = 1.0 / kNormal;6994var kEqualized = bodyA.m_mass * bodyA.m_invMass + bodyB.m_mass * bodyB.m_invMass;6995kEqualized += bodyA.m_mass * bodyA.m_invI * rnA + bodyB.m_mass * bodyB.m_invI * rnB;6996ccp.equalizedMass = 1.0 / kEqualized;6997var tangentX = normalY;6998var tangentY = (-normalX);6999var rtA = rAX * tangentY - rAY * tangentX;7000var rtB = rBX * tangentY - rBY * tangentX;7001rtA *= rtA;7002rtB *= rtB;7003var kTangent = bodyA.m_invMass + bodyB.m_invMass + bodyA.m_invI * rtA + bodyB.m_invI * rtB;7004ccp.tangentMass = 1.0 / kTangent;7005ccp.velocityBias = 0.0;7006var tX = vBX + ((-wB * rBY)) - vAX - ((-wA * rAY));7007var tY = vBY + (wB * rBX) - vAY - (wA * rAX);7008var vRel = cc.normal.x * tX + cc.normal.y * tY;7009if (vRel < (-b2Settings.b2_velocityThreshold)) {7010ccp.velocityBias += (-cc.restitution * vRel);7011}7012}7013if (cc.pointCount == 2) {7014var ccp1 = cc.points[0];7015var ccp2 = cc.points[1];7016var invMassA = bodyA.m_invMass;7017var invIA = bodyA.m_invI;7018var invMassB = bodyB.m_invMass;7019var invIB = bodyB.m_invI;7020var rn1A = ccp1.rA.x * normalY - ccp1.rA.y * normalX;7021var rn1B = ccp1.rB.x * normalY - ccp1.rB.y * normalX;7022var rn2A = ccp2.rA.x * normalY - ccp2.rA.y * normalX;7023var rn2B = ccp2.rB.x * normalY - ccp2.rB.y * normalX;7024var k11 = invMassA + invMassB + invIA * rn1A * rn1A + invIB * rn1B * rn1B;7025var k22 = invMassA + invMassB + invIA * rn2A * rn2A + invIB * rn2B * rn2B;7026var k12 = invMassA + invMassB + invIA * rn1A * rn2A + invIB * rn1B * rn2B;7027var k_maxConditionNumber = 100.0;7028if (k11 * k11 < k_maxConditionNumber * (k11 * k22 - k12 * k12)) {7029cc.K.col1.Set(k11, k12);7030cc.K.col2.Set(k12, k22);7031cc.K.GetInverse(cc.normalMass);7032}7033else {7034cc.pointCount = 1;7035}7036}7037}7038}7039b2ContactSolver.prototype.InitVelocityConstraints = function (step) {7040var tVec;7041var tVec2;7042var tMat;7043for (var i = 0; i < this.m_constraintCount; ++i) {7044var c = this.m_constraints[i];7045var bodyA = c.bodyA;7046var bodyB = c.bodyB;7047var invMassA = bodyA.m_invMass;7048var invIA = bodyA.m_invI;7049var invMassB = bodyB.m_invMass;7050var invIB = bodyB.m_invI;7051var normalX = c.normal.x;7052var normalY = c.normal.y;7053var tangentX = normalY;7054var tangentY = (-normalX);7055var tX = 0;7056var j = 0;7057var tCount = 0;7058if (step.warmStarting) {7059tCount = c.pointCount;7060for (j = 0;7061j < tCount; ++j) {7062var ccp = c.points[j];7063ccp.normalImpulse *= step.dtRatio;7064ccp.tangentImpulse *= step.dtRatio;7065var PX = ccp.normalImpulse * normalX + ccp.tangentImpulse * tangentX;7066var PY = ccp.normalImpulse * normalY + ccp.tangentImpulse * tangentY;7067bodyA.m_angularVelocity -= invIA * (ccp.rA.x * PY - ccp.rA.y * PX);7068bodyA.m_linearVelocity.x -= invMassA * PX;7069bodyA.m_linearVelocity.y -= invMassA * PY;7070bodyB.m_angularVelocity += invIB * (ccp.rB.x * PY - ccp.rB.y * PX);7071bodyB.m_linearVelocity.x += invMassB * PX;7072bodyB.m_linearVelocity.y += invMassB * PY;7073}7074}7075else {7076tCount = c.pointCount;7077for (j = 0;7078j < tCount; ++j) {7079var ccp2 = c.points[j];7080ccp2.normalImpulse = 0.0;7081ccp2.tangentImpulse = 0.0;7082}7083}7084}7085}7086b2ContactSolver.prototype.SolveVelocityConstraints = function () {7087var j = 0;7088var ccp;7089var rAX = 0;7090var rAY = 0;7091var rBX = 0;7092var rBY = 0;7093var dvX = 0;7094var dvY = 0;7095var vn = 0;7096var vt = 0;7097var lambda = 0;7098var maxFriction = 0;7099var newImpulse = 0;7100var PX = 0;7101var PY = 0;7102var dX = 0;7103var dY = 0;7104var P1X = 0;7105var P1Y = 0;7106var P2X = 0;7107var P2Y = 0;7108var tMat;7109var tVec;7110for (var i = 0; i < this.m_constraintCount; ++i) {7111var c = this.m_constraints[i];7112var bodyA = c.bodyA;7113var bodyB = c.bodyB;7114var wA = bodyA.m_angularVelocity;7115var wB = bodyB.m_angularVelocity;7116var vA = bodyA.m_linearVelocity;7117var vB = bodyB.m_linearVelocity;7118var invMassA = bodyA.m_invMass;7119var invIA = bodyA.m_invI;7120var invMassB = bodyB.m_invMass;7121var invIB = bodyB.m_invI;7122var normalX = c.normal.x;7123var normalY = c.normal.y;7124var tangentX = normalY;7125var tangentY = (-normalX);7126var friction = c.friction;7127var tX = 0;7128for (j = 0;7129j < c.pointCount; j++) {7130ccp = c.points[j];7131dvX = vB.x - wB * ccp.rB.y - vA.x + wA * ccp.rA.y;7132dvY = vB.y + wB * ccp.rB.x - vA.y - wA * ccp.rA.x;7133vt = dvX * tangentX + dvY * tangentY;7134lambda = ccp.tangentMass * (-vt);7135maxFriction = friction * ccp.normalImpulse;7136newImpulse = b2Math.Clamp(ccp.tangentImpulse + lambda, (-maxFriction), maxFriction);7137lambda = newImpulse - ccp.tangentImpulse;7138PX = lambda * tangentX;7139PY = lambda * tangentY;7140vA.x -= invMassA * PX;7141vA.y -= invMassA * PY;7142wA -= invIA * (ccp.rA.x * PY - ccp.rA.y * PX);7143vB.x += invMassB * PX;7144vB.y += invMassB * PY;7145wB += invIB * (ccp.rB.x * PY - ccp.rB.y * PX);7146ccp.tangentImpulse = newImpulse;7147}7148var tCount = parseInt(c.pointCount);7149if (c.pointCount == 1) {7150ccp = c.points[0];7151dvX = vB.x + ((-wB * ccp.rB.y)) - vA.x - ((-wA * ccp.rA.y));7152dvY = vB.y + (wB * ccp.rB.x) - vA.y - (wA * ccp.rA.x);7153vn = dvX * normalX + dvY * normalY;7154lambda = (-ccp.normalMass * (vn - ccp.velocityBias));7155newImpulse = ccp.normalImpulse + lambda;7156newImpulse = newImpulse > 0 ? newImpulse : 0.0;7157lambda = newImpulse - ccp.normalImpulse;7158PX = lambda * normalX;7159PY = lambda * normalY;7160vA.x -= invMassA * PX;7161vA.y -= invMassA * PY;7162wA -= invIA * (ccp.rA.x * PY - ccp.rA.y * PX);7163vB.x += invMassB * PX;7164vB.y += invMassB * PY;7165wB += invIB * (ccp.rB.x * PY - ccp.rB.y * PX);7166ccp.normalImpulse = newImpulse;7167}7168else {7169var cp1 = c.points[0];7170var cp2 = c.points[1];7171var aX = cp1.normalImpulse;7172var aY = cp2.normalImpulse;7173var dv1X = vB.x - wB * cp1.rB.y - vA.x + wA * cp1.rA.y;7174var dv1Y = vB.y + wB * cp1.rB.x - vA.y - wA * cp1.rA.x;7175var dv2X = vB.x - wB * cp2.rB.y - vA.x + wA * cp2.rA.y;7176var dv2Y = vB.y + wB * cp2.rB.x - vA.y - wA * cp2.rA.x;7177var vn1 = dv1X * normalX + dv1Y * normalY;7178var vn2 = dv2X * normalX + dv2Y * normalY;7179var bX = vn1 - cp1.velocityBias;7180var bY = vn2 - cp2.velocityBias;7181tMat = c.K;7182bX -= tMat.col1.x * aX + tMat.col2.x * aY;7183bY -= tMat.col1.y * aX + tMat.col2.y * aY;7184var k_errorTol = 0.001;7185for (;;) {7186tMat = c.normalMass;7187var xX = (-(tMat.col1.x * bX + tMat.col2.x * bY));7188var xY = (-(tMat.col1.y * bX + tMat.col2.y * bY));7189if (xX >= 0.0 && xY >= 0.0) {7190dX = xX - aX;7191dY = xY - aY;7192P1X = dX * normalX;7193P1Y = dX * normalY;7194P2X = dY * normalX;7195P2Y = dY * normalY;7196vA.x -= invMassA * (P1X + P2X);7197vA.y -= invMassA * (P1Y + P2Y);7198wA -= invIA * (cp1.rA.x * P1Y - cp1.rA.y * P1X + cp2.rA.x * P2Y - cp2.rA.y * P2X);7199vB.x += invMassB * (P1X + P2X);7200vB.y += invMassB * (P1Y + P2Y);7201wB += invIB * (cp1.rB.x * P1Y - cp1.rB.y * P1X + cp2.rB.x * P2Y - cp2.rB.y * P2X);7202cp1.normalImpulse = xX;7203cp2.normalImpulse = xY;7204break;7205}7206xX = (-cp1.normalMass * bX);7207xY = 0.0;7208vn1 = 0.0;7209vn2 = c.K.col1.y * xX + bY;7210if (xX >= 0.0 && vn2 >= 0.0) {7211dX = xX - aX;7212dY = xY - aY;7213P1X = dX * normalX;7214P1Y = dX * normalY;7215P2X = dY * normalX;7216P2Y = dY * normalY;7217vA.x -= invMassA * (P1X + P2X);7218vA.y -= invMassA * (P1Y + P2Y);7219wA -= invIA * (cp1.rA.x * P1Y - cp1.rA.y * P1X + cp2.rA.x * P2Y - cp2.rA.y * P2X);7220vB.x += invMassB * (P1X + P2X);7221vB.y += invMassB * (P1Y + P2Y);7222wB += invIB * (cp1.rB.x * P1Y - cp1.rB.y * P1X + cp2.rB.x * P2Y - cp2.rB.y * P2X);7223cp1.normalImpulse = xX;7224cp2.normalImpulse = xY;7225break;7226}7227xX = 0.0;7228xY = (-cp2.normalMass * bY);7229vn1 = c.K.col2.x * xY + bX;7230vn2 = 0.0;7231if (xY >= 0.0 && vn1 >= 0.0) {7232dX = xX - aX;7233dY = xY - aY;7234P1X = dX * normalX;7235P1Y = dX * normalY;7236P2X = dY * normalX;7237P2Y = dY * normalY;7238vA.x -= invMassA * (P1X + P2X);7239vA.y -= invMassA * (P1Y + P2Y);7240wA -= invIA * (cp1.rA.x * P1Y - cp1.rA.y * P1X + cp2.rA.x * P2Y - cp2.rA.y * P2X);7241vB.x += invMassB * (P1X + P2X);7242vB.y += invMassB * (P1Y + P2Y);7243wB += invIB * (cp1.rB.x * P1Y - cp1.rB.y * P1X + cp2.rB.x * P2Y - cp2.rB.y * P2X);7244cp1.normalImpulse = xX;7245cp2.normalImpulse = xY;7246break;7247}7248xX = 0.0;7249xY = 0.0;7250vn1 = bX;7251vn2 = bY;7252if (vn1 >= 0.0 && vn2 >= 0.0) {7253dX = xX - aX;7254dY = xY - aY;7255P1X = dX * normalX;7256P1Y = dX * normalY;7257P2X = dY * normalX;7258P2Y = dY * normalY;7259vA.x -= invMassA * (P1X + P2X);7260vA.y -= invMassA * (P1Y + P2Y);7261wA -= invIA * (cp1.rA.x * P1Y - cp1.rA.y * P1X + cp2.rA.x * P2Y - cp2.rA.y * P2X);7262vB.x += invMassB * (P1X + P2X);7263vB.y += invMassB * (P1Y + P2Y);7264wB += invIB * (cp1.rB.x * P1Y - cp1.rB.y * P1X + cp2.rB.x * P2Y - cp2.rB.y * P2X);7265cp1.normalImpulse = xX;7266cp2.normalImpulse = xY;7267break;7268}7269break;7270}7271}7272bodyA.m_angularVelocity = wA;7273bodyB.m_angularVelocity = wB;7274}7275}7276b2ContactSolver.prototype.FinalizeVelocityConstraints = function () {7277for (var i = 0; i < this.m_constraintCount; ++i) {7278var c = this.m_constraints[i];7279var m = c.manifold;7280for (var j = 0; j < c.pointCount; ++j) {7281var point1 = m.m_points[j];7282var point2 = c.points[j];7283point1.m_normalImpulse = point2.normalImpulse;7284point1.m_tangentImpulse = point2.tangentImpulse;7285}7286}7287}7288b2ContactSolver.prototype.SolvePositionConstraints = function (baumgarte) {7289if (baumgarte === undefined) baumgarte = 0;7290var minSeparation = 0.0;7291for (var i = 0; i < this.m_constraintCount; i++) {7292var c = this.m_constraints[i];7293var bodyA = c.bodyA;7294var bodyB = c.bodyB;7295var invMassA = bodyA.m_mass * bodyA.m_invMass;7296var invIA = bodyA.m_mass * bodyA.m_invI;7297var invMassB = bodyB.m_mass * bodyB.m_invMass;7298var invIB = bodyB.m_mass * bodyB.m_invI;7299b2ContactSolver.s_psm.Initialize(c);7300var normal = b2ContactSolver.s_psm.m_normal;7301for (var j = 0; j < c.pointCount; j++) {7302var ccp = c.points[j];7303var point = b2ContactSolver.s_psm.m_points[j];7304var separation = b2ContactSolver.s_psm.m_separations[j];7305var rAX = point.x - bodyA.m_sweep.c.x;7306var rAY = point.y - bodyA.m_sweep.c.y;7307var rBX = point.x - bodyB.m_sweep.c.x;7308var rBY = point.y - bodyB.m_sweep.c.y;7309minSeparation = minSeparation < separation ? minSeparation : separation;7310var C = b2Math.Clamp(baumgarte * (separation + b2Settings.b2_linearSlop), (-b2Settings.b2_maxLinearCorrection), 0.0);7311var impulse = (-ccp.equalizedMass * C);7312var PX = impulse * normal.x;7313var PY = impulse * normal.y;bodyA.m_sweep.c.x -= invMassA * PX;7314bodyA.m_sweep.c.y -= invMassA * PY;7315bodyA.m_sweep.a -= invIA * (rAX * PY - rAY * PX);7316bodyA.SynchronizeTransform();7317bodyB.m_sweep.c.x += invMassB * PX;7318bodyB.m_sweep.c.y += invMassB * PY;7319bodyB.m_sweep.a += invIB * (rBX * PY - rBY * PX);7320bodyB.SynchronizeTransform();7321}7322}7323return minSeparation > (-1.5 * b2Settings.b2_linearSlop);7324}7325Box2D.postDefs.push(function () {7326Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold = new b2WorldManifold();7327Box2D.Dynamics.Contacts.b2ContactSolver.s_psm = new b2PositionSolverManifold();7328});7329Box2D.inherit(b2EdgeAndCircleContact, Box2D.Dynamics.Contacts.b2Contact);7330b2EdgeAndCircleContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;7331b2EdgeAndCircleContact.b2EdgeAndCircleContact = function () {7332Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);7333};7334b2EdgeAndCircleContact.Create = function (allocator) {7335return new b2EdgeAndCircleContact();7336}7337b2EdgeAndCircleContact.Destroy = function (contact, allocator) {}7338b2EdgeAndCircleContact.prototype.Reset = function (fixtureA, fixtureB) {7339this.__super.Reset.call(this, fixtureA, fixtureB);7340}7341b2EdgeAndCircleContact.prototype.Evaluate = function () {7342var bA = this.m_fixtureA.GetBody();7343var bB = this.m_fixtureB.GetBody();7344this.b2CollideEdgeAndCircle(this.m_manifold, (this.m_fixtureA.GetShape() instanceof b2EdgeShape ? this.m_fixtureA.GetShape() : null), bA.m_xf, (this.m_fixtureB.GetShape() instanceof b2CircleShape ? this.m_fixtureB.GetShape() : null), bB.m_xf);7345}7346b2EdgeAndCircleContact.prototype.b2CollideEdgeAndCircle = function (manifold, edge, xf1, circle, xf2) {}7347Box2D.inherit(b2NullContact, Box2D.Dynamics.Contacts.b2Contact);7348b2NullContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;7349b2NullContact.b2NullContact = function () {7350Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);7351};7352b2NullContact.prototype.b2NullContact = function () {7353this.__super.b2Contact.call(this);7354}7355b2NullContact.prototype.Evaluate = function () {}7356Box2D.inherit(b2PolyAndCircleContact, Box2D.Dynamics.Contacts.b2Contact);7357b2PolyAndCircleContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;7358b2PolyAndCircleContact.b2PolyAndCircleContact = function () {7359Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);7360};7361b2PolyAndCircleContact.Create = function (allocator) {7362return new b2PolyAndCircleContact();7363}7364b2PolyAndCircleContact.Destroy = function (contact, allocator) {}7365b2PolyAndCircleContact.prototype.Reset = function (fixtureA, fixtureB) {7366this.__super.Reset.call(this, fixtureA, fixtureB);7367b2Settings.b2Assert(fixtureA.GetType() == b2Shape.e_polygonShape);7368b2Settings.b2Assert(fixtureB.GetType() == b2Shape.e_circleShape);7369}7370b2PolyAndCircleContact.prototype.Evaluate = function () {7371var bA = this.m_fixtureA.m_body;7372var bB = this.m_fixtureB.m_body;7373b2Collision.CollidePolygonAndCircle(this.m_manifold, (this.m_fixtureA.GetShape() instanceof b2PolygonShape ? this.m_fixtureA.GetShape() : null), bA.m_xf, (this.m_fixtureB.GetShape() instanceof b2CircleShape ? this.m_fixtureB.GetShape() : null), bB.m_xf);7374}7375Box2D.inherit(b2PolyAndEdgeContact, Box2D.Dynamics.Contacts.b2Contact);7376b2PolyAndEdgeContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;7377b2PolyAndEdgeContact.b2PolyAndEdgeContact = function () {7378Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);7379};7380b2PolyAndEdgeContact.Create = function (allocator) {7381return new b2PolyAndEdgeContact();7382}7383b2PolyAndEdgeContact.Destroy = function (contact, allocator) {}7384b2PolyAndEdgeContact.prototype.Reset = function (fixtureA, fixtureB) {7385this.__super.Reset.call(this, fixtureA, fixtureB);7386b2Settings.b2Assert(fixtureA.GetType() == b2Shape.e_polygonShape);7387b2Settings.b2Assert(fixtureB.GetType() == b2Shape.e_edgeShape);7388}7389b2PolyAndEdgeContact.prototype.Evaluate = function () {7390var bA = this.m_fixtureA.GetBody();7391var bB = this.m_fixtureB.GetBody();7392this.b2CollidePolyAndEdge(this.m_manifold, (this.m_fixtureA.GetShape() instanceof b2PolygonShape ? this.m_fixtureA.GetShape() : null), bA.m_xf, (this.m_fixtureB.GetShape() instanceof b2EdgeShape ? this.m_fixtureB.GetShape() : null), bB.m_xf);7393}7394b2PolyAndEdgeContact.prototype.b2CollidePolyAndEdge = function (manifold, polygon, xf1, edge, xf2) {}7395Box2D.inherit(b2PolygonContact, Box2D.Dynamics.Contacts.b2Contact);7396b2PolygonContact.prototype.__super = Box2D.Dynamics.Contacts.b2Contact.prototype;7397b2PolygonContact.b2PolygonContact = function () {7398Box2D.Dynamics.Contacts.b2Contact.b2Contact.apply(this, arguments);7399};7400b2PolygonContact.Create = function (allocator) {7401return new b2PolygonContact();7402}7403b2PolygonContact.Destroy = function (contact, allocator) {}7404b2PolygonContact.prototype.Reset = function (fixtureA, fixtureB) {7405this.__super.Reset.call(this, fixtureA, fixtureB);7406}7407b2PolygonContact.prototype.Evaluate = function () {7408var bA = this.m_fixtureA.GetBody();7409var bB = this.m_fixtureB.GetBody();7410b2Collision.CollidePolygons(this.m_manifold, (this.m_fixtureA.GetShape() instanceof b2PolygonShape ? this.m_fixtureA.GetShape() : null), bA.m_xf, (this.m_fixtureB.GetShape() instanceof b2PolygonShape ? this.m_fixtureB.GetShape() : null), bB.m_xf);7411}7412b2PositionSolverManifold.b2PositionSolverManifold = function () {};7413b2PositionSolverManifold.prototype.b2PositionSolverManifold = function () {7414this.m_normal = new b2Vec2();7415this.m_separations = new Vector_a2j_Number(b2Settings.b2_maxManifoldPoints);7416this.m_points = new Vector(b2Settings.b2_maxManifoldPoints);7417for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++) {7418this.m_points[i] = new b2Vec2();7419}7420}7421b2PositionSolverManifold.prototype.Initialize = function (cc) {7422b2Settings.b2Assert(cc.pointCount > 0);7423var i = 0;7424var clipPointX = 0;7425var clipPointY = 0;7426var tMat;7427var tVec;7428var planePointX = 0;7429var planePointY = 0;7430switch (cc.type) {7431case b2Manifold.e_circles:7432{7433tMat = cc.bodyA.m_xf.R;7434tVec = cc.localPoint;7435var pointAX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7436var pointAY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7437tMat = cc.bodyB.m_xf.R;7438tVec = cc.points[0].localPoint;7439var pointBX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7440var pointBY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7441var dX = pointBX - pointAX;7442var dY = pointBY - pointAY;7443var d2 = dX * dX + dY * dY;7444if (d2 > Number.MIN_VALUE * Number.MIN_VALUE) {7445var d = Math.sqrt(d2);7446this.m_normal.x = dX / d;7447this.m_normal.y = dY / d;7448}7449else {7450this.m_normal.x = 1.0;7451this.m_normal.y = 0.0;7452}7453this.m_points[0].x = 0.5 * (pointAX + pointBX);7454this.m_points[0].y = 0.5 * (pointAY + pointBY);7455this.m_separations[0] = dX * this.m_normal.x + dY * this.m_normal.y - cc.radius;7456}7457break;7458case b2Manifold.e_faceA:7459{7460tMat = cc.bodyA.m_xf.R;7461tVec = cc.localPlaneNormal;7462this.m_normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;7463this.m_normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;7464tMat = cc.bodyA.m_xf.R;7465tVec = cc.localPoint;7466planePointX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7467planePointY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7468tMat = cc.bodyB.m_xf.R;7469for (i = 0;7470i < cc.pointCount; ++i) {7471tVec = cc.points[i].localPoint;7472clipPointX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7473clipPointY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7474this.m_separations[i] = (clipPointX - planePointX) * this.m_normal.x + (clipPointY - planePointY) * this.m_normal.y - cc.radius;7475this.m_points[i].x = clipPointX;7476this.m_points[i].y = clipPointY;7477}7478}7479break;7480case b2Manifold.e_faceB:7481{7482tMat = cc.bodyB.m_xf.R;7483tVec = cc.localPlaneNormal;7484this.m_normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;7485this.m_normal.y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;7486tMat = cc.bodyB.m_xf.R;7487tVec = cc.localPoint;7488planePointX = cc.bodyB.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7489planePointY = cc.bodyB.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7490tMat = cc.bodyA.m_xf.R;7491for (i = 0;7492i < cc.pointCount; ++i) {7493tVec = cc.points[i].localPoint;7494clipPointX = cc.bodyA.m_xf.position.x + (tMat.col1.x * tVec.x + tMat.col2.x * tVec.y);7495clipPointY = cc.bodyA.m_xf.position.y + (tMat.col1.y * tVec.x + tMat.col2.y * tVec.y);7496this.m_separations[i] = (clipPointX - planePointX) * this.m_normal.x + (clipPointY - planePointY) * this.m_normal.y - cc.radius;7497this.m_points[i].Set(clipPointX, clipPointY);7498}7499this.m_normal.x *= (-1);7500this.m_normal.y *= (-1);7501}7502break;7503}7504}7505Box2D.postDefs.push(function () {7506Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointA = new b2Vec2();7507Box2D.Dynamics.Contacts.b2PositionSolverManifold.circlePointB = new b2Vec2();7508});7509})();7510(function () {7511var b2Body = Box2D.Dynamics.b2Body,7512b2BodyDef = Box2D.Dynamics.b2BodyDef,7513b2ContactFilter = Box2D.Dynamics.b2ContactFilter,7514b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,7515b2ContactListener = Box2D.Dynamics.b2ContactListener,7516b2ContactManager = Box2D.Dynamics.b2ContactManager,7517b2DebugDraw = Box2D.Dynamics.b2DebugDraw,7518b2DestructionListener = Box2D.Dynamics.b2DestructionListener,7519b2FilterData = Box2D.Dynamics.b2FilterData,7520b2Fixture = Box2D.Dynamics.b2Fixture,7521b2FixtureDef = Box2D.Dynamics.b2FixtureDef,7522b2Island = Box2D.Dynamics.b2Island,7523b2TimeStep = Box2D.Dynamics.b2TimeStep,7524b2World = Box2D.Dynamics.b2World,7525b2Mat22 = Box2D.Common.Math.b2Mat22,7526b2Mat33 = Box2D.Common.Math.b2Mat33,7527b2Math = Box2D.Common.Math.b2Math,7528b2Sweep = Box2D.Common.Math.b2Sweep,7529b2Transform = Box2D.Common.Math.b2Transform,7530b2Vec2 = Box2D.Common.Math.b2Vec2,7531b2Vec3 = Box2D.Common.Math.b2Vec3,7532b2Color = Box2D.Common.b2Color,7533b2internal = Box2D.Common.b2internal,7534b2Settings = Box2D.Common.b2Settings,7535b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,7536b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,7537b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,7538b2MassData = Box2D.Collision.Shapes.b2MassData,7539b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,7540b2Shape = Box2D.Collision.Shapes.b2Shape,7541b2BuoyancyController = Box2D.Dynamics.Controllers.b2BuoyancyController,7542b2ConstantAccelController = Box2D.Dynamics.Controllers.b2ConstantAccelController,7543b2ConstantForceController = Box2D.Dynamics.Controllers.b2ConstantForceController,7544b2Controller = Box2D.Dynamics.Controllers.b2Controller,7545b2ControllerEdge = Box2D.Dynamics.Controllers.b2ControllerEdge,7546b2GravityController = Box2D.Dynamics.Controllers.b2GravityController,7547b2TensorDampingController = Box2D.Dynamics.Controllers.b2TensorDampingController;75487549Box2D.inherit(b2BuoyancyController, Box2D.Dynamics.Controllers.b2Controller);7550b2BuoyancyController.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;7551b2BuoyancyController.b2BuoyancyController = function () {7552Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);7553this.normal = new b2Vec2(0, (-1));7554this.offset = 0;7555this.density = 0;7556this.velocity = new b2Vec2(0, 0);7557this.linearDrag = 2;7558this.angularDrag = 1;7559this.useDensity = false;7560this.useWorldGravity = true;7561this.gravity = null;7562};7563b2BuoyancyController.prototype.Step = function (step) {7564if (!this.m_bodyList) return;7565if (this.useWorldGravity) {7566this.gravity = this.GetWorld().GetGravity().Copy();7567}7568for (var i = this.m_bodyList; i; i = i.nextBody) {7569var body = i.body;7570if (body.IsAwake() == false) {7571continue;7572}7573var areac = new b2Vec2();7574var massc = new b2Vec2();7575var area = 0.0;7576var mass = 0.0;7577for (var fixture = body.GetFixtureList(); fixture; fixture = fixture.GetNext()) {7578var sc = new b2Vec2();7579var sarea = fixture.GetShape().ComputeSubmergedArea(this.normal, this.offset, body.GetTransform(), sc);7580area += sarea;7581areac.x += sarea * sc.x;7582areac.y += sarea * sc.y;7583var shapeDensity = 0;7584if (this.useDensity) {7585shapeDensity = 1;7586}7587else {7588shapeDensity = 1;7589}7590mass += sarea * shapeDensity;7591massc.x += sarea * sc.x * shapeDensity;7592massc.y += sarea * sc.y * shapeDensity;7593}7594areac.x /= area;7595areac.y /= area;7596massc.x /= mass;7597massc.y /= mass;7598if (area < Number.MIN_VALUE) continue;7599var buoyancyForce = this.gravity.GetNegative();7600buoyancyForce.Multiply(this.density * area);7601body.ApplyForce(buoyancyForce, massc);7602var dragForce = body.GetLinearVelocityFromWorldPoint(areac);7603dragForce.Subtract(this.velocity);7604dragForce.Multiply((-this.linearDrag * area));7605body.ApplyForce(dragForce, areac);7606body.ApplyTorque((-body.GetInertia() / body.GetMass() * area * body.GetAngularVelocity() * this.angularDrag));7607}7608}7609b2BuoyancyController.prototype.Draw = function (debugDraw) {7610var r = 1000;7611var p1 = new b2Vec2();7612var p2 = new b2Vec2();7613p1.x = this.normal.x * this.offset + this.normal.y * r;7614p1.y = this.normal.y * this.offset - this.normal.x * r;7615p2.x = this.normal.x * this.offset - this.normal.y * r;7616p2.y = this.normal.y * this.offset + this.normal.x * r;7617var color = new b2Color(0, 0, 1);7618debugDraw.DrawSegment(p1, p2, color);7619}7620Box2D.inherit(b2ConstantAccelController, Box2D.Dynamics.Controllers.b2Controller);7621b2ConstantAccelController.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;7622b2ConstantAccelController.b2ConstantAccelController = function () {7623Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);7624this.A = new b2Vec2(0, 0);7625};7626b2ConstantAccelController.prototype.Step = function (step) {7627var smallA = new b2Vec2(this.A.x * step.dt, this.A.y * step.dt);7628for (var i = this.m_bodyList; i; i = i.nextBody) {7629var body = i.body;7630if (!body.IsAwake()) continue;7631body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + smallA.x, body.GetLinearVelocity().y + smallA.y));7632}7633}7634Box2D.inherit(b2ConstantForceController, Box2D.Dynamics.Controllers.b2Controller);7635b2ConstantForceController.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;7636b2ConstantForceController.b2ConstantForceController = function () {7637Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);7638this.F = new b2Vec2(0, 0);7639};7640b2ConstantForceController.prototype.Step = function (step) {7641for (var i = this.m_bodyList; i; i = i.nextBody) {7642var body = i.body;7643if (!body.IsAwake()) continue;7644body.ApplyForce(this.F, body.GetWorldCenter());7645}7646}7647b2Controller.b2Controller = function () {};7648b2Controller.prototype.Step = function (step) {}7649b2Controller.prototype.Draw = function (debugDraw) {}7650b2Controller.prototype.AddBody = function (body) {7651var edge = new b2ControllerEdge();7652edge.controller = this;7653edge.body = body;7654edge.nextBody = this.m_bodyList;7655edge.prevBody = null;7656this.m_bodyList = edge;7657if (edge.nextBody) edge.nextBody.prevBody = edge;7658this.m_bodyCount++;7659edge.nextController = body.m_controllerList;7660edge.prevController = null;7661body.m_controllerList = edge;7662if (edge.nextController) edge.nextController.prevController = edge;7663body.m_controllerCount++;7664}7665b2Controller.prototype.RemoveBody = function (body) {7666var edge = body.m_controllerList;7667while (edge && edge.controller != this)7668edge = edge.nextController;7669if (edge.prevBody) edge.prevBody.nextBody = edge.nextBody;7670if (edge.nextBody) edge.nextBody.prevBody = edge.prevBody;7671if (edge.nextController) edge.nextController.prevController = edge.prevController;7672if (edge.prevController) edge.prevController.nextController = edge.nextController;7673if (this.m_bodyList == edge) this.m_bodyList = edge.nextBody;7674if (body.m_controllerList == edge) body.m_controllerList = edge.nextController;7675body.m_controllerCount--;7676this.m_bodyCount--;7677}7678b2Controller.prototype.Clear = function () {7679while (this.m_bodyList)7680this.RemoveBody(this.m_bodyList.body);7681}7682b2Controller.prototype.GetNext = function () {7683return this.m_next;7684}7685b2Controller.prototype.GetWorld = function () {7686return this.m_world;7687}7688b2Controller.prototype.GetBodyList = function () {7689return this.m_bodyList;7690}7691b2ControllerEdge.b2ControllerEdge = function () {};7692Box2D.inherit(b2GravityController, Box2D.Dynamics.Controllers.b2Controller);7693b2GravityController.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;7694b2GravityController.b2GravityController = function () {7695Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);7696this.G = 1;7697this.invSqr = true;7698};7699b2GravityController.prototype.Step = function (step) {7700var i = null;7701var body1 = null;7702var p1 = null;7703var mass1 = 0;7704var j = null;7705var body2 = null;7706var p2 = null;7707var dx = 0;7708var dy = 0;7709var r2 = 0;7710var f = null;7711if (this.invSqr) {7712for (i = this.m_bodyList;7713i; i = i.nextBody) {7714body1 = i.body;7715p1 = body1.GetWorldCenter();7716mass1 = body1.GetMass();7717for (j = this.m_bodyList;7718j != i; j = j.nextBody) {7719body2 = j.body;7720p2 = body2.GetWorldCenter();7721dx = p2.x - p1.x;7722dy = p2.y - p1.y;7723r2 = dx * dx + dy * dy;7724if (r2 < Number.MIN_VALUE) continue;7725f = new b2Vec2(dx, dy);7726f.Multiply(this.G / r2 / Math.sqrt(r2) * mass1 * body2.GetMass());7727if (body1.IsAwake()) body1.ApplyForce(f, p1);7728f.Multiply((-1));7729if (body2.IsAwake()) body2.ApplyForce(f, p2);7730}7731}7732}7733else {7734for (i = this.m_bodyList;7735i; i = i.nextBody) {7736body1 = i.body;7737p1 = body1.GetWorldCenter();7738mass1 = body1.GetMass();7739for (j = this.m_bodyList;7740j != i; j = j.nextBody) {7741body2 = j.body;7742p2 = body2.GetWorldCenter();7743dx = p2.x - p1.x;7744dy = p2.y - p1.y;7745r2 = dx * dx + dy * dy;7746if (r2 < Number.MIN_VALUE) continue;7747f = new b2Vec2(dx, dy);7748f.Multiply(this.G / r2 * mass1 * body2.GetMass());7749if (body1.IsAwake()) body1.ApplyForce(f, p1);7750f.Multiply((-1));7751if (body2.IsAwake()) body2.ApplyForce(f, p2);7752}7753}7754}7755}7756Box2D.inherit(b2TensorDampingController, Box2D.Dynamics.Controllers.b2Controller);7757b2TensorDampingController.prototype.__super = Box2D.Dynamics.Controllers.b2Controller.prototype;7758b2TensorDampingController.b2TensorDampingController = function () {7759Box2D.Dynamics.Controllers.b2Controller.b2Controller.apply(this, arguments);7760this.T = new b2Mat22();7761this.maxTimestep = 0;7762};7763b2TensorDampingController.prototype.SetAxisAligned = function (xDamping, yDamping) {7764if (xDamping === undefined) xDamping = 0;7765if (yDamping === undefined) yDamping = 0;7766this.T.col1.x = (-xDamping);7767this.T.col1.y = 0;7768this.T.col2.x = 0;7769this.T.col2.y = (-yDamping);7770if (xDamping > 0 || yDamping > 0) {7771this.maxTimestep = 1 / Math.max(xDamping, yDamping);7772}7773else {7774this.maxTimestep = 0;7775}7776}7777b2TensorDampingController.prototype.Step = function (step) {7778var timestep = step.dt;7779if (timestep <= Number.MIN_VALUE) return;7780if (timestep > this.maxTimestep && this.maxTimestep > 0) timestep = this.maxTimestep;7781for (var i = this.m_bodyList; i; i = i.nextBody) {7782var body = i.body;7783if (!body.IsAwake()) {7784continue;7785}7786var damping = body.GetWorldVector(b2Math.MulMV(this.T, body.GetLocalVector(body.GetLinearVelocity())));7787body.SetLinearVelocity(new b2Vec2(body.GetLinearVelocity().x + damping.x * timestep, body.GetLinearVelocity().y + damping.y * timestep));7788}7789}7790})();7791(function () {7792var b2Color = Box2D.Common.b2Color,7793b2internal = Box2D.Common.b2internal,7794b2Settings = Box2D.Common.b2Settings,7795b2Mat22 = Box2D.Common.Math.b2Mat22,7796b2Mat33 = Box2D.Common.Math.b2Mat33,7797b2Math = Box2D.Common.Math.b2Math,7798b2Sweep = Box2D.Common.Math.b2Sweep,7799b2Transform = Box2D.Common.Math.b2Transform,7800b2Vec2 = Box2D.Common.Math.b2Vec2,7801b2Vec3 = Box2D.Common.Math.b2Vec3,7802b2DistanceJoint = Box2D.Dynamics.Joints.b2DistanceJoint,7803b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef,7804b2FrictionJoint = Box2D.Dynamics.Joints.b2FrictionJoint,7805b2FrictionJointDef = Box2D.Dynamics.Joints.b2FrictionJointDef,7806b2GearJoint = Box2D.Dynamics.Joints.b2GearJoint,7807b2GearJointDef = Box2D.Dynamics.Joints.b2GearJointDef,7808b2Jacobian = Box2D.Dynamics.Joints.b2Jacobian,7809b2Joint = Box2D.Dynamics.Joints.b2Joint,7810b2JointDef = Box2D.Dynamics.Joints.b2JointDef,7811b2JointEdge = Box2D.Dynamics.Joints.b2JointEdge,7812b2LineJoint = Box2D.Dynamics.Joints.b2LineJoint,7813b2LineJointDef = Box2D.Dynamics.Joints.b2LineJointDef,7814b2MouseJoint = Box2D.Dynamics.Joints.b2MouseJoint,7815b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef,7816b2PrismaticJoint = Box2D.Dynamics.Joints.b2PrismaticJoint,7817b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef,7818b2PulleyJoint = Box2D.Dynamics.Joints.b2PulleyJoint,7819b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef,7820b2RevoluteJoint = Box2D.Dynamics.Joints.b2RevoluteJoint,7821b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef,7822b2WeldJoint = Box2D.Dynamics.Joints.b2WeldJoint,7823b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDef,7824b2Body = Box2D.Dynamics.b2Body,7825b2BodyDef = Box2D.Dynamics.b2BodyDef,7826b2ContactFilter = Box2D.Dynamics.b2ContactFilter,7827b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,7828b2ContactListener = Box2D.Dynamics.b2ContactListener,7829b2ContactManager = Box2D.Dynamics.b2ContactManager,7830b2DebugDraw = Box2D.Dynamics.b2DebugDraw,7831b2DestructionListener = Box2D.Dynamics.b2DestructionListener,7832b2FilterData = Box2D.Dynamics.b2FilterData,7833b2Fixture = Box2D.Dynamics.b2Fixture,7834b2FixtureDef = Box2D.Dynamics.b2FixtureDef,7835b2Island = Box2D.Dynamics.b2Island,7836b2TimeStep = Box2D.Dynamics.b2TimeStep,7837b2World = Box2D.Dynamics.b2World;78387839Box2D.inherit(b2DistanceJoint, Box2D.Dynamics.Joints.b2Joint);7840b2DistanceJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;7841b2DistanceJoint.b2DistanceJoint = function () {7842Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);7843this.m_localAnchor1 = new b2Vec2();7844this.m_localAnchor2 = new b2Vec2();7845this.m_u = new b2Vec2();7846};7847b2DistanceJoint.prototype.GetAnchorA = function () {7848return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);7849}7850b2DistanceJoint.prototype.GetAnchorB = function () {7851return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);7852}7853b2DistanceJoint.prototype.GetReactionForce = function (inv_dt) {7854if (inv_dt === undefined) inv_dt = 0;7855return new b2Vec2(inv_dt * this.m_impulse * this.m_u.x, inv_dt * this.m_impulse * this.m_u.y);7856}7857b2DistanceJoint.prototype.GetReactionTorque = function (inv_dt) {7858if (inv_dt === undefined) inv_dt = 0;7859return 0.0;7860}7861b2DistanceJoint.prototype.GetLength = function () {7862return this.m_length;7863}7864b2DistanceJoint.prototype.SetLength = function (length) {7865if (length === undefined) length = 0;7866this.m_length = length;7867}7868b2DistanceJoint.prototype.GetFrequency = function () {7869return this.m_frequencyHz;7870}7871b2DistanceJoint.prototype.SetFrequency = function (hz) {7872if (hz === undefined) hz = 0;7873this.m_frequencyHz = hz;7874}7875b2DistanceJoint.prototype.GetDampingRatio = function () {7876return this.m_dampingRatio;7877}7878b2DistanceJoint.prototype.SetDampingRatio = function (ratio) {7879if (ratio === undefined) ratio = 0;7880this.m_dampingRatio = ratio;7881}7882b2DistanceJoint.prototype.b2DistanceJoint = function (def) {7883this.__super.b2Joint.call(this, def);7884var tMat;7885var tX = 0;7886var tY = 0;7887this.m_localAnchor1.SetV(def.localAnchorA);7888this.m_localAnchor2.SetV(def.localAnchorB);7889this.m_length = def.length;7890this.m_frequencyHz = def.frequencyHz;7891this.m_dampingRatio = def.dampingRatio;7892this.m_impulse = 0.0;7893this.m_gamma = 0.0;7894this.m_bias = 0.0;7895}7896b2DistanceJoint.prototype.InitVelocityConstraints = function (step) {7897var tMat;7898var tX = 0;7899var bA = this.m_bodyA;7900var bB = this.m_bodyB;7901tMat = bA.m_xf.R;7902var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;7903var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;7904tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);7905r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);7906r1X = tX;7907tMat = bB.m_xf.R;7908var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;7909var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;7910tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);7911r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);7912r2X = tX;7913this.m_u.x = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;7914this.m_u.y = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;7915var length = Math.sqrt(this.m_u.x * this.m_u.x + this.m_u.y * this.m_u.y);7916if (length > b2Settings.b2_linearSlop) {7917this.m_u.Multiply(1.0 / length);7918}7919else {7920this.m_u.SetZero();7921}7922var cr1u = (r1X * this.m_u.y - r1Y * this.m_u.x);7923var cr2u = (r2X * this.m_u.y - r2Y * this.m_u.x);7924var invMass = bA.m_invMass + bA.m_invI * cr1u * cr1u + bB.m_invMass + bB.m_invI * cr2u * cr2u;7925this.m_mass = invMass != 0.0 ? 1.0 / invMass : 0.0;7926if (this.m_frequencyHz > 0.0) {7927var C = length - this.m_length;7928var omega = 2.0 * Math.PI * this.m_frequencyHz;7929var d = 2.0 * this.m_mass * this.m_dampingRatio * omega;7930var k = this.m_mass * omega * omega;7931this.m_gamma = step.dt * (d + step.dt * k);7932this.m_gamma = this.m_gamma != 0.0 ? 1 / this.m_gamma : 0.0;7933this.m_bias = C * step.dt * k * this.m_gamma;7934this.m_mass = invMass + this.m_gamma;7935this.m_mass = this.m_mass != 0.0 ? 1.0 / this.m_mass : 0.0;7936}7937if (step.warmStarting) {7938this.m_impulse *= step.dtRatio;7939var PX = this.m_impulse * this.m_u.x;7940var PY = this.m_impulse * this.m_u.y;7941bA.m_linearVelocity.x -= bA.m_invMass * PX;7942bA.m_linearVelocity.y -= bA.m_invMass * PY;7943bA.m_angularVelocity -= bA.m_invI * (r1X * PY - r1Y * PX);7944bB.m_linearVelocity.x += bB.m_invMass * PX;7945bB.m_linearVelocity.y += bB.m_invMass * PY;7946bB.m_angularVelocity += bB.m_invI * (r2X * PY - r2Y * PX);7947}7948else {7949this.m_impulse = 0.0;7950}7951}7952b2DistanceJoint.prototype.SolveVelocityConstraints = function (step) {7953var tMat;7954var bA = this.m_bodyA;7955var bB = this.m_bodyB;7956tMat = bA.m_xf.R;7957var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;7958var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;7959var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);7960r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);7961r1X = tX;7962tMat = bB.m_xf.R;7963var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;7964var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;7965tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);7966r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);7967r2X = tX;7968var v1X = bA.m_linearVelocity.x + ((-bA.m_angularVelocity * r1Y));7969var v1Y = bA.m_linearVelocity.y + (bA.m_angularVelocity * r1X);7970var v2X = bB.m_linearVelocity.x + ((-bB.m_angularVelocity * r2Y));7971var v2Y = bB.m_linearVelocity.y + (bB.m_angularVelocity * r2X);7972var Cdot = (this.m_u.x * (v2X - v1X) + this.m_u.y * (v2Y - v1Y));7973var impulse = (-this.m_mass * (Cdot + this.m_bias + this.m_gamma * this.m_impulse));7974this.m_impulse += impulse;7975var PX = impulse * this.m_u.x;7976var PY = impulse * this.m_u.y;7977bA.m_linearVelocity.x -= bA.m_invMass * PX;7978bA.m_linearVelocity.y -= bA.m_invMass * PY;7979bA.m_angularVelocity -= bA.m_invI * (r1X * PY - r1Y * PX);7980bB.m_linearVelocity.x += bB.m_invMass * PX;7981bB.m_linearVelocity.y += bB.m_invMass * PY;7982bB.m_angularVelocity += bB.m_invI * (r2X * PY - r2Y * PX);7983}7984b2DistanceJoint.prototype.SolvePositionConstraints = function (baumgarte) {7985if (baumgarte === undefined) baumgarte = 0;7986var tMat;7987if (this.m_frequencyHz > 0.0) {7988return true;7989}7990var bA = this.m_bodyA;7991var bB = this.m_bodyB;7992tMat = bA.m_xf.R;7993var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;7994var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;7995var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);7996r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);7997r1X = tX;7998tMat = bB.m_xf.R;7999var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;8000var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;8001tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);8002r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);8003r2X = tX;8004var dX = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;8005var dY = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;8006var length = Math.sqrt(dX * dX + dY * dY);8007dX /= length;8008dY /= length;8009var C = length - this.m_length;8010C = b2Math.Clamp(C, (-b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);8011var impulse = (-this.m_mass * C);8012this.m_u.Set(dX, dY);8013var PX = impulse * this.m_u.x;8014var PY = impulse * this.m_u.y;8015bA.m_sweep.c.x -= bA.m_invMass * PX;8016bA.m_sweep.c.y -= bA.m_invMass * PY;8017bA.m_sweep.a -= bA.m_invI * (r1X * PY - r1Y * PX);8018bB.m_sweep.c.x += bB.m_invMass * PX;8019bB.m_sweep.c.y += bB.m_invMass * PY;8020bB.m_sweep.a += bB.m_invI * (r2X * PY - r2Y * PX);8021bA.SynchronizeTransform();8022bB.SynchronizeTransform();8023return b2Math.Abs(C) < b2Settings.b2_linearSlop;8024}8025Box2D.inherit(b2DistanceJointDef, Box2D.Dynamics.Joints.b2JointDef);8026b2DistanceJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;8027b2DistanceJointDef.b2DistanceJointDef = function () {8028Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);8029this.localAnchorA = new b2Vec2();8030this.localAnchorB = new b2Vec2();8031};8032b2DistanceJointDef.prototype.b2DistanceJointDef = function () {8033this.__super.b2JointDef.call(this);8034this.type = b2Joint.e_distanceJoint;8035this.length = 1.0;8036this.frequencyHz = 0.0;8037this.dampingRatio = 0.0;8038}8039b2DistanceJointDef.prototype.Initialize = function (bA, bB, anchorA, anchorB) {8040this.bodyA = bA;8041this.bodyB = bB;8042this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchorA));8043this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchorB));8044var dX = anchorB.x - anchorA.x;8045var dY = anchorB.y - anchorA.y;8046this.length = Math.sqrt(dX * dX + dY * dY);8047this.frequencyHz = 0.0;8048this.dampingRatio = 0.0;8049}8050Box2D.inherit(b2FrictionJoint, Box2D.Dynamics.Joints.b2Joint);8051b2FrictionJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;8052b2FrictionJoint.b2FrictionJoint = function () {8053Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);8054this.m_localAnchorA = new b2Vec2();8055this.m_localAnchorB = new b2Vec2();8056this.m_linearMass = new b2Mat22();8057this.m_linearImpulse = new b2Vec2();8058};8059b2FrictionJoint.prototype.GetAnchorA = function () {8060return this.m_bodyA.GetWorldPoint(this.m_localAnchorA);8061}8062b2FrictionJoint.prototype.GetAnchorB = function () {8063return this.m_bodyB.GetWorldPoint(this.m_localAnchorB);8064}8065b2FrictionJoint.prototype.GetReactionForce = function (inv_dt) {8066if (inv_dt === undefined) inv_dt = 0;8067return new b2Vec2(inv_dt * this.m_linearImpulse.x, inv_dt * this.m_linearImpulse.y);8068}8069b2FrictionJoint.prototype.GetReactionTorque = function (inv_dt) {8070if (inv_dt === undefined) inv_dt = 0;8071return inv_dt * this.m_angularImpulse;8072}8073b2FrictionJoint.prototype.SetMaxForce = function (force) {8074if (force === undefined) force = 0;8075this.m_maxForce = force;8076}8077b2FrictionJoint.prototype.GetMaxForce = function () {8078return this.m_maxForce;8079}8080b2FrictionJoint.prototype.SetMaxTorque = function (torque) {8081if (torque === undefined) torque = 0;8082this.m_maxTorque = torque;8083}8084b2FrictionJoint.prototype.GetMaxTorque = function () {8085return this.m_maxTorque;8086}8087b2FrictionJoint.prototype.b2FrictionJoint = function (def) {8088this.__super.b2Joint.call(this, def);8089this.m_localAnchorA.SetV(def.localAnchorA);8090this.m_localAnchorB.SetV(def.localAnchorB);8091this.m_linearMass.SetZero();8092this.m_angularMass = 0.0;8093this.m_linearImpulse.SetZero();8094this.m_angularImpulse = 0.0;8095this.m_maxForce = def.maxForce;8096this.m_maxTorque = def.maxTorque;8097}8098b2FrictionJoint.prototype.InitVelocityConstraints = function (step) {8099var tMat;8100var tX = 0;8101var bA = this.m_bodyA;8102var bB = this.m_bodyB;8103tMat = bA.m_xf.R;8104var rAX = this.m_localAnchorA.x - bA.m_sweep.localCenter.x;8105var rAY = this.m_localAnchorA.y - bA.m_sweep.localCenter.y;8106tX = (tMat.col1.x * rAX + tMat.col2.x * rAY);8107rAY = (tMat.col1.y * rAX + tMat.col2.y * rAY);8108rAX = tX;8109tMat = bB.m_xf.R;8110var rBX = this.m_localAnchorB.x - bB.m_sweep.localCenter.x;8111var rBY = this.m_localAnchorB.y - bB.m_sweep.localCenter.y;8112tX = (tMat.col1.x * rBX + tMat.col2.x * rBY);8113rBY = (tMat.col1.y * rBX + tMat.col2.y * rBY);8114rBX = tX;8115var mA = bA.m_invMass;8116var mB = bB.m_invMass;8117var iA = bA.m_invI;8118var iB = bB.m_invI;8119var K = new b2Mat22();8120K.col1.x = mA + mB;8121K.col2.x = 0.0;8122K.col1.y = 0.0;8123K.col2.y = mA + mB;8124K.col1.x += iA * rAY * rAY;8125K.col2.x += (-iA * rAX * rAY);8126K.col1.y += (-iA * rAX * rAY);8127K.col2.y += iA * rAX * rAX;8128K.col1.x += iB * rBY * rBY;8129K.col2.x += (-iB * rBX * rBY);8130K.col1.y += (-iB * rBX * rBY);8131K.col2.y += iB * rBX * rBX;8132K.GetInverse(this.m_linearMass);8133this.m_angularMass = iA + iB;8134if (this.m_angularMass > 0.0) {8135this.m_angularMass = 1.0 / this.m_angularMass;8136}8137if (step.warmStarting) {8138this.m_linearImpulse.x *= step.dtRatio;8139this.m_linearImpulse.y *= step.dtRatio;8140this.m_angularImpulse *= step.dtRatio;8141var P = this.m_linearImpulse;8142bA.m_linearVelocity.x -= mA * P.x;8143bA.m_linearVelocity.y -= mA * P.y;8144bA.m_angularVelocity -= iA * (rAX * P.y - rAY * P.x + this.m_angularImpulse);8145bB.m_linearVelocity.x += mB * P.x;8146bB.m_linearVelocity.y += mB * P.y;8147bB.m_angularVelocity += iB * (rBX * P.y - rBY * P.x + this.m_angularImpulse);8148}8149else {8150this.m_linearImpulse.SetZero();8151this.m_angularImpulse = 0.0;8152}8153}8154b2FrictionJoint.prototype.SolveVelocityConstraints = function (step) {8155var tMat;8156var tX = 0;8157var bA = this.m_bodyA;8158var bB = this.m_bodyB;8159var vA = bA.m_linearVelocity;8160var wA = bA.m_angularVelocity;8161var vB = bB.m_linearVelocity;8162var wB = bB.m_angularVelocity;8163var mA = bA.m_invMass;8164var mB = bB.m_invMass;8165var iA = bA.m_invI;8166var iB = bB.m_invI;8167tMat = bA.m_xf.R;8168var rAX = this.m_localAnchorA.x - bA.m_sweep.localCenter.x;8169var rAY = this.m_localAnchorA.y - bA.m_sweep.localCenter.y;8170tX = (tMat.col1.x * rAX + tMat.col2.x * rAY);8171rAY = (tMat.col1.y * rAX + tMat.col2.y * rAY);8172rAX = tX;8173tMat = bB.m_xf.R;8174var rBX = this.m_localAnchorB.x - bB.m_sweep.localCenter.x;8175var rBY = this.m_localAnchorB.y - bB.m_sweep.localCenter.y;8176tX = (tMat.col1.x * rBX + tMat.col2.x * rBY);8177rBY = (tMat.col1.y * rBX + tMat.col2.y * rBY);8178rBX = tX;8179var maxImpulse = 0; {8180var Cdot = wB - wA;8181var impulse = (-this.m_angularMass * Cdot);8182var oldImpulse = this.m_angularImpulse;8183maxImpulse = step.dt * this.m_maxTorque;8184this.m_angularImpulse = b2Math.Clamp(this.m_angularImpulse + impulse, (-maxImpulse), maxImpulse);8185impulse = this.m_angularImpulse - oldImpulse;8186wA -= iA * impulse;8187wB += iB * impulse;8188} {8189var CdotX = vB.x - wB * rBY - vA.x + wA * rAY;8190var CdotY = vB.y + wB * rBX - vA.y - wA * rAX;8191var impulseV = b2Math.MulMV(this.m_linearMass, new b2Vec2((-CdotX), (-CdotY)));8192var oldImpulseV = this.m_linearImpulse.Copy();8193this.m_linearImpulse.Add(impulseV);8194maxImpulse = step.dt * this.m_maxForce;8195if (this.m_linearImpulse.LengthSquared() > maxImpulse * maxImpulse) {8196this.m_linearImpulse.Normalize();8197this.m_linearImpulse.Multiply(maxImpulse);8198}8199impulseV = b2Math.SubtractVV(this.m_linearImpulse, oldImpulseV);8200vA.x -= mA * impulseV.x;8201vA.y -= mA * impulseV.y;8202wA -= iA * (rAX * impulseV.y - rAY * impulseV.x);8203vB.x += mB * impulseV.x;8204vB.y += mB * impulseV.y;8205wB += iB * (rBX * impulseV.y - rBY * impulseV.x);8206}8207bA.m_angularVelocity = wA;8208bB.m_angularVelocity = wB;8209}8210b2FrictionJoint.prototype.SolvePositionConstraints = function (baumgarte) {8211if (baumgarte === undefined) baumgarte = 0;8212return true;8213}8214Box2D.inherit(b2FrictionJointDef, Box2D.Dynamics.Joints.b2JointDef);8215b2FrictionJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;8216b2FrictionJointDef.b2FrictionJointDef = function () {8217Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);8218this.localAnchorA = new b2Vec2();8219this.localAnchorB = new b2Vec2();8220};8221b2FrictionJointDef.prototype.b2FrictionJointDef = function () {8222this.__super.b2JointDef.call(this);8223this.type = b2Joint.e_frictionJoint;8224this.maxForce = 0.0;8225this.maxTorque = 0.0;8226}8227b2FrictionJointDef.prototype.Initialize = function (bA, bB, anchor) {8228this.bodyA = bA;8229this.bodyB = bB;8230this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchor));8231this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchor));8232}8233Box2D.inherit(b2GearJoint, Box2D.Dynamics.Joints.b2Joint);8234b2GearJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;8235b2GearJoint.b2GearJoint = function () {8236Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);8237this.m_groundAnchor1 = new b2Vec2();8238this.m_groundAnchor2 = new b2Vec2();8239this.m_localAnchor1 = new b2Vec2();8240this.m_localAnchor2 = new b2Vec2();8241this.m_J = new b2Jacobian();8242};8243b2GearJoint.prototype.GetAnchorA = function () {8244return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);8245}8246b2GearJoint.prototype.GetAnchorB = function () {8247return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);8248}8249b2GearJoint.prototype.GetReactionForce = function (inv_dt) {8250if (inv_dt === undefined) inv_dt = 0;8251return new b2Vec2(inv_dt * this.m_impulse * this.m_J.linearB.x, inv_dt * this.m_impulse * this.m_J.linearB.y);8252}8253b2GearJoint.prototype.GetReactionTorque = function (inv_dt) {8254if (inv_dt === undefined) inv_dt = 0;8255var tMat = this.m_bodyB.m_xf.R;8256var rX = this.m_localAnchor1.x - this.m_bodyB.m_sweep.localCenter.x;8257var rY = this.m_localAnchor1.y - this.m_bodyB.m_sweep.localCenter.y;8258var tX = tMat.col1.x * rX + tMat.col2.x * rY;8259rY = tMat.col1.y * rX + tMat.col2.y * rY;8260rX = tX;8261var PX = this.m_impulse * this.m_J.linearB.x;8262var PY = this.m_impulse * this.m_J.linearB.y;8263return inv_dt * (this.m_impulse * this.m_J.angularB - rX * PY + rY * PX);8264}8265b2GearJoint.prototype.GetRatio = function () {8266return this.m_ratio;8267}8268b2GearJoint.prototype.SetRatio = function (ratio) {8269if (ratio === undefined) ratio = 0;8270this.m_ratio = ratio;8271}8272b2GearJoint.prototype.b2GearJoint = function (def) {8273this.__super.b2Joint.call(this, def);8274var type1 = parseInt(def.joint1.m_type);8275var type2 = parseInt(def.joint2.m_type);8276this.m_revolute1 = null;8277this.m_prismatic1 = null;8278this.m_revolute2 = null;8279this.m_prismatic2 = null;8280var coordinate1 = 0;8281var coordinate2 = 0;8282this.m_ground1 = def.joint1.GetBodyA();8283this.m_bodyA = def.joint1.GetBodyB();8284if (type1 == b2Joint.e_revoluteJoint) {8285this.m_revolute1 = (def.joint1 instanceof b2RevoluteJoint ? def.joint1 : null);8286this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1);8287this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2);8288coordinate1 = this.m_revolute1.GetJointAngle();8289}8290else {8291this.m_prismatic1 = (def.joint1 instanceof b2PrismaticJoint ? def.joint1 : null);8292this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1);8293this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2);8294coordinate1 = this.m_prismatic1.GetJointTranslation();8295}8296this.m_ground2 = def.joint2.GetBodyA();8297this.m_bodyB = def.joint2.GetBodyB();8298if (type2 == b2Joint.e_revoluteJoint) {8299this.m_revolute2 = (def.joint2 instanceof b2RevoluteJoint ? def.joint2 : null);8300this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1);8301this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2);8302coordinate2 = this.m_revolute2.GetJointAngle();8303}8304else {8305this.m_prismatic2 = (def.joint2 instanceof b2PrismaticJoint ? def.joint2 : null);8306this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1);8307this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2);8308coordinate2 = this.m_prismatic2.GetJointTranslation();8309}8310this.m_ratio = def.ratio;8311this.m_constant = coordinate1 + this.m_ratio * coordinate2;8312this.m_impulse = 0.0;8313}8314b2GearJoint.prototype.InitVelocityConstraints = function (step) {8315var g1 = this.m_ground1;8316var g2 = this.m_ground2;8317var bA = this.m_bodyA;8318var bB = this.m_bodyB;8319var ugX = 0;8320var ugY = 0;8321var rX = 0;8322var rY = 0;8323var tMat;8324var tVec;8325var crug = 0;8326var tX = 0;8327var K = 0.0;8328this.m_J.SetZero();8329if (this.m_revolute1) {8330this.m_J.angularA = (-1.0);8331K += bA.m_invI;8332}8333else {8334tMat = g1.m_xf.R;8335tVec = this.m_prismatic1.m_localXAxis1;8336ugX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;8337ugY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;8338tMat = bA.m_xf.R;8339rX = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;8340rY = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;8341tX = tMat.col1.x * rX + tMat.col2.x * rY;8342rY = tMat.col1.y * rX + tMat.col2.y * rY;8343rX = tX;8344crug = rX * ugY - rY * ugX;8345this.m_J.linearA.Set((-ugX), (-ugY));8346this.m_J.angularA = (-crug);8347K += bA.m_invMass + bA.m_invI * crug * crug;8348}8349if (this.m_revolute2) {8350this.m_J.angularB = (-this.m_ratio);8351K += this.m_ratio * this.m_ratio * bB.m_invI;8352}8353else {8354tMat = g2.m_xf.R;8355tVec = this.m_prismatic2.m_localXAxis1;8356ugX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;8357ugY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;8358tMat = bB.m_xf.R;8359rX = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;8360rY = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;8361tX = tMat.col1.x * rX + tMat.col2.x * rY;8362rY = tMat.col1.y * rX + tMat.col2.y * rY;8363rX = tX;8364crug = rX * ugY - rY * ugX;8365this.m_J.linearB.Set((-this.m_ratio * ugX), (-this.m_ratio * ugY));8366this.m_J.angularB = (-this.m_ratio * crug);8367K += this.m_ratio * this.m_ratio * (bB.m_invMass + bB.m_invI * crug * crug);8368}8369this.m_mass = K > 0.0 ? 1.0 / K : 0.0;8370if (step.warmStarting) {8371bA.m_linearVelocity.x += bA.m_invMass * this.m_impulse * this.m_J.linearA.x;8372bA.m_linearVelocity.y += bA.m_invMass * this.m_impulse * this.m_J.linearA.y;8373bA.m_angularVelocity += bA.m_invI * this.m_impulse * this.m_J.angularA;8374bB.m_linearVelocity.x += bB.m_invMass * this.m_impulse * this.m_J.linearB.x;8375bB.m_linearVelocity.y += bB.m_invMass * this.m_impulse * this.m_J.linearB.y;8376bB.m_angularVelocity += bB.m_invI * this.m_impulse * this.m_J.angularB;8377}8378else {8379this.m_impulse = 0.0;8380}8381}8382b2GearJoint.prototype.SolveVelocityConstraints = function (step) {8383var bA = this.m_bodyA;8384var bB = this.m_bodyB;8385var Cdot = this.m_J.Compute(bA.m_linearVelocity, bA.m_angularVelocity, bB.m_linearVelocity, bB.m_angularVelocity);8386var impulse = (-this.m_mass * Cdot);8387this.m_impulse += impulse;8388bA.m_linearVelocity.x += bA.m_invMass * impulse * this.m_J.linearA.x;8389bA.m_linearVelocity.y += bA.m_invMass * impulse * this.m_J.linearA.y;8390bA.m_angularVelocity += bA.m_invI * impulse * this.m_J.angularA;8391bB.m_linearVelocity.x += bB.m_invMass * impulse * this.m_J.linearB.x;8392bB.m_linearVelocity.y += bB.m_invMass * impulse * this.m_J.linearB.y;8393bB.m_angularVelocity += bB.m_invI * impulse * this.m_J.angularB;8394}8395b2GearJoint.prototype.SolvePositionConstraints = function (baumgarte) {8396if (baumgarte === undefined) baumgarte = 0;8397var linearError = 0.0;8398var bA = this.m_bodyA;8399var bB = this.m_bodyB;8400var coordinate1 = 0;8401var coordinate2 = 0;8402if (this.m_revolute1) {8403coordinate1 = this.m_revolute1.GetJointAngle();8404}8405else {8406coordinate1 = this.m_prismatic1.GetJointTranslation();8407}8408if (this.m_revolute2) {8409coordinate2 = this.m_revolute2.GetJointAngle();8410}8411else {8412coordinate2 = this.m_prismatic2.GetJointTranslation();8413}8414var C = this.m_constant - (coordinate1 + this.m_ratio * coordinate2);8415var impulse = (-this.m_mass * C);8416bA.m_sweep.c.x += bA.m_invMass * impulse * this.m_J.linearA.x;8417bA.m_sweep.c.y += bA.m_invMass * impulse * this.m_J.linearA.y;8418bA.m_sweep.a += bA.m_invI * impulse * this.m_J.angularA;8419bB.m_sweep.c.x += bB.m_invMass * impulse * this.m_J.linearB.x;8420bB.m_sweep.c.y += bB.m_invMass * impulse * this.m_J.linearB.y;8421bB.m_sweep.a += bB.m_invI * impulse * this.m_J.angularB;8422bA.SynchronizeTransform();8423bB.SynchronizeTransform();8424return linearError < b2Settings.b2_linearSlop;8425}8426Box2D.inherit(b2GearJointDef, Box2D.Dynamics.Joints.b2JointDef);8427b2GearJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;8428b2GearJointDef.b2GearJointDef = function () {8429Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);8430};8431b2GearJointDef.prototype.b2GearJointDef = function () {8432this.__super.b2JointDef.call(this);8433this.type = b2Joint.e_gearJoint;8434this.joint1 = null;8435this.joint2 = null;8436this.ratio = 1.0;8437}8438b2Jacobian.b2Jacobian = function () {8439this.linearA = new b2Vec2();8440this.linearB = new b2Vec2();8441};8442b2Jacobian.prototype.SetZero = function () {8443this.linearA.SetZero();8444this.angularA = 0.0;8445this.linearB.SetZero();8446this.angularB = 0.0;8447}8448b2Jacobian.prototype.Set = function (x1, a1, x2, a2) {8449if (a1 === undefined) a1 = 0;8450if (a2 === undefined) a2 = 0;8451this.linearA.SetV(x1);8452this.angularA = a1;8453this.linearB.SetV(x2);8454this.angularB = a2;8455}8456b2Jacobian.prototype.Compute = function (x1, a1, x2, a2) {8457if (a1 === undefined) a1 = 0;8458if (a2 === undefined) a2 = 0;8459return (this.linearA.x * x1.x + this.linearA.y * x1.y) + this.angularA * a1 + (this.linearB.x * x2.x + this.linearB.y * x2.y) + this.angularB * a2;8460}8461b2Joint.b2Joint = function () {8462this.m_edgeA = new b2JointEdge();8463this.m_edgeB = new b2JointEdge();8464this.m_localCenterA = new b2Vec2();8465this.m_localCenterB = new b2Vec2();8466};8467b2Joint.prototype.GetType = function () {8468return this.m_type;8469}8470b2Joint.prototype.GetAnchorA = function () {8471return null;8472}8473b2Joint.prototype.GetAnchorB = function () {8474return null;8475}8476b2Joint.prototype.GetReactionForce = function (inv_dt) {8477if (inv_dt === undefined) inv_dt = 0;8478return null;8479}8480b2Joint.prototype.GetReactionTorque = function (inv_dt) {8481if (inv_dt === undefined) inv_dt = 0;8482return 0.0;8483}8484b2Joint.prototype.GetBodyA = function () {8485return this.m_bodyA;8486}8487b2Joint.prototype.GetBodyB = function () {8488return this.m_bodyB;8489}8490b2Joint.prototype.GetNext = function () {8491return this.m_next;8492}8493b2Joint.prototype.GetUserData = function () {8494return this.m_userData;8495}8496b2Joint.prototype.SetUserData = function (data) {8497this.m_userData = data;8498}8499b2Joint.prototype.IsActive = function () {8500return this.m_bodyA.IsActive() && this.m_bodyB.IsActive();8501}8502b2Joint.Create = function (def, allocator) {8503var joint = null;8504switch (def.type) {8505case b2Joint.e_distanceJoint:8506{8507joint = new b2DistanceJoint((def instanceof b2DistanceJointDef ? def : null));8508}8509break;8510case b2Joint.e_mouseJoint:8511{8512joint = new b2MouseJoint((def instanceof b2MouseJointDef ? def : null));8513}8514break;8515case b2Joint.e_prismaticJoint:8516{8517joint = new b2PrismaticJoint((def instanceof b2PrismaticJointDef ? def : null));8518}8519break;8520case b2Joint.e_revoluteJoint:8521{8522joint = new b2RevoluteJoint((def instanceof b2RevoluteJointDef ? def : null));8523}8524break;8525case b2Joint.e_pulleyJoint:8526{8527joint = new b2PulleyJoint((def instanceof b2PulleyJointDef ? def : null));8528}8529break;8530case b2Joint.e_gearJoint:8531{8532joint = new b2GearJoint((def instanceof b2GearJointDef ? def : null));8533}8534break;8535case b2Joint.e_lineJoint:8536{8537joint = new b2LineJoint((def instanceof b2LineJointDef ? def : null));8538}8539break;8540case b2Joint.e_weldJoint:8541{8542joint = new b2WeldJoint((def instanceof b2WeldJointDef ? def : null));8543}8544break;8545case b2Joint.e_frictionJoint:8546{8547joint = new b2FrictionJoint((def instanceof b2FrictionJointDef ? def : null));8548}8549break;8550default:8551break;8552}8553return joint;8554}8555b2Joint.Destroy = function (joint, allocator) {}8556b2Joint.prototype.b2Joint = function (def) {8557b2Settings.b2Assert(def.bodyA != def.bodyB);8558this.m_type = def.type;8559this.m_prev = null;8560this.m_next = null;8561this.m_bodyA = def.bodyA;8562this.m_bodyB = def.bodyB;8563this.m_collideConnected = def.collideConnected;8564this.m_islandFlag = false;8565this.m_userData = def.userData;8566}8567b2Joint.prototype.InitVelocityConstraints = function (step) {}8568b2Joint.prototype.SolveVelocityConstraints = function (step) {}8569b2Joint.prototype.FinalizeVelocityConstraints = function () {}8570b2Joint.prototype.SolvePositionConstraints = function (baumgarte) {8571if (baumgarte === undefined) baumgarte = 0;8572return false;8573}8574Box2D.postDefs.push(function () {8575Box2D.Dynamics.Joints.b2Joint.e_unknownJoint = 0;8576Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint = 1;8577Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint = 2;8578Box2D.Dynamics.Joints.b2Joint.e_distanceJoint = 3;8579Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint = 4;8580Box2D.Dynamics.Joints.b2Joint.e_mouseJoint = 5;8581Box2D.Dynamics.Joints.b2Joint.e_gearJoint = 6;8582Box2D.Dynamics.Joints.b2Joint.e_lineJoint = 7;8583Box2D.Dynamics.Joints.b2Joint.e_weldJoint = 8;8584Box2D.Dynamics.Joints.b2Joint.e_frictionJoint = 9;8585Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit = 0;8586Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit = 1;8587Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit = 2;8588Box2D.Dynamics.Joints.b2Joint.e_equalLimits = 3;8589});8590b2JointDef.b2JointDef = function () {};8591b2JointDef.prototype.b2JointDef = function () {8592this.type = b2Joint.e_unknownJoint;8593this.userData = null;8594this.bodyA = null;8595this.bodyB = null;8596this.collideConnected = false;8597}8598b2JointEdge.b2JointEdge = function () {};8599Box2D.inherit(b2LineJoint, Box2D.Dynamics.Joints.b2Joint);8600b2LineJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;8601b2LineJoint.b2LineJoint = function () {8602Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);8603this.m_localAnchor1 = new b2Vec2();8604this.m_localAnchor2 = new b2Vec2();8605this.m_localXAxis1 = new b2Vec2();8606this.m_localYAxis1 = new b2Vec2();8607this.m_axis = new b2Vec2();8608this.m_perp = new b2Vec2();8609this.m_K = new b2Mat22();8610this.m_impulse = new b2Vec2();8611};8612b2LineJoint.prototype.GetAnchorA = function () {8613return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);8614}8615b2LineJoint.prototype.GetAnchorB = function () {8616return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);8617}8618b2LineJoint.prototype.GetReactionForce = function (inv_dt) {8619if (inv_dt === undefined) inv_dt = 0;8620return new b2Vec2(inv_dt * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x), inv_dt * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y));8621}8622b2LineJoint.prototype.GetReactionTorque = function (inv_dt) {8623if (inv_dt === undefined) inv_dt = 0;8624return inv_dt * this.m_impulse.y;8625}8626b2LineJoint.prototype.GetJointTranslation = function () {8627var bA = this.m_bodyA;8628var bB = this.m_bodyB;8629var tMat;8630var p1 = bA.GetWorldPoint(this.m_localAnchor1);8631var p2 = bB.GetWorldPoint(this.m_localAnchor2);8632var dX = p2.x - p1.x;8633var dY = p2.y - p1.y;8634var axis = bA.GetWorldVector(this.m_localXAxis1);8635var translation = axis.x * dX + axis.y * dY;8636return translation;8637}8638b2LineJoint.prototype.GetJointSpeed = function () {8639var bA = this.m_bodyA;8640var bB = this.m_bodyB;8641var tMat;8642tMat = bA.m_xf.R;8643var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;8644var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;8645var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);8646r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);8647r1X = tX;8648tMat = bB.m_xf.R;8649var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;8650var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;8651tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);8652r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);8653r2X = tX;8654var p1X = bA.m_sweep.c.x + r1X;8655var p1Y = bA.m_sweep.c.y + r1Y;8656var p2X = bB.m_sweep.c.x + r2X;8657var p2Y = bB.m_sweep.c.y + r2Y;8658var dX = p2X - p1X;8659var dY = p2Y - p1Y;8660var axis = bA.GetWorldVector(this.m_localXAxis1);8661var v1 = bA.m_linearVelocity;8662var v2 = bB.m_linearVelocity;8663var w1 = bA.m_angularVelocity;8664var w2 = bB.m_angularVelocity;8665var speed = (dX * ((-w1 * axis.y)) + dY * (w1 * axis.x)) + (axis.x * (((v2.x + ((-w2 * r2Y))) - v1.x) - ((-w1 * r1Y))) + axis.y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)));8666return speed;8667}8668b2LineJoint.prototype.IsLimitEnabled = function () {8669return this.m_enableLimit;8670}8671b2LineJoint.prototype.EnableLimit = function (flag) {8672this.m_bodyA.SetAwake(true);8673this.m_bodyB.SetAwake(true);8674this.m_enableLimit = flag;8675}8676b2LineJoint.prototype.GetLowerLimit = function () {8677return this.m_lowerTranslation;8678}8679b2LineJoint.prototype.GetUpperLimit = function () {8680return this.m_upperTranslation;8681}8682b2LineJoint.prototype.SetLimits = function (lower, upper) {8683if (lower === undefined) lower = 0;8684if (upper === undefined) upper = 0;8685this.m_bodyA.SetAwake(true);8686this.m_bodyB.SetAwake(true);8687this.m_lowerTranslation = lower;8688this.m_upperTranslation = upper;8689}8690b2LineJoint.prototype.IsMotorEnabled = function () {8691return this.m_enableMotor;8692}8693b2LineJoint.prototype.EnableMotor = function (flag) {8694this.m_bodyA.SetAwake(true);8695this.m_bodyB.SetAwake(true);8696this.m_enableMotor = flag;8697}8698b2LineJoint.prototype.SetMotorSpeed = function (speed) {8699if (speed === undefined) speed = 0;8700this.m_bodyA.SetAwake(true);8701this.m_bodyB.SetAwake(true);8702this.m_motorSpeed = speed;8703}8704b2LineJoint.prototype.GetMotorSpeed = function () {8705return this.m_motorSpeed;8706}8707b2LineJoint.prototype.SetMaxMotorForce = function (force) {8708if (force === undefined) force = 0;8709this.m_bodyA.SetAwake(true);8710this.m_bodyB.SetAwake(true);8711this.m_maxMotorForce = force;8712}8713b2LineJoint.prototype.GetMaxMotorForce = function () {8714return this.m_maxMotorForce;8715}8716b2LineJoint.prototype.GetMotorForce = function () {8717return this.m_motorImpulse;8718}8719b2LineJoint.prototype.b2LineJoint = function (def) {8720this.__super.b2Joint.call(this, def);8721var tMat;8722var tX = 0;8723var tY = 0;8724this.m_localAnchor1.SetV(def.localAnchorA);8725this.m_localAnchor2.SetV(def.localAnchorB);8726this.m_localXAxis1.SetV(def.localAxisA);8727this.m_localYAxis1.x = (-this.m_localXAxis1.y);8728this.m_localYAxis1.y = this.m_localXAxis1.x;8729this.m_impulse.SetZero();8730this.m_motorMass = 0.0;8731this.m_motorImpulse = 0.0;8732this.m_lowerTranslation = def.lowerTranslation;8733this.m_upperTranslation = def.upperTranslation;8734this.m_maxMotorForce = def.maxMotorForce;8735this.m_motorSpeed = def.motorSpeed;8736this.m_enableLimit = def.enableLimit;8737this.m_enableMotor = def.enableMotor;8738this.m_limitState = b2Joint.e_inactiveLimit;8739this.m_axis.SetZero();8740this.m_perp.SetZero();8741}8742b2LineJoint.prototype.InitVelocityConstraints = function (step) {8743var bA = this.m_bodyA;8744var bB = this.m_bodyB;8745var tMat;8746var tX = 0;8747this.m_localCenterA.SetV(bA.GetLocalCenter());8748this.m_localCenterB.SetV(bB.GetLocalCenter());8749var xf1 = bA.GetTransform();8750var xf2 = bB.GetTransform();8751tMat = bA.m_xf.R;8752var r1X = this.m_localAnchor1.x - this.m_localCenterA.x;8753var r1Y = this.m_localAnchor1.y - this.m_localCenterA.y;8754tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);8755r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);8756r1X = tX;8757tMat = bB.m_xf.R;8758var r2X = this.m_localAnchor2.x - this.m_localCenterB.x;8759var r2Y = this.m_localAnchor2.y - this.m_localCenterB.y;8760tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);8761r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);8762r2X = tX;8763var dX = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;8764var dY = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;8765this.m_invMassA = bA.m_invMass;8766this.m_invMassB = bB.m_invMass;8767this.m_invIA = bA.m_invI;8768this.m_invIB = bB.m_invI; {8769this.m_axis.SetV(b2Math.MulMV(xf1.R, this.m_localXAxis1));8770this.m_a1 = (dX + r1X) * this.m_axis.y - (dY + r1Y) * this.m_axis.x;8771this.m_a2 = r2X * this.m_axis.y - r2Y * this.m_axis.x;8772this.m_motorMass = this.m_invMassA + this.m_invMassB + this.m_invIA * this.m_a1 * this.m_a1 + this.m_invIB * this.m_a2 * this.m_a2;8773this.m_motorMass = this.m_motorMass > Number.MIN_VALUE ? 1.0 / this.m_motorMass : 0.0;8774} {8775this.m_perp.SetV(b2Math.MulMV(xf1.R, this.m_localYAxis1));8776this.m_s1 = (dX + r1X) * this.m_perp.y - (dY + r1Y) * this.m_perp.x;8777this.m_s2 = r2X * this.m_perp.y - r2Y * this.m_perp.x;8778var m1 = this.m_invMassA;8779var m2 = this.m_invMassB;8780var i1 = this.m_invIA;8781var i2 = this.m_invIB;8782this.m_K.col1.x = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;8783this.m_K.col1.y = i1 * this.m_s1 * this.m_a1 + i2 * this.m_s2 * this.m_a2;8784this.m_K.col2.x = this.m_K.col1.y;8785this.m_K.col2.y = m1 + m2 + i1 * this.m_a1 * this.m_a1 + i2 * this.m_a2 * this.m_a2;8786}8787if (this.m_enableLimit) {8788var jointTransition = this.m_axis.x * dX + this.m_axis.y * dY;8789if (b2Math.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2.0 * b2Settings.b2_linearSlop) {8790this.m_limitState = b2Joint.e_equalLimits;8791}8792else if (jointTransition <= this.m_lowerTranslation) {8793if (this.m_limitState != b2Joint.e_atLowerLimit) {8794this.m_limitState = b2Joint.e_atLowerLimit;8795this.m_impulse.y = 0.0;8796}8797}8798else if (jointTransition >= this.m_upperTranslation) {8799if (this.m_limitState != b2Joint.e_atUpperLimit) {8800this.m_limitState = b2Joint.e_atUpperLimit;8801this.m_impulse.y = 0.0;8802}8803}8804else {8805this.m_limitState = b2Joint.e_inactiveLimit;8806this.m_impulse.y = 0.0;8807}8808}8809else {8810this.m_limitState = b2Joint.e_inactiveLimit;8811}8812if (this.m_enableMotor == false) {8813this.m_motorImpulse = 0.0;8814}8815if (step.warmStarting) {8816this.m_impulse.x *= step.dtRatio;8817this.m_impulse.y *= step.dtRatio;8818this.m_motorImpulse *= step.dtRatio;8819var PX = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.x;8820var PY = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.y) * this.m_axis.y;8821var L1 = this.m_impulse.x * this.m_s1 + (this.m_motorImpulse + this.m_impulse.y) * this.m_a1;8822var L2 = this.m_impulse.x * this.m_s2 + (this.m_motorImpulse + this.m_impulse.y) * this.m_a2;8823bA.m_linearVelocity.x -= this.m_invMassA * PX;8824bA.m_linearVelocity.y -= this.m_invMassA * PY;8825bA.m_angularVelocity -= this.m_invIA * L1;8826bB.m_linearVelocity.x += this.m_invMassB * PX;8827bB.m_linearVelocity.y += this.m_invMassB * PY;8828bB.m_angularVelocity += this.m_invIB * L2;8829}8830else {8831this.m_impulse.SetZero();8832this.m_motorImpulse = 0.0;8833}8834}8835b2LineJoint.prototype.SolveVelocityConstraints = function (step) {8836var bA = this.m_bodyA;8837var bB = this.m_bodyB;8838var v1 = bA.m_linearVelocity;8839var w1 = bA.m_angularVelocity;8840var v2 = bB.m_linearVelocity;8841var w2 = bB.m_angularVelocity;8842var PX = 0;8843var PY = 0;8844var L1 = 0;8845var L2 = 0;8846if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits) {8847var Cdot = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;8848var impulse = this.m_motorMass * (this.m_motorSpeed - Cdot);8849var oldImpulse = this.m_motorImpulse;8850var maxImpulse = step.dt * this.m_maxMotorForce;8851this.m_motorImpulse = b2Math.Clamp(this.m_motorImpulse + impulse, (-maxImpulse), maxImpulse);8852impulse = this.m_motorImpulse - oldImpulse;8853PX = impulse * this.m_axis.x;8854PY = impulse * this.m_axis.y;8855L1 = impulse * this.m_a1;8856L2 = impulse * this.m_a2;8857v1.x -= this.m_invMassA * PX;8858v1.y -= this.m_invMassA * PY;8859w1 -= this.m_invIA * L1;8860v2.x += this.m_invMassB * PX;8861v2.y += this.m_invMassB * PY;8862w2 += this.m_invIB * L2;8863}8864var Cdot1 = this.m_perp.x * (v2.x - v1.x) + this.m_perp.y * (v2.y - v1.y) + this.m_s2 * w2 - this.m_s1 * w1;8865if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {8866var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;8867var f1 = this.m_impulse.Copy();8868var df = this.m_K.Solve(new b2Vec2(), (-Cdot1), (-Cdot2));8869this.m_impulse.Add(df);8870if (this.m_limitState == b2Joint.e_atLowerLimit) {8871this.m_impulse.y = b2Math.Max(this.m_impulse.y, 0.0);8872}8873else if (this.m_limitState == b2Joint.e_atUpperLimit) {8874this.m_impulse.y = b2Math.Min(this.m_impulse.y, 0.0);8875}8876var b = (-Cdot1) - (this.m_impulse.y - f1.y) * this.m_K.col2.x;8877var f2r = 0;8878if (this.m_K.col1.x != 0.0) {8879f2r = b / this.m_K.col1.x + f1.x;8880}8881else {8882f2r = f1.x;8883}8884this.m_impulse.x = f2r;8885df.x = this.m_impulse.x - f1.x;8886df.y = this.m_impulse.y - f1.y;8887PX = df.x * this.m_perp.x + df.y * this.m_axis.x;8888PY = df.x * this.m_perp.y + df.y * this.m_axis.y;8889L1 = df.x * this.m_s1 + df.y * this.m_a1;8890L2 = df.x * this.m_s2 + df.y * this.m_a2;8891v1.x -= this.m_invMassA * PX;8892v1.y -= this.m_invMassA * PY;8893w1 -= this.m_invIA * L1;8894v2.x += this.m_invMassB * PX;8895v2.y += this.m_invMassB * PY;8896w2 += this.m_invIB * L2;8897}8898else {8899var df2 = 0;8900if (this.m_K.col1.x != 0.0) {8901df2 = ((-Cdot1)) / this.m_K.col1.x;8902}8903else {8904df2 = 0.0;8905}8906this.m_impulse.x += df2;8907PX = df2 * this.m_perp.x;8908PY = df2 * this.m_perp.y;8909L1 = df2 * this.m_s1;8910L2 = df2 * this.m_s2;8911v1.x -= this.m_invMassA * PX;8912v1.y -= this.m_invMassA * PY;8913w1 -= this.m_invIA * L1;8914v2.x += this.m_invMassB * PX;8915v2.y += this.m_invMassB * PY;8916w2 += this.m_invIB * L2;8917}8918bA.m_linearVelocity.SetV(v1);8919bA.m_angularVelocity = w1;8920bB.m_linearVelocity.SetV(v2);8921bB.m_angularVelocity = w2;8922}8923b2LineJoint.prototype.SolvePositionConstraints = function (baumgarte) {8924if (baumgarte === undefined) baumgarte = 0;8925var limitC = 0;8926var oldLimitImpulse = 0;8927var bA = this.m_bodyA;8928var bB = this.m_bodyB;8929var c1 = bA.m_sweep.c;8930var a1 = bA.m_sweep.a;8931var c2 = bB.m_sweep.c;8932var a2 = bB.m_sweep.a;8933var tMat;8934var tX = 0;8935var m1 = 0;8936var m2 = 0;8937var i1 = 0;8938var i2 = 0;8939var linearError = 0.0;8940var angularError = 0.0;8941var active = false;8942var C2 = 0.0;8943var R1 = b2Mat22.FromAngle(a1);8944var R2 = b2Mat22.FromAngle(a2);8945tMat = R1;8946var r1X = this.m_localAnchor1.x - this.m_localCenterA.x;8947var r1Y = this.m_localAnchor1.y - this.m_localCenterA.y;8948tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);8949r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);8950r1X = tX;8951tMat = R2;8952var r2X = this.m_localAnchor2.x - this.m_localCenterB.x;8953var r2Y = this.m_localAnchor2.y - this.m_localCenterB.y;8954tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);8955r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);8956r2X = tX;8957var dX = c2.x + r2X - c1.x - r1X;8958var dY = c2.y + r2Y - c1.y - r1Y;8959if (this.m_enableLimit) {8960this.m_axis = b2Math.MulMV(R1, this.m_localXAxis1);8961this.m_a1 = (dX + r1X) * this.m_axis.y - (dY + r1Y) * this.m_axis.x;8962this.m_a2 = r2X * this.m_axis.y - r2Y * this.m_axis.x;8963var translation = this.m_axis.x * dX + this.m_axis.y * dY;8964if (b2Math.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2.0 * b2Settings.b2_linearSlop) {8965C2 = b2Math.Clamp(translation, (-b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);8966linearError = b2Math.Abs(translation);8967active = true;8968}8969else if (translation <= this.m_lowerTranslation) {8970C2 = b2Math.Clamp(translation - this.m_lowerTranslation + b2Settings.b2_linearSlop, (-b2Settings.b2_maxLinearCorrection), 0.0);8971linearError = this.m_lowerTranslation - translation;8972active = true;8973}8974else if (translation >= this.m_upperTranslation) {8975C2 = b2Math.Clamp(translation - this.m_upperTranslation + b2Settings.b2_linearSlop, 0.0, b2Settings.b2_maxLinearCorrection);8976linearError = translation - this.m_upperTranslation;8977active = true;8978}8979}8980this.m_perp = b2Math.MulMV(R1, this.m_localYAxis1);8981this.m_s1 = (dX + r1X) * this.m_perp.y - (dY + r1Y) * this.m_perp.x;8982this.m_s2 = r2X * this.m_perp.y - r2Y * this.m_perp.x;8983var impulse = new b2Vec2();8984var C1 = this.m_perp.x * dX + this.m_perp.y * dY;8985linearError = b2Math.Max(linearError, b2Math.Abs(C1));8986angularError = 0.0;8987if (active) {8988m1 = this.m_invMassA;8989m2 = this.m_invMassB;8990i1 = this.m_invIA;8991i2 = this.m_invIB;8992this.m_K.col1.x = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;8993this.m_K.col1.y = i1 * this.m_s1 * this.m_a1 + i2 * this.m_s2 * this.m_a2;8994this.m_K.col2.x = this.m_K.col1.y;8995this.m_K.col2.y = m1 + m2 + i1 * this.m_a1 * this.m_a1 + i2 * this.m_a2 * this.m_a2;8996this.m_K.Solve(impulse, (-C1), (-C2));8997}8998else {8999m1 = this.m_invMassA;9000m2 = this.m_invMassB;9001i1 = this.m_invIA;9002i2 = this.m_invIB;9003var k11 = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;9004var impulse1 = 0;9005if (k11 != 0.0) {9006impulse1 = ((-C1)) / k11;9007}9008else {9009impulse1 = 0.0;9010}9011impulse.x = impulse1;9012impulse.y = 0.0;9013}9014var PX = impulse.x * this.m_perp.x + impulse.y * this.m_axis.x;9015var PY = impulse.x * this.m_perp.y + impulse.y * this.m_axis.y;9016var L1 = impulse.x * this.m_s1 + impulse.y * this.m_a1;9017var L2 = impulse.x * this.m_s2 + impulse.y * this.m_a2;9018c1.x -= this.m_invMassA * PX;9019c1.y -= this.m_invMassA * PY;9020a1 -= this.m_invIA * L1;9021c2.x += this.m_invMassB * PX;9022c2.y += this.m_invMassB * PY;9023a2 += this.m_invIB * L2;9024bA.m_sweep.a = a1;9025bB.m_sweep.a = a2;9026bA.SynchronizeTransform();9027bB.SynchronizeTransform();9028return linearError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;9029}9030Box2D.inherit(b2LineJointDef, Box2D.Dynamics.Joints.b2JointDef);9031b2LineJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;9032b2LineJointDef.b2LineJointDef = function () {9033Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);9034this.localAnchorA = new b2Vec2();9035this.localAnchorB = new b2Vec2();9036this.localAxisA = new b2Vec2();9037};9038b2LineJointDef.prototype.b2LineJointDef = function () {9039this.__super.b2JointDef.call(this);9040this.type = b2Joint.e_lineJoint;9041this.localAxisA.Set(1.0, 0.0);9042this.enableLimit = false;9043this.lowerTranslation = 0.0;9044this.upperTranslation = 0.0;9045this.enableMotor = false;9046this.maxMotorForce = 0.0;9047this.motorSpeed = 0.0;9048}9049b2LineJointDef.prototype.Initialize = function (bA, bB, anchor, axis) {9050this.bodyA = bA;9051this.bodyB = bB;9052this.localAnchorA = this.bodyA.GetLocalPoint(anchor);9053this.localAnchorB = this.bodyB.GetLocalPoint(anchor);9054this.localAxisA = this.bodyA.GetLocalVector(axis);9055}9056Box2D.inherit(b2MouseJoint, Box2D.Dynamics.Joints.b2Joint);9057b2MouseJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;9058b2MouseJoint.b2MouseJoint = function () {9059Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);9060this.K = new b2Mat22();9061this.K1 = new b2Mat22();9062this.K2 = new b2Mat22();9063this.m_localAnchor = new b2Vec2();9064this.m_target = new b2Vec2();9065this.m_impulse = new b2Vec2();9066this.m_mass = new b2Mat22();9067this.m_C = new b2Vec2();9068};9069b2MouseJoint.prototype.GetAnchorA = function () {9070return this.m_target;9071}9072b2MouseJoint.prototype.GetAnchorB = function () {9073return this.m_bodyB.GetWorldPoint(this.m_localAnchor);9074}9075b2MouseJoint.prototype.GetReactionForce = function (inv_dt) {9076if (inv_dt === undefined) inv_dt = 0;9077return new b2Vec2(inv_dt * this.m_impulse.x, inv_dt * this.m_impulse.y);9078}9079b2MouseJoint.prototype.GetReactionTorque = function (inv_dt) {9080if (inv_dt === undefined) inv_dt = 0;9081return 0.0;9082}9083b2MouseJoint.prototype.GetTarget = function () {9084return this.m_target;9085}9086b2MouseJoint.prototype.SetTarget = function (target) {9087if (this.m_bodyB.IsAwake() == false) {9088this.m_bodyB.SetAwake(true);9089}9090this.m_target = target;9091}9092b2MouseJoint.prototype.GetMaxForce = function () {9093return this.m_maxForce;9094}9095b2MouseJoint.prototype.SetMaxForce = function (maxForce) {9096if (maxForce === undefined) maxForce = 0;9097this.m_maxForce = maxForce;9098}9099b2MouseJoint.prototype.GetFrequency = function () {9100return this.m_frequencyHz;9101}9102b2MouseJoint.prototype.SetFrequency = function (hz) {9103if (hz === undefined) hz = 0;9104this.m_frequencyHz = hz;9105}9106b2MouseJoint.prototype.GetDampingRatio = function () {9107return this.m_dampingRatio;9108}9109b2MouseJoint.prototype.SetDampingRatio = function (ratio) {9110if (ratio === undefined) ratio = 0;9111this.m_dampingRatio = ratio;9112}9113b2MouseJoint.prototype.b2MouseJoint = function (def) {9114this.__super.b2Joint.call(this, def);9115this.m_target.SetV(def.target);9116var tX = this.m_target.x - this.m_bodyB.m_xf.position.x;9117var tY = this.m_target.y - this.m_bodyB.m_xf.position.y;9118var tMat = this.m_bodyB.m_xf.R;9119this.m_localAnchor.x = (tX * tMat.col1.x + tY * tMat.col1.y);9120this.m_localAnchor.y = (tX * tMat.col2.x + tY * tMat.col2.y);9121this.m_maxForce = def.maxForce;9122this.m_impulse.SetZero();9123this.m_frequencyHz = def.frequencyHz;9124this.m_dampingRatio = def.dampingRatio;9125this.m_beta = 0.0;9126this.m_gamma = 0.0;9127}9128b2MouseJoint.prototype.InitVelocityConstraints = function (step) {9129var b = this.m_bodyB;9130var mass = b.GetMass();9131var omega = 2.0 * Math.PI * this.m_frequencyHz;9132var d = 2.0 * mass * this.m_dampingRatio * omega;9133var k = mass * omega * omega;9134this.m_gamma = step.dt * (d + step.dt * k);9135this.m_gamma = this.m_gamma != 0 ? 1 / this.m_gamma : 0.0;9136this.m_beta = step.dt * k * this.m_gamma;9137var tMat;tMat = b.m_xf.R;9138var rX = this.m_localAnchor.x - b.m_sweep.localCenter.x;9139var rY = this.m_localAnchor.y - b.m_sweep.localCenter.y;9140var tX = (tMat.col1.x * rX + tMat.col2.x * rY);rY = (tMat.col1.y * rX + tMat.col2.y * rY);9141rX = tX;9142var invMass = b.m_invMass;9143var invI = b.m_invI;this.K1.col1.x = invMass;9144this.K1.col2.x = 0.0;9145this.K1.col1.y = 0.0;9146this.K1.col2.y = invMass;9147this.K2.col1.x = invI * rY * rY;9148this.K2.col2.x = (-invI * rX * rY);9149this.K2.col1.y = (-invI * rX * rY);9150this.K2.col2.y = invI * rX * rX;9151this.K.SetM(this.K1);9152this.K.AddM(this.K2);9153this.K.col1.x += this.m_gamma;9154this.K.col2.y += this.m_gamma;9155this.K.GetInverse(this.m_mass);9156this.m_C.x = b.m_sweep.c.x + rX - this.m_target.x;9157this.m_C.y = b.m_sweep.c.y + rY - this.m_target.y;9158b.m_angularVelocity *= 0.98;9159this.m_impulse.x *= step.dtRatio;9160this.m_impulse.y *= step.dtRatio;9161b.m_linearVelocity.x += invMass * this.m_impulse.x;9162b.m_linearVelocity.y += invMass * this.m_impulse.y;9163b.m_angularVelocity += invI * (rX * this.m_impulse.y - rY * this.m_impulse.x);9164}9165b2MouseJoint.prototype.SolveVelocityConstraints = function (step) {9166var b = this.m_bodyB;9167var tMat;9168var tX = 0;9169var tY = 0;9170tMat = b.m_xf.R;9171var rX = this.m_localAnchor.x - b.m_sweep.localCenter.x;9172var rY = this.m_localAnchor.y - b.m_sweep.localCenter.y;9173tX = (tMat.col1.x * rX + tMat.col2.x * rY);9174rY = (tMat.col1.y * rX + tMat.col2.y * rY);9175rX = tX;9176var CdotX = b.m_linearVelocity.x + ((-b.m_angularVelocity * rY));9177var CdotY = b.m_linearVelocity.y + (b.m_angularVelocity * rX);9178tMat = this.m_mass;9179tX = CdotX + this.m_beta * this.m_C.x + this.m_gamma * this.m_impulse.x;9180tY = CdotY + this.m_beta * this.m_C.y + this.m_gamma * this.m_impulse.y;9181var impulseX = (-(tMat.col1.x * tX + tMat.col2.x * tY));9182var impulseY = (-(tMat.col1.y * tX + tMat.col2.y * tY));9183var oldImpulseX = this.m_impulse.x;9184var oldImpulseY = this.m_impulse.y;9185this.m_impulse.x += impulseX;9186this.m_impulse.y += impulseY;9187var maxImpulse = step.dt * this.m_maxForce;9188if (this.m_impulse.LengthSquared() > maxImpulse * maxImpulse) {9189this.m_impulse.Multiply(maxImpulse / this.m_impulse.Length());9190}9191impulseX = this.m_impulse.x - oldImpulseX;9192impulseY = this.m_impulse.y - oldImpulseY;9193b.m_linearVelocity.x += b.m_invMass * impulseX;9194b.m_linearVelocity.y += b.m_invMass * impulseY;9195b.m_angularVelocity += b.m_invI * (rX * impulseY - rY * impulseX);9196}9197b2MouseJoint.prototype.SolvePositionConstraints = function (baumgarte) {9198if (baumgarte === undefined) baumgarte = 0;9199return true;9200}9201Box2D.inherit(b2MouseJointDef, Box2D.Dynamics.Joints.b2JointDef);9202b2MouseJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;9203b2MouseJointDef.b2MouseJointDef = function () {9204Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);9205this.target = new b2Vec2();9206};9207b2MouseJointDef.prototype.b2MouseJointDef = function () {9208this.__super.b2JointDef.call(this);9209this.type = b2Joint.e_mouseJoint;9210this.maxForce = 0.0;9211this.frequencyHz = 5.0;9212this.dampingRatio = 0.7;9213}9214Box2D.inherit(b2PrismaticJoint, Box2D.Dynamics.Joints.b2Joint);9215b2PrismaticJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;9216b2PrismaticJoint.b2PrismaticJoint = function () {9217Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);9218this.m_localAnchor1 = new b2Vec2();9219this.m_localAnchor2 = new b2Vec2();9220this.m_localXAxis1 = new b2Vec2();9221this.m_localYAxis1 = new b2Vec2();9222this.m_axis = new b2Vec2();9223this.m_perp = new b2Vec2();9224this.m_K = new b2Mat33();9225this.m_impulse = new b2Vec3();9226};9227b2PrismaticJoint.prototype.GetAnchorA = function () {9228return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);9229}9230b2PrismaticJoint.prototype.GetAnchorB = function () {9231return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);9232}9233b2PrismaticJoint.prototype.GetReactionForce = function (inv_dt) {9234if (inv_dt === undefined) inv_dt = 0;9235return new b2Vec2(inv_dt * (this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x), inv_dt * (this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y));9236}9237b2PrismaticJoint.prototype.GetReactionTorque = function (inv_dt) {9238if (inv_dt === undefined) inv_dt = 0;9239return inv_dt * this.m_impulse.y;9240}9241b2PrismaticJoint.prototype.GetJointTranslation = function () {9242var bA = this.m_bodyA;9243var bB = this.m_bodyB;9244var tMat;9245var p1 = bA.GetWorldPoint(this.m_localAnchor1);9246var p2 = bB.GetWorldPoint(this.m_localAnchor2);9247var dX = p2.x - p1.x;9248var dY = p2.y - p1.y;9249var axis = bA.GetWorldVector(this.m_localXAxis1);9250var translation = axis.x * dX + axis.y * dY;9251return translation;9252}9253b2PrismaticJoint.prototype.GetJointSpeed = function () {9254var bA = this.m_bodyA;9255var bB = this.m_bodyB;9256var tMat;9257tMat = bA.m_xf.R;9258var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;9259var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;9260var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9261r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9262r1X = tX;9263tMat = bB.m_xf.R;9264var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;9265var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;9266tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9267r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9268r2X = tX;9269var p1X = bA.m_sweep.c.x + r1X;9270var p1Y = bA.m_sweep.c.y + r1Y;9271var p2X = bB.m_sweep.c.x + r2X;9272var p2Y = bB.m_sweep.c.y + r2Y;9273var dX = p2X - p1X;9274var dY = p2Y - p1Y;9275var axis = bA.GetWorldVector(this.m_localXAxis1);9276var v1 = bA.m_linearVelocity;9277var v2 = bB.m_linearVelocity;9278var w1 = bA.m_angularVelocity;9279var w2 = bB.m_angularVelocity;9280var speed = (dX * ((-w1 * axis.y)) + dY * (w1 * axis.x)) + (axis.x * (((v2.x + ((-w2 * r2Y))) - v1.x) - ((-w1 * r1Y))) + axis.y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)));9281return speed;9282}9283b2PrismaticJoint.prototype.IsLimitEnabled = function () {9284return this.m_enableLimit;9285}9286b2PrismaticJoint.prototype.EnableLimit = function (flag) {9287this.m_bodyA.SetAwake(true);9288this.m_bodyB.SetAwake(true);9289this.m_enableLimit = flag;9290}9291b2PrismaticJoint.prototype.GetLowerLimit = function () {9292return this.m_lowerTranslation;9293}9294b2PrismaticJoint.prototype.GetUpperLimit = function () {9295return this.m_upperTranslation;9296}9297b2PrismaticJoint.prototype.SetLimits = function (lower, upper) {9298if (lower === undefined) lower = 0;9299if (upper === undefined) upper = 0;9300this.m_bodyA.SetAwake(true);9301this.m_bodyB.SetAwake(true);9302this.m_lowerTranslation = lower;9303this.m_upperTranslation = upper;9304}9305b2PrismaticJoint.prototype.IsMotorEnabled = function () {9306return this.m_enableMotor;9307}9308b2PrismaticJoint.prototype.EnableMotor = function (flag) {9309this.m_bodyA.SetAwake(true);9310this.m_bodyB.SetAwake(true);9311this.m_enableMotor = flag;9312}9313b2PrismaticJoint.prototype.SetMotorSpeed = function (speed) {9314if (speed === undefined) speed = 0;9315this.m_bodyA.SetAwake(true);9316this.m_bodyB.SetAwake(true);9317this.m_motorSpeed = speed;9318}9319b2PrismaticJoint.prototype.GetMotorSpeed = function () {9320return this.m_motorSpeed;9321}9322b2PrismaticJoint.prototype.SetMaxMotorForce = function (force) {9323if (force === undefined) force = 0;9324this.m_bodyA.SetAwake(true);9325this.m_bodyB.SetAwake(true);9326this.m_maxMotorForce = force;9327}9328b2PrismaticJoint.prototype.GetMotorForce = function () {9329return this.m_motorImpulse;9330}9331b2PrismaticJoint.prototype.b2PrismaticJoint = function (def) {9332this.__super.b2Joint.call(this, def);9333var tMat;9334var tX = 0;9335var tY = 0;9336this.m_localAnchor1.SetV(def.localAnchorA);9337this.m_localAnchor2.SetV(def.localAnchorB);9338this.m_localXAxis1.SetV(def.localAxisA);9339this.m_localYAxis1.x = (-this.m_localXAxis1.y);9340this.m_localYAxis1.y = this.m_localXAxis1.x;9341this.m_refAngle = def.referenceAngle;9342this.m_impulse.SetZero();9343this.m_motorMass = 0.0;9344this.m_motorImpulse = 0.0;9345this.m_lowerTranslation = def.lowerTranslation;9346this.m_upperTranslation = def.upperTranslation;9347this.m_maxMotorForce = def.maxMotorForce;9348this.m_motorSpeed = def.motorSpeed;9349this.m_enableLimit = def.enableLimit;9350this.m_enableMotor = def.enableMotor;9351this.m_limitState = b2Joint.e_inactiveLimit;9352this.m_axis.SetZero();9353this.m_perp.SetZero();9354}9355b2PrismaticJoint.prototype.InitVelocityConstraints = function (step) {9356var bA = this.m_bodyA;9357var bB = this.m_bodyB;9358var tMat;9359var tX = 0;9360this.m_localCenterA.SetV(bA.GetLocalCenter());9361this.m_localCenterB.SetV(bB.GetLocalCenter());9362var xf1 = bA.GetTransform();9363var xf2 = bB.GetTransform();9364tMat = bA.m_xf.R;9365var r1X = this.m_localAnchor1.x - this.m_localCenterA.x;9366var r1Y = this.m_localAnchor1.y - this.m_localCenterA.y;9367tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9368r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9369r1X = tX;9370tMat = bB.m_xf.R;9371var r2X = this.m_localAnchor2.x - this.m_localCenterB.x;9372var r2Y = this.m_localAnchor2.y - this.m_localCenterB.y;9373tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9374r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9375r2X = tX;9376var dX = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;9377var dY = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;9378this.m_invMassA = bA.m_invMass;9379this.m_invMassB = bB.m_invMass;9380this.m_invIA = bA.m_invI;9381this.m_invIB = bB.m_invI; {9382this.m_axis.SetV(b2Math.MulMV(xf1.R, this.m_localXAxis1));9383this.m_a1 = (dX + r1X) * this.m_axis.y - (dY + r1Y) * this.m_axis.x;9384this.m_a2 = r2X * this.m_axis.y - r2Y * this.m_axis.x;9385this.m_motorMass = this.m_invMassA + this.m_invMassB + this.m_invIA * this.m_a1 * this.m_a1 + this.m_invIB * this.m_a2 * this.m_a2;9386if (this.m_motorMass > Number.MIN_VALUE) this.m_motorMass = 1.0 / this.m_motorMass;9387} {9388this.m_perp.SetV(b2Math.MulMV(xf1.R, this.m_localYAxis1));9389this.m_s1 = (dX + r1X) * this.m_perp.y - (dY + r1Y) * this.m_perp.x;9390this.m_s2 = r2X * this.m_perp.y - r2Y * this.m_perp.x;9391var m1 = this.m_invMassA;9392var m2 = this.m_invMassB;9393var i1 = this.m_invIA;9394var i2 = this.m_invIB;9395this.m_K.col1.x = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;9396this.m_K.col1.y = i1 * this.m_s1 + i2 * this.m_s2;9397this.m_K.col1.z = i1 * this.m_s1 * this.m_a1 + i2 * this.m_s2 * this.m_a2;9398this.m_K.col2.x = this.m_K.col1.y;9399this.m_K.col2.y = i1 + i2;9400this.m_K.col2.z = i1 * this.m_a1 + i2 * this.m_a2;9401this.m_K.col3.x = this.m_K.col1.z;9402this.m_K.col3.y = this.m_K.col2.z;9403this.m_K.col3.z = m1 + m2 + i1 * this.m_a1 * this.m_a1 + i2 * this.m_a2 * this.m_a2;9404}9405if (this.m_enableLimit) {9406var jointTransition = this.m_axis.x * dX + this.m_axis.y * dY;9407if (b2Math.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2.0 * b2Settings.b2_linearSlop) {9408this.m_limitState = b2Joint.e_equalLimits;9409}9410else if (jointTransition <= this.m_lowerTranslation) {9411if (this.m_limitState != b2Joint.e_atLowerLimit) {9412this.m_limitState = b2Joint.e_atLowerLimit;9413this.m_impulse.z = 0.0;9414}9415}9416else if (jointTransition >= this.m_upperTranslation) {9417if (this.m_limitState != b2Joint.e_atUpperLimit) {9418this.m_limitState = b2Joint.e_atUpperLimit;9419this.m_impulse.z = 0.0;9420}9421}9422else {9423this.m_limitState = b2Joint.e_inactiveLimit;9424this.m_impulse.z = 0.0;9425}9426}9427else {9428this.m_limitState = b2Joint.e_inactiveLimit;9429}9430if (this.m_enableMotor == false) {9431this.m_motorImpulse = 0.0;9432}9433if (step.warmStarting) {9434this.m_impulse.x *= step.dtRatio;9435this.m_impulse.y *= step.dtRatio;9436this.m_motorImpulse *= step.dtRatio;9437var PX = this.m_impulse.x * this.m_perp.x + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.x;9438var PY = this.m_impulse.x * this.m_perp.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_axis.y;9439var L1 = this.m_impulse.x * this.m_s1 + this.m_impulse.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_a1;9440var L2 = this.m_impulse.x * this.m_s2 + this.m_impulse.y + (this.m_motorImpulse + this.m_impulse.z) * this.m_a2;9441bA.m_linearVelocity.x -= this.m_invMassA * PX;9442bA.m_linearVelocity.y -= this.m_invMassA * PY;9443bA.m_angularVelocity -= this.m_invIA * L1;9444bB.m_linearVelocity.x += this.m_invMassB * PX;9445bB.m_linearVelocity.y += this.m_invMassB * PY;9446bB.m_angularVelocity += this.m_invIB * L2;9447}9448else {9449this.m_impulse.SetZero();9450this.m_motorImpulse = 0.0;9451}9452}9453b2PrismaticJoint.prototype.SolveVelocityConstraints = function (step) {9454var bA = this.m_bodyA;9455var bB = this.m_bodyB;9456var v1 = bA.m_linearVelocity;9457var w1 = bA.m_angularVelocity;9458var v2 = bB.m_linearVelocity;9459var w2 = bB.m_angularVelocity;9460var PX = 0;9461var PY = 0;9462var L1 = 0;9463var L2 = 0;9464if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits) {9465var Cdot = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;9466var impulse = this.m_motorMass * (this.m_motorSpeed - Cdot);9467var oldImpulse = this.m_motorImpulse;9468var maxImpulse = step.dt * this.m_maxMotorForce;9469this.m_motorImpulse = b2Math.Clamp(this.m_motorImpulse + impulse, (-maxImpulse), maxImpulse);9470impulse = this.m_motorImpulse - oldImpulse;9471PX = impulse * this.m_axis.x;9472PY = impulse * this.m_axis.y;9473L1 = impulse * this.m_a1;9474L2 = impulse * this.m_a2;9475v1.x -= this.m_invMassA * PX;9476v1.y -= this.m_invMassA * PY;9477w1 -= this.m_invIA * L1;9478v2.x += this.m_invMassB * PX;9479v2.y += this.m_invMassB * PY;9480w2 += this.m_invIB * L2;9481}9482var Cdot1X = this.m_perp.x * (v2.x - v1.x) + this.m_perp.y * (v2.y - v1.y) + this.m_s2 * w2 - this.m_s1 * w1;9483var Cdot1Y = w2 - w1;9484if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {9485var Cdot2 = this.m_axis.x * (v2.x - v1.x) + this.m_axis.y * (v2.y - v1.y) + this.m_a2 * w2 - this.m_a1 * w1;9486var f1 = this.m_impulse.Copy();9487var df = this.m_K.Solve33(new b2Vec3(), (-Cdot1X), (-Cdot1Y), (-Cdot2));9488this.m_impulse.Add(df);9489if (this.m_limitState == b2Joint.e_atLowerLimit) {9490this.m_impulse.z = b2Math.Max(this.m_impulse.z, 0.0);9491}9492else if (this.m_limitState == b2Joint.e_atUpperLimit) {9493this.m_impulse.z = b2Math.Min(this.m_impulse.z, 0.0);9494}9495var bX = (-Cdot1X) - (this.m_impulse.z - f1.z) * this.m_K.col3.x;9496var bY = (-Cdot1Y) - (this.m_impulse.z - f1.z) * this.m_K.col3.y;9497var f2r = this.m_K.Solve22(new b2Vec2(), bX, bY);9498f2r.x += f1.x;9499f2r.y += f1.y;9500this.m_impulse.x = f2r.x;9501this.m_impulse.y = f2r.y;9502df.x = this.m_impulse.x - f1.x;9503df.y = this.m_impulse.y - f1.y;9504df.z = this.m_impulse.z - f1.z;9505PX = df.x * this.m_perp.x + df.z * this.m_axis.x;9506PY = df.x * this.m_perp.y + df.z * this.m_axis.y;9507L1 = df.x * this.m_s1 + df.y + df.z * this.m_a1;9508L2 = df.x * this.m_s2 + df.y + df.z * this.m_a2;9509v1.x -= this.m_invMassA * PX;9510v1.y -= this.m_invMassA * PY;9511w1 -= this.m_invIA * L1;9512v2.x += this.m_invMassB * PX;9513v2.y += this.m_invMassB * PY;9514w2 += this.m_invIB * L2;9515}9516else {9517var df2 = this.m_K.Solve22(new b2Vec2(), (-Cdot1X), (-Cdot1Y));9518this.m_impulse.x += df2.x;9519this.m_impulse.y += df2.y;9520PX = df2.x * this.m_perp.x;9521PY = df2.x * this.m_perp.y;9522L1 = df2.x * this.m_s1 + df2.y;9523L2 = df2.x * this.m_s2 + df2.y;9524v1.x -= this.m_invMassA * PX;9525v1.y -= this.m_invMassA * PY;9526w1 -= this.m_invIA * L1;9527v2.x += this.m_invMassB * PX;9528v2.y += this.m_invMassB * PY;9529w2 += this.m_invIB * L2;9530}9531bA.m_linearVelocity.SetV(v1);9532bA.m_angularVelocity = w1;9533bB.m_linearVelocity.SetV(v2);9534bB.m_angularVelocity = w2;9535}9536b2PrismaticJoint.prototype.SolvePositionConstraints = function (baumgarte) {9537if (baumgarte === undefined) baumgarte = 0;9538var limitC = 0;9539var oldLimitImpulse = 0;9540var bA = this.m_bodyA;9541var bB = this.m_bodyB;9542var c1 = bA.m_sweep.c;9543var a1 = bA.m_sweep.a;9544var c2 = bB.m_sweep.c;9545var a2 = bB.m_sweep.a;9546var tMat;9547var tX = 0;9548var m1 = 0;9549var m2 = 0;9550var i1 = 0;9551var i2 = 0;9552var linearError = 0.0;9553var angularError = 0.0;9554var active = false;9555var C2 = 0.0;9556var R1 = b2Mat22.FromAngle(a1);9557var R2 = b2Mat22.FromAngle(a2);9558tMat = R1;9559var r1X = this.m_localAnchor1.x - this.m_localCenterA.x;9560var r1Y = this.m_localAnchor1.y - this.m_localCenterA.y;9561tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9562r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9563r1X = tX;9564tMat = R2;9565var r2X = this.m_localAnchor2.x - this.m_localCenterB.x;9566var r2Y = this.m_localAnchor2.y - this.m_localCenterB.y;9567tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9568r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9569r2X = tX;9570var dX = c2.x + r2X - c1.x - r1X;9571var dY = c2.y + r2Y - c1.y - r1Y;9572if (this.m_enableLimit) {9573this.m_axis = b2Math.MulMV(R1, this.m_localXAxis1);9574this.m_a1 = (dX + r1X) * this.m_axis.y - (dY + r1Y) * this.m_axis.x;9575this.m_a2 = r2X * this.m_axis.y - r2Y * this.m_axis.x;9576var translation = this.m_axis.x * dX + this.m_axis.y * dY;9577if (b2Math.Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2.0 * b2Settings.b2_linearSlop) {9578C2 = b2Math.Clamp(translation, (-b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);9579linearError = b2Math.Abs(translation);9580active = true;9581}9582else if (translation <= this.m_lowerTranslation) {9583C2 = b2Math.Clamp(translation - this.m_lowerTranslation + b2Settings.b2_linearSlop, (-b2Settings.b2_maxLinearCorrection), 0.0);9584linearError = this.m_lowerTranslation - translation;9585active = true;9586}9587else if (translation >= this.m_upperTranslation) {9588C2 = b2Math.Clamp(translation - this.m_upperTranslation + b2Settings.b2_linearSlop, 0.0, b2Settings.b2_maxLinearCorrection);9589linearError = translation - this.m_upperTranslation;9590active = true;9591}9592}9593this.m_perp = b2Math.MulMV(R1, this.m_localYAxis1);9594this.m_s1 = (dX + r1X) * this.m_perp.y - (dY + r1Y) * this.m_perp.x;9595this.m_s2 = r2X * this.m_perp.y - r2Y * this.m_perp.x;9596var impulse = new b2Vec3();9597var C1X = this.m_perp.x * dX + this.m_perp.y * dY;9598var C1Y = a2 - a1 - this.m_refAngle;9599linearError = b2Math.Max(linearError, b2Math.Abs(C1X));9600angularError = b2Math.Abs(C1Y);9601if (active) {9602m1 = this.m_invMassA;9603m2 = this.m_invMassB;9604i1 = this.m_invIA;9605i2 = this.m_invIB;9606this.m_K.col1.x = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;9607this.m_K.col1.y = i1 * this.m_s1 + i2 * this.m_s2;9608this.m_K.col1.z = i1 * this.m_s1 * this.m_a1 + i2 * this.m_s2 * this.m_a2;9609this.m_K.col2.x = this.m_K.col1.y;9610this.m_K.col2.y = i1 + i2;9611this.m_K.col2.z = i1 * this.m_a1 + i2 * this.m_a2;9612this.m_K.col3.x = this.m_K.col1.z;9613this.m_K.col3.y = this.m_K.col2.z;9614this.m_K.col3.z = m1 + m2 + i1 * this.m_a1 * this.m_a1 + i2 * this.m_a2 * this.m_a2;9615this.m_K.Solve33(impulse, (-C1X), (-C1Y), (-C2));9616}9617else {9618m1 = this.m_invMassA;9619m2 = this.m_invMassB;9620i1 = this.m_invIA;9621i2 = this.m_invIB;9622var k11 = m1 + m2 + i1 * this.m_s1 * this.m_s1 + i2 * this.m_s2 * this.m_s2;9623var k12 = i1 * this.m_s1 + i2 * this.m_s2;9624var k22 = i1 + i2;9625this.m_K.col1.Set(k11, k12, 0.0);9626this.m_K.col2.Set(k12, k22, 0.0);9627var impulse1 = this.m_K.Solve22(new b2Vec2(), (-C1X), (-C1Y));9628impulse.x = impulse1.x;9629impulse.y = impulse1.y;9630impulse.z = 0.0;9631}9632var PX = impulse.x * this.m_perp.x + impulse.z * this.m_axis.x;9633var PY = impulse.x * this.m_perp.y + impulse.z * this.m_axis.y;9634var L1 = impulse.x * this.m_s1 + impulse.y + impulse.z * this.m_a1;9635var L2 = impulse.x * this.m_s2 + impulse.y + impulse.z * this.m_a2;9636c1.x -= this.m_invMassA * PX;9637c1.y -= this.m_invMassA * PY;9638a1 -= this.m_invIA * L1;9639c2.x += this.m_invMassB * PX;9640c2.y += this.m_invMassB * PY;9641a2 += this.m_invIB * L2;9642bA.m_sweep.a = a1;9643bB.m_sweep.a = a2;9644bA.SynchronizeTransform();9645bB.SynchronizeTransform();9646return linearError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;9647}9648Box2D.inherit(b2PrismaticJointDef, Box2D.Dynamics.Joints.b2JointDef);9649b2PrismaticJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;9650b2PrismaticJointDef.b2PrismaticJointDef = function () {9651Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);9652this.localAnchorA = new b2Vec2();9653this.localAnchorB = new b2Vec2();9654this.localAxisA = new b2Vec2();9655};9656b2PrismaticJointDef.prototype.b2PrismaticJointDef = function () {9657this.__super.b2JointDef.call(this);9658this.type = b2Joint.e_prismaticJoint;9659this.localAxisA.Set(1.0, 0.0);9660this.referenceAngle = 0.0;9661this.enableLimit = false;9662this.lowerTranslation = 0.0;9663this.upperTranslation = 0.0;9664this.enableMotor = false;9665this.maxMotorForce = 0.0;9666this.motorSpeed = 0.0;9667}9668b2PrismaticJointDef.prototype.Initialize = function (bA, bB, anchor, axis) {9669this.bodyA = bA;9670this.bodyB = bB;9671this.localAnchorA = this.bodyA.GetLocalPoint(anchor);9672this.localAnchorB = this.bodyB.GetLocalPoint(anchor);9673this.localAxisA = this.bodyA.GetLocalVector(axis);9674this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();9675}9676Box2D.inherit(b2PulleyJoint, Box2D.Dynamics.Joints.b2Joint);9677b2PulleyJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;9678b2PulleyJoint.b2PulleyJoint = function () {9679Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);9680this.m_groundAnchor1 = new b2Vec2();9681this.m_groundAnchor2 = new b2Vec2();9682this.m_localAnchor1 = new b2Vec2();9683this.m_localAnchor2 = new b2Vec2();9684this.m_u1 = new b2Vec2();9685this.m_u2 = new b2Vec2();9686};9687b2PulleyJoint.prototype.GetAnchorA = function () {9688return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);9689}9690b2PulleyJoint.prototype.GetAnchorB = function () {9691return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);9692}9693b2PulleyJoint.prototype.GetReactionForce = function (inv_dt) {9694if (inv_dt === undefined) inv_dt = 0;9695return new b2Vec2(inv_dt * this.m_impulse * this.m_u2.x, inv_dt * this.m_impulse * this.m_u2.y);9696}9697b2PulleyJoint.prototype.GetReactionTorque = function (inv_dt) {9698if (inv_dt === undefined) inv_dt = 0;9699return 0.0;9700}9701b2PulleyJoint.prototype.GetGroundAnchorA = function () {9702var a = this.m_ground.m_xf.position.Copy();9703a.Add(this.m_groundAnchor1);9704return a;9705}9706b2PulleyJoint.prototype.GetGroundAnchorB = function () {9707var a = this.m_ground.m_xf.position.Copy();9708a.Add(this.m_groundAnchor2);9709return a;9710}9711b2PulleyJoint.prototype.GetLength1 = function () {9712var p = this.m_bodyA.GetWorldPoint(this.m_localAnchor1);9713var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x;9714var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y;9715var dX = p.x - sX;9716var dY = p.y - sY;9717return Math.sqrt(dX * dX + dY * dY);9718}9719b2PulleyJoint.prototype.GetLength2 = function () {9720var p = this.m_bodyB.GetWorldPoint(this.m_localAnchor2);9721var sX = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x;9722var sY = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;9723var dX = p.x - sX;9724var dY = p.y - sY;9725return Math.sqrt(dX * dX + dY * dY);9726}9727b2PulleyJoint.prototype.GetRatio = function () {9728return this.m_ratio;9729}9730b2PulleyJoint.prototype.b2PulleyJoint = function (def) {9731this.__super.b2Joint.call(this, def);9732var tMat;9733var tX = 0;9734var tY = 0;9735this.m_ground = this.m_bodyA.m_world.m_groundBody;9736this.m_groundAnchor1.x = def.groundAnchorA.x - this.m_ground.m_xf.position.x;9737this.m_groundAnchor1.y = def.groundAnchorA.y - this.m_ground.m_xf.position.y;9738this.m_groundAnchor2.x = def.groundAnchorB.x - this.m_ground.m_xf.position.x;9739this.m_groundAnchor2.y = def.groundAnchorB.y - this.m_ground.m_xf.position.y;9740this.m_localAnchor1.SetV(def.localAnchorA);9741this.m_localAnchor2.SetV(def.localAnchorB);9742this.m_ratio = def.ratio;9743this.m_constant = def.lengthA + this.m_ratio * def.lengthB;9744this.m_maxLength1 = b2Math.Min(def.maxLengthA, this.m_constant - this.m_ratio * b2PulleyJoint.b2_minPulleyLength);9745this.m_maxLength2 = b2Math.Min(def.maxLengthB, (this.m_constant - b2PulleyJoint.b2_minPulleyLength) / this.m_ratio);9746this.m_impulse = 0.0;9747this.m_limitImpulse1 = 0.0;9748this.m_limitImpulse2 = 0.0;9749}9750b2PulleyJoint.prototype.InitVelocityConstraints = function (step) {9751var bA = this.m_bodyA;9752var bB = this.m_bodyB;9753var tMat;9754tMat = bA.m_xf.R;9755var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;9756var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;9757var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9758r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9759r1X = tX;9760tMat = bB.m_xf.R;9761var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;9762var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;9763tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9764r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9765r2X = tX;9766var p1X = bA.m_sweep.c.x + r1X;9767var p1Y = bA.m_sweep.c.y + r1Y;9768var p2X = bB.m_sweep.c.x + r2X;9769var p2Y = bB.m_sweep.c.y + r2Y;9770var s1X = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x;9771var s1Y = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y;9772var s2X = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x;9773var s2Y = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;9774this.m_u1.Set(p1X - s1X, p1Y - s1Y);9775this.m_u2.Set(p2X - s2X, p2Y - s2Y);9776var length1 = this.m_u1.Length();9777var length2 = this.m_u2.Length();9778if (length1 > b2Settings.b2_linearSlop) {9779this.m_u1.Multiply(1.0 / length1);9780}9781else {9782this.m_u1.SetZero();9783}9784if (length2 > b2Settings.b2_linearSlop) {9785this.m_u2.Multiply(1.0 / length2);9786}9787else {9788this.m_u2.SetZero();9789}9790var C = this.m_constant - length1 - this.m_ratio * length2;9791if (C > 0.0) {9792this.m_state = b2Joint.e_inactiveLimit;9793this.m_impulse = 0.0;9794}9795else {9796this.m_state = b2Joint.e_atUpperLimit;9797}9798if (length1 < this.m_maxLength1) {9799this.m_limitState1 = b2Joint.e_inactiveLimit;9800this.m_limitImpulse1 = 0.0;9801}9802else {9803this.m_limitState1 = b2Joint.e_atUpperLimit;9804}9805if (length2 < this.m_maxLength2) {9806this.m_limitState2 = b2Joint.e_inactiveLimit;9807this.m_limitImpulse2 = 0.0;9808}9809else {9810this.m_limitState2 = b2Joint.e_atUpperLimit;9811}9812var cr1u1 = r1X * this.m_u1.y - r1Y * this.m_u1.x;9813var cr2u2 = r2X * this.m_u2.y - r2Y * this.m_u2.x;9814this.m_limitMass1 = bA.m_invMass + bA.m_invI * cr1u1 * cr1u1;9815this.m_limitMass2 = bB.m_invMass + bB.m_invI * cr2u2 * cr2u2;9816this.m_pulleyMass = this.m_limitMass1 + this.m_ratio * this.m_ratio * this.m_limitMass2;9817this.m_limitMass1 = 1.0 / this.m_limitMass1;9818this.m_limitMass2 = 1.0 / this.m_limitMass2;9819this.m_pulleyMass = 1.0 / this.m_pulleyMass;9820if (step.warmStarting) {9821this.m_impulse *= step.dtRatio;9822this.m_limitImpulse1 *= step.dtRatio;9823this.m_limitImpulse2 *= step.dtRatio;9824var P1X = ((-this.m_impulse) - this.m_limitImpulse1) * this.m_u1.x;9825var P1Y = ((-this.m_impulse) - this.m_limitImpulse1) * this.m_u1.y;9826var P2X = ((-this.m_ratio * this.m_impulse) - this.m_limitImpulse2) * this.m_u2.x;9827var P2Y = ((-this.m_ratio * this.m_impulse) - this.m_limitImpulse2) * this.m_u2.y;9828bA.m_linearVelocity.x += bA.m_invMass * P1X;9829bA.m_linearVelocity.y += bA.m_invMass * P1Y;9830bA.m_angularVelocity += bA.m_invI * (r1X * P1Y - r1Y * P1X);9831bB.m_linearVelocity.x += bB.m_invMass * P2X;9832bB.m_linearVelocity.y += bB.m_invMass * P2Y;9833bB.m_angularVelocity += bB.m_invI * (r2X * P2Y - r2Y * P2X);9834}9835else {9836this.m_impulse = 0.0;9837this.m_limitImpulse1 = 0.0;9838this.m_limitImpulse2 = 0.0;9839}9840}9841b2PulleyJoint.prototype.SolveVelocityConstraints = function (step) {9842var bA = this.m_bodyA;9843var bB = this.m_bodyB;9844var tMat;9845tMat = bA.m_xf.R;9846var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;9847var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;9848var tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9849r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9850r1X = tX;9851tMat = bB.m_xf.R;9852var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;9853var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;9854tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9855r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9856r2X = tX;9857var v1X = 0;9858var v1Y = 0;9859var v2X = 0;9860var v2Y = 0;9861var P1X = 0;9862var P1Y = 0;9863var P2X = 0;9864var P2Y = 0;9865var Cdot = 0;9866var impulse = 0;9867var oldImpulse = 0;9868if (this.m_state == b2Joint.e_atUpperLimit) {9869v1X = bA.m_linearVelocity.x + ((-bA.m_angularVelocity * r1Y));9870v1Y = bA.m_linearVelocity.y + (bA.m_angularVelocity * r1X);9871v2X = bB.m_linearVelocity.x + ((-bB.m_angularVelocity * r2Y));9872v2Y = bB.m_linearVelocity.y + (bB.m_angularVelocity * r2X);9873Cdot = (-(this.m_u1.x * v1X + this.m_u1.y * v1Y)) - this.m_ratio * (this.m_u2.x * v2X + this.m_u2.y * v2Y);9874impulse = this.m_pulleyMass * ((-Cdot));9875oldImpulse = this.m_impulse;9876this.m_impulse = b2Math.Max(0.0, this.m_impulse + impulse);9877impulse = this.m_impulse - oldImpulse;9878P1X = (-impulse * this.m_u1.x);9879P1Y = (-impulse * this.m_u1.y);9880P2X = (-this.m_ratio * impulse * this.m_u2.x);9881P2Y = (-this.m_ratio * impulse * this.m_u2.y);9882bA.m_linearVelocity.x += bA.m_invMass * P1X;9883bA.m_linearVelocity.y += bA.m_invMass * P1Y;9884bA.m_angularVelocity += bA.m_invI * (r1X * P1Y - r1Y * P1X);9885bB.m_linearVelocity.x += bB.m_invMass * P2X;9886bB.m_linearVelocity.y += bB.m_invMass * P2Y;9887bB.m_angularVelocity += bB.m_invI * (r2X * P2Y - r2Y * P2X);9888}9889if (this.m_limitState1 == b2Joint.e_atUpperLimit) {9890v1X = bA.m_linearVelocity.x + ((-bA.m_angularVelocity * r1Y));9891v1Y = bA.m_linearVelocity.y + (bA.m_angularVelocity * r1X);9892Cdot = (-(this.m_u1.x * v1X + this.m_u1.y * v1Y));9893impulse = (-this.m_limitMass1 * Cdot);9894oldImpulse = this.m_limitImpulse1;9895this.m_limitImpulse1 = b2Math.Max(0.0, this.m_limitImpulse1 + impulse);9896impulse = this.m_limitImpulse1 - oldImpulse;9897P1X = (-impulse * this.m_u1.x);9898P1Y = (-impulse * this.m_u1.y);9899bA.m_linearVelocity.x += bA.m_invMass * P1X;9900bA.m_linearVelocity.y += bA.m_invMass * P1Y;9901bA.m_angularVelocity += bA.m_invI * (r1X * P1Y - r1Y * P1X);9902}9903if (this.m_limitState2 == b2Joint.e_atUpperLimit) {9904v2X = bB.m_linearVelocity.x + ((-bB.m_angularVelocity * r2Y));9905v2Y = bB.m_linearVelocity.y + (bB.m_angularVelocity * r2X);9906Cdot = (-(this.m_u2.x * v2X + this.m_u2.y * v2Y));9907impulse = (-this.m_limitMass2 * Cdot);9908oldImpulse = this.m_limitImpulse2;9909this.m_limitImpulse2 = b2Math.Max(0.0, this.m_limitImpulse2 + impulse);9910impulse = this.m_limitImpulse2 - oldImpulse;9911P2X = (-impulse * this.m_u2.x);9912P2Y = (-impulse * this.m_u2.y);9913bB.m_linearVelocity.x += bB.m_invMass * P2X;9914bB.m_linearVelocity.y += bB.m_invMass * P2Y;9915bB.m_angularVelocity += bB.m_invI * (r2X * P2Y - r2Y * P2X);9916}9917}9918b2PulleyJoint.prototype.SolvePositionConstraints = function (baumgarte) {9919if (baumgarte === undefined) baumgarte = 0;9920var bA = this.m_bodyA;9921var bB = this.m_bodyB;9922var tMat;9923var s1X = this.m_ground.m_xf.position.x + this.m_groundAnchor1.x;9924var s1Y = this.m_ground.m_xf.position.y + this.m_groundAnchor1.y;9925var s2X = this.m_ground.m_xf.position.x + this.m_groundAnchor2.x;9926var s2Y = this.m_ground.m_xf.position.y + this.m_groundAnchor2.y;9927var r1X = 0;9928var r1Y = 0;9929var r2X = 0;9930var r2Y = 0;9931var p1X = 0;9932var p1Y = 0;9933var p2X = 0;9934var p2Y = 0;9935var length1 = 0;9936var length2 = 0;9937var C = 0;9938var impulse = 0;9939var oldImpulse = 0;9940var oldLimitPositionImpulse = 0;9941var tX = 0;9942var linearError = 0.0;9943if (this.m_state == b2Joint.e_atUpperLimit) {9944tMat = bA.m_xf.R;9945r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;9946r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;9947tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9948r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9949r1X = tX;9950tMat = bB.m_xf.R;9951r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;9952r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;9953tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);9954r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);9955r2X = tX;9956p1X = bA.m_sweep.c.x + r1X;9957p1Y = bA.m_sweep.c.y + r1Y;9958p2X = bB.m_sweep.c.x + r2X;9959p2Y = bB.m_sweep.c.y + r2Y;9960this.m_u1.Set(p1X - s1X, p1Y - s1Y);9961this.m_u2.Set(p2X - s2X, p2Y - s2Y);9962length1 = this.m_u1.Length();9963length2 = this.m_u2.Length();9964if (length1 > b2Settings.b2_linearSlop) {9965this.m_u1.Multiply(1.0 / length1);9966}9967else {9968this.m_u1.SetZero();9969}9970if (length2 > b2Settings.b2_linearSlop) {9971this.m_u2.Multiply(1.0 / length2);9972}9973else {9974this.m_u2.SetZero();9975}9976C = this.m_constant - length1 - this.m_ratio * length2;9977linearError = b2Math.Max(linearError, (-C));9978C = b2Math.Clamp(C + b2Settings.b2_linearSlop, (-b2Settings.b2_maxLinearCorrection), 0.0);9979impulse = (-this.m_pulleyMass * C);9980p1X = (-impulse * this.m_u1.x);9981p1Y = (-impulse * this.m_u1.y);9982p2X = (-this.m_ratio * impulse * this.m_u2.x);9983p2Y = (-this.m_ratio * impulse * this.m_u2.y);9984bA.m_sweep.c.x += bA.m_invMass * p1X;9985bA.m_sweep.c.y += bA.m_invMass * p1Y;9986bA.m_sweep.a += bA.m_invI * (r1X * p1Y - r1Y * p1X);9987bB.m_sweep.c.x += bB.m_invMass * p2X;9988bB.m_sweep.c.y += bB.m_invMass * p2Y;9989bB.m_sweep.a += bB.m_invI * (r2X * p2Y - r2Y * p2X);9990bA.SynchronizeTransform();9991bB.SynchronizeTransform();9992}9993if (this.m_limitState1 == b2Joint.e_atUpperLimit) {9994tMat = bA.m_xf.R;9995r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;9996r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;9997tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);9998r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);9999r1X = tX;10000p1X = bA.m_sweep.c.x + r1X;10001p1Y = bA.m_sweep.c.y + r1Y;10002this.m_u1.Set(p1X - s1X, p1Y - s1Y);10003length1 = this.m_u1.Length();10004if (length1 > b2Settings.b2_linearSlop) {10005this.m_u1.x *= 1.0 / length1;10006this.m_u1.y *= 1.0 / length1;10007}10008else {10009this.m_u1.SetZero();10010}10011C = this.m_maxLength1 - length1;10012linearError = b2Math.Max(linearError, (-C));10013C = b2Math.Clamp(C + b2Settings.b2_linearSlop, (-b2Settings.b2_maxLinearCorrection), 0.0);10014impulse = (-this.m_limitMass1 * C);10015p1X = (-impulse * this.m_u1.x);10016p1Y = (-impulse * this.m_u1.y);10017bA.m_sweep.c.x += bA.m_invMass * p1X;10018bA.m_sweep.c.y += bA.m_invMass * p1Y;10019bA.m_sweep.a += bA.m_invI * (r1X * p1Y - r1Y * p1X);10020bA.SynchronizeTransform();10021}10022if (this.m_limitState2 == b2Joint.e_atUpperLimit) {10023tMat = bB.m_xf.R;10024r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;10025r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;10026tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);10027r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);10028r2X = tX;10029p2X = bB.m_sweep.c.x + r2X;10030p2Y = bB.m_sweep.c.y + r2Y;10031this.m_u2.Set(p2X - s2X, p2Y - s2Y);10032length2 = this.m_u2.Length();10033if (length2 > b2Settings.b2_linearSlop) {10034this.m_u2.x *= 1.0 / length2;10035this.m_u2.y *= 1.0 / length2;10036}10037else {10038this.m_u2.SetZero();10039}10040C = this.m_maxLength2 - length2;10041linearError = b2Math.Max(linearError, (-C));10042C = b2Math.Clamp(C + b2Settings.b2_linearSlop, (-b2Settings.b2_maxLinearCorrection), 0.0);10043impulse = (-this.m_limitMass2 * C);10044p2X = (-impulse * this.m_u2.x);10045p2Y = (-impulse * this.m_u2.y);10046bB.m_sweep.c.x += bB.m_invMass * p2X;10047bB.m_sweep.c.y += bB.m_invMass * p2Y;10048bB.m_sweep.a += bB.m_invI * (r2X * p2Y - r2Y * p2X);10049bB.SynchronizeTransform();10050}10051return linearError < b2Settings.b2_linearSlop;10052}10053Box2D.postDefs.push(function () {10054Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength = 2.0;10055});10056Box2D.inherit(b2PulleyJointDef, Box2D.Dynamics.Joints.b2JointDef);10057b2PulleyJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;10058b2PulleyJointDef.b2PulleyJointDef = function () {10059Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);10060this.groundAnchorA = new b2Vec2();10061this.groundAnchorB = new b2Vec2();10062this.localAnchorA = new b2Vec2();10063this.localAnchorB = new b2Vec2();10064};10065b2PulleyJointDef.prototype.b2PulleyJointDef = function () {10066this.__super.b2JointDef.call(this);10067this.type = b2Joint.e_pulleyJoint;10068this.groundAnchorA.Set((-1.0), 1.0);10069this.groundAnchorB.Set(1.0, 1.0);10070this.localAnchorA.Set((-1.0), 0.0);10071this.localAnchorB.Set(1.0, 0.0);10072this.lengthA = 0.0;10073this.maxLengthA = 0.0;10074this.lengthB = 0.0;10075this.maxLengthB = 0.0;10076this.ratio = 1.0;10077this.collideConnected = true;10078}10079b2PulleyJointDef.prototype.Initialize = function (bA, bB, gaA, gaB, anchorA, anchorB, r) {10080if (r === undefined) r = 0;10081this.bodyA = bA;10082this.bodyB = bB;10083this.groundAnchorA.SetV(gaA);10084this.groundAnchorB.SetV(gaB);10085this.localAnchorA = this.bodyA.GetLocalPoint(anchorA);10086this.localAnchorB = this.bodyB.GetLocalPoint(anchorB);10087var d1X = anchorA.x - gaA.x;10088var d1Y = anchorA.y - gaA.y;10089this.lengthA = Math.sqrt(d1X * d1X + d1Y * d1Y);10090var d2X = anchorB.x - gaB.x;10091var d2Y = anchorB.y - gaB.y;10092this.lengthB = Math.sqrt(d2X * d2X + d2Y * d2Y);10093this.ratio = r;10094var C = this.lengthA + this.ratio * this.lengthB;10095this.maxLengthA = C - this.ratio * b2PulleyJoint.b2_minPulleyLength;10096this.maxLengthB = (C - b2PulleyJoint.b2_minPulleyLength) / this.ratio;10097}10098Box2D.inherit(b2RevoluteJoint, Box2D.Dynamics.Joints.b2Joint);10099b2RevoluteJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;10100b2RevoluteJoint.b2RevoluteJoint = function () {10101Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);10102this.K = new b2Mat22();10103this.K1 = new b2Mat22();10104this.K2 = new b2Mat22();10105this.K3 = new b2Mat22();10106this.impulse3 = new b2Vec3();10107this.impulse2 = new b2Vec2();10108this.reduced = new b2Vec2();10109this.m_localAnchor1 = new b2Vec2();10110this.m_localAnchor2 = new b2Vec2();10111this.m_impulse = new b2Vec3();10112this.m_mass = new b2Mat33();10113};10114b2RevoluteJoint.prototype.GetAnchorA = function () {10115return this.m_bodyA.GetWorldPoint(this.m_localAnchor1);10116}10117b2RevoluteJoint.prototype.GetAnchorB = function () {10118return this.m_bodyB.GetWorldPoint(this.m_localAnchor2);10119}10120b2RevoluteJoint.prototype.GetReactionForce = function (inv_dt) {10121if (inv_dt === undefined) inv_dt = 0;10122return new b2Vec2(inv_dt * this.m_impulse.x, inv_dt * this.m_impulse.y);10123}10124b2RevoluteJoint.prototype.GetReactionTorque = function (inv_dt) {10125if (inv_dt === undefined) inv_dt = 0;10126return inv_dt * this.m_impulse.z;10127}10128b2RevoluteJoint.prototype.GetJointAngle = function () {10129return this.m_bodyB.m_sweep.a - this.m_bodyA.m_sweep.a - this.m_referenceAngle;10130}10131b2RevoluteJoint.prototype.GetJointSpeed = function () {10132return this.m_bodyB.m_angularVelocity - this.m_bodyA.m_angularVelocity;10133}10134b2RevoluteJoint.prototype.IsLimitEnabled = function () {10135return this.m_enableLimit;10136}10137b2RevoluteJoint.prototype.EnableLimit = function (flag) {10138this.m_enableLimit = flag;10139}10140b2RevoluteJoint.prototype.GetLowerLimit = function () {10141return this.m_lowerAngle;10142}10143b2RevoluteJoint.prototype.GetUpperLimit = function () {10144return this.m_upperAngle;10145}10146b2RevoluteJoint.prototype.SetLimits = function (lower, upper) {10147if (lower === undefined) lower = 0;10148if (upper === undefined) upper = 0;10149this.m_lowerAngle = lower;10150this.m_upperAngle = upper;10151}10152b2RevoluteJoint.prototype.IsMotorEnabled = function () {10153this.m_bodyA.SetAwake(true);10154this.m_bodyB.SetAwake(true);10155return this.m_enableMotor;10156}10157b2RevoluteJoint.prototype.EnableMotor = function (flag) {10158this.m_enableMotor = flag;10159}10160b2RevoluteJoint.prototype.SetMotorSpeed = function (speed) {10161if (speed === undefined) speed = 0;10162this.m_bodyA.SetAwake(true);10163this.m_bodyB.SetAwake(true);10164this.m_motorSpeed = speed;10165}10166b2RevoluteJoint.prototype.GetMotorSpeed = function () {10167return this.m_motorSpeed;10168}10169b2RevoluteJoint.prototype.SetMaxMotorTorque = function (torque) {10170if (torque === undefined) torque = 0;10171this.m_maxMotorTorque = torque;10172}10173b2RevoluteJoint.prototype.GetMotorTorque = function () {10174return this.m_maxMotorTorque;10175}10176b2RevoluteJoint.prototype.b2RevoluteJoint = function (def) {10177this.__super.b2Joint.call(this, def);10178this.m_localAnchor1.SetV(def.localAnchorA);10179this.m_localAnchor2.SetV(def.localAnchorB);10180this.m_referenceAngle = def.referenceAngle;10181this.m_impulse.SetZero();10182this.m_motorImpulse = 0.0;10183this.m_lowerAngle = def.lowerAngle;10184this.m_upperAngle = def.upperAngle;10185this.m_maxMotorTorque = def.maxMotorTorque;10186this.m_motorSpeed = def.motorSpeed;10187this.m_enableLimit = def.enableLimit;10188this.m_enableMotor = def.enableMotor;10189this.m_limitState = b2Joint.e_inactiveLimit;10190}10191b2RevoluteJoint.prototype.InitVelocityConstraints = function (step) {10192var bA = this.m_bodyA;10193var bB = this.m_bodyB;10194var tMat;10195var tX = 0;10196if (this.m_enableMotor || this.m_enableLimit) {}10197tMat = bA.m_xf.R;10198var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;10199var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;10200tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);10201r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);10202r1X = tX;10203tMat = bB.m_xf.R;10204var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;10205var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;10206tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);10207r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);10208r2X = tX;10209var m1 = bA.m_invMass;10210var m2 = bB.m_invMass;10211var i1 = bA.m_invI;10212var i2 = bB.m_invI;10213this.m_mass.col1.x = m1 + m2 + r1Y * r1Y * i1 + r2Y * r2Y * i2;10214this.m_mass.col2.x = (-r1Y * r1X * i1) - r2Y * r2X * i2;10215this.m_mass.col3.x = (-r1Y * i1) - r2Y * i2;10216this.m_mass.col1.y = this.m_mass.col2.x;10217this.m_mass.col2.y = m1 + m2 + r1X * r1X * i1 + r2X * r2X * i2;10218this.m_mass.col3.y = r1X * i1 + r2X * i2;10219this.m_mass.col1.z = this.m_mass.col3.x;10220this.m_mass.col2.z = this.m_mass.col3.y;10221this.m_mass.col3.z = i1 + i2;10222this.m_motorMass = 1.0 / (i1 + i2);10223if (this.m_enableMotor == false) {10224this.m_motorImpulse = 0.0;10225}10226if (this.m_enableLimit) {10227var jointAngle = bB.m_sweep.a - bA.m_sweep.a - this.m_referenceAngle;10228if (b2Math.Abs(this.m_upperAngle - this.m_lowerAngle) < 2.0 * b2Settings.b2_angularSlop) {10229this.m_limitState = b2Joint.e_equalLimits;10230}10231else if (jointAngle <= this.m_lowerAngle) {10232if (this.m_limitState != b2Joint.e_atLowerLimit) {10233this.m_impulse.z = 0.0;10234}10235this.m_limitState = b2Joint.e_atLowerLimit;10236}10237else if (jointAngle >= this.m_upperAngle) {10238if (this.m_limitState != b2Joint.e_atUpperLimit) {10239this.m_impulse.z = 0.0;10240}10241this.m_limitState = b2Joint.e_atUpperLimit;10242}10243else {10244this.m_limitState = b2Joint.e_inactiveLimit;10245this.m_impulse.z = 0.0;10246}10247}10248else {10249this.m_limitState = b2Joint.e_inactiveLimit;10250}10251if (step.warmStarting) {10252this.m_impulse.x *= step.dtRatio;10253this.m_impulse.y *= step.dtRatio;10254this.m_motorImpulse *= step.dtRatio;10255var PX = this.m_impulse.x;10256var PY = this.m_impulse.y;10257bA.m_linearVelocity.x -= m1 * PX;10258bA.m_linearVelocity.y -= m1 * PY;10259bA.m_angularVelocity -= i1 * ((r1X * PY - r1Y * PX) + this.m_motorImpulse + this.m_impulse.z);10260bB.m_linearVelocity.x += m2 * PX;10261bB.m_linearVelocity.y += m2 * PY;10262bB.m_angularVelocity += i2 * ((r2X * PY - r2Y * PX) + this.m_motorImpulse + this.m_impulse.z);10263}10264else {10265this.m_impulse.SetZero();10266this.m_motorImpulse = 0.0;10267}10268}10269b2RevoluteJoint.prototype.SolveVelocityConstraints = function (step) {10270var bA = this.m_bodyA;10271var bB = this.m_bodyB;10272var tMat;10273var tX = 0;10274var newImpulse = 0;10275var r1X = 0;10276var r1Y = 0;10277var r2X = 0;10278var r2Y = 0;10279var v1 = bA.m_linearVelocity;10280var w1 = bA.m_angularVelocity;10281var v2 = bB.m_linearVelocity;10282var w2 = bB.m_angularVelocity;10283var m1 = bA.m_invMass;10284var m2 = bB.m_invMass;10285var i1 = bA.m_invI;10286var i2 = bB.m_invI;10287if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits) {10288var Cdot = w2 - w1 - this.m_motorSpeed;10289var impulse = this.m_motorMass * ((-Cdot));10290var oldImpulse = this.m_motorImpulse;10291var maxImpulse = step.dt * this.m_maxMotorTorque;10292this.m_motorImpulse = b2Math.Clamp(this.m_motorImpulse + impulse, (-maxImpulse), maxImpulse);10293impulse = this.m_motorImpulse - oldImpulse;10294w1 -= i1 * impulse;10295w2 += i2 * impulse;10296}10297if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {10298tMat = bA.m_xf.R;10299r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;10300r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;10301tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);10302r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);10303r1X = tX;10304tMat = bB.m_xf.R;10305r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;10306r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;10307tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);10308r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);10309r2X = tX;10310var Cdot1X = v2.x + ((-w2 * r2Y)) - v1.x - ((-w1 * r1Y));10311var Cdot1Y = v2.y + (w2 * r2X) - v1.y - (w1 * r1X);10312var Cdot2 = w2 - w1;10313this.m_mass.Solve33(this.impulse3, (-Cdot1X), (-Cdot1Y), (-Cdot2));10314if (this.m_limitState == b2Joint.e_equalLimits) {10315this.m_impulse.Add(this.impulse3);10316}10317else if (this.m_limitState == b2Joint.e_atLowerLimit) {10318newImpulse = this.m_impulse.z + this.impulse3.z;10319if (newImpulse < 0.0) {10320this.m_mass.Solve22(this.reduced, (-Cdot1X), (-Cdot1Y));10321this.impulse3.x = this.reduced.x;10322this.impulse3.y = this.reduced.y;10323this.impulse3.z = (-this.m_impulse.z);10324this.m_impulse.x += this.reduced.x;10325this.m_impulse.y += this.reduced.y;10326this.m_impulse.z = 0.0;10327}10328}10329else if (this.m_limitState == b2Joint.e_atUpperLimit) {10330newImpulse = this.m_impulse.z + this.impulse3.z;10331if (newImpulse > 0.0) {10332this.m_mass.Solve22(this.reduced, (-Cdot1X), (-Cdot1Y));10333this.impulse3.x = this.reduced.x;10334this.impulse3.y = this.reduced.y;10335this.impulse3.z = (-this.m_impulse.z);10336this.m_impulse.x += this.reduced.x;10337this.m_impulse.y += this.reduced.y;10338this.m_impulse.z = 0.0;10339}10340}10341v1.x -= m1 * this.impulse3.x;10342v1.y -= m1 * this.impulse3.y;10343w1 -= i1 * (r1X * this.impulse3.y - r1Y * this.impulse3.x + this.impulse3.z);10344v2.x += m2 * this.impulse3.x;10345v2.y += m2 * this.impulse3.y;10346w2 += i2 * (r2X * this.impulse3.y - r2Y * this.impulse3.x + this.impulse3.z);10347}10348else {10349tMat = bA.m_xf.R;10350r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;10351r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;10352tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);10353r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);10354r1X = tX;10355tMat = bB.m_xf.R;10356r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;10357r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;10358tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);10359r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);10360r2X = tX;10361var CdotX = v2.x + ((-w2 * r2Y)) - v1.x - ((-w1 * r1Y));10362var CdotY = v2.y + (w2 * r2X) - v1.y - (w1 * r1X);10363this.m_mass.Solve22(this.impulse2, (-CdotX), (-CdotY));10364this.m_impulse.x += this.impulse2.x;10365this.m_impulse.y += this.impulse2.y;10366v1.x -= m1 * this.impulse2.x;10367v1.y -= m1 * this.impulse2.y;10368w1 -= i1 * (r1X * this.impulse2.y - r1Y * this.impulse2.x);10369v2.x += m2 * this.impulse2.x;10370v2.y += m2 * this.impulse2.y;10371w2 += i2 * (r2X * this.impulse2.y - r2Y * this.impulse2.x);10372}10373bA.m_linearVelocity.SetV(v1);10374bA.m_angularVelocity = w1;10375bB.m_linearVelocity.SetV(v2);10376bB.m_angularVelocity = w2;10377}10378b2RevoluteJoint.prototype.SolvePositionConstraints = function (baumgarte) {10379if (baumgarte === undefined) baumgarte = 0;10380var oldLimitImpulse = 0;10381var C = 0;10382var tMat;10383var bA = this.m_bodyA;10384var bB = this.m_bodyB;10385var angularError = 0.0;10386var positionError = 0.0;10387var tX = 0;10388var impulseX = 0;10389var impulseY = 0;10390if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit) {10391var angle = bB.m_sweep.a - bA.m_sweep.a - this.m_referenceAngle;10392var limitImpulse = 0.0;10393if (this.m_limitState == b2Joint.e_equalLimits) {10394C = b2Math.Clamp(angle - this.m_lowerAngle, (-b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);10395limitImpulse = (-this.m_motorMass * C);10396angularError = b2Math.Abs(C);10397}10398else if (this.m_limitState == b2Joint.e_atLowerLimit) {10399C = angle - this.m_lowerAngle;10400angularError = (-C);10401C = b2Math.Clamp(C + b2Settings.b2_angularSlop, (-b2Settings.b2_maxAngularCorrection), 0.0);10402limitImpulse = (-this.m_motorMass * C);10403}10404else if (this.m_limitState == b2Joint.e_atUpperLimit) {10405C = angle - this.m_upperAngle;10406angularError = C;10407C = b2Math.Clamp(C - b2Settings.b2_angularSlop, 0.0, b2Settings.b2_maxAngularCorrection);10408limitImpulse = (-this.m_motorMass * C);10409}10410bA.m_sweep.a -= bA.m_invI * limitImpulse;10411bB.m_sweep.a += bB.m_invI * limitImpulse;10412bA.SynchronizeTransform();10413bB.SynchronizeTransform();10414} {10415tMat = bA.m_xf.R;10416var r1X = this.m_localAnchor1.x - bA.m_sweep.localCenter.x;10417var r1Y = this.m_localAnchor1.y - bA.m_sweep.localCenter.y;10418tX = (tMat.col1.x * r1X + tMat.col2.x * r1Y);10419r1Y = (tMat.col1.y * r1X + tMat.col2.y * r1Y);10420r1X = tX;10421tMat = bB.m_xf.R;10422var r2X = this.m_localAnchor2.x - bB.m_sweep.localCenter.x;10423var r2Y = this.m_localAnchor2.y - bB.m_sweep.localCenter.y;10424tX = (tMat.col1.x * r2X + tMat.col2.x * r2Y);10425r2Y = (tMat.col1.y * r2X + tMat.col2.y * r2Y);10426r2X = tX;10427var CX = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;10428var CY = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;10429var CLengthSquared = CX * CX + CY * CY;10430var CLength = Math.sqrt(CLengthSquared);10431positionError = CLength;10432var invMass1 = bA.m_invMass;10433var invMass2 = bB.m_invMass;10434var invI1 = bA.m_invI;10435var invI2 = bB.m_invI;10436var k_allowedStretch = 10.0 * b2Settings.b2_linearSlop;10437if (CLengthSquared > k_allowedStretch * k_allowedStretch) {10438var uX = CX / CLength;10439var uY = CY / CLength;10440var k = invMass1 + invMass2;10441var m = 1.0 / k;10442impulseX = m * ((-CX));10443impulseY = m * ((-CY));10444var k_beta = 0.5;10445bA.m_sweep.c.x -= k_beta * invMass1 * impulseX;10446bA.m_sweep.c.y -= k_beta * invMass1 * impulseY;10447bB.m_sweep.c.x += k_beta * invMass2 * impulseX;10448bB.m_sweep.c.y += k_beta * invMass2 * impulseY;10449CX = bB.m_sweep.c.x + r2X - bA.m_sweep.c.x - r1X;10450CY = bB.m_sweep.c.y + r2Y - bA.m_sweep.c.y - r1Y;10451}10452this.K1.col1.x = invMass1 + invMass2;10453this.K1.col2.x = 0.0;10454this.K1.col1.y = 0.0;10455this.K1.col2.y = invMass1 + invMass2;10456this.K2.col1.x = invI1 * r1Y * r1Y;10457this.K2.col2.x = (-invI1 * r1X * r1Y);10458this.K2.col1.y = (-invI1 * r1X * r1Y);10459this.K2.col2.y = invI1 * r1X * r1X;10460this.K3.col1.x = invI2 * r2Y * r2Y;10461this.K3.col2.x = (-invI2 * r2X * r2Y);10462this.K3.col1.y = (-invI2 * r2X * r2Y);10463this.K3.col2.y = invI2 * r2X * r2X;10464this.K.SetM(this.K1);10465this.K.AddM(this.K2);10466this.K.AddM(this.K3);10467this.K.Solve(b2RevoluteJoint.tImpulse, (-CX), (-CY));10468impulseX = b2RevoluteJoint.tImpulse.x;10469impulseY = b2RevoluteJoint.tImpulse.y;10470bA.m_sweep.c.x -= bA.m_invMass * impulseX;10471bA.m_sweep.c.y -= bA.m_invMass * impulseY;10472bA.m_sweep.a -= bA.m_invI * (r1X * impulseY - r1Y * impulseX);10473bB.m_sweep.c.x += bB.m_invMass * impulseX;10474bB.m_sweep.c.y += bB.m_invMass * impulseY;10475bB.m_sweep.a += bB.m_invI * (r2X * impulseY - r2Y * impulseX);10476bA.SynchronizeTransform();10477bB.SynchronizeTransform();10478}10479return positionError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;10480}10481Box2D.postDefs.push(function () {10482Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse = new b2Vec2();10483});10484Box2D.inherit(b2RevoluteJointDef, Box2D.Dynamics.Joints.b2JointDef);10485b2RevoluteJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;10486b2RevoluteJointDef.b2RevoluteJointDef = function () {10487Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);10488this.localAnchorA = new b2Vec2();10489this.localAnchorB = new b2Vec2();10490};10491b2RevoluteJointDef.prototype.b2RevoluteJointDef = function () {10492this.__super.b2JointDef.call(this);10493this.type = b2Joint.e_revoluteJoint;10494this.localAnchorA.Set(0.0, 0.0);10495this.localAnchorB.Set(0.0, 0.0);10496this.referenceAngle = 0.0;10497this.lowerAngle = 0.0;10498this.upperAngle = 0.0;10499this.maxMotorTorque = 0.0;10500this.motorSpeed = 0.0;10501this.enableLimit = false;10502this.enableMotor = false;10503}10504b2RevoluteJointDef.prototype.Initialize = function (bA, bB, anchor) {10505this.bodyA = bA;10506this.bodyB = bB;10507this.localAnchorA = this.bodyA.GetLocalPoint(anchor);10508this.localAnchorB = this.bodyB.GetLocalPoint(anchor);10509this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();10510}10511Box2D.inherit(b2WeldJoint, Box2D.Dynamics.Joints.b2Joint);10512b2WeldJoint.prototype.__super = Box2D.Dynamics.Joints.b2Joint.prototype;10513b2WeldJoint.b2WeldJoint = function () {10514Box2D.Dynamics.Joints.b2Joint.b2Joint.apply(this, arguments);10515this.m_localAnchorA = new b2Vec2();10516this.m_localAnchorB = new b2Vec2();10517this.m_impulse = new b2Vec3();10518this.m_mass = new b2Mat33();10519};10520b2WeldJoint.prototype.GetAnchorA = function () {10521return this.m_bodyA.GetWorldPoint(this.m_localAnchorA);10522}10523b2WeldJoint.prototype.GetAnchorB = function () {10524return this.m_bodyB.GetWorldPoint(this.m_localAnchorB);10525}10526b2WeldJoint.prototype.GetReactionForce = function (inv_dt) {10527if (inv_dt === undefined) inv_dt = 0;10528return new b2Vec2(inv_dt * this.m_impulse.x, inv_dt * this.m_impulse.y);10529}10530b2WeldJoint.prototype.GetReactionTorque = function (inv_dt) {10531if (inv_dt === undefined) inv_dt = 0;10532return inv_dt * this.m_impulse.z;10533}10534b2WeldJoint.prototype.b2WeldJoint = function (def) {10535this.__super.b2Joint.call(this, def);10536this.m_localAnchorA.SetV(def.localAnchorA);10537this.m_localAnchorB.SetV(def.localAnchorB);10538this.m_referenceAngle = def.referenceAngle;10539this.m_impulse.SetZero();10540this.m_mass = new b2Mat33();10541}10542b2WeldJoint.prototype.InitVelocityConstraints = function (step) {10543var tMat;10544var tX = 0;10545var bA = this.m_bodyA;10546var bB = this.m_bodyB;10547tMat = bA.m_xf.R;10548var rAX = this.m_localAnchorA.x - bA.m_sweep.localCenter.x;10549var rAY = this.m_localAnchorA.y - bA.m_sweep.localCenter.y;10550tX = (tMat.col1.x * rAX + tMat.col2.x * rAY);10551rAY = (tMat.col1.y * rAX + tMat.col2.y * rAY);10552rAX = tX;10553tMat = bB.m_xf.R;10554var rBX = this.m_localAnchorB.x - bB.m_sweep.localCenter.x;10555var rBY = this.m_localAnchorB.y - bB.m_sweep.localCenter.y;10556tX = (tMat.col1.x * rBX + tMat.col2.x * rBY);10557rBY = (tMat.col1.y * rBX + tMat.col2.y * rBY);10558rBX = tX;10559var mA = bA.m_invMass;10560var mB = bB.m_invMass;10561var iA = bA.m_invI;10562var iB = bB.m_invI;10563this.m_mass.col1.x = mA + mB + rAY * rAY * iA + rBY * rBY * iB;10564this.m_mass.col2.x = (-rAY * rAX * iA) - rBY * rBX * iB;10565this.m_mass.col3.x = (-rAY * iA) - rBY * iB;10566this.m_mass.col1.y = this.m_mass.col2.x;10567this.m_mass.col2.y = mA + mB + rAX * rAX * iA + rBX * rBX * iB;10568this.m_mass.col3.y = rAX * iA + rBX * iB;10569this.m_mass.col1.z = this.m_mass.col3.x;10570this.m_mass.col2.z = this.m_mass.col3.y;10571this.m_mass.col3.z = iA + iB;10572if (step.warmStarting) {10573this.m_impulse.x *= step.dtRatio;10574this.m_impulse.y *= step.dtRatio;10575this.m_impulse.z *= step.dtRatio;10576bA.m_linearVelocity.x -= mA * this.m_impulse.x;10577bA.m_linearVelocity.y -= mA * this.m_impulse.y;10578bA.m_angularVelocity -= iA * (rAX * this.m_impulse.y - rAY * this.m_impulse.x + this.m_impulse.z);10579bB.m_linearVelocity.x += mB * this.m_impulse.x;10580bB.m_linearVelocity.y += mB * this.m_impulse.y;10581bB.m_angularVelocity += iB * (rBX * this.m_impulse.y - rBY * this.m_impulse.x + this.m_impulse.z);10582}10583else {10584this.m_impulse.SetZero();10585}10586}10587b2WeldJoint.prototype.SolveVelocityConstraints = function (step) {10588var tMat;10589var tX = 0;10590var bA = this.m_bodyA;10591var bB = this.m_bodyB;10592var vA = bA.m_linearVelocity;10593var wA = bA.m_angularVelocity;10594var vB = bB.m_linearVelocity;10595var wB = bB.m_angularVelocity;10596var mA = bA.m_invMass;10597var mB = bB.m_invMass;10598var iA = bA.m_invI;10599var iB = bB.m_invI;10600tMat = bA.m_xf.R;10601var rAX = this.m_localAnchorA.x - bA.m_sweep.localCenter.x;10602var rAY = this.m_localAnchorA.y - bA.m_sweep.localCenter.y;10603tX = (tMat.col1.x * rAX + tMat.col2.x * rAY);10604rAY = (tMat.col1.y * rAX + tMat.col2.y * rAY);10605rAX = tX;10606tMat = bB.m_xf.R;10607var rBX = this.m_localAnchorB.x - bB.m_sweep.localCenter.x;10608var rBY = this.m_localAnchorB.y - bB.m_sweep.localCenter.y;10609tX = (tMat.col1.x * rBX + tMat.col2.x * rBY);10610rBY = (tMat.col1.y * rBX + tMat.col2.y * rBY);10611rBX = tX;10612var Cdot1X = vB.x - wB * rBY - vA.x + wA * rAY;10613var Cdot1Y = vB.y + wB * rBX - vA.y - wA * rAX;10614var Cdot2 = wB - wA;10615var impulse = new b2Vec3();10616this.m_mass.Solve33(impulse, (-Cdot1X), (-Cdot1Y), (-Cdot2));10617this.m_impulse.Add(impulse);10618vA.x -= mA * impulse.x;10619vA.y -= mA * impulse.y;10620wA -= iA * (rAX * impulse.y - rAY * impulse.x + impulse.z);10621vB.x += mB * impulse.x;10622vB.y += mB * impulse.y;10623wB += iB * (rBX * impulse.y - rBY * impulse.x + impulse.z);10624bA.m_angularVelocity = wA;10625bB.m_angularVelocity = wB;10626}10627b2WeldJoint.prototype.SolvePositionConstraints = function (baumgarte) {10628if (baumgarte === undefined) baumgarte = 0;10629var tMat;10630var tX = 0;10631var bA = this.m_bodyA;10632var bB = this.m_bodyB;10633tMat = bA.m_xf.R;10634var rAX = this.m_localAnchorA.x - bA.m_sweep.localCenter.x;10635var rAY = this.m_localAnchorA.y - bA.m_sweep.localCenter.y;10636tX = (tMat.col1.x * rAX + tMat.col2.x * rAY);10637rAY = (tMat.col1.y * rAX + tMat.col2.y * rAY);10638rAX = tX;10639tMat = bB.m_xf.R;10640var rBX = this.m_localAnchorB.x - bB.m_sweep.localCenter.x;10641var rBY = this.m_localAnchorB.y - bB.m_sweep.localCenter.y;10642tX = (tMat.col1.x * rBX + tMat.col2.x * rBY);10643rBY = (tMat.col1.y * rBX + tMat.col2.y * rBY);10644rBX = tX;10645var mA = bA.m_invMass;10646var mB = bB.m_invMass;10647var iA = bA.m_invI;10648var iB = bB.m_invI;10649var C1X = bB.m_sweep.c.x + rBX - bA.m_sweep.c.x - rAX;10650var C1Y = bB.m_sweep.c.y + rBY - bA.m_sweep.c.y - rAY;10651var C2 = bB.m_sweep.a - bA.m_sweep.a - this.m_referenceAngle;10652var k_allowedStretch = 10.0 * b2Settings.b2_linearSlop;10653var positionError = Math.sqrt(C1X * C1X + C1Y * C1Y);10654var angularError = b2Math.Abs(C2);10655if (positionError > k_allowedStretch) {10656iA *= 1.0;10657iB *= 1.0;10658}10659this.m_mass.col1.x = mA + mB + rAY * rAY * iA + rBY * rBY * iB;10660this.m_mass.col2.x = (-rAY * rAX * iA) - rBY * rBX * iB;10661this.m_mass.col3.x = (-rAY * iA) - rBY * iB;10662this.m_mass.col1.y = this.m_mass.col2.x;10663this.m_mass.col2.y = mA + mB + rAX * rAX * iA + rBX * rBX * iB;10664this.m_mass.col3.y = rAX * iA + rBX * iB;10665this.m_mass.col1.z = this.m_mass.col3.x;10666this.m_mass.col2.z = this.m_mass.col3.y;10667this.m_mass.col3.z = iA + iB;10668var impulse = new b2Vec3();10669this.m_mass.Solve33(impulse, (-C1X), (-C1Y), (-C2));10670bA.m_sweep.c.x -= mA * impulse.x;10671bA.m_sweep.c.y -= mA * impulse.y;10672bA.m_sweep.a -= iA * (rAX * impulse.y - rAY * impulse.x + impulse.z);10673bB.m_sweep.c.x += mB * impulse.x;10674bB.m_sweep.c.y += mB * impulse.y;10675bB.m_sweep.a += iB * (rBX * impulse.y - rBY * impulse.x + impulse.z);10676bA.SynchronizeTransform();10677bB.SynchronizeTransform();10678return positionError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;10679}10680Box2D.inherit(b2WeldJointDef, Box2D.Dynamics.Joints.b2JointDef);10681b2WeldJointDef.prototype.__super = Box2D.Dynamics.Joints.b2JointDef.prototype;10682b2WeldJointDef.b2WeldJointDef = function () {10683Box2D.Dynamics.Joints.b2JointDef.b2JointDef.apply(this, arguments);10684this.localAnchorA = new b2Vec2();10685this.localAnchorB = new b2Vec2();10686};10687b2WeldJointDef.prototype.b2WeldJointDef = function () {10688this.__super.b2JointDef.call(this);10689this.type = b2Joint.e_weldJoint;10690this.referenceAngle = 0.0;10691}10692b2WeldJointDef.prototype.Initialize = function (bA, bB, anchor) {10693this.bodyA = bA;10694this.bodyB = bB;10695this.localAnchorA.SetV(this.bodyA.GetLocalPoint(anchor));10696this.localAnchorB.SetV(this.bodyB.GetLocalPoint(anchor));10697this.referenceAngle = this.bodyB.GetAngle() - this.bodyA.GetAngle();10698}10699})();10700(function () {10701var b2DebugDraw = Box2D.Dynamics.b2DebugDraw;10702b2DebugDraw.b2DebugDraw = function () {10703this.m_drawScale = 1.0;10704this.m_lineThickness = 1.0;10705this.m_alpha = 1.0;10706this.m_fillAlpha = 1.0;10707this.m_xformScale = 1.0;10708var __this = this;10709//#WORKAROUND10710this.m_sprite = {10711graphics: {10712clear: function () {10713__this.m_ctx.clearRect(0, 0, __this.m_ctx.canvas.width, __this.m_ctx.canvas.height)10714}10715}10716};10717};10718b2DebugDraw.prototype._color = function (color, alpha) {10719return "rgba(" + ((color & 0xFF0000) >> 16) + "," + ((color & 0xFF00) >> 8) + "," + (color & 0xFF) + "," + alpha + ")";10720};10721b2DebugDraw.prototype.b2DebugDraw = function () {10722this.m_drawFlags = 0;10723};10724b2DebugDraw.prototype.SetFlags = function (flags) {10725if (flags === undefined) flags = 0;10726this.m_drawFlags = flags;10727};10728b2DebugDraw.prototype.GetFlags = function () {10729return this.m_drawFlags;10730};10731b2DebugDraw.prototype.AppendFlags = function (flags) {10732if (flags === undefined) flags = 0;10733this.m_drawFlags |= flags;10734};10735b2DebugDraw.prototype.ClearFlags = function (flags) {10736if (flags === undefined) flags = 0;10737this.m_drawFlags &= ~flags;10738};10739b2DebugDraw.prototype.SetSprite = function (sprite) {10740this.m_ctx = sprite;10741};10742b2DebugDraw.prototype.GetSprite = function () {10743return this.m_ctx;10744};10745b2DebugDraw.prototype.SetDrawScale = function (drawScale) {10746if (drawScale === undefined) drawScale = 0;10747this.m_drawScale = drawScale;10748};10749b2DebugDraw.prototype.GetDrawScale = function () {10750return this.m_drawScale;10751};10752b2DebugDraw.prototype.SetLineThickness = function (lineThickness) {10753if (lineThickness === undefined) lineThickness = 0;10754this.m_lineThickness = lineThickness;10755this.m_ctx.strokeWidth = lineThickness;10756};10757b2DebugDraw.prototype.GetLineThickness = function () {10758return this.m_lineThickness;10759};10760b2DebugDraw.prototype.SetAlpha = function (alpha) {10761if (alpha === undefined) alpha = 0;10762this.m_alpha = alpha;10763};10764b2DebugDraw.prototype.GetAlpha = function () {10765return this.m_alpha;10766};10767b2DebugDraw.prototype.SetFillAlpha = function (alpha) {10768if (alpha === undefined) alpha = 0;10769this.m_fillAlpha = alpha;10770};10771b2DebugDraw.prototype.GetFillAlpha = function () {10772return this.m_fillAlpha;10773};10774b2DebugDraw.prototype.SetXFormScale = function (xformScale) {10775if (xformScale === undefined) xformScale = 0;10776this.m_xformScale = xformScale;10777};10778b2DebugDraw.prototype.GetXFormScale = function () {10779return this.m_xformScale;10780};10781b2DebugDraw.prototype.DrawPolygon = function (vertices, vertexCount, color) {10782if (!vertexCount) return;10783var s = this.m_ctx;10784var drawScale = this.m_drawScale;10785s.beginPath();10786s.strokeStyle = this._color(color.color, this.m_alpha);10787s.moveTo(vertices[0].x * drawScale, vertices[0].y * drawScale);10788for (var i = 1; i < vertexCount; i++) {10789s.lineTo(vertices[i].x * drawScale, vertices[i].y * drawScale);10790}10791s.lineTo(vertices[0].x * drawScale, vertices[0].y * drawScale);10792s.closePath();10793s.stroke();10794};10795b2DebugDraw.prototype.DrawSolidPolygon = function (vertices, vertexCount, color) {10796if (!vertexCount) return;10797var s = this.m_ctx;10798var drawScale = this.m_drawScale;10799s.beginPath();10800s.strokeStyle = this._color(color.color, this.m_alpha);10801s.fillStyle = this._color(color.color, this.m_fillAlpha);10802s.moveTo(vertices[0].x * drawScale, vertices[0].y * drawScale);10803for (var i = 1; i < vertexCount; i++) {10804s.lineTo(vertices[i].x * drawScale, vertices[i].y * drawScale);10805}10806s.lineTo(vertices[0].x * drawScale, vertices[0].y * drawScale);10807s.closePath();10808s.fill();10809s.stroke();10810};10811b2DebugDraw.prototype.DrawCircle = function (center, radius, color) {10812if (!radius) return;10813var s = this.m_ctx;10814var drawScale = this.m_drawScale;10815s.beginPath();10816s.strokeStyle = this._color(color.color, this.m_alpha);10817s.arc(center.x * drawScale, center.y * drawScale, radius * drawScale, 0, Math.PI * 2, true);10818s.closePath();10819s.stroke();10820};10821b2DebugDraw.prototype.DrawSolidCircle = function (center, radius, axis, color) {10822if (!radius) return;10823var s = this.m_ctx,10824drawScale = this.m_drawScale,10825cx = center.x * drawScale,10826cy = center.y * drawScale;10827s.moveTo(0, 0);10828s.beginPath();10829s.strokeStyle = this._color(color.color, this.m_alpha);10830s.fillStyle = this._color(color.color, this.m_fillAlpha);10831s.arc(cx, cy, radius * drawScale, 0, Math.PI * 2, true);10832s.moveTo(cx, cy);10833s.lineTo((center.x + axis.x * radius) * drawScale, (center.y + axis.y * radius) * drawScale);10834s.closePath();10835s.fill();10836s.stroke();10837};10838b2DebugDraw.prototype.DrawSegment = function (p1, p2, color) {10839var s = this.m_ctx,10840drawScale = this.m_drawScale;10841s.strokeStyle = this._color(color.color, this.m_alpha);10842s.beginPath();10843s.moveTo(p1.x * drawScale, p1.y * drawScale);10844s.lineTo(p2.x * drawScale, p2.y * drawScale);10845s.closePath();10846s.stroke();10847};10848b2DebugDraw.prototype.DrawTransform = function (xf) {10849var s = this.m_ctx,10850drawScale = this.m_drawScale;10851s.beginPath();10852s.strokeStyle = this._color(0xff0000, this.m_alpha);10853s.moveTo(xf.position.x * drawScale, xf.position.y * drawScale);10854s.lineTo((xf.position.x + this.m_xformScale * xf.R.col1.x) * drawScale, (xf.position.y + this.m_xformScale * xf.R.col1.y) * drawScale);1085510856s.strokeStyle = this._color(0xff00, this.m_alpha);10857s.moveTo(xf.position.x * drawScale, xf.position.y * drawScale);10858s.lineTo((xf.position.x + this.m_xformScale * xf.R.col2.x) * drawScale, (xf.position.y + this.m_xformScale * xf.R.col2.y) * drawScale);10859s.closePath();10860s.stroke();10861};10862})(); //post-definitions10863var i;10864for (i = 0; i < Box2D.postDefs.length; ++i) Box2D.postDefs[i]();10865delete Box2D.postDefs;1086610867