├── README ├── bower.json ├── contrib ├── enhancements │ └── controllers │ │ ├── buoyancycontroller.js │ │ ├── constantaccelcontroller.js │ │ ├── constantforcecontroller.js │ │ ├── controller.js │ │ ├── gravitycontroller.js │ │ └── tensordampingcontroller.js └── paths.json ├── lib ├── box2d.js ├── collision │ ├── broadphase.js │ ├── collidecircle.js │ ├── collideedge.js │ ├── collidepolygon.js │ ├── collision.js │ ├── distance.js │ ├── dynamictree.js │ ├── shapes │ │ ├── chainshape.js │ │ ├── circleshape.js │ │ ├── edgeshape.js │ │ ├── polygonshape.js │ │ └── shape.js │ └── timeofimpact.js ├── common │ ├── blockallocator.js │ ├── draw.js │ ├── growablestack.js │ ├── math.js │ ├── settings.js │ ├── stackallocator.js │ └── timer.js ├── dynamics │ ├── body.js │ ├── contactmanager.js │ ├── contacts │ │ ├── chainandcirclecontact.js │ │ ├── chainandpolygoncontact.js │ │ ├── circlecontact.js │ │ ├── contact.js │ │ ├── contactfactory.js │ │ ├── contactsolver.js │ │ ├── edgeandcirclecontact.js │ │ ├── edgeandpolygoncontact.js │ │ ├── polygonandcirclecontact.js │ │ └── polygoncontact.js │ ├── fixture.js │ ├── island.js │ ├── joints │ │ ├── areajoint.js │ │ ├── distancejoint.js │ │ ├── frictionjoint.js │ │ ├── gearjoint.js │ │ ├── joint.js │ │ ├── jointfactory.js │ │ ├── motorjoint.js │ │ ├── mousejoint.js │ │ ├── prismaticjoint.js │ │ ├── pulleyjoint.js │ │ ├── revolutejoint.js │ │ ├── ropejoint.js │ │ ├── weldjoint.js │ │ └── wheeljoint.js │ ├── timestep.js │ ├── world.js │ └── worldcallbacks.js ├── paths.json └── rope │ └── rope.js ├── package.json ├── package ├── box2d-html5-testbed.js └── box2d-html5.js ├── requirements ├── promise.js └── require.js ├── test ├── framework │ ├── main.js │ ├── render.js │ └── test.js ├── load.html ├── load.package.html ├── loader.js ├── paths.json ├── testbed.html ├── testbed.js ├── testbed.package.html └── tests │ ├── addpair.js │ ├── applyforce.js │ ├── blobtest.js │ ├── bodytypes.js │ ├── breakable.js │ ├── bridge.js │ ├── bullettest.js │ ├── buoyancytest.js │ ├── cantilever.js │ ├── car.js │ ├── chain.js │ ├── charactercollision.js │ ├── collisionfiltering.js │ ├── collisionprocessing.js │ ├── compoundshapes.js │ ├── confined.js │ ├── continuoustest.js │ ├── convexhull.js │ ├── conveyorbelt.js │ ├── distancetest.js │ ├── dominos.js │ ├── dumpshell.js │ ├── dynamictreetest.js │ ├── edgeshapes.js │ ├── edgetest.js │ ├── gears.js │ ├── mobile.js │ ├── mobilebalanced.js │ ├── motorjoint.js │ ├── onesidedplatform.js │ ├── pinball.js │ ├── polycollision.js │ ├── polyshapes.js │ ├── prismatic.js │ ├── pulleys.js │ ├── pyramid.js │ ├── raycast.js │ ├── revolute.js │ ├── rope.js │ ├── ropejoint.js │ ├── sensortest.js │ ├── shapeediting.js │ ├── slidercrank.js │ ├── spherestack.js │ ├── testccd.js │ ├── testentries.js │ ├── testragdoll.js │ ├── teststack.js │ ├── theojansen.js │ ├── tiles.js │ ├── timeofimpact.js │ ├── tumbler.js │ ├── varyingfriction.js │ ├── varyingrestitution.js │ ├── verticalstack.js │ └── web.js └── utils ├── goog ├── base.js ├── browserevent.js ├── browserfeature.js ├── event.js ├── eventid.js ├── eventtype.js ├── keycodes.js ├── reflect.js ├── string.js ├── stringformat.js └── useragent.js └── paths.json /README: -------------------------------------------------------------------------------- 1 | box2d-html5 2 | ----------- 3 | 4 | An HTML5 port of Box2D physics engine. 5 | 6 | Box2D is an open source C++ engine for simulating rigid bodies in 2D. 7 | Box2D is developed by Erin Catto and has the zlib license. 8 | 9 | This port is based on the work done by Isaac Burns. 10 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "box2d-html5", 3 | "version": "0.1.230", 4 | "description": "A 2D Physics Engine for HTML5 Games", 5 | "keywords": ["box2d", "html5", "game", "physics", "engine"], 6 | "main": "package/box2d-html5.js", 7 | "ignore": ["*", "!package/box2d-html5.js", "!README"], 8 | "repository": { 9 | "type": "git", 10 | "url": "git@github.com:mvasilkov/box2d-html5.git" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /contrib/enhancements/controllers/constantaccelcontroller.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_controller', 'mod_box2d_math', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2ConstantAccelController'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2ConstantAccelController === 'undefined') 26 | box2d.b2ConstantAccelController = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Controller'); 31 | // -removed- goog.require('box2d.b2Math'); 32 | 33 | /** 34 | * Applies a force every frame 35 | * @export 36 | * @constructor 37 | * @extends {box2d.b2Controller} 38 | */ 39 | box2d.b2ConstantAccelController = function () 40 | { 41 | goog.base(this); // base class constructor 42 | 43 | this.A = new box2d.b2Vec2(0, 0); 44 | }; 45 | 46 | goog.inherits(box2d.b2ConstantAccelController, box2d.b2Controller); 47 | 48 | /** 49 | * The acceleration to apply 50 | * @export 51 | * @type {box2d.b2Vec2} 52 | */ 53 | box2d.b2ConstantAccelController.prototype.A = null; 54 | 55 | /** 56 | * @see box2d.b2Controller::Step 57 | * @export 58 | * @return {void} 59 | * @param {box2d.b2TimeStep} step 60 | */ 61 | box2d.b2ConstantAccelController.prototype.Step = function (step) 62 | { 63 | var dtA = box2d.b2MulSV(step.dt, this.A, box2d.b2ConstantAccelController.prototype.Step.s_dtA); 64 | for (var i = this.m_bodyList; i; i = i.nextBody) 65 | { 66 | var body = i.body; 67 | if (!body.IsAwake()) 68 | continue; 69 | body.SetLinearVelocity(box2d.b2AddVV(body.GetLinearVelocity(), dtA, box2d.b2Vec2.s_t0)); 70 | } 71 | } 72 | box2d.b2ConstantAccelController.prototype.Step.s_dtA = new box2d.b2Vec2(); 73 | 74 | return box2d 75 | }) 76 | // End auto-generated code. 77 | -------------------------------------------------------------------------------- /contrib/enhancements/controllers/constantforcecontroller.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_controller', 'mod_box2d_math', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2ConstantForceController'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2ConstantForceController === 'undefined') 26 | box2d.b2ConstantForceController = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Controller'); 31 | // -removed- goog.require('box2d.b2Math'); 32 | 33 | /** 34 | * Applies a force every frame 35 | * @export 36 | * @constructor 37 | * @extends {box2d.b2Controller} 38 | */ 39 | box2d.b2ConstantForceController = function () 40 | { 41 | goog.base(this); // base class constructor 42 | 43 | this.F = new box2d.b2Vec2(0, 0); 44 | }; 45 | 46 | goog.inherits(box2d.b2ConstantForceController, box2d.b2Controller); 47 | 48 | /** 49 | * The force to apply 50 | * @export 51 | * @type {box2d.b2Vec2} 52 | */ 53 | box2d.b2ConstantForceController.prototype.F = null; 54 | 55 | /** 56 | * @see box2d.b2Controller::Step 57 | * @export 58 | * @return {void} 59 | * @param {box2d.b2TimeStep} step 60 | */ 61 | box2d.b2ConstantForceController.prototype.Step = function (step) 62 | { 63 | for (var i = this.m_bodyList; i; i = i.nextBody) 64 | { 65 | var body = i.body; 66 | if (!body.IsAwake()) 67 | continue; 68 | body.ApplyForce(this.F, body.GetWorldCenter()); 69 | } 70 | } 71 | 72 | return box2d 73 | }) 74 | // End auto-generated code. 75 | -------------------------------------------------------------------------------- /contrib/enhancements/controllers/gravitycontroller.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_controller', 'mod_box2d_math', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2GravityController'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2GravityController === 'undefined') 26 | box2d.b2GravityController = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Controller'); 31 | // -removed- goog.require('box2d.b2Math'); 32 | 33 | /** 34 | * Applies simplified gravity between every pair of bodies 35 | * @export 36 | * @constructor 37 | * @extends {box2d.b2Controller} 38 | */ 39 | box2d.b2GravityController = function () 40 | { 41 | goog.base(this); // base class constructor 42 | }; 43 | 44 | goog.inherits(box2d.b2GravityController, box2d.b2Controller); 45 | 46 | /** 47 | * Specifies the strength of the gravitiation force 48 | * @export 49 | * @type {number} 50 | */ 51 | box2d.b2GravityController.prototype.G = 1; 52 | /** 53 | * If true, gravity is proportional to r^-2, otherwise r^-1 54 | * @export 55 | * @type {boolean} 56 | */ 57 | box2d.b2GravityController.prototype.invSqr = true; 58 | 59 | /** 60 | * @see b2Controller::Step 61 | * @export 62 | * @return {void} 63 | * @param {box2d.b2TimeStep} step 64 | */ 65 | box2d.b2GravityController.prototype.Step = function (step) 66 | { 67 | if (this.invSqr) 68 | { 69 | for (var i = this.m_bodyList; i; i = i.nextBody) 70 | { 71 | var body1 = i.body; 72 | var p1 = body1.GetWorldCenter(); 73 | var mass1 = body1.GetMass(); 74 | for (var j = this.m_bodyList; j != i; j = j.nextBody) 75 | { 76 | var body2 = j.body; 77 | var p2 = body2.GetWorldCenter(); 78 | var mass2 = body2.GetMass(); 79 | var dx = p2.x - p1.x; 80 | var dy = p2.y - p1.y; 81 | var r2 = dx * dx + dy * dy; 82 | if (r2 < box2d.b2_epsilon) 83 | continue; 84 | var f = box2d.b2GravityController.prototype.Step.s_f.Set(dx, dy); 85 | f.SelfMul(this.G / r2 / box2d.b2Sqrt(r2) * mass1 * mass2); 86 | if (body1.IsAwake()) 87 | body1.ApplyForce(f, p1); 88 | if (body2.IsAwake()) 89 | body2.ApplyForce(f.SelfMul(-1), p2); 90 | } 91 | } 92 | } 93 | else 94 | { 95 | for (var i = this.m_bodyList; i; i = i.nextBody) 96 | { 97 | var body1 = i.body; 98 | var p1 = body1.GetWorldCenter(); 99 | var mass1 = body1.GetMass(); 100 | for (var j = this.m_bodyList; j != i; j = j.nextBody) 101 | { 102 | var body2 = j.body; 103 | var p2 = body2.GetWorldCenter(); 104 | var mass2 = body2.GetMass(); 105 | var dx = p2.x - p1.x; 106 | var dy = p2.y - p1.y; 107 | var r2 = dx * dx + dy * dy; 108 | if (r2 < box2d.b2_epsilon) 109 | continue; 110 | var f = box2d.b2GravityController.prototype.Step.s_f.Set(dx, dy); 111 | f.SelfMul(this.G / r2 * mass1 * mass2); 112 | if (body1.IsAwake()) 113 | body1.ApplyForce(f, p1); 114 | if (body2.IsAwake()) 115 | body2.ApplyForce(f.SelfMul(-1), p2); 116 | } 117 | } 118 | } 119 | } 120 | box2d.b2GravityController.prototype.Step.s_f = new box2d.b2Vec2(); 121 | 122 | return box2d 123 | }) 124 | // End auto-generated code. 125 | -------------------------------------------------------------------------------- /contrib/enhancements/controllers/tensordampingcontroller.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_controller', 'mod_box2d_math', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2TensorDampingController'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2TensorDampingController === 'undefined') 26 | box2d.b2TensorDampingController = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Controller'); 31 | // -removed- goog.require('box2d.b2Math'); 32 | 33 | /** 34 | * Applies top down linear damping to the controlled bodies 35 | * The damping is calculated by multiplying velocity by a matrix 36 | * in local co-ordinates. 37 | * @export 38 | * @constructor 39 | * @extends {box2d.b2Controller} 40 | */ 41 | box2d.b2TensorDampingController = function () 42 | { 43 | goog.base(this); // base class constructor 44 | 45 | /// Tensor to use in damping model 46 | /** @type {box2d.b2Mat22} */ this.T = new box2d.b2Mat22(); 47 | /*Some examples (matrixes in format (row1; row2)) 48 | (-a 0; 0 -a) Standard isotropic damping with strength a 49 | ( 0 a; -a 0) Electron in fixed field - a force at right angles to velocity with proportional magnitude 50 | (-a 0; 0 -b) Differing x and y damping. Useful e.g. for top-down wheels. 51 | */ 52 | //By the way, tensor in this case just means matrix, don't let the terminology get you down. 53 | 54 | /// Set this to a positive number to clamp the maximum amount of damping done. 55 | /** @type {number} */ this.maxTimestep = 0; 56 | // Typically one wants maxTimestep to be 1/(max eigenvalue of T), so that damping will never cause something to reverse direction 57 | }; 58 | 59 | goog.inherits(box2d.b2TensorDampingController, box2d.b2Controller); 60 | 61 | /** 62 | * Tensor to use in damping model 63 | * @export 64 | * @type {box2d.b2Mat22} 65 | */ 66 | box2d.b2TensorDampingController.prototype.T = new box2d.b2Mat22(); 67 | /*Some examples (matrixes in format (row1; row2)) 68 | (-a 0; 0 -a) Standard isotropic damping with strength a 69 | ( 0 a; -a 0) Electron in fixed field - a force at right angles to velocity with proportional magnitude 70 | (-a 0; 0 -b) Differing x and y damping. Useful e.g. for top-down wheels. 71 | */ 72 | //By the way, tensor in this case just means matrix, don't let the terminology get you down. 73 | 74 | /** 75 | * Set this to a positive number to clamp the maximum amount of 76 | * damping done. 77 | * @export 78 | * @type {number} 79 | */ 80 | box2d.b2TensorDampingController.prototype.maxTimestep = 0; 81 | // Typically one wants maxTimestep to be 1/(max eigenvalue of T), so that damping will never cause something to reverse direction 82 | 83 | /** 84 | * @see b2Controller::Step 85 | * @return {void} 86 | * @param {box2d.b2TimeStep} step 87 | */ 88 | box2d.b2TensorDampingController.prototype.Step = function (step) 89 | { 90 | var timestep = step.dt; 91 | if (timestep <= box2d.b2_epsilon) 92 | return; 93 | if (timestep > this.maxTimestep && this.maxTimestep > 0) 94 | timestep = this.maxTimestep; 95 | for (var i = this.m_bodyList; i; i = i.nextBody) 96 | { 97 | var body = i.body; 98 | if (!body.IsAwake()) 99 | continue; 100 | var damping = body.GetWorldVector( 101 | box2d.b2MulMV( 102 | this.T, 103 | body.GetLocalVector( 104 | body.GetLinearVelocity(), 105 | box2d.b2Vec2.s_t0), 106 | box2d.b2Vec2.s_t1), 107 | box2d.b2TensorDampingController.prototype.Step.s_damping); 108 | // body->SetLinearVelocity(body->GetLinearVelocity() + timestep * damping); 109 | body.SetLinearVelocity(box2d.b2AddVV(body.GetLinearVelocity(), box2d.b2MulSV(timestep, damping, box2d.b2Vec2.s_t0), box2d.b2Vec2.s_t1)); 110 | } 111 | } 112 | box2d.b2TensorDampingController.prototype.Step.s_damping = new box2d.b2Vec2(); 113 | 114 | /** 115 | * Sets damping independantly along the x and y axes 116 | * @return {void} 117 | * @param {number} xDamping 118 | * @param {number} yDamping 119 | */ 120 | box2d.b2TensorDampingController.prototype.SetAxisAligned = function (xDamping, yDamping) 121 | { 122 | this.T.ex.x = (-xDamping); 123 | this.T.ex.y = 0; 124 | this.T.ey.x = 0; 125 | this.T.ey.y = (-yDamping); 126 | if (xDamping > 0 || yDamping > 0) 127 | { 128 | this.maxTimestep = 1 / box2d.b2Max(xDamping, yDamping); 129 | } 130 | else 131 | { 132 | this.maxTimestep = 0; 133 | } 134 | } 135 | 136 | return box2d 137 | }) 138 | // End auto-generated code. 139 | -------------------------------------------------------------------------------- /contrib/paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "mod_box2d_buoyancycontroller": "contrib/enhancements/controllers/buoyancycontroller", 3 | "mod_box2d_constantaccelcontroller": "contrib/enhancements/controllers/constantaccelcontroller", 4 | "mod_box2d_constantforcecontroller": "contrib/enhancements/controllers/constantforcecontroller", 5 | "mod_box2d_controller": "contrib/enhancements/controllers/controller", 6 | "mod_box2d_gravitycontroller": "contrib/enhancements/controllers/gravitycontroller", 7 | "mod_box2d_tensordampingcontroller": "contrib/enhancements/controllers/tensordampingcontroller" 8 | } 9 | -------------------------------------------------------------------------------- /lib/box2d.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_areajoint', 'mod_box2d_body', 'mod_box2d_broadphase', 'mod_box2d_buoyancycontroller', 'mod_box2d_chainshape', 'mod_box2d_circleshape', 'mod_box2d_constantaccelcontroller', 'mod_box2d_constantforcecontroller', 'mod_box2d_contact', 'mod_box2d_distance', 'mod_box2d_distancejoint', 'mod_box2d_draw', 'mod_box2d_dynamictree', 'mod_box2d_edgeshape', 'mod_box2d_fixture', 'mod_box2d_frictionjoint', 'mod_box2d_gearjoint', 'mod_box2d_gravitycontroller', 'mod_box2d_motorjoint', 'mod_box2d_mousejoint', 'mod_box2d_polygonshape', 'mod_box2d_prismaticjoint', 'mod_box2d_pulleyjoint', 'mod_box2d_revolutejoint', 'mod_box2d_rope', 'mod_box2d_ropejoint', 'mod_box2d_settings', 'mod_box2d_tensordampingcontroller', 'mod_box2d_timeofimpact', 'mod_box2d_timestep', 'mod_box2d_timer', 'mod_box2d_weldjoint', 'mod_box2d_wheeljoint', 'mod_box2d_world', 'mod_box2d_worldcallbacks'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | 26 | 27 | /** 28 | \mainpage Box2D API Documentation 29 | 30 | \section intro_sec Getting Started 31 | 32 | For documentation please see http://box2d.org/documentation.html 33 | 34 | For discussion please visit http://box2d.org/forum 35 | */ 36 | 37 | // These include files constitute the main Box2D API 38 | 39 | // -removed- goog.require('box2d.b2Settings'); 40 | // -removed- goog.require('box2d.b2Draw'); 41 | // -removed- goog.require('box2d.b2Timer'); 42 | 43 | // -removed- goog.require('box2d.b2CircleShape'); 44 | // -removed- goog.require('box2d.b2EdgeShape'); 45 | // -removed- goog.require('box2d.b2ChainShape'); 46 | // -removed- goog.require('box2d.b2PolygonShape'); 47 | 48 | // -removed- goog.require('box2d.b2BroadPhase'); 49 | // -removed- goog.require('box2d.b2Distance'); 50 | // -removed- goog.require('box2d.b2DynamicTree'); 51 | // -removed- goog.require('box2d.b2TimeOfImpact'); 52 | 53 | // -removed- goog.require('box2d.b2Body'); 54 | // -removed- goog.require('box2d.b2Fixture'); 55 | // -removed- goog.require('box2d.b2WorldCallbacks'); 56 | // -removed- goog.require('box2d.b2TimeStep'); 57 | // -removed- goog.require('box2d.b2World'); 58 | 59 | // -removed- goog.require('box2d.b2Contact'); 60 | 61 | // -removed- goog.require('box2d.b2AreaJoint'); 62 | // -removed- goog.require('box2d.b2DistanceJoint'); 63 | // -removed- goog.require('box2d.b2FrictionJoint'); 64 | // -removed- goog.require('box2d.b2GearJoint'); 65 | // -removed- goog.require('box2d.b2MotorJoint'); 66 | // -removed- goog.require('box2d.b2MouseJoint'); 67 | // -removed- goog.require('box2d.b2PrismaticJoint'); 68 | // -removed- goog.require('box2d.b2PulleyJoint'); 69 | // -removed- goog.require('box2d.b2RevoluteJoint'); 70 | // -removed- goog.require('box2d.b2RopeJoint'); 71 | // -removed- goog.require('box2d.b2WeldJoint'); 72 | // -removed- goog.require('box2d.b2WheelJoint'); 73 | 74 | // -removed- goog.require('box2d.b2Rope'); 75 | 76 | // -removed- goog.require('box2d.b2BuoyancyController'); 77 | // -removed- goog.require('box2d.b2ConstantAccelController'); 78 | // -removed- goog.require('box2d.b2ConstantForceController'); 79 | // -removed- goog.require('box2d.b2GravityController'); 80 | // -removed- goog.require('box2d.b2TensorDampingController'); 81 | 82 | return box2d 83 | }) 84 | // End auto-generated code. 85 | -------------------------------------------------------------------------------- /lib/common/blockallocator.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog'], function (goog) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2BlockAllocator'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2BlockAllocator === 'undefined') 26 | box2d.b2BlockAllocator = {} 27 | 28 | 29 | /** 30 | * @export 31 | * @constructor 32 | */ 33 | box2d.b2BlockAllocator = function () 34 | { 35 | } 36 | 37 | return box2d 38 | }) 39 | // End auto-generated code. 40 | -------------------------------------------------------------------------------- /lib/common/growablestack.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2010 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2GrowableStack'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2GrowableStack === 'undefined') 26 | box2d.b2GrowableStack = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | 31 | /** 32 | * This is a growable LIFO stack with an initial capacity of N. 33 | * If the stack size exceeds the initial capacity, the heap is 34 | * used to increase the size of the stack. 35 | * @export 36 | * @constructor 37 | * @param {number} N 38 | */ 39 | box2d.b2GrowableStack = function (N) 40 | { 41 | this.m_stack = new Array(N); 42 | } 43 | 44 | /** 45 | * @export 46 | * @type {Array.<*>} 47 | */ 48 | box2d.b2GrowableStack.prototype.m_stack = null; 49 | /** 50 | * @export 51 | * @type {number} 52 | */ 53 | box2d.b2GrowableStack.prototype.m_count = 0; 54 | 55 | /** 56 | * @export 57 | * @return {box2d.b2GrowableStack} 58 | */ 59 | box2d.b2GrowableStack.prototype.Reset = function () 60 | { 61 | this.m_count = 0; 62 | return this; 63 | } 64 | 65 | /** 66 | * @export 67 | * @return {void} 68 | * @param {*} element 69 | */ 70 | box2d.b2GrowableStack.prototype.Push = function (element) 71 | { 72 | this.m_stack[this.m_count] = element; 73 | ++this.m_count; 74 | } 75 | 76 | /** 77 | * @export 78 | * @return {*} 79 | */ 80 | box2d.b2GrowableStack.prototype.Pop = function () 81 | { 82 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(this.m_count > 0); } 83 | --this.m_count; 84 | var element = this.m_stack[this.m_count]; 85 | this.m_stack[this.m_count] = null; 86 | return element; 87 | } 88 | 89 | /** 90 | * @export 91 | * @return {number} 92 | */ 93 | box2d.b2GrowableStack.prototype.GetCount = function () 94 | { 95 | return this.m_count; 96 | } 97 | 98 | return box2d 99 | }) 100 | // End auto-generated code. 101 | -------------------------------------------------------------------------------- /lib/common/stackallocator.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog'], function (goog) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2StackAllocator'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2StackAllocator === 'undefined') 26 | box2d.b2StackAllocator = {} 27 | 28 | 29 | /** 30 | * @export 31 | * @constructor 32 | */ 33 | box2d.b2StackAllocator = function () 34 | { 35 | } 36 | 37 | return box2d 38 | }) 39 | // End auto-generated code. 40 | -------------------------------------------------------------------------------- /lib/common/timer.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2Timer'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2Timer === 'undefined') 26 | box2d.b2Timer = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | 31 | /** 32 | * Timer for profiling. This has platform specific code and may 33 | * not work on every platform. 34 | * @export 35 | * @constructor 36 | */ 37 | box2d.b2Timer = function () 38 | { 39 | this.m_start = new Date().getTime(); 40 | } 41 | 42 | /** 43 | * @export 44 | * @type {number} 45 | */ 46 | box2d.b2Timer.prototype.m_start = 0; 47 | 48 | /** 49 | * @export 50 | * @return {box2d.b2Timer} 51 | */ 52 | box2d.b2Timer.prototype.Reset = function () 53 | { 54 | this.m_start = new Date().getTime(); 55 | return this; 56 | } 57 | 58 | /** 59 | * @export 60 | * @return {number} 61 | */ 62 | box2d.b2Timer.prototype.GetMilliseconds = function () 63 | { 64 | return new Date().getTime() - this.m_start; 65 | } 66 | 67 | /** 68 | * @export 69 | * @constructor 70 | */ 71 | box2d.b2Counter = function () 72 | { 73 | } 74 | 75 | /** 76 | * @export 77 | * @type {number} 78 | */ 79 | box2d.b2Counter.prototype.m_count = 0; 80 | /** 81 | * @export 82 | * @type {number} 83 | */ 84 | box2d.b2Counter.prototype.m_min_count = 0; 85 | /** 86 | * @export 87 | * @type {number} 88 | */ 89 | box2d.b2Counter.prototype.m_max_count = 0; 90 | 91 | /** 92 | * @export 93 | * @return {number} 94 | */ 95 | box2d.b2Counter.prototype.GetCount = function () 96 | { 97 | return this.m_count; 98 | } 99 | 100 | /** 101 | * @export 102 | * @return {number} 103 | */ 104 | box2d.b2Counter.prototype.GetMinCount = function () 105 | { 106 | return this.m_min_count; 107 | } 108 | 109 | /** 110 | * @export 111 | * @return {number} 112 | */ 113 | box2d.b2Counter.prototype.GetMaxCount = function () 114 | { 115 | return this.m_max_count; 116 | } 117 | 118 | /** 119 | * @export 120 | * @return {number} 121 | */ 122 | box2d.b2Counter.prototype.ResetCount = function () 123 | { 124 | var count = this.m_count; 125 | this.m_count = 0; 126 | return count; 127 | } 128 | 129 | /** 130 | * @export 131 | * @return {void} 132 | */ 133 | box2d.b2Counter.prototype.ResetMinCount = function () 134 | { 135 | this.m_min_count = 0; 136 | } 137 | 138 | /** 139 | * @export 140 | * @return {void} 141 | */ 142 | box2d.b2Counter.prototype.ResetMaxCount = function () 143 | { 144 | this.m_max_count = 0; 145 | } 146 | 147 | /** 148 | * @export 149 | * @return {void} 150 | */ 151 | box2d.b2Counter.prototype.Increment = function () 152 | { 153 | this.m_count++; 154 | 155 | if (this.m_max_count < this.m_count) 156 | { 157 | this.m_max_count = this.m_count; 158 | } 159 | } 160 | 161 | /** 162 | * @export 163 | * @return {void} 164 | */ 165 | box2d.b2Counter.prototype.Decrement = function () 166 | { 167 | this.m_count--; 168 | 169 | if (this.m_min_count > this.m_count) 170 | { 171 | this.m_min_count = this.m_count; 172 | } 173 | } 174 | 175 | return box2d 176 | }) 177 | // End auto-generated code. 178 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/chainandcirclecontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_collideedge', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2ChainAndCircleContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2ChainAndCircleContact === 'undefined') 26 | box2d.b2ChainAndCircleContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | // -removed- goog.require('box2d.b2CollideEdge'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.b2Contact} 37 | */ 38 | box2d.b2ChainAndCircleContact = function () 39 | { 40 | goog.base(this); // base class constructor 41 | }; 42 | 43 | goog.inherits(box2d.b2ChainAndCircleContact, box2d.b2Contact); 44 | 45 | /** 46 | * @export 47 | * @return {box2d.b2Contact} 48 | * @param allocator 49 | */ 50 | box2d.b2ChainAndCircleContact.Create = function (allocator) 51 | { 52 | return new box2d.b2ChainAndCircleContact(); 53 | } 54 | 55 | /** 56 | * @export 57 | * @return {void} 58 | * @param {box2d.b2Contact} contact 59 | * @param allocator 60 | */ 61 | box2d.b2ChainAndCircleContact.Destroy = function (contact, allocator) 62 | { 63 | } 64 | 65 | /** 66 | * @export 67 | * @return {void} 68 | * @param {box2d.b2Fixture} fixtureA 69 | * @param {box2d.b2Fixture} fixtureB 70 | */ 71 | box2d.b2ChainAndCircleContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 72 | { 73 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 74 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureA.GetType() == box2d.b2ShapeType.e_chainShape); } 75 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureB.GetType() == box2d.b2ShapeType.e_circleShape); } 76 | } 77 | 78 | /** 79 | * @export 80 | * @return {void} 81 | * @param {box2d.b2Manifold} manifold 82 | * @param {box2d.b2Transform} xfA 83 | * @param {box2d.b2Transform} xfB 84 | */ 85 | box2d.b2ChainAndCircleContact.prototype.Evaluate = function (manifold, xfA, xfB) 86 | { 87 | var shapeA = this.m_fixtureA.GetShape(); 88 | var shapeB = this.m_fixtureB.GetShape(); 89 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2ChainShape); } 90 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2CircleShape); } 91 | /*box2d.b2ChainShape*/ var chain = (shapeA instanceof box2d.b2ChainShape)? shapeA : null; 92 | /*box2d.b2EdgeShape*/ var edge = box2d.b2ChainAndCircleContact.prototype.Evaluate.s_edge; 93 | chain.GetChildEdge(edge, this.m_indexA); 94 | box2d.b2CollideEdgeAndCircle( 95 | manifold, 96 | edge, xfA, 97 | (shapeB instanceof box2d.b2CircleShape)? shapeB : null, xfB); 98 | } 99 | box2d.b2ChainAndCircleContact.prototype.Evaluate.s_edge = new box2d.b2EdgeShape(); 100 | 101 | return box2d 102 | }) 103 | // End auto-generated code. 104 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/chainandpolygoncontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_chainshape', 'mod_box2d_collideedge', 'mod_box2d_contact', 'mod_box2d_polygonshape', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2ChainAndPolygonContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2ChainAndPolygonContact === 'undefined') 26 | box2d.b2ChainAndPolygonContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | // -removed- goog.require('box2d.b2CollideEdge'); 32 | // -removed- goog.require('box2d.b2ChainShape'); 33 | // -removed- goog.require('box2d.b2PolygonShape'); 34 | 35 | /** 36 | * @export 37 | * @constructor 38 | * @extends {box2d.b2Contact} 39 | */ 40 | box2d.b2ChainAndPolygonContact = function () 41 | { 42 | goog.base(this); // base class constructor 43 | }; 44 | 45 | goog.inherits(box2d.b2ChainAndPolygonContact, box2d.b2Contact); 46 | 47 | /** 48 | * @export 49 | * @return {box2d.b2Contact} 50 | * @param allocator 51 | */ 52 | box2d.b2ChainAndPolygonContact.Create = function (allocator) 53 | { 54 | return new box2d.b2ChainAndPolygonContact(); 55 | } 56 | 57 | /** 58 | * @export 59 | * @return {void} 60 | * @param {box2d.b2Contact} contact 61 | * @param allocator 62 | */ 63 | box2d.b2ChainAndPolygonContact.Destroy = function (contact, allocator) 64 | { 65 | } 66 | 67 | /** 68 | * @export 69 | * @return {void} 70 | * @param {box2d.b2Fixture} fixtureA 71 | * @param {box2d.b2Fixture} fixtureB 72 | */ 73 | box2d.b2ChainAndPolygonContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 74 | { 75 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 76 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureA.GetType() == box2d.b2ShapeType.e_chainShape); } 77 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureB.GetType() == box2d.b2ShapeType.e_polygonShape); } 78 | } 79 | 80 | /** 81 | * @export 82 | * @return {void} 83 | * @param {box2d.b2Manifold} manifold 84 | * @param {box2d.b2Transform} xfA 85 | * @param {box2d.b2Transform} xfB 86 | */ 87 | box2d.b2ChainAndPolygonContact.prototype.Evaluate = function (manifold, xfA, xfB) 88 | { 89 | var shapeA = this.m_fixtureA.GetShape(); 90 | var shapeB = this.m_fixtureB.GetShape(); 91 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2ChainShape); } 92 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2PolygonShape); } 93 | /*box2d.b2ChainShape*/ var chain = (shapeA instanceof box2d.b2ChainShape)? shapeA : null; 94 | /*box2d.b2EdgeShape*/ var edge = box2d.b2ChainAndPolygonContact.prototype.Evaluate.s_edge; 95 | chain.GetChildEdge(edge, this.m_indexA); 96 | box2d.b2CollideEdgeAndPolygon( 97 | manifold, 98 | edge, xfA, 99 | (shapeB instanceof box2d.b2PolygonShape)? shapeB : null, xfB); 100 | } 101 | box2d.b2ChainAndPolygonContact.prototype.Evaluate.s_edge = new box2d.b2EdgeShape(); 102 | 103 | return box2d 104 | }) 105 | // End auto-generated code. 106 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/circlecontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_collidecircle', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2CircleContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2CircleContact === 'undefined') 26 | box2d.b2CircleContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | // -removed- goog.require('box2d.b2CollideCircle'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.b2Contact} 37 | */ 38 | box2d.b2CircleContact = function () 39 | { 40 | goog.base(this); // base class constructor 41 | }; 42 | 43 | goog.inherits(box2d.b2CircleContact, box2d.b2Contact); 44 | 45 | /** 46 | * @export 47 | * @return {box2d.b2Contact} 48 | * @param allocator 49 | */ 50 | box2d.b2CircleContact.Create = function (allocator) 51 | { 52 | return new box2d.b2CircleContact(); 53 | } 54 | 55 | /** 56 | * @export 57 | * @return {void} 58 | * @param {box2d.b2Contact} contact 59 | * @param allocator 60 | */ 61 | box2d.b2CircleContact.Destroy = function (contact, allocator) 62 | { 63 | } 64 | 65 | /** 66 | * @export 67 | * @return {void} 68 | * @param {box2d.b2Fixture} fixtureA 69 | * @param {number} indexA 70 | * @param {box2d.b2Fixture} fixtureB 71 | * @param {number} indexB 72 | */ 73 | box2d.b2CircleContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 74 | { 75 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 76 | } 77 | 78 | /** 79 | * @export 80 | * @return {void} 81 | * @param {box2d.b2Manifold} manifold 82 | * @param {box2d.b2Transform} xfA 83 | * @param {box2d.b2Transform} xfB 84 | */ 85 | box2d.b2CircleContact.prototype.Evaluate = function (manifold, xfA, xfB) 86 | { 87 | var shapeA = this.m_fixtureA.GetShape(); 88 | var shapeB = this.m_fixtureB.GetShape(); 89 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2CircleShape); } 90 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2CircleShape); } 91 | box2d.b2CollideCircles( 92 | manifold, 93 | (shapeA instanceof box2d.b2CircleShape)? shapeA : null, xfA, 94 | (shapeB instanceof box2d.b2CircleShape)? shapeB : null, xfB); 95 | } 96 | 97 | return box2d 98 | }) 99 | // End auto-generated code. 100 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/edgeandcirclecontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_collideedge', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2EdgeAndCircleContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2EdgeAndCircleContact === 'undefined') 26 | box2d.b2EdgeAndCircleContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | // -removed- goog.require('box2d.b2CollideEdge'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.b2Contact} 37 | */ 38 | box2d.b2EdgeAndCircleContact = function () 39 | { 40 | goog.base(this); // base class constructor 41 | }; 42 | 43 | goog.inherits(box2d.b2EdgeAndCircleContact, box2d.b2Contact); 44 | 45 | /** 46 | * @export 47 | * @return {box2d.b2Contact} 48 | * @param allocator 49 | */ 50 | box2d.b2EdgeAndCircleContact.Create = function (allocator) 51 | { 52 | return new box2d.b2EdgeAndCircleContact(); 53 | } 54 | 55 | /** 56 | * @export 57 | * @return {void} 58 | * @param {box2d.b2Contact} contact 59 | * @param allocator 60 | */ 61 | box2d.b2EdgeAndCircleContact.Destroy = function (contact, allocator) 62 | { 63 | } 64 | 65 | /** 66 | * @export 67 | * @return {void} 68 | * @param {box2d.b2Fixture} fixtureA 69 | * @param {box2d.b2Fixture} fixtureB 70 | */ 71 | box2d.b2EdgeAndCircleContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 72 | { 73 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 74 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureA.GetType() == box2d.b2ShapeType.e_edgeShape); } 75 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureB.GetType() == box2d.b2ShapeType.e_circleShape); } 76 | } 77 | 78 | /** 79 | * @export 80 | * @return {void} 81 | * @param {box2d.b2Manifold} manifold 82 | * @param {box2d.b2Transform} xfA 83 | * @param {box2d.b2Transform} xfB 84 | */ 85 | box2d.b2EdgeAndCircleContact.prototype.Evaluate = function (manifold, xfA, xfB) 86 | { 87 | var shapeA = this.m_fixtureA.GetShape(); 88 | var shapeB = this.m_fixtureB.GetShape(); 89 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2EdgeShape); } 90 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2CircleShape); } 91 | box2d.b2CollideEdgeAndCircle( 92 | manifold, 93 | (shapeA instanceof box2d.b2EdgeShape)? shapeA : null, xfA, 94 | (shapeB instanceof box2d.b2CircleShape)? shapeB : null, xfB); 95 | } 96 | 97 | return box2d 98 | }) 99 | // End auto-generated code. 100 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/edgeandpolygoncontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2EdgeAndPolygonContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2EdgeAndPolygonContact === 'undefined') 26 | box2d.b2EdgeAndPolygonContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | 32 | /** 33 | * @export 34 | * @constructor 35 | * @extends {box2d.b2Contact} 36 | */ 37 | box2d.b2EdgeAndPolygonContact = function () 38 | { 39 | goog.base(this); // base class constructor 40 | }; 41 | 42 | goog.inherits(box2d.b2EdgeAndPolygonContact, box2d.b2Contact); 43 | 44 | /** 45 | * @export 46 | * @return {box2d.b2Contact} 47 | * @param allocator 48 | */ 49 | box2d.b2EdgeAndPolygonContact.Create = function (allocator) 50 | { 51 | return new box2d.b2EdgeAndPolygonContact(); 52 | } 53 | 54 | /** 55 | * @export 56 | * @return {void} 57 | * @param {box2d.b2Contact} contact 58 | * @param allocator 59 | */ 60 | box2d.b2EdgeAndPolygonContact.Destroy = function (contact, allocator) 61 | { 62 | } 63 | 64 | /** 65 | * @export 66 | * @return {void} 67 | * @param {box2d.b2Fixture} fixtureA 68 | * @param {box2d.b2Fixture} fixtureB 69 | */ 70 | box2d.b2EdgeAndPolygonContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 71 | { 72 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 73 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureA.GetType() == box2d.b2ShapeType.e_edgeShape); } 74 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureB.GetType() == box2d.b2ShapeType.e_polygonShape); } 75 | } 76 | 77 | /** 78 | * @export 79 | * @return {void} 80 | * @param {box2d.b2Manifold} manifold 81 | * @param {box2d.b2Transform} xfA 82 | * @param {box2d.b2Transform} xfB 83 | */ 84 | box2d.b2EdgeAndPolygonContact.prototype.Evaluate = function (manifold, xfA, xfB) 85 | { 86 | var shapeA = this.m_fixtureA.GetShape(); 87 | var shapeB = this.m_fixtureB.GetShape(); 88 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2EdgeShape); } 89 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2PolygonShape); } 90 | box2d.b2CollideEdgeAndPolygon( 91 | manifold, 92 | (shapeA instanceof box2d.b2EdgeShape)? shapeA : null, xfA, 93 | (shapeB instanceof box2d.b2PolygonShape)? shapeB : null, xfB); 94 | } 95 | 96 | return box2d 97 | }) 98 | // End auto-generated code. 99 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/polygonandcirclecontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2PolygonAndCircleContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2PolygonAndCircleContact === 'undefined') 26 | box2d.b2PolygonAndCircleContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | 32 | /** 33 | * @export 34 | * @constructor 35 | * @extends {box2d.b2Contact} 36 | */ 37 | box2d.b2PolygonAndCircleContact = function () 38 | { 39 | goog.base(this); // base class constructor 40 | }; 41 | 42 | goog.inherits(box2d.b2PolygonAndCircleContact, box2d.b2Contact); 43 | 44 | /** 45 | * @export 46 | * @return {box2d.b2Contact} 47 | * @param allocator 48 | */ 49 | box2d.b2PolygonAndCircleContact.Create = function (allocator) 50 | { 51 | return new box2d.b2PolygonAndCircleContact(); 52 | } 53 | 54 | /** 55 | * @export 56 | * @return {void} 57 | * @param {box2d.b2Contact} contact 58 | * @param allocator 59 | */ 60 | box2d.b2PolygonAndCircleContact.Destroy = function (contact, allocator) 61 | { 62 | } 63 | 64 | /** 65 | * @export 66 | * @return {void} 67 | * @param {box2d.b2Fixture} fixtureA 68 | * @param {box2d.b2Fixture} fixtureB 69 | */ 70 | box2d.b2PolygonAndCircleContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 71 | { 72 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 73 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureA.GetType() == box2d.b2ShapeType.e_polygonShape); } 74 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(fixtureB.GetType() == box2d.b2ShapeType.e_circleShape); } 75 | } 76 | 77 | /** 78 | * @export 79 | * @return {void} 80 | * @param {box2d.b2Manifold} manifold 81 | * @param {box2d.b2Transform} xfA 82 | * @param {box2d.b2Transform} xfB 83 | */ 84 | box2d.b2PolygonAndCircleContact.prototype.Evaluate = function (manifold, xfA, xfB) 85 | { 86 | var shapeA = this.m_fixtureA.GetShape(); 87 | var shapeB = this.m_fixtureB.GetShape(); 88 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2PolygonShape); } 89 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2CircleShape); } 90 | box2d.b2CollidePolygonAndCircle( 91 | manifold, 92 | (shapeA instanceof box2d.b2PolygonShape)? shapeA : null, xfA, 93 | (shapeB instanceof box2d.b2CircleShape)? shapeB : null, xfB); 94 | } 95 | 96 | return box2d 97 | }) 98 | // End auto-generated code. 99 | -------------------------------------------------------------------------------- /lib/dynamics/contacts/polygoncontact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_collidepolygon', 'mod_box2d_contact', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2PolygonContact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2PolygonContact === 'undefined') 26 | box2d.b2PolygonContact = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Contact'); 31 | // -removed- goog.require('box2d.b2CollidePolygon'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.b2Contact} 37 | */ 38 | box2d.b2PolygonContact = function () 39 | { 40 | goog.base(this); // base class constructor 41 | }; 42 | 43 | goog.inherits(box2d.b2PolygonContact, box2d.b2Contact); 44 | 45 | /** 46 | * @export 47 | * @return {box2d.b2Contact} 48 | * @param allocator 49 | */ 50 | box2d.b2PolygonContact.Create = function (allocator) 51 | { 52 | return new box2d.b2PolygonContact(); 53 | } 54 | 55 | /** 56 | * @export 57 | * @return {void} 58 | * @param {box2d.b2Contact} contact 59 | * @param allocator 60 | */ 61 | box2d.b2PolygonContact.Destroy = function (contact, allocator) 62 | { 63 | } 64 | 65 | /** 66 | * @export 67 | * @return {void} 68 | * @param {box2d.b2Fixture} fixtureA 69 | * @param {box2d.b2Fixture} fixtureB 70 | */ 71 | box2d.b2PolygonContact.prototype.Reset = function (fixtureA, indexA, fixtureB, indexB) 72 | { 73 | goog.base(this, 'Reset', fixtureA, indexA, fixtureB, indexB); 74 | } 75 | 76 | /** 77 | * @export 78 | * @return {void} 79 | * @param {box2d.b2Manifold} manifold 80 | * @param {box2d.b2Transform} xfA 81 | * @param {box2d.b2Transform} xfB 82 | */ 83 | box2d.b2PolygonContact.prototype.Evaluate = function (manifold, xfA, xfB) 84 | { 85 | var shapeA = this.m_fixtureA.GetShape(); 86 | var shapeB = this.m_fixtureB.GetShape(); 87 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeA instanceof box2d.b2PolygonShape); } 88 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(shapeB instanceof box2d.b2PolygonShape); } 89 | box2d.b2CollidePolygons( 90 | manifold, 91 | (shapeA instanceof box2d.b2PolygonShape)? shapeA : null, xfA, 92 | (shapeB instanceof box2d.b2PolygonShape)? shapeB : null, xfB); 93 | } 94 | 95 | return box2d 96 | }) 97 | // End auto-generated code. 98 | -------------------------------------------------------------------------------- /lib/dynamics/joints/jointfactory.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_joint', 'mod_box2d_math', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2007 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2JointFactory'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2JointFactory === 'undefined') 26 | box2d.b2JointFactory = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | // -removed- goog.require('box2d.b2Math'); 31 | // -removed- goog.require('box2d.b2Joint'); 32 | 33 | /** 34 | * @export 35 | * @return {box2d.b2Joint} 36 | * @param {box2d.b2JointDef} def 37 | * @param allocator 38 | */ 39 | box2d.b2JointFactory.Create = function (def, allocator) 40 | { 41 | var joint = null; 42 | 43 | switch (def.type) 44 | { 45 | case box2d.b2JointType.e_distanceJoint: 46 | { 47 | joint = new box2d.b2DistanceJoint((def instanceof box2d.b2DistanceJointDef ? def : null)); 48 | } 49 | break; 50 | 51 | case box2d.b2JointType.e_mouseJoint: 52 | { 53 | joint = new box2d.b2MouseJoint((def instanceof box2d.b2MouseJointDef ? def : null)); 54 | } 55 | break; 56 | 57 | case box2d.b2JointType.e_prismaticJoint: 58 | { 59 | joint = new box2d.b2PrismaticJoint((def instanceof box2d.b2PrismaticJointDef ? def : null)); 60 | } 61 | break; 62 | 63 | case box2d.b2JointType.e_revoluteJoint: 64 | { 65 | joint = new box2d.b2RevoluteJoint((def instanceof box2d.b2RevoluteJointDef ? def : null)); 66 | } 67 | break; 68 | 69 | case box2d.b2JointType.e_pulleyJoint: 70 | { 71 | joint = new box2d.b2PulleyJoint((def instanceof box2d.b2PulleyJointDef ? def : null)); 72 | } 73 | break; 74 | 75 | case box2d.b2JointType.e_gearJoint: 76 | { 77 | joint = new box2d.b2GearJoint((def instanceof box2d.b2GearJointDef ? def : null)); 78 | } 79 | break; 80 | 81 | case box2d.b2JointType.e_wheelJoint: 82 | { 83 | joint = new box2d.b2WheelJoint((def instanceof box2d.b2WheelJointDef ? def : null)); 84 | } 85 | break; 86 | 87 | case box2d.b2JointType.e_weldJoint: 88 | { 89 | joint = new box2d.b2WeldJoint((def instanceof box2d.b2WeldJointDef ? def : null)); 90 | } 91 | break; 92 | 93 | case box2d.b2JointType.e_frictionJoint: 94 | { 95 | joint = new box2d.b2FrictionJoint((def instanceof box2d.b2FrictionJointDef ? def : null)); 96 | } 97 | break; 98 | 99 | case box2d.b2JointType.e_ropeJoint: 100 | { 101 | joint = new box2d.b2RopeJoint((def instanceof box2d.b2RopeJointDef ? def : null)); 102 | } 103 | break; 104 | 105 | case box2d.b2JointType.e_motorJoint: 106 | { 107 | joint = new box2d.b2MotorJoint((def instanceof box2d.b2MotorJointDef ? def : null)); 108 | } 109 | break; 110 | 111 | case box2d.b2JointType.e_areaJoint: 112 | { 113 | joint = new box2d.b2AreaJoint((def instanceof box2d.b2AreaJointDef ? def : null)); 114 | } 115 | break; 116 | 117 | default: 118 | if (box2d.ENABLE_ASSERTS) { box2d.b2Assert(false); } 119 | break; 120 | } 121 | 122 | return joint; 123 | } 124 | 125 | /** 126 | * @export 127 | * @return {void} 128 | * @param {box2d.b2Joint} joint 129 | * @param allocator 130 | */ 131 | box2d.b2JointFactory.Destroy = function (joint, allocator) 132 | { 133 | } 134 | 135 | return box2d 136 | }) 137 | // End auto-generated code. 138 | -------------------------------------------------------------------------------- /lib/dynamics/timestep.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_settings'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.b2TimeStep'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.b2TimeStep === 'undefined') 26 | box2d.b2TimeStep = {} 27 | 28 | 29 | // -removed- goog.require('box2d.b2Settings'); 30 | 31 | /** 32 | * Profiling data. Times are in milliseconds. 33 | * @export 34 | * @constructor 35 | */ 36 | box2d.b2Profile = function () 37 | { 38 | }; 39 | 40 | /** 41 | * @export 42 | * @type {number} 43 | */ 44 | box2d.b2Profile.prototype.step = 0; 45 | /** 46 | * @export 47 | * @type {number} 48 | */ 49 | box2d.b2Profile.prototype.collide = 0; 50 | /** 51 | * @export 52 | * @type {number} 53 | */ 54 | box2d.b2Profile.prototype.solve = 0; 55 | /** 56 | * @export 57 | * @type {number} 58 | */ 59 | box2d.b2Profile.prototype.solveInit = 0; 60 | /** 61 | * @export 62 | * @type {number} 63 | */ 64 | box2d.b2Profile.prototype.solveVelocity = 0; 65 | /** 66 | * @export 67 | * @type {number} 68 | */ 69 | box2d.b2Profile.prototype.solvePosition = 0; 70 | /** 71 | * @export 72 | * @type {number} 73 | */ 74 | box2d.b2Profile.prototype.broadphase = 0; 75 | /** 76 | * @export 77 | * @type {number} 78 | */ 79 | box2d.b2Profile.prototype.solveTOI = 0; 80 | 81 | /** 82 | * @export 83 | * @return {box2d.b2Profile} 84 | */ 85 | box2d.b2Profile.prototype.Reset = function () 86 | { 87 | this.step = 0; 88 | this.collide = 0; 89 | this.solve = 0; 90 | this.solveInit = 0; 91 | this.solveVelocity = 0; 92 | this.solvePosition = 0; 93 | this.broadphase = 0; 94 | this.solveTOI = 0; 95 | return this; 96 | } 97 | 98 | /** 99 | * This is an internal structure. 100 | * @export 101 | * @constructor 102 | */ 103 | box2d.b2TimeStep = function () 104 | { 105 | }; 106 | 107 | /** 108 | * @export 109 | * @type {number} 110 | */ 111 | box2d.b2TimeStep.prototype.dt = 0; // time step 112 | /** 113 | * @export 114 | * @type {number} 115 | */ 116 | box2d.b2TimeStep.prototype.inv_dt = 0; // inverse time step (0 if dt == 0). 117 | /** 118 | * @export 119 | * @type {number} 120 | */ 121 | box2d.b2TimeStep.prototype.dtRatio = 0; // dt * inv_dt0 122 | /** 123 | * @export 124 | * @type {number} 125 | */ 126 | box2d.b2TimeStep.prototype.velocityIterations = 0; 127 | /** 128 | * @export 129 | * @type {number} 130 | */ 131 | box2d.b2TimeStep.prototype.positionIterations = 0; 132 | /** 133 | * @export 134 | * @type {boolean} 135 | */ 136 | box2d.b2TimeStep.prototype.warmStarting = false; 137 | 138 | /** 139 | * @export 140 | * @return {box2d.b2TimeStep} 141 | * @param {box2d.b2TimeStep} step 142 | */ 143 | box2d.b2TimeStep.prototype.Copy = function (step) 144 | { 145 | this.dt = step.dt; // time step 146 | this.inv_dt = step.inv_dt; // inverse time step (0 if dt == 0). 147 | this.dtRatio = step.dtRatio; // dt * inv_dt0 148 | this.positionIterations = step.positionIterations; 149 | this.velocityIterations = step.velocityIterations; 150 | this.warmStarting = step.warmStarting; 151 | return this; 152 | } 153 | 154 | /** 155 | * This is an internal structure. 156 | * @export 157 | * @constructor 158 | */ 159 | box2d.b2Position = function () 160 | { 161 | this.c = new box2d.b2Vec2(); 162 | }; 163 | 164 | /** 165 | * @export 166 | * @type {box2d.b2Vec2} 167 | */ 168 | box2d.b2Position.prototype.c = null; 169 | /** 170 | * @export 171 | * @type {number} 172 | */ 173 | box2d.b2Position.prototype.a = 0; 174 | 175 | /** 176 | * @export 177 | * @return {Array.} 178 | * @param {number} length 179 | */ 180 | box2d.b2Position.MakeArray = function (length) 181 | { 182 | return box2d.b2MakeArray(length, function (i) { return new box2d.b2Position(); } ); 183 | } 184 | 185 | /** 186 | * This is an internal structure. 187 | * @export 188 | * @constructor 189 | */ 190 | box2d.b2Velocity = function () 191 | { 192 | this.v = new box2d.b2Vec2(); 193 | }; 194 | 195 | /** 196 | * @export 197 | * @type {box2d.b2Vec2} 198 | */ 199 | box2d.b2Velocity.prototype.v = null; 200 | /** 201 | * @export 202 | * @type {number} 203 | */ 204 | box2d.b2Velocity.prototype.w = 0; 205 | 206 | /** 207 | * @export 208 | * @return {Array.} 209 | * @param {number} length 210 | */ 211 | box2d.b2Velocity.MakeArray = function (length) 212 | { 213 | return box2d.b2MakeArray(length, function (i) { return new box2d.b2Velocity(); } ); 214 | } 215 | 216 | /** 217 | * Solver Data 218 | * @export 219 | * @constructor 220 | */ 221 | box2d.b2SolverData = function () 222 | { 223 | this.step = new box2d.b2TimeStep(); 224 | }; 225 | 226 | /** 227 | * @export 228 | * @type {box2d.b2TimeStep} 229 | */ 230 | box2d.b2SolverData.prototype.step = null; 231 | /** 232 | * @export 233 | * @type {Array.} 234 | */ 235 | box2d.b2SolverData.prototype.positions = null; 236 | /** 237 | * @export 238 | * @type {Array.} 239 | */ 240 | box2d.b2SolverData.prototype.velocities = null; 241 | 242 | return box2d 243 | }) 244 | // End auto-generated code. 245 | -------------------------------------------------------------------------------- /lib/paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "mod_box2d": "lib/box2d", 3 | "mod_box2d_areajoint": "lib/dynamics/joints/areajoint", 4 | "mod_box2d_blockallocator": "lib/common/blockallocator", 5 | "mod_box2d_body": "lib/dynamics/body", 6 | "mod_box2d_broadphase": "lib/collision/broadphase", 7 | "mod_box2d_chainandcirclecontact": "lib/dynamics/contacts/chainandcirclecontact", 8 | "mod_box2d_chainandpolygoncontact": "lib/dynamics/contacts/chainandpolygoncontact", 9 | "mod_box2d_chainshape": "lib/collision/shapes/chainshape", 10 | "mod_box2d_circlecontact": "lib/dynamics/contacts/circlecontact", 11 | "mod_box2d_circleshape": "lib/collision/shapes/circleshape", 12 | "mod_box2d_collidecircle": "lib/collision/collidecircle", 13 | "mod_box2d_collideedge": "lib/collision/collideedge", 14 | "mod_box2d_collidepolygon": "lib/collision/collidepolygon", 15 | "mod_box2d_collision": "lib/collision/collision", 16 | "mod_box2d_contact": "lib/dynamics/contacts/contact", 17 | "mod_box2d_contactfactory": "lib/dynamics/contacts/contactfactory", 18 | "mod_box2d_contactmanager": "lib/dynamics/contactmanager", 19 | "mod_box2d_contactsolver": "lib/dynamics/contacts/contactsolver", 20 | "mod_box2d_distance": "lib/collision/distance", 21 | "mod_box2d_distancejoint": "lib/dynamics/joints/distancejoint", 22 | "mod_box2d_draw": "lib/common/draw", 23 | "mod_box2d_dynamictree": "lib/collision/dynamictree", 24 | "mod_box2d_edgeandcirclecontact": "lib/dynamics/contacts/edgeandcirclecontact", 25 | "mod_box2d_edgeandpolygoncontact": "lib/dynamics/contacts/edgeandpolygoncontact", 26 | "mod_box2d_edgeshape": "lib/collision/shapes/edgeshape", 27 | "mod_box2d_fixture": "lib/dynamics/fixture", 28 | "mod_box2d_frictionjoint": "lib/dynamics/joints/frictionjoint", 29 | "mod_box2d_gearjoint": "lib/dynamics/joints/gearjoint", 30 | "mod_box2d_growablestack": "lib/common/growablestack", 31 | "mod_box2d_island": "lib/dynamics/island", 32 | "mod_box2d_joint": "lib/dynamics/joints/joint", 33 | "mod_box2d_jointfactory": "lib/dynamics/joints/jointfactory", 34 | "mod_box2d_math": "lib/common/math", 35 | "mod_box2d_motorjoint": "lib/dynamics/joints/motorjoint", 36 | "mod_box2d_mousejoint": "lib/dynamics/joints/mousejoint", 37 | "mod_box2d_polygonandcirclecontact": "lib/dynamics/contacts/polygonandcirclecontact", 38 | "mod_box2d_polygoncontact": "lib/dynamics/contacts/polygoncontact", 39 | "mod_box2d_polygonshape": "lib/collision/shapes/polygonshape", 40 | "mod_box2d_prismaticjoint": "lib/dynamics/joints/prismaticjoint", 41 | "mod_box2d_pulleyjoint": "lib/dynamics/joints/pulleyjoint", 42 | "mod_box2d_revolutejoint": "lib/dynamics/joints/revolutejoint", 43 | "mod_box2d_rope": "lib/rope/rope", 44 | "mod_box2d_ropejoint": "lib/dynamics/joints/ropejoint", 45 | "mod_box2d_settings": "lib/common/settings", 46 | "mod_box2d_shape": "lib/collision/shapes/shape", 47 | "mod_box2d_stackallocator": "lib/common/stackallocator", 48 | "mod_box2d_timeofimpact": "lib/collision/timeofimpact", 49 | "mod_box2d_timestep": "lib/dynamics/timestep", 50 | "mod_box2d_timer": "lib/common/timer", 51 | "mod_box2d_weldjoint": "lib/dynamics/joints/weldjoint", 52 | "mod_box2d_wheeljoint": "lib/dynamics/joints/wheeljoint", 53 | "mod_box2d_world": "lib/dynamics/world", 54 | "mod_box2d_worldcallbacks": "lib/dynamics/worldcallbacks" 55 | } 56 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "box2d-html5", 3 | "version": "0.1.230", 4 | "description": "A 2D Physics Engine for HTML5 Games", 5 | "keywords": ["box2d", "html5", "game", "physics", "engine"], 6 | "files": ["package/box2d-html5.js", "README"], 7 | "main": "package/box2d-html5.js", 8 | "repository": { 9 | "type": "git", 10 | "url": "git@github.com:mvasilkov/box2d-html5.git" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/load.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | box2d-html5 :: A 2D Physics Engine for HTML5 Games 6 | 7 | 8 | 9 | 10 | 11 | 12 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/load.package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | box2d-html5 :: A 2D Physics Engine for HTML5 Games 6 | 7 | 8 | 9 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/loader.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | function concatObj() { 3 | var args = Array.prototype.slice.call(arguments), res = {} 4 | args.forEach(function (obj) { 5 | for (var p in obj) { if (obj.hasOwnProperty(p)) res[p] = obj[p] } 6 | }) 7 | return res 8 | } 9 | 10 | function load() { 11 | var args = Array.prototype.slice.call(arguments), done = args.pop(), 12 | pros = args.map(function (dir) { 13 | return promise.get(dir + '/paths.json') 14 | }) 15 | promise.join(pros).then(function (res) { 16 | var err = res.some(function (args) { return args.shift() }) 17 | if (err) return done(err) 18 | 19 | var retval = concatObj.apply(null, res.map(function (args) { 20 | return JSON.parse(args.shift()) 21 | })) 22 | done(0, retval) 23 | }) 24 | } 25 | 26 | this.loader = { load: load } 27 | }()) 28 | -------------------------------------------------------------------------------- /test/paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "mod_box2d_testbed_addpair": "test/tests/addpair", 3 | "mod_box2d_testbed_applyforce": "test/tests/applyforce", 4 | "mod_box2d_testbed_blobtest": "test/tests/blobtest", 5 | "mod_box2d_testbed_bodytypes": "test/tests/bodytypes", 6 | "mod_box2d_testbed_breakable": "test/tests/breakable", 7 | "mod_box2d_testbed_bridge": "test/tests/bridge", 8 | "mod_box2d_testbed_bullettest": "test/tests/bullettest", 9 | "mod_box2d_testbed_buoyancytest": "test/tests/buoyancytest", 10 | "mod_box2d_testbed_cantilever": "test/tests/cantilever", 11 | "mod_box2d_testbed_car": "test/tests/car", 12 | "mod_box2d_testbed_chain": "test/tests/chain", 13 | "mod_box2d_testbed_charactercollision": "test/tests/charactercollision", 14 | "mod_box2d_testbed_collisionfiltering": "test/tests/collisionfiltering", 15 | "mod_box2d_testbed_collisionprocessing": "test/tests/collisionprocessing", 16 | "mod_box2d_testbed_compoundshapes": "test/tests/compoundshapes", 17 | "mod_box2d_testbed_confined": "test/tests/confined", 18 | "mod_box2d_testbed_continuoustest": "test/tests/continuoustest", 19 | "mod_box2d_testbed_convexhull": "test/tests/convexhull", 20 | "mod_box2d_testbed_conveyorbelt": "test/tests/conveyorbelt", 21 | "mod_box2d_testbed_distancetest": "test/tests/distancetest", 22 | "mod_box2d_testbed_dominos": "test/tests/dominos", 23 | "mod_box2d_testbed_dumpshell": "test/tests/dumpshell", 24 | "mod_box2d_testbed_dynamictreetest": "test/tests/dynamictreetest", 25 | "mod_box2d_testbed_edgeshapes": "test/tests/edgeshapes", 26 | "mod_box2d_testbed_edgetest": "test/tests/edgetest", 27 | "mod_box2d_testbed_gears": "test/tests/gears", 28 | "mod_box2d_testbed_main": "test/framework/main", 29 | "mod_box2d_testbed_mobile": "test/tests/mobile", 30 | "mod_box2d_testbed_mobilebalanced": "test/tests/mobilebalanced", 31 | "mod_box2d_testbed_motorjoint": "test/tests/motorjoint", 32 | "mod_box2d_testbed_onesidedplatform": "test/tests/onesidedplatform", 33 | "mod_box2d_testbed_pinball": "test/tests/pinball", 34 | "mod_box2d_testbed_polycollision": "test/tests/polycollision", 35 | "mod_box2d_testbed_polyshapes": "test/tests/polyshapes", 36 | "mod_box2d_testbed_prismatic": "test/tests/prismatic", 37 | "mod_box2d_testbed_pulleys": "test/tests/pulleys", 38 | "mod_box2d_testbed_pyramid": "test/tests/pyramid", 39 | "mod_box2d_testbed_raycast": "test/tests/raycast", 40 | "mod_box2d_testbed_render": "test/framework/render", 41 | "mod_box2d_testbed_revolute": "test/tests/revolute", 42 | "mod_box2d_testbed_rope": "test/tests/rope", 43 | "mod_box2d_testbed_ropejoint": "test/tests/ropejoint", 44 | "mod_box2d_testbed_sensortest": "test/tests/sensortest", 45 | "mod_box2d_testbed_shapeediting": "test/tests/shapeediting", 46 | "mod_box2d_testbed_slidercrank": "test/tests/slidercrank", 47 | "mod_box2d_testbed_spherestack": "test/tests/spherestack", 48 | "mod_box2d_testbed_test": "test/framework/test", 49 | "mod_box2d_testbed_testccd": "test/tests/testccd", 50 | "mod_box2d_testbed_testentries": "test/tests/testentries", 51 | "mod_box2d_testbed_testragdoll": "test/tests/testragdoll", 52 | "mod_box2d_testbed_teststack": "test/tests/teststack", 53 | "mod_box2d_testbed_theojansen": "test/tests/theojansen", 54 | "mod_box2d_testbed_tiles": "test/tests/tiles", 55 | "mod_box2d_testbed_timeofimpact": "test/tests/timeofimpact", 56 | "mod_box2d_testbed_tumbler": "test/tests/tumbler", 57 | "mod_box2d_testbed_varyingfriction": "test/tests/varyingfriction", 58 | "mod_box2d_testbed_varyingrestitution": "test/tests/varyingrestitution", 59 | "mod_box2d_testbed_verticalstack": "test/tests/verticalstack", 60 | "mod_box2d_testbed_web": "test/tests/web", 61 | "mod_main_start": "test/testbed" 62 | } 63 | -------------------------------------------------------------------------------- /test/testbed.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | box2d-html5 :: A 2D Physics Engine for HTML5 Games 6 | 7 | 8 | 9 | 10 | 11 | 12 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/testbed.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_box2d_testbed_main'], function (box2d) { 3 | 4 | // -removed- goog.provide('main.start'); 5 | if (typeof main === 'undefined') 6 | main = {} 7 | if (typeof main.start === 'undefined') 8 | main.start = {} 9 | 10 | 11 | // -removed- goog.require('box2d.Testbed.Main'); 12 | 13 | /** 14 | * @export 15 | * @type {box2d.Testbed.Main} 16 | */ 17 | main.m_app = null; 18 | 19 | /** 20 | * @export 21 | * @return {void} 22 | */ 23 | main.start = function () 24 | { 25 | main.m_app = new box2d.Testbed.Main(); 26 | 27 | main.loop(); 28 | } 29 | 30 | /** 31 | * @export 32 | * @return {void} 33 | */ 34 | main.loop = function () 35 | { 36 | requestAnimationFrame(main.loop); 37 | 38 | main.m_app.SimulationLoop(); 39 | } 40 | 41 | return main 42 | }) 43 | // End auto-generated code. 44 | -------------------------------------------------------------------------------- /test/testbed.package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | box2d-html5 :: A 2D Physics Engine for HTML5 Games 6 | 7 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /test/tests/addpair.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2012 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.AddPair'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.AddPair === 'undefined') 28 | box2d.Testbed.AddPair = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.AddPair = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_world.SetGravity(new box2d.b2Vec2(0.0,0.0)); 45 | if (true) 46 | { 47 | /*float32*/ var a = 0.1; 48 | 49 | /*box2d.b2CircleShape*/ var shape = new box2d.b2CircleShape(); 50 | shape.m_p.SetZero(); 51 | shape.m_radius = 0.1; 52 | 53 | /*float*/ var minX = -6.0; 54 | /*float*/ var maxX = 0.0; 55 | /*float*/ var minY = 4.0; 56 | /*float*/ var maxY = 6.0; 57 | 58 | for (/*int32*/ var i = 0; i < 400; ++i) 59 | { 60 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 61 | bd.type = box2d.b2BodyType.b2_dynamicBody; 62 | bd.position = new box2d.b2Vec2(box2d.b2RandomRange(minX,maxX),box2d.b2RandomRange(minY,maxY)); 63 | /*box2d.b2Body*/ var body = this.m_world.CreateBody(bd); 64 | body.CreateFixture2(shape, 0.01); 65 | } 66 | } 67 | 68 | if (true) 69 | { 70 | /*box2d.b2PolygonShape*/ var shape = new box2d.b2PolygonShape(); 71 | shape.SetAsBox(1.5, 1.5); 72 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 73 | bd.type = box2d.b2BodyType.b2_dynamicBody; 74 | bd.position.Set(-40.0,5.0); 75 | bd.bullet = true; 76 | /*box2d.b2Body*/ var body = this.m_world.CreateBody(bd); 77 | body.CreateFixture2(shape, 1.0); 78 | body.SetLinearVelocity(new box2d.b2Vec2(150.0, 0.0)); 79 | } 80 | } 81 | 82 | goog.inherits(box2d.Testbed.AddPair, box2d.Testbed.Test); 83 | 84 | /** 85 | * @export 86 | * @return {box2d.Testbed.Test} 87 | * @param {HTMLCanvasElement} canvas 88 | * @param {box2d.Testbed.Settings} settings 89 | */ 90 | box2d.Testbed.AddPair.Create = function (canvas, settings) 91 | { 92 | return new box2d.Testbed.AddPair(canvas, settings); 93 | } 94 | 95 | return box2d 96 | }) 97 | // End auto-generated code. 98 | -------------------------------------------------------------------------------- /test/tests/blobtest.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.BlobTest'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.BlobTest === 'undefined') 28 | box2d.Testbed.BlobTest = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.BlobTest = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var ground = this.m_world.CreateBody(new box2d.b2BodyDef()); 45 | 46 | if (true) 47 | { 48 | var shape = new box2d.b2EdgeShape(); 49 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2( 40.0, 0.0)); 50 | ground.CreateFixture2(shape, 0.0); 51 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(-40.0, 25.0)); 52 | ground.CreateFixture2(shape, 0.0); 53 | shape.SetAsEdge(new box2d.b2Vec2( 40.0, 0.0), new box2d.b2Vec2( 40.0, 25.0)); 54 | ground.CreateFixture2(shape, 0.0); 55 | } 56 | 57 | if (true) 58 | { 59 | var ajd = new box2d.b2AreaJointDef(); 60 | ajd.world = this.m_world; 61 | 62 | var cx = 0.0; 63 | var cy = 10.0; 64 | var rx = 5.0; 65 | var ry = 5.0; 66 | var nBodies = 20; 67 | var bodyRadius = 0.5; 68 | for (var i = 0; i < nBodies; ++i) 69 | { 70 | var angle = (i * 2.0 * Math.PI) / nBodies; 71 | var bd = new box2d.b2BodyDef(); 72 | //bd.isBullet = true; 73 | bd.fixedRotation = true; 74 | 75 | var x = cx + rx * Math.cos(angle); 76 | var y = cy + ry * Math.sin(angle); 77 | bd.position.Set(x, y); 78 | bd.type = box2d.b2BodyType.b2_dynamicBody; 79 | var body = this.m_world.CreateBody(bd); 80 | 81 | var fd = new box2d.b2FixtureDef(); 82 | fd.shape = new box2d.b2CircleShape(bodyRadius); 83 | fd.density = 1.0; 84 | body.CreateFixture(fd); 85 | 86 | ajd.AddBody(body); 87 | } 88 | 89 | ajd.frquencyHz = 10.0; 90 | ajd.dampingRatio = 1.0; 91 | this.m_world.CreateJoint(ajd); 92 | } 93 | } 94 | 95 | goog.inherits(box2d.Testbed.BlobTest, box2d.Testbed.Test); 96 | 97 | /** 98 | * @export 99 | * @return {void} 100 | * @param {number} key 101 | */ 102 | box2d.Testbed.BlobTest.prototype.Keyboard = function (key) 103 | { 104 | switch (key) 105 | { 106 | case goog.events.KeyCodes.A: 107 | break; 108 | } 109 | } 110 | 111 | /** 112 | * @export 113 | * @return {void} 114 | * @param {box2d.Testbed.Settings} settings 115 | */ 116 | box2d.Testbed.BlobTest.prototype.Step = function (settings) 117 | { 118 | goog.base(this, 'Step', settings); 119 | } 120 | 121 | /** 122 | * @export 123 | * @return {box2d.Testbed.Test} 124 | * @param {HTMLCanvasElement} canvas 125 | * @param {box2d.Testbed.Settings} settings 126 | */ 127 | box2d.Testbed.BlobTest.Create = function (canvas, settings) 128 | { 129 | return new box2d.Testbed.BlobTest(canvas, settings); 130 | } 131 | 132 | return box2d 133 | }) 134 | // End auto-generated code. 135 | -------------------------------------------------------------------------------- /test/tests/bridge.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Bridge'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Bridge === 'undefined') 28 | box2d.Testbed.Bridge = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Bridge = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var ground = null; 45 | if (true) 46 | { 47 | var bd = new box2d.b2BodyDef(); 48 | ground = this.m_world.CreateBody(bd); 49 | 50 | var shape = new box2d.b2EdgeShape(); 51 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 52 | ground.CreateFixture2(shape, 0.0); 53 | } 54 | 55 | if (true) 56 | { 57 | var shape = new box2d.b2PolygonShape(); 58 | shape.SetAsBox(0.5, 0.125); 59 | 60 | var fd = new box2d.b2FixtureDef(); 61 | fd.shape = shape; 62 | fd.density = 20.0; 63 | fd.friction = 0.2; 64 | 65 | var jd = new box2d.b2RevoluteJointDef(); 66 | 67 | var prevBody = ground; 68 | for (var i = 0; i < box2d.Testbed.Bridge.e_count; ++i) 69 | { 70 | var bd = new box2d.b2BodyDef(); 71 | bd.type = box2d.b2BodyType.b2_dynamicBody; 72 | bd.position.Set(-14.5 + 1.0 * i, 5.0); 73 | var body = this.m_world.CreateBody(bd); 74 | body.CreateFixture(fd); 75 | 76 | var anchor = new box2d.b2Vec2(-15.0 + 1.0 * i, 5.0); 77 | jd.Initialize(prevBody, body, anchor); 78 | this.m_world.CreateJoint(jd); 79 | 80 | if (i == (box2d.Testbed.Bridge.e_count >> 1)) 81 | { 82 | this.m_middle = body; 83 | } 84 | prevBody = body; 85 | } 86 | 87 | var anchor = new box2d.b2Vec2(-15.0 + 1.0 * box2d.Testbed.Bridge.e_count, 5.0); 88 | jd.Initialize(prevBody, ground, anchor); 89 | this.m_world.CreateJoint(jd); 90 | } 91 | 92 | for (var i = 0; i < 2; ++i) 93 | { 94 | var vertices = new Array(); 95 | vertices[0] = new box2d.b2Vec2(-0.5, 0.0); 96 | vertices[1] = new box2d.b2Vec2(0.5, 0.0); 97 | vertices[2] = new box2d.b2Vec2(0.0, 1.5); 98 | 99 | var shape = new box2d.b2PolygonShape(); 100 | shape.SetAsArray(vertices); 101 | 102 | var fd = new box2d.b2FixtureDef(); 103 | fd.shape = shape; 104 | fd.density = 1.0; 105 | 106 | var bd = new box2d.b2BodyDef(); 107 | bd.type = box2d.b2BodyType.b2_dynamicBody; 108 | bd.position.Set(-8.0 + 8.0 * i, 12.0); 109 | var body = this.m_world.CreateBody(bd); 110 | body.CreateFixture(fd); 111 | } 112 | 113 | for (var i = 0; i < 3; ++i) 114 | { 115 | var shape = new box2d.b2CircleShape(); 116 | shape.m_radius = 0.5; 117 | 118 | var fd = new box2d.b2FixtureDef(); 119 | fd.shape = shape; 120 | fd.density = 1.0; 121 | 122 | var bd = new box2d.b2BodyDef(); 123 | bd.type = box2d.b2BodyType.b2_dynamicBody; 124 | bd.position.Set(-6.0 + 6.0 * i, 10.0); 125 | var body = this.m_world.CreateBody(bd); 126 | body.CreateFixture(fd); 127 | } 128 | } 129 | 130 | goog.inherits(box2d.Testbed.Bridge, box2d.Testbed.Test); 131 | 132 | /** 133 | * @export 134 | * @const 135 | * @type {number} 136 | */ 137 | box2d.Testbed.Bridge.e_count = 30; 138 | 139 | /** 140 | * @export 141 | * @type {box2d.b2Body} 142 | */ 143 | box2d.Testbed.Bridge.prototype.m_middle = null; 144 | 145 | /** 146 | * @export 147 | * @return {box2d.Testbed.Test} 148 | * @param {HTMLCanvasElement} canvas 149 | * @param {box2d.Testbed.Settings} settings 150 | */ 151 | box2d.Testbed.Bridge.Create = function (canvas, settings) 152 | { 153 | return new box2d.Testbed.Bridge(canvas, settings); 154 | } 155 | 156 | return box2d 157 | }) 158 | // End auto-generated code. 159 | -------------------------------------------------------------------------------- /test/tests/chain.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Chain'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Chain === 'undefined') 28 | box2d.Testbed.Chain = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Chain = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var ground = null; 45 | if (true) 46 | { 47 | var bd = new box2d.b2BodyDef(); 48 | ground = this.m_world.CreateBody(bd); 49 | 50 | var shape = new box2d.b2EdgeShape(); 51 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 52 | ground.CreateFixture2(shape, 0.0); 53 | } 54 | 55 | if (true) 56 | { 57 | var shape = new box2d.b2PolygonShape(); 58 | shape.SetAsBox(0.6, 0.125); 59 | 60 | var fd = new box2d.b2FixtureDef(); 61 | fd.shape = shape; 62 | fd.density = 20.0; 63 | fd.friction = 0.2; 64 | 65 | var jd = new box2d.b2RevoluteJointDef(); 66 | jd.collideConnected = false; 67 | 68 | var y = 25.0; 69 | var prevBody = ground; 70 | for (var i = 0; i < box2d.Testbed.Chain.e_count; ++i) 71 | { 72 | var bd = new box2d.b2BodyDef(); 73 | bd.type = box2d.b2BodyType.b2_dynamicBody; 74 | bd.position.Set(0.5 + i, y); 75 | var body = this.m_world.CreateBody(bd); 76 | body.CreateFixture(fd); 77 | 78 | var anchor = new box2d.b2Vec2(i, y); 79 | jd.Initialize(prevBody, body, anchor); 80 | this.m_world.CreateJoint(jd); 81 | 82 | prevBody = body; 83 | } 84 | } 85 | } 86 | 87 | goog.inherits(box2d.Testbed.Chain, box2d.Testbed.Test); 88 | 89 | /** 90 | * @export 91 | * @const 92 | * @type {number} 93 | */ 94 | box2d.Testbed.Chain.e_count = 30; 95 | 96 | /** 97 | * @export 98 | * @return {box2d.Testbed.Test} 99 | * @param {HTMLCanvasElement} canvas 100 | * @param {box2d.Testbed.Settings} settings 101 | */ 102 | box2d.Testbed.Chain.Create = function (canvas, settings) 103 | { 104 | return new box2d.Testbed.Chain(canvas, settings); 105 | } 106 | 107 | return box2d 108 | }) 109 | // End auto-generated code. 110 | -------------------------------------------------------------------------------- /test/tests/compoundshapes.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.CompoundShapes'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.CompoundShapes === 'undefined') 28 | box2d.Testbed.CompoundShapes = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.CompoundShapes = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | var body = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(50.0, 0.0), new box2d.b2Vec2(-50.0, 0.0)); 51 | 52 | body.CreateFixture2(shape, 0.0); 53 | } 54 | 55 | if (true) 56 | { 57 | var circle1 = new box2d.b2CircleShape(); 58 | circle1.m_radius = 0.5; 59 | circle1.m_p.Set(-0.5, 0.5); 60 | 61 | var circle2 = new box2d.b2CircleShape(); 62 | circle2.m_radius = 0.5; 63 | circle2.m_p.Set(0.5, 0.5); 64 | 65 | for (var i = 0; i < 10; ++i) 66 | { 67 | var x = box2d.b2RandomRange(-0.1, 0.1); 68 | var bd = new box2d.b2BodyDef(); 69 | bd.type = box2d.b2BodyType.b2_dynamicBody; 70 | bd.position.Set(x + 5.0, 1.05 + 2.5 * i); 71 | bd.angle = box2d.b2RandomRange(-box2d.b2_pi, box2d.b2_pi); 72 | var body = this.m_world.CreateBody(bd); 73 | body.CreateFixture2(circle1, 2.0); 74 | body.CreateFixture2(circle2, 0.0); 75 | } 76 | } 77 | 78 | if (true) 79 | { 80 | var polygon1 = new box2d.b2PolygonShape(); 81 | polygon1.SetAsBox(0.25, 0.5); 82 | 83 | var polygon2 = new box2d.b2PolygonShape(); 84 | polygon2.SetAsOrientedBox(0.25, 0.5, new box2d.b2Vec2(0.0, -0.5), 0.5 * box2d.b2_pi); 85 | 86 | for (var i = 0; i < 10; ++i) 87 | { 88 | var x = box2d.b2RandomRange(-0.1, 0.1); 89 | var bd = new box2d.b2BodyDef(); 90 | bd.type = box2d.b2BodyType.b2_dynamicBody; 91 | bd.position.Set(x - 5.0, 1.05 + 2.5 * i); 92 | bd.angle = box2d.b2RandomRange(-box2d.b2_pi, box2d.b2_pi); 93 | var body = this.m_world.CreateBody(bd); 94 | body.CreateFixture2(polygon1, 2.0); 95 | body.CreateFixture2(polygon2, 2.0); 96 | } 97 | } 98 | 99 | if (true) 100 | { 101 | var xf1 = new box2d.b2Transform(); 102 | xf1.q.SetAngleRadians(0.3524 * box2d.b2_pi); 103 | xf1.p.Copy(box2d.b2MulRV(xf1.q, new box2d.b2Vec2(1.0, 0.0), new box2d.b2Vec2())); 104 | 105 | var vertices = new Array(); 106 | 107 | var triangle1 = new box2d.b2PolygonShape(); 108 | vertices[0] = box2d.b2MulXV(xf1, new box2d.b2Vec2(-1.0, 0.0), new box2d.b2Vec2()); 109 | vertices[1] = box2d.b2MulXV(xf1, new box2d.b2Vec2(1.0, 0.0), new box2d.b2Vec2()); 110 | vertices[2] = box2d.b2MulXV(xf1, new box2d.b2Vec2(0.0, 0.5), new box2d.b2Vec2()); 111 | triangle1.SetAsArray(vertices, 3); 112 | 113 | var xf2 = new box2d.b2Transform(); 114 | xf2.q.SetAngleRadians(-0.3524 * box2d.b2_pi); 115 | xf2.p.Copy(box2d.b2MulRV(xf2.q, new box2d.b2Vec2(-1.0, 0.0), new box2d.b2Vec2())); 116 | 117 | var triangle2 = new box2d.b2PolygonShape(); 118 | vertices[0] = box2d.b2MulXV(xf2, new box2d.b2Vec2(-1.0, 0.0), new box2d.b2Vec2()); 119 | vertices[1] = box2d.b2MulXV(xf2, new box2d.b2Vec2(1.0, 0.0), new box2d.b2Vec2()); 120 | vertices[2] = box2d.b2MulXV(xf2, new box2d.b2Vec2(0.0, 0.5), new box2d.b2Vec2()); 121 | triangle2.SetAsArray(vertices, 3); 122 | 123 | for (var i = 0; i < 10; ++i) 124 | { 125 | var x = box2d.b2RandomRange(-0.1, 0.1); 126 | var bd = new box2d.b2BodyDef(); 127 | bd.type = box2d.b2BodyType.b2_dynamicBody; 128 | bd.position.Set(x, 2.05 + 2.5 * i); 129 | bd.angle = 0; 130 | var body = this.m_world.CreateBody(bd); 131 | body.CreateFixture2(triangle1, 2.0); 132 | body.CreateFixture2(triangle2, 2.0); 133 | } 134 | } 135 | 136 | if (true) 137 | { 138 | var bottom = new box2d.b2PolygonShape(); 139 | bottom.SetAsBox( 1.5, 0.15 ); 140 | 141 | var left = new box2d.b2PolygonShape(); 142 | left.SetAsOrientedBox(0.15, 2.7, new box2d.b2Vec2(-1.45, 2.35), 0.2); 143 | 144 | var right = new box2d.b2PolygonShape(); 145 | right.SetAsOrientedBox(0.15, 2.7, new box2d.b2Vec2(1.45, 2.35), -0.2); 146 | 147 | var bd = new box2d.b2BodyDef(); 148 | bd.type = box2d.b2BodyType.b2_dynamicBody; 149 | bd.position.Set( 0.0, 2.0 ); 150 | var body = this.m_world.CreateBody(bd); 151 | body.CreateFixture2(bottom, 4.0); 152 | body.CreateFixture2(left, 4.0); 153 | body.CreateFixture2(right, 4.0); 154 | } 155 | } 156 | 157 | goog.inherits(box2d.Testbed.CompoundShapes, box2d.Testbed.Test); 158 | 159 | /** 160 | * @export 161 | * @return {box2d.Testbed.Test} 162 | * @param {HTMLCanvasElement} canvas 163 | * @param {box2d.Testbed.Settings} settings 164 | */ 165 | box2d.Testbed.CompoundShapes.Create = function (canvas, settings) 166 | { 167 | return new box2d.Testbed.CompoundShapes(canvas, settings); 168 | } 169 | 170 | return box2d 171 | }) 172 | // End auto-generated code. 173 | -------------------------------------------------------------------------------- /test/tests/confined.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Confined'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Confined === 'undefined') 28 | box2d.Testbed.Confined = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Confined = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | var ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | 51 | // Floor 52 | shape.SetAsEdge(new box2d.b2Vec2(-10.0, 0.0), new box2d.b2Vec2(10.0, 0.0)); 53 | ground.CreateFixture2(shape, 0.0); 54 | 55 | // Left wall 56 | shape.SetAsEdge(new box2d.b2Vec2(-10.0, 0.0), new box2d.b2Vec2(-10.0, 20.0)); 57 | ground.CreateFixture2(shape, 0.0); 58 | 59 | // Right wall 60 | shape.SetAsEdge(new box2d.b2Vec2(10.0, 0.0), new box2d.b2Vec2(10.0, 20.0)); 61 | ground.CreateFixture2(shape, 0.0); 62 | 63 | // Roof 64 | shape.SetAsEdge(new box2d.b2Vec2(-10.0, 20.0), new box2d.b2Vec2(10.0, 20.0)); 65 | ground.CreateFixture2(shape, 0.0); 66 | } 67 | 68 | var radius = 0.5; 69 | var shape = new box2d.b2CircleShape(); 70 | shape.m_p.SetZero(); 71 | shape.m_radius = radius; 72 | 73 | var fd = new box2d.b2FixtureDef(); 74 | fd.shape = shape; 75 | fd.density = 1.0; 76 | fd.friction = 0.1; 77 | 78 | for (var j = 0; j < box2d.Testbed.Confined.e_columnCount; ++j) 79 | { 80 | for (var i = 0; i < box2d.Testbed.Confined.e_rowCount; ++i) 81 | { 82 | var bd = new box2d.b2BodyDef(); 83 | bd.type = box2d.b2BodyType.b2_dynamicBody; 84 | bd.position.Set(-10.0 + (2.1 * j + 1.0 + 0.01 * i) * radius, (2.0 * i + 1.0) * radius); 85 | var body = this.m_world.CreateBody(bd); 86 | 87 | body.CreateFixture(fd); 88 | } 89 | } 90 | 91 | this.m_world.SetGravity(new box2d.b2Vec2(0.0, 0.0)); 92 | } 93 | 94 | goog.inherits(box2d.Testbed.Confined, box2d.Testbed.Test); 95 | 96 | /** 97 | * @export 98 | * @const 99 | * @type {number} 100 | */ 101 | box2d.Testbed.Confined.e_columnCount = 0; 102 | /** 103 | * @export 104 | * @const 105 | * @type {number} 106 | */ 107 | box2d.Testbed.Confined.e_rowCount = 0; 108 | 109 | /** 110 | * @export 111 | * @return {void} 112 | */ 113 | box2d.Testbed.Confined.prototype.CreateCircle = function () 114 | { 115 | var radius = 2.0; 116 | var shape = new box2d.b2CircleShape(); 117 | shape.m_p.SetZero(); 118 | shape.m_radius = radius; 119 | 120 | var fd = new box2d.b2FixtureDef(); 121 | fd.shape = shape; 122 | fd.density = 1.0; 123 | fd.friction = 0.0; 124 | 125 | var p = new box2d.b2Vec2(box2d.b2Random(), 3.0 + box2d.b2Random()); 126 | var bd = new box2d.b2BodyDef(); 127 | bd.type = box2d.b2BodyType.b2_dynamicBody; 128 | bd.position.Copy(p); 129 | //bd.allowSleep = false; 130 | var body = this.m_world.CreateBody(bd); 131 | 132 | body.CreateFixture(fd); 133 | } 134 | 135 | /** 136 | * @export 137 | * @return {void} 138 | * @param {number} key 139 | */ 140 | box2d.Testbed.Confined.prototype.Keyboard = function (key) 141 | { 142 | switch (key) 143 | { 144 | case goog.events.KeyCodes.C: 145 | this.CreateCircle(); 146 | break; 147 | } 148 | } 149 | 150 | /** 151 | * @export 152 | * @return {void} 153 | * @param {box2d.Testbed.Settings} settings 154 | */ 155 | box2d.Testbed.Confined.prototype.Step = function (settings) 156 | { 157 | var sleeping = true; 158 | for (var b = this.m_world.GetBodyList(); b; b = b.m_next) 159 | { 160 | if (b.GetType() != box2d.b2BodyType.b2_dynamicBody) 161 | { 162 | continue; 163 | } 164 | 165 | if (b.IsAwake()) 166 | { 167 | sleeping = false; 168 | } 169 | } 170 | 171 | if (this.m_stepCount == 180) 172 | { 173 | this.m_stepCount += 0; 174 | } 175 | 176 | //if (sleeping) 177 | //{ 178 | // CreateCircle(); 179 | //} 180 | 181 | goog.base(this, 'Step', settings); 182 | 183 | for (var b = this.m_world.GetBodyList(); b; b = b.m_next) 184 | { 185 | if (b.GetType() != box2d.b2BodyType.b2_dynamicBody) 186 | { 187 | continue; 188 | } 189 | 190 | var p = b.GetPosition(); 191 | if (p.x <= -10.0 || 10.0 <= p.x || p.y <= 0.0 || 20.0 <= p.y) 192 | { 193 | p.x += 0.0; 194 | } 195 | } 196 | 197 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press 'c' to create a circle."); 198 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 199 | } 200 | 201 | /** 202 | * @export 203 | * @return {box2d.Testbed.Test} 204 | * @param {HTMLCanvasElement} canvas 205 | * @param {box2d.Testbed.Settings} settings 206 | */ 207 | box2d.Testbed.Confined.Create = function (canvas, settings) 208 | { 209 | return new box2d.Testbed.Confined(canvas, settings); 210 | } 211 | 212 | return box2d 213 | }) 214 | // End auto-generated code. 215 | -------------------------------------------------------------------------------- /test/tests/convexhull.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.ConvexHull'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.ConvexHull === 'undefined') 28 | box2d.Testbed.ConvexHull = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.ConvexHull = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_test_points = box2d.b2Vec2.MakeArray(box2d.b2_maxPolygonVertices); 45 | 46 | this.Generate(); 47 | this.m_auto = false; 48 | } 49 | 50 | goog.inherits(box2d.Testbed.ConvexHull, box2d.Testbed.Test); 51 | 52 | /** 53 | * @export 54 | * @const 55 | * @type {number} 56 | */ 57 | box2d.Testbed.ConvexHull.e_count = box2d.b2_maxPolygonVertices; 58 | 59 | /** 60 | * @export 61 | * @type {Array.} 62 | */ 63 | box2d.Testbed.ConvexHull.prototype.m_test_points = null; 64 | /** 65 | * @export 66 | * @type {number} 67 | */ 68 | box2d.Testbed.ConvexHull.prototype.m_count = 0; 69 | /** 70 | * @export 71 | * @type {boolean} 72 | */ 73 | box2d.Testbed.ConvexHull.prototype.m_auto = false; 74 | 75 | /** 76 | * @export 77 | * @return {void} 78 | */ 79 | box2d.Testbed.ConvexHull.prototype.Generate = function () 80 | { 81 | for (var i = 0; i < box2d.Testbed.ConvexHull.e_count; ++i) 82 | { 83 | var x = box2d.b2RandomRange(-10.0, 10.0); 84 | var y = box2d.b2RandomRange(-10.0, 10.0); 85 | 86 | // Clamp onto a square to help create collinearities. 87 | // This will stress the convex hull algorithm. 88 | x = box2d.b2Clamp(x, -8.0, 8.0); 89 | y = box2d.b2Clamp(y, -8.0, 8.0); 90 | this.m_test_points[i].Set(x, y); 91 | } 92 | 93 | this.m_count = box2d.Testbed.ConvexHull.e_count; 94 | 95 | //this.m_test_points[0].Set( -1.70082211, -1.43221712 ); 96 | //this.m_test_points[1].Set( 0.5, -0.5 ); 97 | //this.m_test_points[2].Set( 0.104992867, 0.97400856 ); 98 | //this.m_test_points[3].Set( -0.658002853, 0.926608086 ); 99 | //this.m_test_points[4].Set( -0.994554818, 0.165337861 ); 100 | //this.m_count = 5; 101 | } 102 | 103 | /** 104 | * @export 105 | * @return {void} 106 | * @param {number} key 107 | */ 108 | box2d.Testbed.ConvexHull.prototype.Keyboard = function (key) 109 | { 110 | switch (key) 111 | { 112 | case goog.events.KeyCodes.A: 113 | this.m_auto = !this.m_auto; 114 | break; 115 | 116 | case goog.events.KeyCodes.G: 117 | this.Generate(); 118 | break; 119 | } 120 | } 121 | 122 | /** 123 | * @export 124 | * @return {void} 125 | * @param {box2d.Testbed.Settings} settings 126 | */ 127 | box2d.Testbed.ConvexHull.prototype.Step = function (settings) 128 | { 129 | goog.base(this, 'Step', settings); 130 | 131 | var shape = new box2d.b2PolygonShape(); 132 | shape.SetAsVector(this.m_test_points, this.m_count); 133 | 134 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press g to generate a new random convex hull"); 135 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 136 | 137 | this.m_debugDraw.DrawPolygon(shape.m_vertices, shape.m_count, new box2d.b2Color(0.9, 0.9, 0.9)); 138 | 139 | for (var i = 0; i < this.m_count; ++i) 140 | { 141 | this.m_debugDraw.DrawPoint(this.m_test_points[i], 2.0, new box2d.b2Color(0.9, 0.5, 0.5)); 142 | this.m_debugDraw.DrawStringWorld(this.m_test_points[i].x + 0.05, this.m_test_points[i].y + 0.05, "%d", i); 143 | } 144 | 145 | if (shape.Validate() == false) 146 | { 147 | this.m_textLine += 0; 148 | } 149 | 150 | if (this.m_auto) 151 | { 152 | this.Generate(); 153 | } 154 | } 155 | 156 | /** 157 | * @export 158 | * @return {box2d.Testbed.Test} 159 | * @param {HTMLCanvasElement} canvas 160 | * @param {box2d.Testbed.Settings} settings 161 | */ 162 | box2d.Testbed.ConvexHull.Create = function (canvas, settings) 163 | { 164 | return new box2d.Testbed.ConvexHull(canvas, settings); 165 | } 166 | 167 | return box2d 168 | }) 169 | // End auto-generated code. 170 | -------------------------------------------------------------------------------- /test/tests/conveyorbelt.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2011 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.ConveyorBelt'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.ConveyorBelt === 'undefined') 28 | box2d.Testbed.ConveyorBelt = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.ConveyorBelt = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | // Ground 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | /*b2Body*/ var ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(-20.0, 0.0), new box2d.b2Vec2(20.0, 0.0)); 51 | ground.CreateFixture2(shape, 0.0); 52 | } 53 | 54 | // Platform 55 | { 56 | var bd = new box2d.b2BodyDef(); 57 | bd.position.Set(-5.0, 5.0); 58 | /*b2Body*/ var body = this.m_world.CreateBody(bd); 59 | 60 | var shape = new box2d.b2PolygonShape(); 61 | shape.SetAsBox(10.0, 0.5); 62 | 63 | var fd = new box2d.b2FixtureDef(); 64 | fd.shape = shape; 65 | fd.friction = 0.8; 66 | this.m_platform = body.CreateFixture(fd); 67 | } 68 | 69 | // Boxes 70 | for (/*int*/ var i = 0; i < 5; ++i) 71 | { 72 | var bd = new box2d.b2BodyDef(); 73 | bd.type = box2d.b2BodyType.b2_dynamicBody; 74 | bd.position.Set(-10.0 + 2.0 * i, 7.0); 75 | /*b2Body*/ var body = this.m_world.CreateBody(bd); 76 | 77 | var shape = new box2d.b2PolygonShape(); 78 | shape.SetAsBox(0.5, 0.5); 79 | body.CreateFixture2(shape, 20.0); 80 | } 81 | } 82 | 83 | goog.inherits(box2d.Testbed.ConveyorBelt, box2d.Testbed.Test); 84 | 85 | /** 86 | * @export 87 | * @type {box2d.b2Fixture} 88 | */ 89 | box2d.Testbed.ConveyorBelt.prototype.m_platform = null; 90 | 91 | /** 92 | * @export 93 | * @return {void} 94 | * @param {box2d.b2Contact} contact 95 | * @param {box2d.b2Manifold} oldManifold 96 | */ 97 | box2d.Testbed.ConveyorBelt.prototype.PreSolve = function (contact, oldManifold) 98 | { 99 | goog.base(this, 'PreSolve', contact, oldManifold); 100 | 101 | /*b2Fixture*/ var fixtureA = contact.GetFixtureA(); 102 | /*b2Fixture*/ var fixtureB = contact.GetFixtureB(); 103 | 104 | if (fixtureA == this.m_platform) 105 | { 106 | contact.SetTangentSpeed(5.0); 107 | } 108 | 109 | if (fixtureB == this.m_platform) 110 | { 111 | contact.SetTangentSpeed(-5.0); 112 | } 113 | } 114 | 115 | /** 116 | * @export 117 | * @return {void} 118 | * @param {box2d.Testbed.Settings} settings 119 | */ 120 | box2d.Testbed.ConveyorBelt.prototype.Step = function (settings) 121 | { 122 | goog.base(this, 'Step', settings); 123 | } 124 | 125 | /** 126 | * @export 127 | * @return {box2d.Testbed.Test} 128 | * @param {HTMLCanvasElement} canvas 129 | * @param {box2d.Testbed.Settings} settings 130 | */ 131 | box2d.Testbed.ConveyorBelt.Create = function (canvas, settings) 132 | { 133 | return new box2d.Testbed.ConveyorBelt(canvas, settings); 134 | } 135 | 136 | return box2d 137 | }) 138 | // End auto-generated code. 139 | -------------------------------------------------------------------------------- /test/tests/edgetest.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.EdgeTest'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.EdgeTest === 'undefined') 28 | box2d.Testbed.EdgeTest = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.EdgeTest = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 47 | /*box2d.b2Body*/ var ground = this.m_world.CreateBody(bd); 48 | 49 | /*box2d.b2Vec2*/ var v1 = new box2d.b2Vec2(-10.0, 0.0), v2 = new box2d.b2Vec2(-7.0, -2.0), v3 = new box2d.b2Vec2(-4.0, 0.0); 50 | /*box2d.b2Vec2*/ var v4 = new box2d.b2Vec2(0.0, 0.0), v5 = new box2d.b2Vec2(4.0, 0.0), v6 = new box2d.b2Vec2(7.0, 2.0), v7 = new box2d.b2Vec2(10.0, 0.0); 51 | 52 | /*box2d.b2EdgeShape*/ var shape = new box2d.b2EdgeShape(); 53 | 54 | shape.SetAsEdge(v1, v2); 55 | shape.m_hasVertex3 = true; 56 | shape.m_vertex3.Copy(v3); 57 | ground.CreateFixture2(shape, 0.0); 58 | 59 | shape.SetAsEdge(v2, v3); 60 | shape.m_hasVertex0 = true; 61 | shape.m_hasVertex3 = true; 62 | shape.m_vertex0.Copy(v1); 63 | shape.m_vertex3.Copy(v4); 64 | ground.CreateFixture2(shape, 0.0); 65 | 66 | shape.SetAsEdge(v3, v4); 67 | shape.m_hasVertex0 = true; 68 | shape.m_hasVertex3 = true; 69 | shape.m_vertex0.Copy(v2); 70 | shape.m_vertex3.Copy(v5); 71 | ground.CreateFixture2(shape, 0.0); 72 | 73 | shape.SetAsEdge(v4, v5); 74 | shape.m_hasVertex0 = true; 75 | shape.m_hasVertex3 = true; 76 | shape.m_vertex0.Copy(v3); 77 | shape.m_vertex3.Copy(v6); 78 | ground.CreateFixture2(shape, 0.0); 79 | 80 | shape.SetAsEdge(v5, v6); 81 | shape.m_hasVertex0 = true; 82 | shape.m_hasVertex3 = true; 83 | shape.m_vertex0.Copy(v4); 84 | shape.m_vertex3.Copy(v7); 85 | ground.CreateFixture2(shape, 0.0); 86 | 87 | shape.SetAsEdge(v6, v7); 88 | shape.m_hasVertex0 = true; 89 | shape.m_vertex0.Copy(v5); 90 | ground.CreateFixture2(shape, 0.0); 91 | } 92 | 93 | if (true) 94 | { 95 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 96 | bd.type = box2d.b2BodyType.b2_dynamicBody; 97 | bd.position.Set(-0.5, 0.6); 98 | bd.allowSleep = false; 99 | /*box2d.b2Body*/ var body = this.m_world.CreateBody(bd); 100 | 101 | /*box2d.b2CircleShape*/ var shape = new box2d.b2CircleShape(); 102 | shape.m_radius = 0.5; 103 | 104 | body.CreateFixture2(shape, 1.0); 105 | } 106 | 107 | if (true) 108 | { 109 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 110 | bd.type = box2d.b2BodyType.b2_dynamicBody; 111 | bd.position.Set(1.0, 0.6); 112 | bd.allowSleep = false; 113 | /*box2d.b2Body*/ var body = this.m_world.CreateBody(bd); 114 | 115 | /*box2d.b2PolygonShape*/ var shape = new box2d.b2PolygonShape(); 116 | shape.SetAsBox(0.5, 0.5); 117 | 118 | body.CreateFixture2(shape, 1.0); 119 | } 120 | } 121 | 122 | goog.inherits(box2d.Testbed.EdgeTest, box2d.Testbed.Test); 123 | 124 | /** 125 | * @export 126 | * @return {box2d.Testbed.Test} 127 | * @param {HTMLCanvasElement} canvas 128 | * @param {box2d.Testbed.Settings} settings 129 | */ 130 | box2d.Testbed.EdgeTest.Create = function (canvas, settings) 131 | { 132 | return new box2d.Testbed.EdgeTest(canvas, settings); 133 | } 134 | 135 | return box2d 136 | }) 137 | // End auto-generated code. 138 | -------------------------------------------------------------------------------- /test/tests/mobile.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Mobile'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Mobile === 'undefined') 28 | box2d.Testbed.Mobile = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Mobile = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var /*b2Body*/ ground; 45 | 46 | // Create ground body. 47 | { 48 | var /*b2BodyDef*/ bodyDef = new box2d.b2BodyDef(); 49 | bodyDef.position.Set(0.0, 20.0); 50 | ground = this.m_world.CreateBody(bodyDef); 51 | } 52 | 53 | var /*float32*/ a = 0.5; 54 | var /*b2Vec2*/ h = new box2d.b2Vec2(0.0, a); 55 | 56 | var /*b2Body*/ root = this.AddNode(ground, box2d.b2Vec2_zero, 0, 3.0, a); 57 | 58 | var /*b2RevoluteJointDef*/ jointDef = new box2d.b2RevoluteJointDef(); 59 | jointDef.bodyA = ground; 60 | jointDef.bodyB = root; 61 | jointDef.localAnchorA.SetZero(); 62 | jointDef.localAnchorB.Copy(h); 63 | this.m_world.CreateJoint(jointDef); 64 | } 65 | 66 | goog.inherits(box2d.Testbed.Mobile, box2d.Testbed.Test); 67 | 68 | /** 69 | * @export 70 | * @const 71 | * @type {number} 72 | */ 73 | box2d.Testbed.Mobile.e_depth = 4; 74 | 75 | /** 76 | * @param {box2d.b2Body} parent 77 | * @param {box2d.b2Vec2} localAnchor 78 | * @param {number} depth 79 | * @param {number} offset 80 | * @param {number} a 81 | * @return {box2d.b2Body} 82 | */ 83 | box2d.Testbed.Mobile.prototype.AddNode = function (parent, localAnchor, depth, offset, a) 84 | { 85 | var /*float32*/ density = 20.0; 86 | var /*b2Vec2*/ h = new box2d.b2Vec2(0.0, a); 87 | 88 | // b2Vec2 p = parent->GetPosition() + localAnchor - h; 89 | var /*b2Vec2*/ p = parent.GetPosition().Clone().SelfAdd(localAnchor).SelfSub(h); 90 | 91 | var /*b2BodyDef*/ bodyDef = new box2d.b2BodyDef(); 92 | bodyDef.type = box2d.b2BodyType.b2_dynamicBody; 93 | bodyDef.position.Copy(p); 94 | var /*b2Body*/ body = this.m_world.CreateBody(bodyDef); 95 | 96 | var /*b2PolygonShape*/ shape = new box2d.b2PolygonShape(); 97 | shape.SetAsBox(0.25 * a, a); 98 | body.CreateFixture2(shape, density); 99 | 100 | if (depth == box2d.Testbed.Mobile.e_depth) 101 | { 102 | return body; 103 | } 104 | 105 | var /*b2Vec2*/ a1 = new box2d.b2Vec2(offset, -a); 106 | var /*b2Vec2*/ a2 = new box2d.b2Vec2(-offset, -a); 107 | var /*b2Body*/ body1 = this.AddNode(body, a1, depth + 1, 0.5 * offset, a); 108 | var /*b2Body*/ body2 = this.AddNode(body, a2, depth + 1, 0.5 * offset, a); 109 | 110 | var /*b2RevoluteJointDef*/ jointDef = new box2d.b2RevoluteJointDef(); 111 | jointDef.bodyA = body; 112 | jointDef.localAnchorB.Copy(h); 113 | 114 | jointDef.localAnchorA.Copy(a1); 115 | jointDef.bodyB = body1; 116 | this.m_world.CreateJoint(jointDef); 117 | 118 | jointDef.localAnchorA.Copy(a2); 119 | jointDef.bodyB = body2; 120 | this.m_world.CreateJoint(jointDef); 121 | 122 | return body; 123 | } 124 | 125 | /** 126 | * @export 127 | * @return {box2d.Testbed.Test} 128 | * @param {HTMLCanvasElement} canvas 129 | * @param {box2d.Testbed.Settings} settings 130 | */ 131 | box2d.Testbed.Mobile.Create = function (canvas, settings) 132 | { 133 | return new box2d.Testbed.Mobile(canvas, settings); 134 | } 135 | 136 | return box2d 137 | }) 138 | // End auto-generated code. 139 | -------------------------------------------------------------------------------- /test/tests/mobilebalanced.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.MobileBalanced'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.MobileBalanced === 'undefined') 28 | box2d.Testbed.MobileBalanced = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.MobileBalanced = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var /*b2Body*/ ground; 45 | 46 | // Create ground body. 47 | { 48 | var /*b2BodyDef*/ bodyDef = new box2d.b2BodyDef(); 49 | bodyDef.position.Set(0.0, 20.0); 50 | ground = this.m_world.CreateBody(bodyDef); 51 | } 52 | 53 | var /*float32*/ a = 0.5; 54 | var /*b2Vec2*/ h = new box2d.b2Vec2(0.0, a); 55 | 56 | var /*b2Body*/ root = this.AddNode(ground, box2d.b2Vec2_zero, 0, 3.0, a); 57 | 58 | var /*b2RevoluteJointDef*/ jointDef = new box2d.b2RevoluteJointDef(); 59 | jointDef.bodyA = ground; 60 | jointDef.bodyB = root; 61 | jointDef.localAnchorA.SetZero(); 62 | jointDef.localAnchorB.Copy(h); 63 | this.m_world.CreateJoint(jointDef); 64 | } 65 | 66 | goog.inherits(box2d.Testbed.MobileBalanced, box2d.Testbed.Test); 67 | 68 | /** 69 | * @export 70 | * @const 71 | * @type {number} 72 | */ 73 | box2d.Testbed.MobileBalanced.e_depth = 4; 74 | 75 | /** 76 | * @param {box2d.b2Body} parent 77 | * @param {box2d.b2Vec2} localAnchor 78 | * @param {number} depth 79 | * @param {number} offset 80 | * @param {number} a 81 | * @return {box2d.b2Body} 82 | */ 83 | box2d.Testbed.MobileBalanced.prototype.AddNode = function (parent, localAnchor, depth, offset, a) 84 | { 85 | var /*float32*/ density = 20.0; 86 | var /*b2Vec2*/ h = new box2d.b2Vec2(0.0, a); 87 | 88 | // b2Vec2 p = parent->GetPosition() + localAnchor - h; 89 | var /*b2Vec2*/ p = parent.GetPosition().Clone().SelfAdd(localAnchor).SelfSub(h); 90 | 91 | var /*b2BodyDef*/ bodyDef = new box2d.b2BodyDef(); 92 | bodyDef.type = box2d.b2BodyType.b2_dynamicBody; 93 | bodyDef.position.Copy(p); 94 | var /*b2Body*/ body = this.m_world.CreateBody(bodyDef); 95 | 96 | var /*b2PolygonShape*/ shape = new box2d.b2PolygonShape(); 97 | shape.SetAsBox(0.25 * a, a); 98 | body.CreateFixture2(shape, density); 99 | 100 | if (depth == box2d.Testbed.MobileBalanced.e_depth) 101 | { 102 | return body; 103 | } 104 | 105 | shape.SetAsOrientedBox(offset, 0.25 * a, new box2d.b2Vec2(0, -a), 0.0); 106 | body.CreateFixture2(shape, density); 107 | 108 | var /*b2Vec2*/ a1 = new box2d.b2Vec2(offset, -a); 109 | var /*b2Vec2*/ a2 = new box2d.b2Vec2(-offset, -a); 110 | var /*b2Body*/ body1 = this.AddNode(body, a1, depth + 1, 0.5 * offset, a); 111 | var /*b2Body*/ body2 = this.AddNode(body, a2, depth + 1, 0.5 * offset, a); 112 | 113 | var /*b2RevoluteJointDef*/ jointDef = new box2d.b2RevoluteJointDef(); 114 | jointDef.bodyA = body; 115 | jointDef.localAnchorB.Copy(h); 116 | 117 | jointDef.localAnchorA.Copy(a1); 118 | jointDef.bodyB = body1; 119 | this.m_world.CreateJoint(jointDef); 120 | 121 | jointDef.localAnchorA.Copy(a2); 122 | jointDef.bodyB = body2; 123 | this.m_world.CreateJoint(jointDef); 124 | 125 | return body; 126 | } 127 | 128 | /** 129 | * @export 130 | * @return {box2d.Testbed.Test} 131 | * @param {HTMLCanvasElement} canvas 132 | * @param {box2d.Testbed.Settings} settings 133 | */ 134 | box2d.Testbed.MobileBalanced.Create = function (canvas, settings) 135 | { 136 | return new box2d.Testbed.MobileBalanced(canvas, settings); 137 | } 138 | 139 | return box2d 140 | }) 141 | // End auto-generated code. 142 | -------------------------------------------------------------------------------- /test/tests/motorjoint.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2012 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.MotorJoint'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.MotorJoint === 'undefined') 28 | box2d.Testbed.MotorJoint = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.MotorJoint = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | /*b2Body*/ var ground = null; 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(-20.0, 0.0), new box2d.b2Vec2(20.0, 0.0)); 51 | 52 | var fd = new box2d.b2FixtureDef(); 53 | fd.shape = shape; 54 | 55 | ground.CreateFixture(fd); 56 | } 57 | 58 | // Define motorized body 59 | { 60 | var bd = new box2d.b2BodyDef(); 61 | bd.type = box2d.b2BodyType.b2_dynamicBody; 62 | bd.position.Set(0.0, 8.0); 63 | /*b2Body*/ var body = this.m_world.CreateBody(bd); 64 | 65 | var shape = new box2d.b2PolygonShape(); 66 | shape.SetAsBox(2.0, 0.5); 67 | 68 | var fd = new box2d.b2FixtureDef(); 69 | fd.shape = shape; 70 | fd.friction = 0.6; 71 | fd.density = 2.0; 72 | body.CreateFixture(fd); 73 | 74 | var mjd = new box2d.b2MotorJointDef(); 75 | mjd.Initialize(ground, body); 76 | mjd.maxForce = 1000.0; 77 | mjd.maxTorque = 1000.0; 78 | this.m_joint = /** @type {box2d.b2MotorJoint} */ (this.m_world.CreateJoint(mjd)); 79 | } 80 | 81 | this.m_go = false; 82 | this.m_time = 0.0; 83 | } 84 | 85 | goog.inherits(box2d.Testbed.MotorJoint, box2d.Testbed.Test); 86 | 87 | /** 88 | * @export 89 | * @type {box2d.b2MotorJoint} 90 | */ 91 | box2d.Testbed.MotorJoint.prototype.m_joint = null; 92 | /** 93 | * @export 94 | * @type {number} 95 | */ 96 | box2d.Testbed.MotorJoint.prototype.m_time = 0.0; 97 | /** 98 | * @export 99 | * @type {boolean} 100 | */ 101 | box2d.Testbed.MotorJoint.prototype.m_go = false; 102 | 103 | /** 104 | * @export 105 | * @return {void} 106 | * @param {number} key 107 | */ 108 | box2d.Testbed.MotorJoint.prototype.Keyboard = function (key) 109 | { 110 | switch (key) 111 | { 112 | case goog.events.KeyCodes.S: 113 | this.m_go = !this.m_go; 114 | break; 115 | } 116 | } 117 | 118 | /** 119 | * @export 120 | * @return {void} 121 | * @param {box2d.Testbed.Settings} settings 122 | */ 123 | box2d.Testbed.MotorJoint.prototype.Step = function (settings) 124 | { 125 | if (this.m_go && settings.hz > 0.0) 126 | { 127 | this.m_time += 1.0 / settings.hz; 128 | } 129 | 130 | /*b2Vec2*/ var linearOffset = new box2d.b2Vec2(); 131 | linearOffset.x = 6.0 * box2d.b2Sin(2.0 * this.m_time); 132 | linearOffset.y = 8.0 + 4.0 * box2d.b2Sin(1.0 * this.m_time); 133 | 134 | /*float32*/ var angularOffset = 4.0 * this.m_time; 135 | 136 | this.m_joint.SetLinearOffset(linearOffset); 137 | this.m_joint.SetAngularOffset(angularOffset); 138 | 139 | this.m_debugDraw.DrawPoint(linearOffset, 4.0, new box2d.b2Color(0.9, 0.9, 0.9)); 140 | 141 | goog.base(this, 'Step', settings); 142 | this.m_debugDraw.DrawString(5, this.m_textLine, "Keys: (s) pause"); 143 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 144 | } 145 | 146 | /** 147 | * @export 148 | * @return {box2d.Testbed.Test} 149 | * @param {HTMLCanvasElement} canvas 150 | * @param {box2d.Testbed.Settings} settings 151 | */ 152 | box2d.Testbed.MotorJoint.Create = function (canvas, settings) 153 | { 154 | return new box2d.Testbed.MotorJoint(canvas, settings); 155 | } 156 | 157 | return box2d 158 | }) 159 | // End auto-generated code. 160 | -------------------------------------------------------------------------------- /test/tests/onesidedplatform.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2008-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.OneSidedPlatform'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.OneSidedPlatform === 'undefined') 28 | box2d.Testbed.OneSidedPlatform = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.OneSidedPlatform = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | // Ground 45 | if (true) 46 | { 47 | var bd = new box2d.b2BodyDef(); 48 | var ground = this.m_world.CreateBody(bd); 49 | 50 | var shape = new box2d.b2EdgeShape(); 51 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 52 | ground.CreateFixture2(shape, 0.0); 53 | } 54 | 55 | // Platform 56 | if (true) 57 | { 58 | var bd = new box2d.b2BodyDef(); 59 | bd.position.Set(0.0, 10.0); 60 | var body = this.m_world.CreateBody(bd); 61 | 62 | var shape = new box2d.b2PolygonShape(); 63 | shape.SetAsBox(3.0, 0.5); 64 | this.m_platform = body.CreateFixture2(shape, 0.0); 65 | 66 | this.m_bottom = 10.0 - 0.5; 67 | this.m_top = 10.0 + 0.5; 68 | } 69 | 70 | // Actor 71 | if (true) 72 | { 73 | var bd = new box2d.b2BodyDef(); 74 | bd.type = box2d.b2BodyType.b2_dynamicBody; 75 | bd.position.Set(0.0, 12.0); 76 | var body = this.m_world.CreateBody(bd); 77 | 78 | this.m_radius = 0.5; 79 | var shape = new box2d.b2CircleShape(); 80 | shape.m_radius = this.m_radius; 81 | this.m_character = body.CreateFixture2(shape, 20.0); 82 | 83 | body.SetLinearVelocity(new box2d.b2Vec2(0.0, -50.0)); 84 | 85 | this.m_state = box2d.Testbed.OneSidedPlatform.e_unknown; 86 | } 87 | } 88 | 89 | goog.inherits(box2d.Testbed.OneSidedPlatform, box2d.Testbed.Test); 90 | 91 | /** 92 | * @export 93 | * @const 94 | * @type {number} 95 | */ 96 | box2d.Testbed.OneSidedPlatform.e_unknown = 0; 97 | /** 98 | * @export 99 | * @const 100 | * @type {number} 101 | */ 102 | box2d.Testbed.OneSidedPlatform.e_above = 1; 103 | /** 104 | * @export 105 | * @const 106 | * @type {number} 107 | */ 108 | box2d.Testbed.OneSidedPlatform.e_below = 2; 109 | 110 | /** 111 | * @export 112 | * @type {number} 113 | */ 114 | box2d.Testbed.OneSidedPlatform.prototype.m_radius = 0.0; 115 | /** 116 | * @export 117 | * @type {number} 118 | */ 119 | box2d.Testbed.OneSidedPlatform.prototype.m_top = 0.0; 120 | /** 121 | * @export 122 | * @type {number} 123 | */ 124 | box2d.Testbed.OneSidedPlatform.prototype.m_bottom = 0.0; 125 | /** 126 | * @export 127 | * @type {number} 128 | */ 129 | box2d.Testbed.OneSidedPlatform.prototype.m_state = box2d.Testbed.OneSidedPlatform.e_unknown; 130 | /** 131 | * @export 132 | * @type {box2d.b2Fixture} 133 | */ 134 | box2d.Testbed.OneSidedPlatform.prototype.m_platform = null; 135 | /** 136 | * @export 137 | * @type {box2d.b2Fixture} 138 | */ 139 | box2d.Testbed.OneSidedPlatform.prototype.m_character = null; 140 | 141 | /** 142 | * @export 143 | * @return {void} 144 | * @param {box2d.b2Contact} contact 145 | * @param {box2d.b2Manifold} oldManifold 146 | */ 147 | box2d.Testbed.OneSidedPlatform.prototype.PreSolve = function (contact, oldManifold) 148 | { 149 | goog.base(this, 'PreSolve', contact, oldManifold); 150 | 151 | var fixtureA = contact.GetFixtureA(); 152 | var fixtureB = contact.GetFixtureB(); 153 | 154 | if (fixtureA != this.m_platform && fixtureA != this.m_character) 155 | { 156 | return; 157 | } 158 | 159 | if (fixtureB != this.m_platform && fixtureB != this.m_character) 160 | { 161 | return; 162 | } 163 | 164 | var position = this.m_character.GetBody().GetPosition(); 165 | 166 | if (position.y < this.m_top + this.m_radius - 3.0 * box2d.b2_linearSlop) 167 | { 168 | contact.SetEnabled(false); 169 | } 170 | } 171 | 172 | /** 173 | * @export 174 | * @return {void} 175 | * @param {box2d.Testbed.Settings} settings 176 | */ 177 | box2d.Testbed.OneSidedPlatform.prototype.Step = function (settings) 178 | { 179 | goog.base(this, 'Step', settings); 180 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press: (c) create a shape, (d) destroy a shape."); 181 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 182 | 183 | var v = this.m_character.GetBody().GetLinearVelocity(); 184 | this.m_debugDraw.DrawString(5, this.m_textLine, "Character Linear Velocity: %f", v.y); 185 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 186 | } 187 | 188 | /** 189 | * @export 190 | * @return {box2d.Testbed.Test} 191 | * @param {HTMLCanvasElement} canvas 192 | * @param {box2d.Testbed.Settings} settings 193 | */ 194 | box2d.Testbed.OneSidedPlatform.Create = function (canvas, settings) 195 | { 196 | return new box2d.Testbed.OneSidedPlatform(canvas, settings); 197 | } 198 | 199 | return box2d 200 | }) 201 | // End auto-generated code. 202 | -------------------------------------------------------------------------------- /test/tests/polycollision.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.PolyCollision'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.PolyCollision === 'undefined') 28 | box2d.Testbed.PolyCollision = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.PolyCollision = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_polygonA = new box2d.b2PolygonShape(); 45 | this.m_polygonB = new box2d.b2PolygonShape(); 46 | this.m_transformA = new box2d.b2Transform(); 47 | this.m_transformB = new box2d.b2Transform(); 48 | this.m_positionB = new box2d.b2Vec2(); 49 | 50 | if (true) 51 | { 52 | this.m_polygonA.SetAsBox(0.2, 0.4); 53 | this.m_transformA.SetPositionAngleRadians(new box2d.b2Vec2(0.0, 0.0), 0.0); 54 | } 55 | 56 | if (true) 57 | { 58 | this.m_polygonB.SetAsBox(0.5, 0.5); 59 | this.m_positionB.Set(19.345284, 1.5632932); 60 | this.m_angleB = 1.9160721; 61 | this.m_transformB.SetPositionAngleRadians(this.m_positionB, this.m_angleB); 62 | } 63 | } 64 | 65 | goog.inherits(box2d.Testbed.PolyCollision, box2d.Testbed.Test); 66 | 67 | /** 68 | * @export 69 | * @type {box2d.b2PolygonShape} 70 | */ 71 | box2d.Testbed.PolyCollision.prototype.m_polygonA = null; 72 | /** 73 | * @export 74 | * @type {box2d.b2PolygonShape} 75 | */ 76 | box2d.Testbed.PolyCollision.prototype.m_polygonB = null; 77 | /** 78 | * @export 79 | * @type {box2d.b2Transform} 80 | */ 81 | box2d.Testbed.PolyCollision.prototype.m_transformA = null; 82 | /** 83 | * @export 84 | * @type {box2d.b2Transform} 85 | */ 86 | box2d.Testbed.PolyCollision.prototype.m_transformB = null; 87 | /** 88 | * @export 89 | * @type {box2d.b2Vec2} 90 | */ 91 | box2d.Testbed.PolyCollision.prototype.m_positionB = null; 92 | /** 93 | * @export 94 | * @type {number} 95 | */ 96 | box2d.Testbed.PolyCollision.prototype.m_angleB = 0; 97 | 98 | /** 99 | * @export 100 | * @return {void} 101 | * @param {box2d.Testbed.Settings} settings 102 | */ 103 | box2d.Testbed.PolyCollision.prototype.Step = function (settings) 104 | { 105 | var manifold = new box2d.b2Manifold(); 106 | box2d.b2CollidePolygons(manifold, this.m_polygonA, this.m_transformA, this.m_polygonB, this.m_transformB); 107 | 108 | var worldManifold = new box2d.b2WorldManifold(); 109 | worldManifold.Initialize(manifold, this.m_transformA, this.m_polygonA.m_radius, this.m_transformB, this.m_polygonB.m_radius); 110 | 111 | this.m_debugDraw.DrawString(5, this.m_textLine, "point count = %d", manifold.pointCount); 112 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 113 | 114 | if (true) 115 | { 116 | var color = new box2d.b2Color(0.9, 0.9, 0.9); 117 | var v = new Array(box2d.b2_maxPolygonVertices); 118 | for (var i = 0; i < this.m_polygonA.m_count; ++i) 119 | { 120 | v[i] = box2d.b2MulXV(this.m_transformA, this.m_polygonA.m_vertices[i], new box2d.b2Vec2()); 121 | } 122 | this.m_debugDraw.DrawPolygon(v, this.m_polygonA.m_count, color); 123 | 124 | for (var i = 0; i < this.m_polygonB.m_count; ++i) 125 | { 126 | v[i] = box2d.b2MulXV(this.m_transformB, this.m_polygonB.m_vertices[i], new box2d.b2Vec2()); 127 | } 128 | this.m_debugDraw.DrawPolygon(v, this.m_polygonB.m_count, color); 129 | } 130 | 131 | for (var i = 0; i < manifold.pointCount; ++i) 132 | { 133 | this.m_debugDraw.DrawPoint(worldManifold.points[i], 4.0, new box2d.b2Color(0.9, 0.3, 0.3)); 134 | } 135 | } 136 | 137 | /** 138 | * @export 139 | * @return {void} 140 | * @param {number} key 141 | */ 142 | box2d.Testbed.PolyCollision.prototype.Keyboard = function (key) 143 | { 144 | switch (key) 145 | { 146 | case goog.events.KeyCodes.A: 147 | this.m_positionB.x -= 0.1; 148 | break; 149 | 150 | case goog.events.KeyCodes.D: 151 | this.m_positionB.x += 0.1; 152 | break; 153 | 154 | case goog.events.KeyCodes.S: 155 | this.m_positionB.y -= 0.1; 156 | break; 157 | 158 | case goog.events.KeyCodes.W: 159 | this.m_positionB.y += 0.1; 160 | break; 161 | 162 | case goog.events.KeyCodes.Q: 163 | this.m_angleB += 0.1 * box2d.b2_pi; 164 | break; 165 | 166 | case goog.events.KeyCodes.E: 167 | this.m_angleB -= 0.1 * box2d.b2_pi; 168 | break; 169 | } 170 | 171 | this.m_transformB.SetPositionAngleRadians(this.m_positionB, this.m_angleB); 172 | } 173 | 174 | /** 175 | * @export 176 | * @return {box2d.Testbed.Test} 177 | * @param {HTMLCanvasElement} canvas 178 | * @param {box2d.Testbed.Settings} settings 179 | */ 180 | box2d.Testbed.PolyCollision.Create = function (canvas, settings) 181 | { 182 | return new box2d.Testbed.PolyCollision(canvas, settings); 183 | } 184 | 185 | return box2d 186 | }) 187 | // End auto-generated code. 188 | -------------------------------------------------------------------------------- /test/tests/prismatic.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Prismatic'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Prismatic === 'undefined') 28 | box2d.Testbed.Prismatic = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | // The motor in this test gets smoother with higher velocity iterations. 34 | /** 35 | * @export 36 | * @constructor 37 | * @extends {box2d.Testbed.Test} 38 | * @param {HTMLCanvasElement} canvas 39 | * @param {box2d.Testbed.Settings} settings 40 | */ 41 | box2d.Testbed.Prismatic = function (canvas, settings) 42 | { 43 | goog.base(this, canvas, settings); // base class constructor 44 | 45 | var ground = null; 46 | if (true) 47 | { 48 | var bd = new box2d.b2BodyDef(); 49 | ground = this.m_world.CreateBody(bd); 50 | 51 | var shape = new box2d.b2EdgeShape(); 52 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 53 | ground.CreateFixture2(shape, 0.0); 54 | } 55 | 56 | if (true) 57 | { 58 | var shape = new box2d.b2PolygonShape(); 59 | shape.SetAsBox(2.0, 0.5); 60 | 61 | var bd = new box2d.b2BodyDef(); 62 | bd.type = box2d.b2BodyType.b2_dynamicBody; 63 | bd.position.Set(-10.0, 10.0); 64 | bd.angle = 0.5 * box2d.b2_pi; 65 | bd.allowSleep = false; 66 | var body = this.m_world.CreateBody(bd); 67 | body.CreateFixture2(shape, 5.0); 68 | 69 | var pjd = new box2d.b2PrismaticJointDef(); 70 | 71 | // Bouncy limit 72 | var axis = new box2d.b2Vec2(2.0, 1.0); 73 | axis.Normalize(); 74 | pjd.Initialize(ground, body, new box2d.b2Vec2(0.0, 0.0), axis); 75 | 76 | // Non-bouncy limit 77 | //pjd.Initialize(ground, body, new box2d.b2Vec2(-10.0, 10.0), new box2d.b2Vec2(1.0, 0.0)); 78 | 79 | pjd.motorSpeed = 10.0; 80 | pjd.maxMotorForce = 10000.0; 81 | pjd.enableMotor = true; 82 | pjd.lowerTranslation = 0.0; 83 | pjd.upperTranslation = 20.0; 84 | pjd.enableLimit = true; 85 | 86 | this.m_joint = /** @type {box2d.b2PrismaticJoint} */ (this.m_world.CreateJoint(pjd)); 87 | } 88 | } 89 | 90 | goog.inherits(box2d.Testbed.Prismatic, box2d.Testbed.Test); 91 | 92 | /** 93 | * @export 94 | * @type {box2d.b2PrismaticJoint} 95 | */ 96 | box2d.Testbed.Prismatic.prototype.m_joint = null; 97 | 98 | /** 99 | * @export 100 | * @return {void} 101 | * @param {number} key 102 | */ 103 | box2d.Testbed.Prismatic.prototype.Keyboard = function (key) 104 | { 105 | switch (key) 106 | { 107 | case goog.events.KeyCodes.L: 108 | this.m_joint.EnableLimit(!this.m_joint.IsLimitEnabled()); 109 | break; 110 | 111 | case goog.events.KeyCodes.M: 112 | this.m_joint.EnableMotor(!this.m_joint.IsMotorEnabled()); 113 | break; 114 | 115 | case goog.events.KeyCodes.S: 116 | this.m_joint.SetMotorSpeed(-this.m_joint.GetMotorSpeed()); 117 | break; 118 | } 119 | } 120 | 121 | /** 122 | * @export 123 | * @return {void} 124 | * @param {box2d.Testbed.Settings} settings 125 | */ 126 | box2d.Testbed.Prismatic.prototype.Step = function (settings) 127 | { 128 | goog.base(this, 'Step', settings); 129 | this.m_debugDraw.DrawString(5, this.m_textLine, "Keys: (l) limits, (m) motors, (s) speed"); 130 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 131 | var force = this.m_joint.GetMotorForce(settings.hz); 132 | this.m_debugDraw.DrawString(5, this.m_textLine, "Motor Force = %4.0f", force); 133 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 134 | } 135 | 136 | /** 137 | * @export 138 | * @return {box2d.Testbed.Test} 139 | * @param {HTMLCanvasElement} canvas 140 | * @param {box2d.Testbed.Settings} settings 141 | */ 142 | box2d.Testbed.Prismatic.Create = function (canvas, settings) 143 | { 144 | return new box2d.Testbed.Prismatic(canvas, settings); 145 | } 146 | 147 | return box2d 148 | }) 149 | // End auto-generated code. 150 | -------------------------------------------------------------------------------- /test/tests/pulleys.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Pulleys'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Pulleys === 'undefined') 28 | box2d.Testbed.Pulleys = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Pulleys = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | var y = 16.0; 45 | var L = 12.0; 46 | var a = 1.0; 47 | var b = 2.0; 48 | 49 | var ground = null; 50 | if (true) 51 | { 52 | var bd = new box2d.b2BodyDef(); 53 | ground = this.m_world.CreateBody(bd); 54 | 55 | var edge = new box2d.b2EdgeShape(); 56 | edge.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 57 | //ground.CreateFixture2(edge, 0.0); 58 | 59 | /*box2d.b2CircleShape*/ var circle = new box2d.b2CircleShape(); 60 | circle.m_radius = 2.0; 61 | 62 | circle.m_p.Set(-10.0, y + b + L); 63 | ground.CreateFixture2(circle, 0.0); 64 | 65 | circle.m_p.Set(10.0, y + b + L); 66 | ground.CreateFixture2(circle, 0.0); 67 | } 68 | 69 | { 70 | 71 | var shape = new box2d.b2PolygonShape(); 72 | shape.SetAsBox(a, b); 73 | 74 | var bd = new box2d.b2BodyDef(); 75 | bd.type = box2d.b2BodyType.b2_dynamicBody; 76 | 77 | //bd.fixedRotation = true; 78 | bd.position.Set(-10.0, y); 79 | var body1 = this.m_world.CreateBody(bd); 80 | body1.CreateFixture2(shape, 5.0); 81 | 82 | bd.position.Set(10.0, y); 83 | var body2 = this.m_world.CreateBody(bd); 84 | body2.CreateFixture2(shape, 5.0); 85 | 86 | var pulleyDef = new box2d.b2PulleyJointDef(); 87 | var anchor1 = new box2d.b2Vec2(-10.0, y + b); 88 | var anchor2 = new box2d.b2Vec2(10.0, y + b); 89 | var groundAnchor1 = new box2d.b2Vec2(-10.0, y + b + L); 90 | var groundAnchor2 = new box2d.b2Vec2(10.0, y + b + L); 91 | pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 1.5); 92 | 93 | this.m_joint1 = /** @type {box2d.b2PulleyJoint} */ (this.m_world.CreateJoint(pulleyDef)); 94 | } 95 | } 96 | 97 | goog.inherits(box2d.Testbed.Pulleys, box2d.Testbed.Test); 98 | 99 | /** 100 | * @export 101 | * @type {box2d.b2PulleyJoint} 102 | */ 103 | box2d.Testbed.Pulleys.prototype.m_joint1 = null; 104 | 105 | /** 106 | * @export 107 | * @return {void} 108 | * @param {number} key 109 | */ 110 | box2d.Testbed.Pulleys.prototype.Keyboard = function (key) 111 | { 112 | switch (key) 113 | { 114 | case goog.events.KeyCodes.ZERO: 115 | break; 116 | } 117 | } 118 | 119 | /** 120 | * @export 121 | * @return {void} 122 | * @param {box2d.Testbed.Settings} settings 123 | */ 124 | box2d.Testbed.Pulleys.prototype.Step = function (settings) 125 | { 126 | goog.base(this, 'Step', settings); 127 | 128 | var ratio = this.m_joint1.GetRatio(); 129 | var L = this.m_joint1.GetCurrentLengthA() + ratio * this.m_joint1.GetCurrentLengthB(); 130 | this.m_debugDraw.DrawString(5, this.m_textLine, "L1 + %4.2f * L2 = %4.2f", ratio, L); 131 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 132 | } 133 | 134 | /** 135 | * @export 136 | * @return {box2d.Testbed.Test} 137 | * @param {HTMLCanvasElement} canvas 138 | * @param {box2d.Testbed.Settings} settings 139 | */ 140 | box2d.Testbed.Pulleys.Create = function (canvas, settings) 141 | { 142 | return new box2d.Testbed.Pulleys(canvas, settings); 143 | } 144 | 145 | return box2d 146 | }) 147 | // End auto-generated code. 148 | -------------------------------------------------------------------------------- /test/tests/pyramid.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Pyramid'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Pyramid === 'undefined') 28 | box2d.Testbed.Pyramid = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Pyramid = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | var ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 51 | ground.CreateFixture2(shape, 0.0); 52 | } 53 | 54 | if (true) 55 | { 56 | var a = 0.5; 57 | var shape = new box2d.b2PolygonShape(); 58 | shape.SetAsBox(a, a); 59 | 60 | var x = new box2d.b2Vec2(-7.0, 0.75); 61 | var y = new box2d.b2Vec2(0.0, 0.0); 62 | var deltaX = new box2d.b2Vec2(0.5625, 1.25); 63 | var deltaY = new box2d.b2Vec2(1.125, 0.0); 64 | 65 | for (var i = 0; i < box2d.Testbed.Pyramid.e_count; ++i) 66 | { 67 | y.Copy(x); 68 | 69 | for (var j = i; j < box2d.Testbed.Pyramid.e_count; ++j) 70 | { 71 | var bd = new box2d.b2BodyDef(); 72 | bd.type = box2d.b2BodyType.b2_dynamicBody; 73 | bd.position.Copy(y); 74 | var body = this.m_world.CreateBody(bd); 75 | body.CreateFixture2(shape, 5.0); 76 | 77 | y.SelfAdd(deltaY); 78 | } 79 | 80 | x.SelfAdd(deltaX); 81 | } 82 | } 83 | } 84 | 85 | goog.inherits(box2d.Testbed.Pyramid, box2d.Testbed.Test); 86 | 87 | /** 88 | * @export 89 | * @const 90 | * @type {number} 91 | */ 92 | box2d.Testbed.Pyramid.e_count = 20; 93 | 94 | /** 95 | * @export 96 | * @return {void} 97 | * @param {box2d.Testbed.Settings} settings 98 | */ 99 | box2d.Testbed.Pyramid.prototype.Step = function (settings) 100 | { 101 | goog.base(this, 'Step', settings); 102 | 103 | //box2d.b2DynamicTree* tree = &m_world.m_contactManager.m_broadPhase.m_tree; 104 | 105 | //if (m_stepCount == 400) 106 | //{ 107 | // tree.RebuildBottomUp(); 108 | //} 109 | } 110 | 111 | /** 112 | * @export 113 | * @return {box2d.Testbed.Test} 114 | * @param {HTMLCanvasElement} canvas 115 | * @param {box2d.Testbed.Settings} settings 116 | */ 117 | box2d.Testbed.Pyramid.Create = function (canvas, settings) 118 | { 119 | return new box2d.Testbed.Pyramid(canvas, settings); 120 | } 121 | 122 | return box2d 123 | }) 124 | // End auto-generated code. 125 | -------------------------------------------------------------------------------- /test/tests/rope.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Rope'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Rope === 'undefined') 28 | box2d.Testbed.Rope = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Rope = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_rope = new box2d.b2Rope(); 45 | 46 | /*const int32*/ var N = 40; 47 | /*box2d.b2Vec2[]*/ var vertices = box2d.b2Vec2.MakeArray(N); 48 | /*float32[]*/ var masses = box2d.b2MakeNumberArray(N); 49 | 50 | for (/*int32*/ var i = 0; i < N; ++i) 51 | { 52 | vertices[i].Set(0.0, 20.0 - 0.25 * i); 53 | masses[i] = 1.0; 54 | } 55 | masses[0] = 0.0; 56 | masses[1] = 0.0; 57 | 58 | /*box2d.b2RopeDef*/ var def = new box2d.b2RopeDef(); 59 | def.vertices = vertices; 60 | def.count = N; 61 | def.gravity.Set(0.0, -10.0); 62 | def.masses = masses; 63 | def.damping = 0.1; 64 | def.k2 = 1.0; 65 | def.k3 = 0.5; 66 | 67 | this.m_rope.Initialize(def); 68 | 69 | this.m_angle = 0.0; 70 | this.m_rope.SetAngleRadians(this.m_angle); 71 | } 72 | 73 | goog.inherits(box2d.Testbed.Rope, box2d.Testbed.Test); 74 | 75 | /** 76 | * @export 77 | * @type {box2d.b2Rope} 78 | */ 79 | box2d.Testbed.Rope.prototype.m_rope = null; 80 | /** 81 | * @export 82 | * @type {number} 83 | */ 84 | box2d.Testbed.Rope.prototype.m_angle = 0.0; 85 | 86 | /** 87 | * @export 88 | * @return {void} 89 | * @param {number} key 90 | */ 91 | box2d.Testbed.Rope.prototype.Keyboard = function (key) 92 | { 93 | switch (key) 94 | { 95 | case goog.events.KeyCodes.Q: 96 | this.m_angle = box2d.b2Max(-box2d.b2_pi, this.m_angle - 0.05 * box2d.b2_pi); 97 | this.m_rope.SetAngleRadians(this.m_angle); 98 | break; 99 | 100 | case goog.events.KeyCodes.E: 101 | this.m_angle = box2d.b2Min(box2d.b2_pi, this.m_angle + 0.05 * box2d.b2_pi); 102 | this.m_rope.SetAngleRadians(this.m_angle); 103 | break; 104 | } 105 | } 106 | 107 | /** 108 | * @export 109 | * @return {void} 110 | * @param {box2d.Testbed.Settings} settings 111 | */ 112 | box2d.Testbed.Rope.prototype.Step = function (settings) 113 | { 114 | /*float32*/ var dt = settings.hz > 0.0 ? 1.0 / settings.hz : 0.0; 115 | 116 | if (settings.pause == 1 && settings.singleStep == 0) 117 | { 118 | dt = 0.0; 119 | } 120 | 121 | this.m_rope.Step(dt, 1); 122 | 123 | goog.base(this, 'Step', settings); 124 | 125 | this.m_rope.Draw(this.m_debugDraw); 126 | 127 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press (q,e) to adjust target angle"); 128 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 129 | this.m_debugDraw.DrawString(5, this.m_textLine, "Target angle = %4.2f degrees", this.m_angle * 180.0 / box2d.b2_pi); 130 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 131 | } 132 | 133 | /** 134 | * @export 135 | * @return {box2d.Testbed.Test} 136 | * @param {HTMLCanvasElement} canvas 137 | * @param {box2d.Testbed.Settings} settings 138 | */ 139 | box2d.Testbed.Rope.Create = function (canvas, settings) 140 | { 141 | return new box2d.Testbed.Rope(canvas, settings); 142 | } 143 | 144 | return box2d 145 | }) 146 | // End auto-generated code. 147 | -------------------------------------------------------------------------------- /test/tests/ropejoint.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.RopeJoint'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.RopeJoint === 'undefined') 28 | box2d.Testbed.RopeJoint = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * This test shows how a rope joint can be used to stabilize a 35 | * chain of bodies with a heavy payload. Notice that the rope 36 | * joint just prevents excessive stretching and has no other 37 | * effect. 38 | * By disabling the rope joint you can see that the Box2D solver 39 | * has trouble supporting heavy bodies with light bodies. Try 40 | * playing around with the densities, time step, and iterations 41 | * to see how they affect stability. This test also shows how to 42 | * use contact filtering. Filtering is configured so that the 43 | * payload does not collide with the chain. 44 | */ 45 | 46 | /** 47 | * @export 48 | * @constructor 49 | * @extends {box2d.Testbed.Test} 50 | * @param {HTMLCanvasElement} canvas 51 | * @param {box2d.Testbed.Settings} settings 52 | */ 53 | box2d.Testbed.RopeJoint = function (canvas, settings) 54 | { 55 | goog.base(this, canvas, settings); // base class constructor 56 | 57 | this.m_ropeDef = new box2d.b2RopeJointDef(); 58 | 59 | /*box2d.b2Body*/ var ground = null; 60 | if (true) 61 | { 62 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 63 | ground = this.m_world.CreateBody(bd); 64 | 65 | /*box2d.b2EdgeShape*/ var shape = new box2d.b2EdgeShape(); 66 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 67 | ground.CreateFixture2(shape, 0.0); 68 | } 69 | 70 | if (true) 71 | { 72 | /*box2d.b2PolygonShape*/ var shape = new box2d.b2PolygonShape(); 73 | shape.SetAsBox(0.5, 0.125); 74 | 75 | /*box2d.b2FixtureDef*/ var fd = new box2d.b2FixtureDef(); 76 | fd.shape = shape; 77 | fd.density = 20.0; 78 | fd.friction = 0.2; 79 | fd.filter.categoryBits = 0x0001; 80 | fd.filter.maskBits = 0xFFFF & ~0x0002; 81 | 82 | /*box2d.b2RevoluteJointDef*/ var jd = new box2d.b2RevoluteJointDef(); 83 | jd.collideConnected = false; 84 | 85 | /*const int32*/ var N = 10; 86 | /*const float32*/ var y = 15.0; 87 | this.m_ropeDef.localAnchorA.Set(0.0, y); 88 | 89 | /*box2d.b2Body*/ var prevBody = ground; 90 | for (/*int32*/ var i = 0; i < N; ++i) 91 | { 92 | /*box2d.b2BodyDef*/ var bd = new box2d.b2BodyDef(); 93 | bd.type = box2d.b2BodyType.b2_dynamicBody; 94 | bd.position.Set(0.5 + 1.0 * i, y); 95 | if (i == N - 1) 96 | { 97 | shape.SetAsBox(1.5, 1.5); 98 | fd.density = 100.0; 99 | fd.filter.categoryBits = 0x0002; 100 | bd.position.Set(1.0 * i, y); 101 | bd.angularDamping = 0.4; 102 | } 103 | 104 | /*box2d.b2Body*/ var body = this.m_world.CreateBody(bd); 105 | 106 | body.CreateFixture(fd); 107 | 108 | /*box2d.b2Vec2*/ var anchor = new box2d.b2Vec2(i, y); 109 | jd.Initialize(prevBody, body, anchor); 110 | this.m_world.CreateJoint(jd); 111 | 112 | prevBody = body; 113 | } 114 | 115 | this.m_ropeDef.localAnchorB.SetZero(); 116 | 117 | /*float32*/ var extraLength = 0.01; 118 | this.m_ropeDef.maxLength = N - 1.0 + extraLength; 119 | this.m_ropeDef.bodyB = prevBody; 120 | } 121 | 122 | if (true) 123 | { 124 | this.m_ropeDef.bodyA = ground; 125 | this.m_rope = this.m_world.CreateJoint(this.m_ropeDef); 126 | } 127 | } 128 | 129 | goog.inherits(box2d.Testbed.RopeJoint, box2d.Testbed.Test); 130 | 131 | /** 132 | * @export 133 | * @type {box2d.b2RopeJointDef} 134 | */ 135 | box2d.Testbed.RopeJoint.prototype.m_ropeDef = null; 136 | /** 137 | * @export 138 | * @type {box2d.b2Joint} 139 | */ 140 | box2d.Testbed.RopeJoint.prototype.m_rope = null; 141 | 142 | /** 143 | * @export 144 | * @return {void} 145 | * @param {number} key 146 | */ 147 | box2d.Testbed.RopeJoint.prototype.Keyboard = function (key) 148 | { 149 | switch (key) 150 | { 151 | case goog.events.KeyCodes.J: 152 | if (this.m_rope) 153 | { 154 | this.m_world.DestroyJoint(this.m_rope); 155 | this.m_rope = null; 156 | } 157 | else 158 | { 159 | this.m_rope = this.m_world.CreateJoint(this.m_ropeDef); 160 | } 161 | break; 162 | } 163 | } 164 | 165 | /** 166 | * @export 167 | * @return {void} 168 | * @param {box2d.Testbed.Settings} settings 169 | */ 170 | box2d.Testbed.RopeJoint.prototype.Step = function (settings) 171 | { 172 | goog.base(this, 'Step', settings); 173 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press (j) to toggle the rope joint."); 174 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 175 | if (this.m_rope) 176 | { 177 | this.m_debugDraw.DrawString(5, this.m_textLine, "Rope ON"); 178 | } 179 | else 180 | { 181 | this.m_debugDraw.DrawString(5, this.m_textLine, "Rope OFF"); 182 | } 183 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 184 | } 185 | 186 | /** 187 | * @export 188 | * @return {box2d.Testbed.Test} 189 | * @param {HTMLCanvasElement} canvas 190 | * @param {box2d.Testbed.Settings} settings 191 | */ 192 | box2d.Testbed.RopeJoint.Create = function (canvas, settings) 193 | { 194 | return new box2d.Testbed.RopeJoint(canvas, settings); 195 | } 196 | 197 | return box2d 198 | }) 199 | // End auto-generated code. 200 | -------------------------------------------------------------------------------- /test/tests/shapeediting.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2008-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.ShapeEditing'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.ShapeEditing === 'undefined') 28 | box2d.Testbed.ShapeEditing = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.ShapeEditing = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | var ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 51 | ground.CreateFixture2(shape, 0.0); 52 | } 53 | 54 | var bd = new box2d.b2BodyDef(); 55 | bd.type = box2d.b2BodyType.b2_dynamicBody; 56 | bd.position.Set(0.0, 10.0); 57 | this.m_body = this.m_world.CreateBody(bd); 58 | 59 | var shape = new box2d.b2PolygonShape(); 60 | shape.SetAsOrientedBox(4.0, 4.0, new box2d.b2Vec2(0.0, 0.0), 0.0); 61 | this.m_fixture1 = this.m_body.CreateFixture2(shape, 10.0); 62 | 63 | this.m_fixture2 = null; 64 | 65 | this.m_sensor = false; 66 | } 67 | 68 | goog.inherits(box2d.Testbed.ShapeEditing, box2d.Testbed.Test); 69 | 70 | /** 71 | * @export 72 | * @type {box2d.b2Body} 73 | */ 74 | box2d.Testbed.ShapeEditing.prototype.m_body = null; 75 | /** 76 | * @export 77 | * @type {box2d.b2Fixture} 78 | */ 79 | box2d.Testbed.ShapeEditing.prototype.m_fixture1 = null; 80 | /** 81 | * @export 82 | * @type {box2d.b2Fixture} 83 | */ 84 | box2d.Testbed.ShapeEditing.prototype.m_fixture2 = null; 85 | /** 86 | * @export 87 | * @type {boolean} 88 | */ 89 | box2d.Testbed.ShapeEditing.prototype.m_sensor = false; 90 | 91 | /** 92 | * @export 93 | * @return {void} 94 | * @param {number} key 95 | */ 96 | box2d.Testbed.ShapeEditing.prototype.Keyboard = function (key) 97 | { 98 | switch (key) 99 | { 100 | case goog.events.KeyCodes.C: 101 | if (this.m_fixture2 === null) 102 | { 103 | var shape = new box2d.b2CircleShape(); 104 | shape.m_radius = 3.0; 105 | shape.m_p.Set(0.5, -4.0); 106 | this.m_fixture2 = this.m_body.CreateFixture2(shape, 10.0); 107 | this.m_body.SetAwake(true); 108 | } 109 | break; 110 | 111 | case goog.events.KeyCodes.D: 112 | if (this.m_fixture2 !== null) 113 | { 114 | this.m_body.DestroyFixture(this.m_fixture2); 115 | this.m_fixture2 = null; 116 | this.m_body.SetAwake(true); 117 | } 118 | break; 119 | 120 | case goog.events.KeyCodes.S: 121 | if (this.m_fixture2 !== null) 122 | { 123 | this.m_sensor = !this.m_sensor; 124 | this.m_fixture2.SetSensor(this.m_sensor); 125 | } 126 | break; 127 | } 128 | } 129 | 130 | /** 131 | * @export 132 | * @return {void} 133 | * @param {box2d.Testbed.Settings} settings 134 | */ 135 | box2d.Testbed.ShapeEditing.prototype.Step = function (settings) 136 | { 137 | goog.base(this, 'Step', settings); 138 | this.m_debugDraw.DrawString(5, this.m_textLine, "Press: (c) create a shape, (d) destroy a shape."); 139 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 140 | this.m_debugDraw.DrawString(5, this.m_textLine, "sensor = %d", (this.m_sensor)?(1):(0)); 141 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 142 | } 143 | 144 | /** 145 | * @export 146 | * @return {box2d.Testbed.Test} 147 | * @param {HTMLCanvasElement} canvas 148 | * @param {box2d.Testbed.Settings} settings 149 | */ 150 | box2d.Testbed.ShapeEditing.Create = function (canvas, settings) 151 | { 152 | return new box2d.Testbed.ShapeEditing(canvas, settings); 153 | } 154 | 155 | return box2d 156 | }) 157 | // End auto-generated code. 158 | -------------------------------------------------------------------------------- /test/tests/spherestack.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.SphereStack'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.SphereStack === 'undefined') 28 | box2d.Testbed.SphereStack = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.SphereStack = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_bodies = new Array(box2d.Testbed.SphereStack.e_count); 45 | 46 | if (true) 47 | { 48 | var bd = new box2d.b2BodyDef(); 49 | var ground = this.m_world.CreateBody(bd); 50 | 51 | var shape = new box2d.b2EdgeShape(); 52 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 53 | ground.CreateFixture2(shape, 0.0); 54 | } 55 | 56 | if (true) 57 | { 58 | var shape = new box2d.b2CircleShape(); 59 | shape.m_radius = 1.0; 60 | 61 | for (var i = 0; i < box2d.Testbed.SphereStack.e_count; ++i) 62 | { 63 | var bd = new box2d.b2BodyDef(); 64 | bd.type = box2d.b2BodyType.b2_dynamicBody; 65 | bd.position.Set(0.0, 4.0 + 3.0 * i); 66 | 67 | this.m_bodies[i] = this.m_world.CreateBody(bd); 68 | 69 | this.m_bodies[i].CreateFixture2(shape, 1.0); 70 | 71 | this.m_bodies[i].SetLinearVelocity(new box2d.b2Vec2(0.0, -50.0)); 72 | } 73 | } 74 | } 75 | 76 | goog.inherits(box2d.Testbed.SphereStack, box2d.Testbed.Test); 77 | 78 | /** 79 | * @export 80 | * @const 81 | * @type {number} 82 | */ 83 | box2d.Testbed.SphereStack.e_count = 10; 84 | 85 | /** 86 | * @export 87 | * @type {Array.} 88 | */ 89 | box2d.Testbed.SphereStack.prototype.m_bodies = null; 90 | 91 | /** 92 | * @export 93 | * @return {void} 94 | * @param {box2d.Testbed.Settings} settings 95 | */ 96 | box2d.Testbed.SphereStack.prototype.Step = function (settings) 97 | { 98 | goog.base(this, 'Step', settings); 99 | 100 | //for (var i = 0; i < box2d.Testbed.SphereStack.e_count; ++i) 101 | //{ 102 | // printf("%g ", this.m_bodies[i].GetWorldCenter().y); 103 | //} 104 | 105 | //for (var i = 0; i < box2d.Testbed.SphereStack.e_count; ++i) 106 | //{ 107 | // printf("%g ", this.m_bodies[i].GetLinearVelocity().y); 108 | //} 109 | 110 | //printf("\n"); 111 | } 112 | 113 | /** 114 | * @export 115 | * @return {box2d.Testbed.Test} 116 | * @param {HTMLCanvasElement} canvas 117 | * @param {box2d.Testbed.Settings} settings 118 | */ 119 | box2d.Testbed.SphereStack.Create = function (canvas, settings) 120 | { 121 | return new box2d.Testbed.SphereStack(canvas, settings); 122 | } 123 | 124 | return box2d 125 | }) 126 | // End auto-generated code. 127 | -------------------------------------------------------------------------------- /test/tests/testccd.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test', 'mod_goog_events_keycodes'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.TestCCD'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.TestCCD === 'undefined') 28 | box2d.Testbed.TestCCD = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | // -removed- goog.require('goog.events.KeyCodes'); 34 | 35 | /** 36 | * @export 37 | * @constructor 38 | * @extends {box2d.Testbed.Test} 39 | * @param {HTMLCanvasElement} canvas 40 | * @param {box2d.Testbed.Settings} settings 41 | */ 42 | box2d.Testbed.TestCCD = function (canvas, settings) 43 | { 44 | goog.base(this, canvas, settings); // base class constructor 45 | 46 | if (true) 47 | { 48 | var bd = new box2d.b2BodyDef(); 49 | var ground = this.m_world.CreateBody(bd); 50 | 51 | var vertices = []; 52 | vertices[0] = new box2d.b2Vec2(-30.0, 0.0); 53 | vertices[1] = new box2d.b2Vec2( 30.0, 0.0); 54 | vertices[2] = new box2d.b2Vec2( 30.0, 40.0); 55 | vertices[3] = new box2d.b2Vec2(-30.0, 40.0); 56 | var shape = new box2d.b2ChainShape(); 57 | shape.CreateLoop(vertices); 58 | ground.CreateFixture2(shape, 0.0); 59 | } 60 | 61 | // Always on, even if default is off 62 | this.m_world.SetContinuousPhysics(true); 63 | 64 | var bd; 65 | var body; 66 | var fd = new box2d.b2FixtureDef(); 67 | // These values are used for all the parts of the 'basket' 68 | fd.density = 4.0; 69 | fd.restitution = 1.4; 70 | 71 | // Create 'basket' 72 | { 73 | bd = new box2d.b2BodyDef(); 74 | bd.type = box2d.b2BodyType.b2_dynamicBody; 75 | bd.bullet = true; 76 | bd.position.Set( 15.0, 5.0 ); 77 | body = this.m_world.CreateBody(bd); 78 | 79 | var sd_bottom = new box2d.b2PolygonShape(); 80 | sd_bottom.SetAsBox( 4.5, 0.45 ); 81 | fd.shape = sd_bottom; 82 | body.CreateFixture(fd); 83 | 84 | var sd_left = new box2d.b2PolygonShape(); 85 | sd_left.SetAsOrientedBox(0.45, 8.1, new box2d.b2Vec2(-4.35, 7.05), 0.2); 86 | fd.shape = sd_left; 87 | body.CreateFixture(fd); 88 | 89 | var sd_right = new box2d.b2PolygonShape(); 90 | sd_right.SetAsOrientedBox(0.45, 8.1, new box2d.b2Vec2(4.35, 7.05), -0.2); 91 | fd.shape = sd_right; 92 | body.CreateFixture(fd); 93 | } 94 | 95 | // add some small circles for effect 96 | for (var i = 0; i < 5; i++) 97 | { 98 | var cd = new box2d.b2CircleShape((Math.random() * 1.0 + 0.5)); 99 | fd.shape = cd; 100 | fd.friction = 0.3; 101 | fd.density = 1.0; 102 | fd.restitution = 1.1; 103 | bd = new box2d.b2BodyDef(); 104 | bd.type = box2d.b2BodyType.b2_dynamicBody; 105 | bd.bullet = true; 106 | bd.position.Set( (Math.random() * 30.0 - 25.0), (Math.random() * 32.0 + 2.0) ); 107 | body = this.m_world.CreateBody(bd); 108 | body.CreateFixture(fd); 109 | } 110 | } 111 | 112 | goog.inherits(box2d.Testbed.TestCCD, box2d.Testbed.Test); 113 | 114 | /** 115 | * @export 116 | * @return {box2d.Testbed.Test} 117 | * @param {HTMLCanvasElement} canvas 118 | * @param {box2d.Testbed.Settings} settings 119 | */ 120 | box2d.Testbed.TestCCD.Create = function (canvas, settings) 121 | { 122 | return new box2d.Testbed.TestCCD(canvas, settings); 123 | } 124 | 125 | return box2d 126 | }) 127 | // End auto-generated code. 128 | -------------------------------------------------------------------------------- /test/tests/teststack.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test', 'mod_goog_events_keycodes'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.TestStack'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.TestStack === 'undefined') 28 | box2d.Testbed.TestStack = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | // -removed- goog.require('goog.events.KeyCodes'); 34 | 35 | /** 36 | * @export 37 | * @constructor 38 | * @extends {box2d.Testbed.Test} 39 | * @param {HTMLCanvasElement} canvas 40 | * @param {box2d.Testbed.Settings} settings 41 | */ 42 | box2d.Testbed.TestStack = function (canvas, settings) 43 | { 44 | goog.base(this, canvas, settings); // base class constructor 45 | 46 | if (true) 47 | { 48 | var bd = new box2d.b2BodyDef(); 49 | var ground = this.m_world.CreateBody(bd); 50 | 51 | var vertices = []; 52 | vertices[0] = new box2d.b2Vec2(-30.0, 0.0); 53 | vertices[1] = new box2d.b2Vec2( 30.0, 0.0); 54 | vertices[2] = new box2d.b2Vec2( 30.0, 40.0); 55 | vertices[3] = new box2d.b2Vec2(-30.0, 40.0); 56 | var shape = new box2d.b2ChainShape(); 57 | shape.CreateLoop(vertices); 58 | ground.CreateFixture2(shape, 0.0); 59 | } 60 | 61 | // Add bodies 62 | var bd = new box2d.b2BodyDef(); 63 | var fd = new box2d.b2FixtureDef(); 64 | bd.type = box2d.b2BodyType.b2_dynamicBody; 65 | //bd.isBullet = true; 66 | fd.shape = new box2d.b2PolygonShape(); 67 | fd.density = 1.0; 68 | fd.friction = 0.5; 69 | fd.restitution = 0.1; 70 | fd.shape.SetAsBox(1.0, 1.0); 71 | // Create 3 stacks 72 | for (var i = 0; i < 10; ++i) 73 | { 74 | bd.position.Set(( 0.0 + Math.random()*0.2 - 0.1), (30.0-i*2.5)); 75 | this.m_world.CreateBody(bd).CreateFixture(fd); 76 | } 77 | for (var i = 0; i < 10; ++i) 78 | { 79 | bd.position.Set((10.0 + Math.random()*0.2 - 0.1), (30.0-i*2.5)); 80 | this.m_world.CreateBody(bd).CreateFixture(fd); 81 | } 82 | for (var i = 0; i < 10; ++i) 83 | { 84 | bd.position.Set((20.0 + Math.random()*0.2 - 0.1), (30.0-i*2.5)); 85 | this.m_world.CreateBody(bd).CreateFixture(fd); 86 | } 87 | // Create ramp 88 | bd.type = box2d.b2BodyType.b2_staticBody; 89 | bd.position.Set(0.0, 0.0); 90 | var vxs = 91 | [ 92 | new box2d.b2Vec2(-30.0, 0.0), 93 | new box2d.b2Vec2(-10.0, 0.0), 94 | new box2d.b2Vec2(-30.0, 10.0) 95 | ]; 96 | fd.shape.SetAsArray(vxs, vxs.length); 97 | fd.density = 0; 98 | this.m_world.CreateBody(bd).CreateFixture(fd); 99 | 100 | // Create ball 101 | bd.type = box2d.b2BodyType.b2_dynamicBody; 102 | bd.position.Set(-25.0, 20.0); 103 | fd.shape = new box2d.b2CircleShape(4.0); 104 | fd.density = 2; 105 | fd.restitution = 0.2; 106 | fd.friction = 0.5; 107 | this.m_world.CreateBody(bd).CreateFixture(fd); 108 | } 109 | 110 | goog.inherits(box2d.Testbed.TestStack, box2d.Testbed.Test); 111 | 112 | /** 113 | * @export 114 | * @return {box2d.Testbed.Test} 115 | * @param {HTMLCanvasElement} canvas 116 | * @param {box2d.Testbed.Settings} settings 117 | */ 118 | box2d.Testbed.TestStack.Create = function (canvas, settings) 119 | { 120 | return new box2d.Testbed.TestStack(canvas, settings); 121 | } 122 | 123 | return box2d 124 | }) 125 | // End auto-generated code. 126 | -------------------------------------------------------------------------------- /test/tests/timeofimpact.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.TimeOfImpact'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.TimeOfImpact === 'undefined') 28 | box2d.Testbed.TimeOfImpact = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.TimeOfImpact = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | this.m_shapeA = new box2d.b2PolygonShape(); 45 | this.m_shapeB = new box2d.b2PolygonShape(); 46 | 47 | this.m_shapeA.SetAsBox(25.0, 5.0); 48 | this.m_shapeB.SetAsBox(2.5, 2.5); 49 | } 50 | 51 | goog.inherits(box2d.Testbed.TimeOfImpact, box2d.Testbed.Test); 52 | 53 | /** 54 | * @export 55 | * @type {box2d.b2PolygonShape} 56 | */ 57 | box2d.Testbed.TimeOfImpact.prototype.m_shapeA = null; 58 | /** 59 | * @export 60 | * @type {box2d.b2PolygonShape} 61 | */ 62 | box2d.Testbed.TimeOfImpact.prototype.m_shapeB = null; 63 | 64 | /** 65 | * @export 66 | * @return {void} 67 | * @param {box2d.Testbed.Settings} settings 68 | */ 69 | box2d.Testbed.TimeOfImpact.prototype.Step = function (settings) 70 | { 71 | goog.base(this, 'Step', settings); 72 | 73 | var sweepA = new box2d.b2Sweep; 74 | sweepA.c0.Set(24.0, -60.0); 75 | sweepA.a0 = 2.95; 76 | sweepA.c = sweepA.c0; 77 | sweepA.a = sweepA.a0; 78 | sweepA.localCenter.SetZero(); 79 | 80 | var sweepB = new box2d.b2Sweep; 81 | sweepB.c0.Set(53.474274, -50.252514); 82 | sweepB.a0 = 513.36676; // - 162.0 * box2d.b2_pi; 83 | sweepB.c.Set(54.595478, -51.083473); 84 | sweepB.a = 513.62781; // - 162.0 * box2d.b2_pi; 85 | sweepB.localCenter.SetZero(); 86 | 87 | //sweepB.a0 -= 300.0 * box2d.b2_pi; 88 | //sweepB.a -= 300.0 * box2d.b2_pi; 89 | 90 | var input = new box2d.b2TOIInput(); 91 | input.proxyA.SetShape(this.m_shapeA, 0); 92 | input.proxyB.SetShape(this.m_shapeB, 0); 93 | input.sweepA.Copy(sweepA); 94 | input.sweepB.Copy(sweepB); 95 | input.tMax = 1.0; 96 | 97 | var output = new box2d.b2TOIOutput(); 98 | 99 | box2d.b2TimeOfImpact(output, input); 100 | 101 | var toi = output.t; 102 | 103 | this.m_debugDraw.DrawString(5, this.m_textLine, "toi = %4.2f", output.t); 104 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 105 | 106 | this.m_debugDraw.DrawString(5, this.m_textLine, "max toi iters = %d, max root iters = %d", box2d.b2_toiMaxIters, box2d.b2_toiMaxRootIters); 107 | this.m_textLine += box2d.Testbed.DRAW_STRING_NEW_LINE; 108 | 109 | var vertices = new Array(box2d.b2_maxPolygonVertices); 110 | 111 | var transformA = new box2d.b2Transform(); 112 | sweepA.GetTransform(transformA, 0.0); 113 | for (var i = 0; i < this.m_shapeA.m_count; ++i) 114 | { 115 | vertices[i] = box2d.b2MulXV(transformA, this.m_shapeA.m_vertices[i], new box2d.b2Vec2()); 116 | } 117 | this.m_debugDraw.DrawPolygon(vertices, this.m_shapeA.m_count, new box2d.b2Color(0.9, 0.9, 0.9)); 118 | 119 | var transformB = new box2d.b2Transform(); 120 | sweepB.GetTransform(transformB, 0.0); 121 | 122 | //box2d.b2Vec2 localPoint(2.0f, -0.1f); 123 | 124 | for (var i = 0; i < this.m_shapeB.m_count; ++i) 125 | { 126 | vertices[i] = box2d.b2MulXV(transformB, this.m_shapeB.m_vertices[i], new box2d.b2Vec2()); 127 | } 128 | this.m_debugDraw.DrawPolygon(vertices, this.m_shapeB.m_count, new box2d.b2Color(0.5, 0.9, 0.5)); 129 | 130 | sweepB.GetTransform(transformB, output.t); 131 | for (var i = 0; i < this.m_shapeB.m_count; ++i) 132 | { 133 | vertices[i] = box2d.b2MulXV(transformB, this.m_shapeB.m_vertices[i], new box2d.b2Vec2()); 134 | } 135 | this.m_debugDraw.DrawPolygon(vertices, this.m_shapeB.m_count, new box2d.b2Color(0.5, 0.7, 0.9)); 136 | 137 | sweepB.GetTransform(transformB, 1.0); 138 | for (var i = 0; i < this.m_shapeB.m_count; ++i) 139 | { 140 | vertices[i] = box2d.b2MulXV(transformB, this.m_shapeB.m_vertices[i], new box2d.b2Vec2()); 141 | } 142 | this.m_debugDraw.DrawPolygon(vertices, this.m_shapeB.m_count, new box2d.b2Color(0.9, 0.5, 0.5)); 143 | 144 | /* 145 | #if 0 146 | for (float32 t = 0.0f; t < 1.0f; t += 0.1f) 147 | { 148 | sweepB.GetTransform(&transformB, t); 149 | for (int32 i = 0; i < m_shapeB.m_count; ++i) 150 | { 151 | vertices[i] = b2Mul(transformB, m_shapeB.m_vertices[i]); 152 | } 153 | m_debugDraw.DrawPolygon(vertices, m_shapeB.m_count, box2d.b2Color(0.9f, 0.5f, 0.5f)); 154 | } 155 | #endif 156 | */ 157 | } 158 | 159 | /** 160 | * @export 161 | * @return {box2d.Testbed.Test} 162 | * @param {HTMLCanvasElement} canvas 163 | * @param {box2d.Testbed.Settings} settings 164 | */ 165 | box2d.Testbed.TimeOfImpact.Create = function (canvas, settings) 166 | { 167 | return new box2d.Testbed.TimeOfImpact(canvas, settings); 168 | } 169 | 170 | return box2d 171 | }) 172 | // End auto-generated code. 173 | -------------------------------------------------------------------------------- /test/tests/tumbler.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2007-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.Tumbler'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.Tumbler === 'undefined') 28 | box2d.Testbed.Tumbler = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.Tumbler = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | /*b2Body*/ var ground = null; 45 | if (true) 46 | { 47 | /*b2BodyDef*/ var bd = new box2d.b2BodyDef(); 48 | ground = this.m_world.CreateBody(bd); 49 | } 50 | 51 | if (true) 52 | { 53 | /*b2BodyDef*/ var bd = new box2d.b2BodyDef(); 54 | bd.type = box2d.b2BodyType.b2_dynamicBody; 55 | bd.allowSleep = false; 56 | bd.position.Set(0.0, 10.0); 57 | /*b2Body*/ var body = this.m_world.CreateBody(bd); 58 | 59 | /*b2PolygonShape*/ var shape = new box2d.b2PolygonShape(); 60 | shape.SetAsOrientedBox(0.5, 10.0, new box2d.b2Vec2( 10.0, 0.0), 0.0); 61 | body.CreateFixture2(shape, 5.0); 62 | shape.SetAsOrientedBox(0.5, 10.0, new box2d.b2Vec2(-10.0, 0.0), 0.0); 63 | body.CreateFixture2(shape, 5.0); 64 | shape.SetAsOrientedBox(10.0, 0.5, new box2d.b2Vec2(0.0, 10.0), 0.0); 65 | body.CreateFixture2(shape, 5.0); 66 | shape.SetAsOrientedBox(10.0, 0.5, new box2d.b2Vec2(0.0, -10.0), 0.0); 67 | body.CreateFixture2(shape, 5.0); 68 | 69 | /*b2RevoluteJointDef*/ var jd = new box2d.b2RevoluteJointDef(); 70 | jd.bodyA = ground; 71 | jd.bodyB = body; 72 | jd.localAnchorA.Set(0.0, 10.0); 73 | jd.localAnchorB.Set(0.0, 0.0); 74 | jd.referenceAngle = 0.0; 75 | jd.motorSpeed = 0.05 * box2d.b2_pi; 76 | jd.maxMotorTorque = 1e8; 77 | jd.enableMotor = true; 78 | this.m_joint = /** @type {box2d.b2RevoluteJoint} */ (this.m_world.CreateJoint(jd)); 79 | } 80 | 81 | this.m_count = 0; 82 | } 83 | 84 | goog.inherits(box2d.Testbed.Tumbler, box2d.Testbed.Test); 85 | 86 | /** 87 | * @export 88 | * @const 89 | * @type {number} 90 | */ 91 | box2d.Testbed.Tumbler.e_count = 800; 92 | 93 | /** 94 | * @export 95 | * @type {box2d.b2RevoluteJoint} 96 | */ 97 | box2d.Testbed.Tumbler.prototype.m_joint = null; 98 | /** 99 | * @export 100 | * @type {number} 101 | */ 102 | box2d.Testbed.Tumbler.prototype.m_count = 0; 103 | 104 | /** 105 | * @export 106 | * @return {void} 107 | * @param {box2d.Testbed.Settings} settings 108 | */ 109 | box2d.Testbed.Tumbler.prototype.Step = function (settings) 110 | { 111 | goog.base(this, 'Step', settings); 112 | 113 | if (this.m_count < box2d.Testbed.Tumbler.e_count) 114 | { 115 | /*b2BodyDef*/ var bd = new box2d.b2BodyDef(); 116 | bd.type = box2d.b2BodyType.b2_dynamicBody; 117 | bd.position.Set(0.0, 10.0); 118 | /*b2Body*/ var body = this.m_world.CreateBody(bd); 119 | 120 | /*b2PolygonShape*/ var shape = new box2d.b2PolygonShape(); 121 | shape.SetAsBox(0.125, 0.125); 122 | body.CreateFixture2(shape, 1.0); 123 | 124 | ++this.m_count; 125 | } 126 | } 127 | 128 | /** 129 | * @export 130 | * @return {box2d.Testbed.Test} 131 | * @param {HTMLCanvasElement} canvas 132 | * @param {box2d.Testbed.Settings} settings 133 | */ 134 | box2d.Testbed.Tumbler.Create = function (canvas, settings) 135 | { 136 | return new box2d.Testbed.Tumbler(canvas, settings); 137 | } 138 | 139 | return box2d 140 | }) 141 | // End auto-generated code. 142 | -------------------------------------------------------------------------------- /test/tests/varyingfriction.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.VaryingFriction'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.VaryingFriction === 'undefined') 28 | box2d.Testbed.VaryingFriction = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | /** 34 | * @export 35 | * @constructor 36 | * @extends {box2d.Testbed.Test} 37 | * @param {HTMLCanvasElement} canvas 38 | * @param {box2d.Testbed.Settings} settings 39 | */ 40 | box2d.Testbed.VaryingFriction = function (canvas, settings) 41 | { 42 | goog.base(this, canvas, settings); // base class constructor 43 | 44 | if (true) 45 | { 46 | var bd = new box2d.b2BodyDef(); 47 | var ground = this.m_world.CreateBody(bd); 48 | 49 | var shape = new box2d.b2EdgeShape(); 50 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 51 | ground.CreateFixture2(shape, 0.0); 52 | } 53 | 54 | if (true) 55 | { 56 | var shape = new box2d.b2PolygonShape(); 57 | shape.SetAsBox(13.0, 0.25); 58 | 59 | var bd = new box2d.b2BodyDef(); 60 | bd.position.Set(-4.0, 22.0); 61 | bd.angle = -0.25; 62 | 63 | var ground = this.m_world.CreateBody(bd); 64 | ground.CreateFixture2(shape, 0.0); 65 | } 66 | 67 | if (true) 68 | { 69 | var shape = new box2d.b2PolygonShape(); 70 | shape.SetAsBox(0.25, 1.0); 71 | 72 | var bd = new box2d.b2BodyDef(); 73 | bd.position.Set(10.5, 19.0); 74 | 75 | var ground = this.m_world.CreateBody(bd); 76 | ground.CreateFixture2(shape, 0.0); 77 | } 78 | 79 | if (true) 80 | { 81 | var shape = new box2d.b2PolygonShape(); 82 | shape.SetAsBox(13.0, 0.25); 83 | 84 | var bd = new box2d.b2BodyDef(); 85 | bd.position.Set(4.0, 14.0); 86 | bd.angle = 0.25; 87 | 88 | var ground = this.m_world.CreateBody(bd); 89 | ground.CreateFixture2(shape, 0.0); 90 | } 91 | 92 | if (true) 93 | { 94 | var shape = new box2d.b2PolygonShape(); 95 | shape.SetAsBox(0.25, 1.0); 96 | 97 | var bd = new box2d.b2BodyDef(); 98 | bd.position.Set(-10.5, 11.0); 99 | 100 | var ground = this.m_world.CreateBody(bd); 101 | ground.CreateFixture2(shape, 0.0); 102 | } 103 | 104 | if (true) 105 | { 106 | var shape = new box2d.b2PolygonShape(); 107 | shape.SetAsBox(13.0, 0.25); 108 | 109 | var bd = new box2d.b2BodyDef(); 110 | bd.position.Set(-4.0, 6.0); 111 | bd.angle = -0.25; 112 | 113 | var ground = this.m_world.CreateBody(bd); 114 | ground.CreateFixture2(shape, 0.0); 115 | } 116 | 117 | if (true) 118 | { 119 | var shape = new box2d.b2PolygonShape(); 120 | shape.SetAsBox(0.5, 0.5); 121 | 122 | var fd = new box2d.b2FixtureDef(); 123 | fd.shape = shape; 124 | fd.density = 25.0; 125 | 126 | var friction = [ 0.75, 0.5, 0.35, 0.1, 0.0 ]; 127 | 128 | for (var i = 0; i < 5; ++i) 129 | { 130 | var bd = new box2d.b2BodyDef(); 131 | bd.type = box2d.b2BodyType.b2_dynamicBody; 132 | bd.position.Set(-15.0 + 4.0 * i, 28.0); 133 | var body = this.m_world.CreateBody(bd); 134 | 135 | fd.friction = friction[i]; 136 | body.CreateFixture(fd); 137 | } 138 | } 139 | } 140 | 141 | goog.inherits(box2d.Testbed.VaryingFriction, box2d.Testbed.Test); 142 | 143 | /** 144 | * @export 145 | * @return {box2d.Testbed.Test} 146 | * @param {HTMLCanvasElement} canvas 147 | * @param {box2d.Testbed.Settings} settings 148 | */ 149 | box2d.Testbed.VaryingFriction.Create = function (canvas, settings) 150 | { 151 | return new box2d.Testbed.VaryingFriction(canvas, settings); 152 | } 153 | 154 | return box2d 155 | }) 156 | // End auto-generated code. 157 | -------------------------------------------------------------------------------- /test/tests/varyingrestitution.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog', 'mod_box2d_testbed_test'], function (goog, box2d) { 3 | 4 | /* 5 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 6 | * 7 | * This software is provided 'as-is', without any express or implied 8 | * warranty. In no event will the authors be held liable for any damages 9 | * arising from the use of this software. 10 | * Permission is granted to anyone to use this software for any purpose, 11 | * including commercial applications, and to alter it and redistribute it 12 | * freely, subject to the following restrictions: 13 | * 1. The origin of this software must not be misrepresented; you must not 14 | * claim that you wrote the original software. If you use this software 15 | * in a product, an acknowledgment in the product documentation would be 16 | * appreciated but is not required. 17 | * 2. Altered source versions must be plainly marked as such, and must not be 18 | * misrepresented as being the original software. 19 | * 3. This notice may not be removed or altered from any source distribution. 20 | */ 21 | 22 | // -removed- goog.provide('box2d.Testbed.VaryingRestitution'); 23 | if (typeof box2d === 'undefined') 24 | box2d = {} 25 | if (typeof box2d.Testbed === 'undefined') 26 | box2d.Testbed = {} 27 | if (typeof box2d.Testbed.VaryingRestitution === 'undefined') 28 | box2d.Testbed.VaryingRestitution = {} 29 | 30 | 31 | // -removed- goog.require('box2d.Testbed.Test'); 32 | 33 | // Note: even with a restitution of 1.0, there is some energy change 34 | // due to position correction. 35 | /** 36 | * @export 37 | * @constructor 38 | * @extends {box2d.Testbed.Test} 39 | * @param {HTMLCanvasElement} canvas 40 | * @param {box2d.Testbed.Settings} settings 41 | */ 42 | box2d.Testbed.VaryingRestitution = function (canvas, settings) 43 | { 44 | goog.base(this, canvas, settings); // base class constructor 45 | 46 | if (true) 47 | { 48 | var bd = new box2d.b2BodyDef(); 49 | var ground = this.m_world.CreateBody(bd); 50 | 51 | var shape = new box2d.b2EdgeShape(); 52 | shape.SetAsEdge(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0)); 53 | ground.CreateFixture2(shape, 0.0); 54 | } 55 | 56 | if (true) 57 | { 58 | var shape = new box2d.b2CircleShape(); 59 | shape.m_radius = 1.0; 60 | 61 | var fd = new box2d.b2FixtureDef(); 62 | fd.shape = shape; 63 | fd.density = 1.0; 64 | 65 | var restitution = [ 0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0 ]; 66 | 67 | for (var i = 0; i < 7; ++i) 68 | { 69 | var bd = new box2d.b2BodyDef(); 70 | bd.type = box2d.b2BodyType.b2_dynamicBody; 71 | bd.position.Set(-10.0 + 3.0 * i, 20.0); 72 | 73 | var body = this.m_world.CreateBody(bd); 74 | 75 | fd.restitution = restitution[i]; 76 | body.CreateFixture(fd); 77 | } 78 | } 79 | } 80 | 81 | goog.inherits(box2d.Testbed.VaryingRestitution, box2d.Testbed.Test); 82 | 83 | /** 84 | * @export 85 | * @return {box2d.Testbed.Test} 86 | * @param {HTMLCanvasElement} canvas 87 | * @param {box2d.Testbed.Settings} settings 88 | */ 89 | box2d.Testbed.VaryingRestitution.Create = function (canvas, settings) 90 | { 91 | return new box2d.Testbed.VaryingRestitution(canvas, settings); 92 | } 93 | 94 | return box2d 95 | }) 96 | // End auto-generated code. 97 | -------------------------------------------------------------------------------- /utils/goog/browserfeature.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog_useragent'], function (goog) { 3 | 4 | // Copyright 2010 The Closure Library Authors. All Rights Reserved. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS-IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | /** 19 | * @fileoverview Browser capability checks for the events package. 20 | * 21 | */ 22 | 23 | 24 | // -removed- goog.provide('goog.events.BrowserFeature'); 25 | if (typeof goog === 'undefined') 26 | goog = {} 27 | if (typeof goog.events === 'undefined') 28 | goog.events = {} 29 | if (typeof goog.events.BrowserFeature === 'undefined') 30 | goog.events.BrowserFeature = {} 31 | 32 | 33 | // -removed- goog.require('goog.userAgent'); 34 | 35 | 36 | /** 37 | * Enum of browser capabilities. 38 | * @enum {boolean} 39 | */ 40 | goog.events.BrowserFeature = { 41 | /** 42 | * Whether the button attribute of the event is W3C compliant. False in 43 | * Internet Explorer prior to version 9; document-version dependent. 44 | */ 45 | HAS_W3C_BUTTON: !goog.userAgent.IE || 46 | goog.userAgent.isDocumentModeOrHigher(9), 47 | 48 | /** 49 | * Whether the browser supports full W3C event model. 50 | */ 51 | HAS_W3C_EVENT_SUPPORT: !goog.userAgent.IE || 52 | goog.userAgent.isDocumentModeOrHigher(9), 53 | 54 | /** 55 | * To prevent default in IE7-8 for certain keydown events we need set the 56 | * keyCode to -1. 57 | */ 58 | SET_KEY_CODE_TO_PREVENT_DEFAULT: goog.userAgent.IE && 59 | !goog.userAgent.isVersionOrHigher('9'), 60 | 61 | /** 62 | * Whether the {@code navigator.onLine} property is supported. 63 | */ 64 | HAS_NAVIGATOR_ONLINE_PROPERTY: !goog.userAgent.WEBKIT || 65 | goog.userAgent.isVersionOrHigher('528'), 66 | 67 | /** 68 | * Whether HTML5 network online/offline events are supported. 69 | */ 70 | HAS_HTML5_NETWORK_EVENT_SUPPORT: 71 | goog.userAgent.GECKO && goog.userAgent.isVersionOrHigher('1.9b') || 72 | goog.userAgent.IE && goog.userAgent.isVersionOrHigher('8') || 73 | goog.userAgent.OPERA && goog.userAgent.isVersionOrHigher('9.5') || 74 | goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher('528'), 75 | 76 | /** 77 | * Whether HTML5 network events fire on document.body, or otherwise the 78 | * window. 79 | */ 80 | HTML5_NETWORK_EVENTS_FIRE_ON_BODY: 81 | goog.userAgent.GECKO && !goog.userAgent.isVersionOrHigher('8') || 82 | goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('9'), 83 | 84 | /** 85 | * Whether touch is enabled in the browser. 86 | */ 87 | TOUCH_ENABLED: 88 | ('ontouchstart' in goog.global || 89 | !!(goog.global['document'] && 90 | document.documentElement && 91 | 'ontouchstart' in document.documentElement) || 92 | // IE10 uses non-standard touch events, so it has a different check. 93 | !!(goog.global['navigator'] && 94 | goog.global['navigator']['msMaxTouchPoints'])) 95 | }; 96 | 97 | return goog 98 | }) 99 | // End auto-generated code. 100 | -------------------------------------------------------------------------------- /utils/goog/event.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog_events_eventid'], function (goog) { 3 | 4 | // Copyright 2005 The Closure Library Authors. All Rights Reserved. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS-IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | /** 19 | * @fileoverview A base class for event objects. 20 | * 21 | */ 22 | 23 | 24 | // -removed- goog.provide('goog.events.Event'); 25 | if (typeof goog === 'undefined') 26 | goog = {} 27 | if (typeof goog.events === 'undefined') 28 | goog.events = {} 29 | if (typeof goog.events.Event === 'undefined') 30 | goog.events.Event = {} 31 | 32 | // -removed- goog.provide('goog.events.EventLike'); 33 | if (typeof goog === 'undefined') 34 | goog = {} 35 | if (typeof goog.events === 'undefined') 36 | goog.events = {} 37 | if (typeof goog.events.EventLike === 'undefined') 38 | goog.events.EventLike = {} 39 | 40 | 41 | // -removed- goog.require('goog.events.EventId'); 42 | 43 | 44 | /** 45 | * A typedef for event like objects that are dispatchable via the 46 | * goog.events.dispatchEvent function. strings are treated as the type for a 47 | * goog.events.Event. Objects are treated as an extension of a new 48 | * goog.events.Event with the type property of the object being used as the type 49 | * of the Event. 50 | * @typedef {string|Object|goog.events.Event|goog.events.EventId} 51 | */ 52 | goog.events.EventLike; 53 | 54 | 55 | 56 | /** 57 | * A base class for event objects, so that they can support preventDefault and 58 | * stopPropagation. 59 | * 60 | * @param {string|!goog.events.EventId} type Event Type. 61 | * @param {Object=} opt_target Reference to the object that is the target of 62 | * this event. It has to implement the {@code EventTarget} interface 63 | * declared at {@link http://developer.mozilla.org/en/DOM/EventTarget}. 64 | * @constructor 65 | */ 66 | goog.events.Event = function(type, opt_target) { 67 | /** 68 | * Event type. 69 | * @type {string} 70 | */ 71 | this.type = type instanceof goog.events.EventId ? String(type) : type; 72 | 73 | /** 74 | * Target of the event. 75 | * @type {Object|undefined} 76 | */ 77 | this.target = opt_target; 78 | 79 | /** 80 | * Object that had the listener attached. 81 | * @type {Object|undefined} 82 | */ 83 | this.currentTarget = this.target; 84 | }; 85 | 86 | 87 | /** 88 | * For backwards compatibility (goog.events.Event used to inherit 89 | * goog.Disposable). 90 | * @deprecated Events don't need to be disposed. 91 | */ 92 | goog.events.Event.prototype.disposeInternal = function() { 93 | }; 94 | 95 | 96 | /** 97 | * For backwards compatibility (goog.events.Event used to inherit 98 | * goog.Disposable). 99 | * @deprecated Events don't need to be disposed. 100 | */ 101 | goog.events.Event.prototype.dispose = function() { 102 | }; 103 | 104 | 105 | /** 106 | * Whether to cancel the event in internal capture/bubble processing for IE. 107 | * @type {boolean} 108 | * @public 109 | * @suppress {underscore|visibility} Technically public, but referencing this 110 | * outside this package is strongly discouraged. 111 | */ 112 | goog.events.Event.prototype.propagationStopped_ = false; 113 | 114 | 115 | /** 116 | * Whether the default action has been prevented. 117 | * This is a property to match the W3C specification at {@link 118 | * http://www.w3.org/TR/DOM-Level-3-Events/#events-event-type-defaultPrevented}. 119 | * Must be treated as read-only outside the class. 120 | * @type {boolean} 121 | */ 122 | goog.events.Event.prototype.defaultPrevented = false; 123 | 124 | 125 | /** 126 | * Return value for in internal capture/bubble processing for IE. 127 | * @type {boolean} 128 | * @public 129 | * @suppress {underscore|visibility} Technically public, but referencing this 130 | * outside this package is strongly discouraged. 131 | */ 132 | goog.events.Event.prototype.returnValue_ = true; 133 | 134 | 135 | /** 136 | * Stops event propagation. 137 | */ 138 | goog.events.Event.prototype.stopPropagation = function() { 139 | this.propagationStopped_ = true; 140 | }; 141 | 142 | 143 | /** 144 | * Prevents the default action, for example a link redirecting to a url. 145 | */ 146 | goog.events.Event.prototype.preventDefault = function() { 147 | this.defaultPrevented = true; 148 | this.returnValue_ = false; 149 | }; 150 | 151 | 152 | /** 153 | * Stops the propagation of the event. It is equivalent to 154 | * {@code e.stopPropagation()}, but can be used as the callback argument of 155 | * {@link goog.events.listen} without declaring another function. 156 | * @param {!goog.events.Event} e An event. 157 | */ 158 | goog.events.Event.stopPropagation = function(e) { 159 | e.stopPropagation(); 160 | }; 161 | 162 | 163 | /** 164 | * Prevents the default action. It is equivalent to 165 | * {@code e.preventDefault()}, but can be used as the callback argument of 166 | * {@link goog.events.listen} without declaring another function. 167 | * @param {!goog.events.Event} e An event. 168 | */ 169 | goog.events.Event.preventDefault = function(e) { 170 | e.preventDefault(); 171 | }; 172 | 173 | return goog 174 | }) 175 | // End auto-generated code. 176 | -------------------------------------------------------------------------------- /utils/goog/eventid.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog'], function (goog) { 3 | 4 | // Copyright 2013 The Closure Library Authors. All Rights Reserved. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS-IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | // -removed- goog.provide('goog.events.EventId'); 19 | if (typeof goog === 'undefined') 20 | goog = {} 21 | if (typeof goog.events === 'undefined') 22 | goog.events = {} 23 | if (typeof goog.events.EventId === 'undefined') 24 | goog.events.EventId = {} 25 | 26 | 27 | 28 | 29 | /** 30 | * A templated class that is used when registering for events. Typical usage: 31 | * 32 | * /** @type {goog.events.EventId.} 33 | * var myEventId = new goog.events.EventId( 34 | * goog.events.getUniqueId(('someEvent')); 35 | * 36 | * // No need to cast or declare here since the compiler knows the correct 37 | * // type of 'evt' (MyEventObj). 38 | * something.listen(myEventId, function(evt) {}); 39 | * 40 | * 41 | * @param {string} eventId 42 | * @template T 43 | * @constructor 44 | * @struct 45 | * @final 46 | */ 47 | goog.events.EventId = function(eventId) { 48 | /** @const */ this.id = eventId; 49 | }; 50 | 51 | 52 | /** 53 | * @override 54 | */ 55 | goog.events.EventId.prototype.toString = function() { 56 | return this.id; 57 | }; 58 | 59 | return goog 60 | }) 61 | // End auto-generated code. 62 | -------------------------------------------------------------------------------- /utils/goog/reflect.js: -------------------------------------------------------------------------------- 1 | // This wrapper was auto-generated. 2 | define(['mod_goog'], function (goog) { 3 | 4 | // Copyright 2009 The Closure Library Authors. All Rights Reserved. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS-IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | /** 19 | * @fileoverview Useful compiler idioms. 20 | * 21 | */ 22 | 23 | // -removed- goog.provide('goog.reflect'); 24 | if (typeof goog === 'undefined') 25 | goog = {} 26 | if (typeof goog.reflect === 'undefined') 27 | goog.reflect = {} 28 | 29 | 30 | 31 | /** 32 | * Syntax for object literal casts. 33 | * @see http://go/jscompiler-renaming 34 | * @see http://code.google.com/p/closure-compiler/wiki/ 35 | * ExperimentalTypeBasedPropertyRenaming 36 | * 37 | * Use this if you have an object literal whose keys need to have the same names 38 | * as the properties of some class even after they are renamed by the compiler. 39 | * 40 | * @param {!Function} type Type to cast to. 41 | * @param {Object} object Object literal to cast. 42 | * @return {Object} The object literal. 43 | */ 44 | goog.reflect.object = function(type, object) { 45 | return object; 46 | }; 47 | 48 | 49 | /** 50 | * To assert to the compiler that an operation is needed when it would 51 | * otherwise be stripped. For example: 52 | * 53 | * // Force a layout 54 | * goog.reflect.sinkValue(dialog.offsetHeight); 55 | * 56 | * @type {!Function} 57 | */ 58 | goog.reflect.sinkValue = function(x) { 59 | goog.reflect.sinkValue[' '](x); 60 | return x; 61 | }; 62 | 63 | 64 | /** 65 | * The compiler should optimize this function away iff no one ever uses 66 | * goog.reflect.sinkValue. 67 | */ 68 | goog.reflect.sinkValue[' '] = goog.nullFunction; 69 | 70 | 71 | /** 72 | * Check if a property can be accessed without throwing an exception. 73 | * @param {Object} obj The owner of the property. 74 | * @param {string} prop The property name. 75 | * @return {boolean} Whether the property is accessible. Will also return true 76 | * if obj is null. 77 | */ 78 | goog.reflect.canAccessProperty = function(obj, prop) { 79 | /** @preserveTry */ 80 | try { 81 | goog.reflect.sinkValue(obj[prop]); 82 | return true; 83 | } catch (e) {} 84 | return false; 85 | }; 86 | 87 | return goog 88 | }) 89 | // End auto-generated code. 90 | -------------------------------------------------------------------------------- /utils/paths.json: -------------------------------------------------------------------------------- 1 | { 2 | "mod_goog": "utils/goog/base", 3 | "mod_goog_events_browserevent": "utils/goog/browserevent", 4 | "mod_goog_events_browserfeature": "utils/goog/browserfeature", 5 | "mod_goog_events_event": "utils/goog/event", 6 | "mod_goog_events_eventid": "utils/goog/eventid", 7 | "mod_goog_events_eventtype": "utils/goog/eventtype", 8 | "mod_goog_events_keycodes": "utils/goog/keycodes", 9 | "mod_goog_reflect": "utils/goog/reflect", 10 | "mod_goog_string": "utils/goog/string", 11 | "mod_goog_string_format": "utils/goog/stringformat", 12 | "mod_goog_useragent": "utils/goog/useragent" 13 | } 14 | --------------------------------------------------------------------------------