├── README
├── flash
├── HelloWorld.fla
├── HelloWorld.swf
├── PhysTest.fla
├── PhysTest.swf
├── Box2DFlashAS3_2.0.2_.zip
├── License.txt
├── Box2D
│ ├── Collision
│ │ ├── b2BufferedPair.as
│ │ ├── b2BoundValues.as
│ │ ├── ClipVertex.as
│ │ ├── b2OBB.as
│ │ ├── Shapes
│ │ │ ├── b2CircleDef.as
│ │ │ ├── b2MassData.as
│ │ │ ├── b2FilterData.as
│ │ │ ├── b2ShapeDef.as
│ │ │ └── b2PolygonDef.as
│ │ ├── b2Point.as
│ │ ├── b2PairCallback.as
│ │ ├── b2Proxy.as
│ │ ├── b2Bound.as
│ │ ├── b2AABB.as
│ │ ├── b2ContactPoint.as
│ │ ├── b2ContactID.as
│ │ ├── b2Manifold.as
│ │ ├── b2ManifoldPoint.as
│ │ ├── Features.as
│ │ ├── b2Pair.as
│ │ └── b2Segment.as
│ ├── Dynamics
│ │ ├── Contacts
│ │ │ ├── b2ContactRegister.as
│ │ │ ├── b2NullContact.as
│ │ │ ├── b2ContactConstraintPoint.as
│ │ │ ├── b2ContactEdge.as
│ │ │ ├── b2ContactConstraint.as
│ │ │ └── b2ContactResult.as
│ │ ├── b2TimeStep.as
│ │ ├── b2BoundaryListener.as
│ │ ├── Joints
│ │ │ ├── b2JointEdge.as
│ │ │ ├── b2GearJointDef.as
│ │ │ ├── b2JointDef.as
│ │ │ ├── b2Jacobian.as
│ │ │ ├── b2MouseJointDef.as
│ │ │ ├── b2DistanceJointDef.as
│ │ │ ├── b2PrismaticJointDef.as
│ │ │ ├── b2RevoluteJointDef.as
│ │ │ └── b2PulleyJointDef.as
│ │ ├── b2DestructionListener.as
│ │ ├── b2ContactFilter.as
│ │ ├── b2ContactListener.as
│ │ └── b2BodyDef.as
│ └── Common
│ │ ├── Math
│ │ ├── b2XForm.as
│ │ ├── b2Sweep.as
│ │ ├── b2Vec2.as
│ │ └── b2Mat22.as
│ │ ├── b2Color.as
│ │ └── b2Settings.as
├── General
│ ├── FRateLimiter.as
│ └── FpsCounter.as
├── ReadMe.txt
├── TestBed
│ ├── TestCCD.as
│ └── TestStack.as
└── HelloWorld.as
├── extend.js
├── test.html
├── javascript
└── Box2D
│ ├── Dynamics
│ ├── b2BoundaryListener.js
│ ├── Joints
│ │ ├── b2JointEdge.js
│ │ ├── b2JointDef.js
│ │ ├── b2GearJointDef.js
│ │ ├── b2MouseJointDef.js
│ │ ├── b2Jacobian.js
│ │ ├── b2DistanceJointDef.js
│ │ ├── b2RevoluteJointDef.js
│ │ ├── b2PrismaticJointDef.js
│ │ ├── b2PulleyJointDef.js
│ │ └── b2Joint.js
│ ├── Contacts
│ │ ├── b2ContactRegister.js
│ │ ├── b2ContactEdge.js
│ │ ├── b2NullContact.js
│ │ ├── b2ContactResult.js
│ │ ├── b2ContactConstraint.js
│ │ ├── b2ContactConstraintPoint.js
│ │ ├── b2CircleContact.js
│ │ ├── b2PolygonContact.js
│ │ └── b2PolyAndCircleContact.js
│ ├── b2DestructionListener.js
│ ├── b2TimeStep.js
│ ├── b2ContactListener.js
│ ├── b2ContactFilter.js
│ ├── b2BodyDef.js
│ └── b2DebugDraw.js
│ ├── Collision
│ ├── b2BufferedPair.js
│ ├── ClipVertex.js
│ ├── Shapes
│ │ ├── b2MassData.js
│ │ ├── b2ShapeDef.js
│ │ ├── b2CircleDef.js
│ │ ├── b2FilterData.js
│ │ └── b2PolygonDef.js
│ ├── b2BoundValues.js
│ ├── b2OBB.js
│ ├── b2PairCallback.js
│ ├── b2Point.js
│ ├── b2AABB.js
│ ├── b2ContactPoint.js
│ ├── b2Proxy.js
│ ├── b2Bound.js
│ ├── b2Manifold.js
│ ├── b2ContactID.js
│ ├── b2Contact_modified.js
│ ├── b2ManifoldPoint.js
│ ├── Features.js
│ ├── Features_edited.js
│ ├── b2Pair.js
│ ├── b2Segment.js
│ └── b2TimeOfImpact.js
│ └── Common
│ ├── Math
│ ├── b2XForm.js
│ ├── b2Sweep.js
│ ├── b2Vec2.js
│ ├── b2Mat22.js
│ ├── b2Vec2_edited.js
│ └── b2Math.js
│ ├── b2Color.js
│ └── b2Settings.js
└── test.js
/README:
--------------------------------------------------------------------------------
1 | See http://29a.ch/2010/4/17/box2d-2-flash-ported-javascript
2 |
--------------------------------------------------------------------------------
/flash/HelloWorld.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwagner/box2d2-js/HEAD/flash/HelloWorld.fla
--------------------------------------------------------------------------------
/flash/HelloWorld.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwagner/box2d2-js/HEAD/flash/HelloWorld.swf
--------------------------------------------------------------------------------
/flash/PhysTest.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwagner/box2d2-js/HEAD/flash/PhysTest.fla
--------------------------------------------------------------------------------
/flash/PhysTest.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwagner/box2d2-js/HEAD/flash/PhysTest.swf
--------------------------------------------------------------------------------
/extend.js:
--------------------------------------------------------------------------------
1 | function extend(a, b) {
2 | for(var c in b) {
3 | a[c] = b[c];
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/flash/Box2DFlashAS3_2.0.2_.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jwagner/box2d2-js/HEAD/flash/Box2DFlashAS3_2.0.2_.zip
--------------------------------------------------------------------------------
/test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2BoundaryListener.js:
--------------------------------------------------------------------------------
1 | var b2BoundaryListener = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2BoundaryListener.prototype.__constructor = function(){}
6 | b2BoundaryListener.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | // methods
12 | b2BoundaryListener.prototype.Violation = function (body) {}
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2BufferedPair.js:
--------------------------------------------------------------------------------
1 | var b2BufferedPair = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2BufferedPair.prototype.__constructor = function(){}
6 | b2BufferedPair.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2BufferedPair.prototype.proxyId1 = 0;
12 | b2BufferedPair.prototype.proxyId2 = 0;
13 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/ClipVertex.js:
--------------------------------------------------------------------------------
1 | var ClipVertex = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | ClipVertex.prototype.__constructor = function(){}
6 | ClipVertex.prototype.__varz = function(){
7 | this.v = new b2Vec2();
8 | this.id = new b2ContactID();
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | ClipVertex.prototype.v = new b2Vec2();
14 | ClipVertex.prototype.id = new b2ContactID();
15 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Shapes/b2MassData.js:
--------------------------------------------------------------------------------
1 | var b2MassData = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2MassData.prototype.__constructor = function(){}
6 | b2MassData.prototype.__varz = function(){
7 | this.center = new b2Vec2(0,0);
8 | }
9 | // static attributes
10 | // static methods
11 | // attributes
12 | b2MassData.prototype.mass = 0.0;
13 | b2MassData.prototype.center = new b2Vec2(0,0);
14 | b2MassData.prototype.I = 0.0;
15 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2BoundValues.js:
--------------------------------------------------------------------------------
1 | var b2BoundValues = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2BoundValues.prototype.__constructor = function(){}
6 | b2BoundValues.prototype.__varz = function(){
7 | this.lowerValues = [0,0];
8 | this.upperValues = [0,0];
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2BoundValues.prototype.lowerValues = [0,0];
14 | b2BoundValues.prototype.upperValues = [0,0];
15 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2JointEdge.js:
--------------------------------------------------------------------------------
1 | var b2JointEdge = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2JointEdge.prototype.__constructor = function(){}
6 | b2JointEdge.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2JointEdge.prototype.other = null;
12 | b2JointEdge.prototype.joint = null;
13 | b2JointEdge.prototype.prev = null;
14 | b2JointEdge.prototype.next = null;
15 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2ContactRegister.js:
--------------------------------------------------------------------------------
1 | var b2ContactRegister = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactRegister.prototype.__constructor = function(){}
6 | b2ContactRegister.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2ContactRegister.prototype.createFcn = null;
12 | b2ContactRegister.prototype.destroyFcn = null;
13 | b2ContactRegister.prototype.primary = null;
14 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2DestructionListener.js:
--------------------------------------------------------------------------------
1 | var b2DestructionListener = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2DestructionListener.prototype.__constructor = function(){}
6 | b2DestructionListener.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | // methods
12 | b2DestructionListener.prototype.SayGoodbyeJoint = function (joint) {}
13 | b2DestructionListener.prototype.SayGoodbyeShape = function (shape) {}
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2ContactEdge.js:
--------------------------------------------------------------------------------
1 | var b2ContactEdge = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactEdge.prototype.__constructor = function(){}
6 | b2ContactEdge.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2ContactEdge.prototype.other = null;
12 | b2ContactEdge.prototype.contact = null;
13 | b2ContactEdge.prototype.prev = null;
14 | b2ContactEdge.prototype.next = null;
15 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2OBB.js:
--------------------------------------------------------------------------------
1 | var b2OBB = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2OBB.prototype.__constructor = function(){}
6 | b2OBB.prototype.__varz = function(){
7 | this.R = new b2Mat22();
8 | this.center = new b2Vec2();
9 | this.extents = new b2Vec2();
10 | }
11 | // static attributes
12 | // static methods
13 | // attributes
14 | b2OBB.prototype.R = new b2Mat22();
15 | b2OBB.prototype.center = new b2Vec2();
16 | b2OBB.prototype.extents = new b2Vec2();
17 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2PairCallback.js:
--------------------------------------------------------------------------------
1 | var b2PairCallback = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2PairCallback.prototype.__constructor = function(){}
6 | b2PairCallback.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | // methods
12 | b2PairCallback.prototype.PairAdded = function (proxyUserData1, proxyUserData2) {return null}
13 | b2PairCallback.prototype.PairRemoved = function (proxyUserData1, proxyUserData2, pairUserData) {}
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Point.js:
--------------------------------------------------------------------------------
1 | var b2Point = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Point.prototype.__constructor = function(){}
6 | b2Point.prototype.__varz = function(){
7 | this.p = new b2Vec2();
8 | }
9 | // static attributes
10 | // static methods
11 | // attributes
12 | b2Point.prototype.p = new b2Vec2();
13 | // methods
14 | b2Point.prototype.Support = function (xf, vX, vY) {
15 | return this.p;
16 | }
17 | b2Point.prototype.GetFirstVertex = function (xf) {
18 | return this.p;
19 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2TimeStep.js:
--------------------------------------------------------------------------------
1 | var b2TimeStep = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2TimeStep.prototype.__constructor = function(){}
6 | b2TimeStep.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2TimeStep.prototype.dt = null;
12 | b2TimeStep.prototype.inv_dt = null;
13 | b2TimeStep.prototype.dtRatio = null;
14 | b2TimeStep.prototype.maxIterations = 0;
15 | b2TimeStep.prototype.warmStarting = null;
16 | b2TimeStep.prototype.positionCorrection = null;
17 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2ContactListener.js:
--------------------------------------------------------------------------------
1 | var b2ContactListener = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactListener.prototype.__constructor = function(){}
6 | b2ContactListener.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | // methods
12 | b2ContactListener.prototype.Add = function (point) {}
13 | b2ContactListener.prototype.Persist = function (point) {}
14 | b2ContactListener.prototype.Remove = function (point) {}
15 | b2ContactListener.prototype.Result = function (point) {}
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2NullContact.js:
--------------------------------------------------------------------------------
1 | var b2NullContact = function() {
2 | b2Contact.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2NullContact.prototype, b2Contact.prototype)
7 | b2NullContact.prototype._super = function(){ b2Contact.prototype.__constructor.apply(this, arguments) }
8 | b2NullContact.prototype.__constructor = function () {}
9 | b2NullContact.prototype.__varz = function(){
10 | }
11 | // static attributes
12 | // static methods
13 | // attributes
14 | // methods
15 | b2NullContact.prototype.Evaluate = function (l) {}
16 | b2NullContact.prototype.GetManifolds = function () { return null; }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2JointDef.js:
--------------------------------------------------------------------------------
1 | var b2JointDef = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2JointDef.prototype.__constructor = function () {
6 | this.type = b2Joint.e_unknownJoint;
7 | this.userData = null;
8 | this.body1 = null;
9 | this.body2 = null;
10 | this.collideConnected = false;
11 | }
12 | b2JointDef.prototype.__varz = function(){
13 | }
14 | // static attributes
15 | // static methods
16 | // attributes
17 | b2JointDef.prototype.type = 0;
18 | b2JointDef.prototype.userData = null;
19 | b2JointDef.prototype.body1 = null;
20 | b2JointDef.prototype.body2 = null;
21 | b2JointDef.prototype.collideConnected = null;
22 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Shapes/b2ShapeDef.js:
--------------------------------------------------------------------------------
1 | var b2ShapeDef = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ShapeDef.prototype.__constructor = function(){}
6 | b2ShapeDef.prototype.__varz = function(){
7 | this.type = b2Shape.e_unknownShape;
8 | this.filter = new b2FilterData();
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2ShapeDef.prototype.type = b2Shape.e_unknownShape;
14 | b2ShapeDef.prototype.userData = null;
15 | b2ShapeDef.prototype.friction = 0.2;
16 | b2ShapeDef.prototype.restitution = 0.0;
17 | b2ShapeDef.prototype.density = 0.0;
18 | b2ShapeDef.prototype.isSensor = false;
19 | b2ShapeDef.prototype.filter = new b2FilterData();
20 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Shapes/b2CircleDef.js:
--------------------------------------------------------------------------------
1 | var b2CircleDef = function() {
2 | b2ShapeDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2CircleDef.prototype, b2ShapeDef.prototype)
7 | b2CircleDef.prototype._super = function(){ b2ShapeDef.prototype.__constructor.apply(this, arguments) }
8 | b2CircleDef.prototype.__constructor = function () {
9 | this.type = b2Shape.e_circleShape;
10 | this.radius = 1.0;
11 | }
12 | b2CircleDef.prototype.__varz = function(){
13 | this.localPosition = new b2Vec2(0.0, 0.0);
14 | }
15 | // static attributes
16 | // static methods
17 | // attributes
18 | b2CircleDef.prototype.localPosition = new b2Vec2(0.0, 0.0);
19 | b2CircleDef.prototype.radius = null;
20 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Shapes/b2FilterData.js:
--------------------------------------------------------------------------------
1 | var b2FilterData = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2FilterData.prototype.__constructor = function(){}
6 | b2FilterData.prototype.__varz = function(){
7 | this.categoryBits = 0x0001;
8 | this.maskBits = 0xFFFF;
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2FilterData.prototype.categoryBits = 0x0001;
14 | b2FilterData.prototype.maskBits = 0xFFFF;
15 | b2FilterData.prototype.groupIndex = 0;
16 | // methods
17 | b2FilterData.prototype.Copy = function () {
18 | var copy = new b2FilterData();
19 | copy.categoryBits = this.categoryBits;
20 | copy.maskBits = this.maskBits;
21 | copy.groupIndex = this.groupIndex;
22 | return copy;
23 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2AABB.js:
--------------------------------------------------------------------------------
1 | var b2AABB = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2AABB.prototype.__constructor = function(){}
6 | b2AABB.prototype.__varz = function(){
7 | this.lowerBound = new b2Vec2();
8 | this.upperBound = new b2Vec2();
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2AABB.prototype.lowerBound = new b2Vec2();
14 | b2AABB.prototype.upperBound = new b2Vec2();
15 | // methods
16 | b2AABB.prototype.IsValid = function () {
17 |
18 | var dX = this.upperBound.x - this.lowerBound.x;
19 | var dY = this.upperBound.y - this.lowerBound.y;
20 | var valid = dX >= 0.0 && dY >= 0.0;
21 | valid = valid && this.lowerBound.IsValid() && this.upperBound.IsValid();
22 | return valid;
23 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2ContactResult.js:
--------------------------------------------------------------------------------
1 | var b2ContactResult = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactResult.prototype.__constructor = function(){}
6 | b2ContactResult.prototype.__varz = function(){
7 | this.position = new b2Vec2();
8 | this.normal = new b2Vec2();
9 | this.id = new b2ContactID();
10 | }
11 | // static attributes
12 | // static methods
13 | // attributes
14 | b2ContactResult.prototype.shape1 = null;
15 | b2ContactResult.prototype.shape2 = null;
16 | b2ContactResult.prototype.position = new b2Vec2();
17 | b2ContactResult.prototype.normal = new b2Vec2();
18 | b2ContactResult.prototype.normalImpulse = null;
19 | b2ContactResult.prototype.tangentImpulse = null;
20 | b2ContactResult.prototype.id = new b2ContactID();
21 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2GearJointDef.js:
--------------------------------------------------------------------------------
1 | var b2GearJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2GearJointDef.prototype, b2JointDef.prototype)
7 | b2GearJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2GearJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_gearJoint;
10 | this.joint1 = null;
11 | this.joint2 = null;
12 | this.ratio = 1.0;
13 | }
14 | b2GearJointDef.prototype.__varz = function(){
15 | }
16 | // static attributes
17 | // static methods
18 | // attributes
19 | b2GearJointDef.prototype.joint1 = null;
20 | b2GearJointDef.prototype.joint2 = null;
21 | b2GearJointDef.prototype.ratio = null;
22 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2ContactFilter.js:
--------------------------------------------------------------------------------
1 | var b2ContactFilter = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactFilter.prototype.__constructor = function(){}
6 | b2ContactFilter.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | b2ContactFilter.b2_defaultFilter = new b2ContactFilter();
10 | // static methods
11 | // attributes
12 | // methods
13 | b2ContactFilter.prototype.ShouldCollide = function (shape1, shape2) {
14 | var filter1 = shape1.GetFilterData();
15 | var filter2 = shape2.GetFilterData();
16 |
17 | if (filter1.groupIndex == filter2.groupIndex && filter1.groupIndex != 0)
18 | {
19 | return filter1.groupIndex > 0;
20 | }
21 |
22 | var collide = (filter1.maskBits & filter2.categoryBits) != 0 && (filter1.categoryBits & filter2.maskBits) != 0;
23 | return collide;
24 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2ContactPoint.js:
--------------------------------------------------------------------------------
1 | var b2ContactPoint = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactPoint.prototype.__constructor = function(){}
6 | b2ContactPoint.prototype.__varz = function(){
7 | this.position = new b2Vec2();
8 | this.velocity = new b2Vec2();
9 | this.normal = new b2Vec2();
10 | this.id = new b2ContactID();
11 | }
12 | // static attributes
13 | // static methods
14 | // attributes
15 | b2ContactPoint.prototype.shape1 = null;
16 | b2ContactPoint.prototype.shape2 = null;
17 | b2ContactPoint.prototype.position = new b2Vec2();
18 | b2ContactPoint.prototype.velocity = new b2Vec2();
19 | b2ContactPoint.prototype.normal = new b2Vec2();
20 | b2ContactPoint.prototype.separation = null;
21 | b2ContactPoint.prototype.friction = null;
22 | b2ContactPoint.prototype.restitution = null;
23 | b2ContactPoint.prototype.id = new b2ContactID();
24 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Proxy.js:
--------------------------------------------------------------------------------
1 | var b2Proxy = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Proxy.prototype.__constructor = function(){}
6 | b2Proxy.prototype.__varz = function(){
7 | this.lowerBounds = [parseInt(0), parseInt(0)];
8 | this.upperBounds = [parseInt(0), parseInt(0)];
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2Proxy.prototype.lowerBounds = [parseInt(0), parseInt(0)];
14 | b2Proxy.prototype.upperBounds = [parseInt(0), parseInt(0)];
15 | b2Proxy.prototype.overlapCount = 0;
16 | b2Proxy.prototype.timeStamp = 0;
17 | b2Proxy.prototype.userData = null;
18 | // methods
19 | b2Proxy.prototype.GetNext = function () { return this.lowerBounds[0]; }
20 | b2Proxy.prototype.SetNext = function (next) { this.lowerBounds[0] = next % 65535; }
21 | b2Proxy.prototype.IsValid = function () { return this.overlapCount != b2BroadPhase.b2_invalid; }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2XForm.js:
--------------------------------------------------------------------------------
1 | var b2XForm = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2XForm.prototype.__constructor = function (pos, r) {
6 | if (pos){
7 | this.position.SetV(pos);
8 | this.R.SetM(r);
9 |
10 | }
11 | }
12 | b2XForm.prototype.__varz = function(){
13 | this.position = new b2Vec2;
14 | this.R = new b2Mat22();
15 | }
16 | // static attributes
17 | // static methods
18 | // attributes
19 | b2XForm.prototype.position = new b2Vec2;
20 | b2XForm.prototype.R = new b2Mat22();
21 | // methods
22 | b2XForm.prototype.Initialize = function (pos, r) {
23 | this.position.SetV(pos);
24 | this.R.SetM(r);
25 | }
26 | b2XForm.prototype.SetIdentity = function () {
27 | this.position.SetZero();
28 | this.R.SetIdentity();
29 | }
30 | b2XForm.prototype.Set = function (x) {
31 |
32 | this.position.SetV(x.position);
33 |
34 | this.R.SetM(x.R);
35 |
36 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Bound.js:
--------------------------------------------------------------------------------
1 | var b2Bound = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Bound.prototype.__constructor = function(){}
6 | b2Bound.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | // static methods
10 | // attributes
11 | b2Bound.prototype.value = 0;
12 | b2Bound.prototype.proxyId = 0;
13 | b2Bound.prototype.stabbingCount = 0;
14 | // methods
15 | b2Bound.prototype.IsLower = function () { return (this.value & 1) == 0; }
16 | b2Bound.prototype.IsUpper = function () { return (this.value & 1) == 1; }
17 | b2Bound.prototype.Swap = function (b) {
18 | var tempValue = this.value;
19 | var tempProxyId = this.proxyId;
20 | var tempStabbingCount = this.stabbingCount;
21 |
22 | this.value = b.value;
23 | this.proxyId = b.proxyId;
24 | this.stabbingCount = b.stabbingCount;
25 |
26 | b.value = tempValue;
27 | b.proxyId = tempProxyId;
28 | b.stabbingCount = tempStabbingCount;
29 | }
--------------------------------------------------------------------------------
/flash/License.txt:
--------------------------------------------------------------------------------
1 | Copyright (C) 2007 Matthew Bush (skatehead [at] gmail.com)
2 |
3 | This software is provided 'as-is', without any express or implied
4 | warranty. In no event will the authors be held liable for any damages
5 | arising from the use of this software.
6 |
7 | Permission is granted to anyone to use this software for any purpose,
8 | including commercial applications, and to alter it and redistribute it
9 | freely, subject to the following restrictions:
10 |
11 | 1. The origin of this software must not be misrepresented; you must not
12 | claim that you wrote the original software. If you use this software
13 | in a product, an acknowledgment in the product documentation would be
14 | appreciated but is not required.
15 | 2. Altered source versions must be plainly marked as such, and must not be
16 | misrepresented as being the original software.
17 | 3. This notice may not be removed or altered from any source distribution.
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2MouseJointDef.js:
--------------------------------------------------------------------------------
1 | var b2MouseJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2MouseJointDef.prototype, b2JointDef.prototype)
7 | b2MouseJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2MouseJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_mouseJoint;
10 | this.maxForce = 0.0;
11 | this.frequencyHz = 5.0;
12 | this.dampingRatio = 0.7;
13 | this.timeStep = 1.0 / 60.0;
14 | }
15 | b2MouseJointDef.prototype.__varz = function(){
16 | this.target = new b2Vec2();
17 | }
18 | // static attributes
19 | // static methods
20 | // attributes
21 | b2MouseJointDef.prototype.target = new b2Vec2();
22 | b2MouseJointDef.prototype.maxForce = null;
23 | b2MouseJointDef.prototype.frequencyHz = null;
24 | b2MouseJointDef.prototype.dampingRatio = null;
25 | b2MouseJointDef.prototype.timeStep = null;
26 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2ContactConstraint.js:
--------------------------------------------------------------------------------
1 | var b2ContactConstraint = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactConstraint.prototype.__constructor = function () {
6 | this.points = new Array(b2Settings.b2_maxManifoldPoints);
7 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
8 | this.points[i] = new b2ContactConstraintPoint();
9 | }
10 |
11 |
12 | }
13 | b2ContactConstraint.prototype.__varz = function(){
14 | this.normal = new b2Vec2();
15 | }
16 | // static attributes
17 | // static methods
18 | // attributes
19 | b2ContactConstraint.prototype.points = null;
20 | b2ContactConstraint.prototype.normal = new b2Vec2();
21 | b2ContactConstraint.prototype.manifold = null;
22 | b2ContactConstraint.prototype.body1 = null;
23 | b2ContactConstraint.prototype.body2 = null;
24 | b2ContactConstraint.prototype.friction = null;
25 | b2ContactConstraint.prototype.restitution = null;
26 | b2ContactConstraint.prototype.pointCount = 0;
27 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Manifold.js:
--------------------------------------------------------------------------------
1 | var b2Manifold = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Manifold.prototype.__constructor = function () {
6 | this.points = new Array(b2Settings.b2_maxManifoldPoints);
7 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
8 | this.points[i] = new b2ManifoldPoint();
9 | }
10 | this.normal = new b2Vec2();
11 | }
12 | b2Manifold.prototype.__varz = function(){
13 | }
14 | // static attributes
15 | // static methods
16 | // attributes
17 | b2Manifold.prototype.points = null;
18 | b2Manifold.prototype.normal = null;
19 | b2Manifold.prototype.pointCount = 0;
20 | // methods
21 | b2Manifold.prototype.Reset = function () {
22 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
23 | (this.points[i]).Reset();
24 | }
25 | this.normal.SetZero();
26 | this.pointCount = 0;
27 | }
28 | b2Manifold.prototype.Set = function (m) {
29 | this.pointCount = m.pointCount;
30 | for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
31 | (this.points[i]).Set(m.points[i]);
32 | }
33 | this.normal.SetV(m.normal);
34 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2Jacobian.js:
--------------------------------------------------------------------------------
1 | var b2Jacobian = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Jacobian.prototype.__constructor = function(){}
6 | b2Jacobian.prototype.__varz = function(){
7 | this.linear1 = new b2Vec2();
8 | this.linear2 = new b2Vec2();
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2Jacobian.prototype.linear1 = new b2Vec2();
14 | b2Jacobian.prototype.angular1 = null;
15 | b2Jacobian.prototype.linear2 = new b2Vec2();
16 | b2Jacobian.prototype.angular2 = null;
17 | // methods
18 | b2Jacobian.prototype.SetZero = function () {
19 | this.linear1.SetZero(); this.angular1 = 0.0;
20 | this.linear2.SetZero(); this.angular2 = 0.0;
21 | }
22 | b2Jacobian.prototype.Set = function (x1, a1, x2, a2) {
23 | this.linear1.SetV(x1); this.angular1 = a1;
24 | this.linear2.SetV(x2); this.angular2 = a2;
25 | }
26 | b2Jacobian.prototype.Compute = function (x1, a1, x2, a2) {
27 |
28 |
29 | return (this.linear1.x*x1.x + this.linear1.y*x1.y) + this.angular1 * a1 + (this.linear2.x*x2.x + this.linear2.y*x2.y) + this.angular2 * a2;
30 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2BufferedPair.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | public class b2BufferedPair{
23 | public var proxyId1:uint;
24 | public var proxyId2:uint;
25 | }
26 |
27 |
28 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2ContactID.js:
--------------------------------------------------------------------------------
1 | var b2ContactID = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactID.prototype = {
6 | get key() {
7 | return this._key;
8 | },
9 | set key(value) {
10 | this._key = value;
11 | this.features._referenceEdge = this._key & 0x000000ff;
12 | this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
13 | this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
14 | this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
15 | }
16 | }
17 | b2ContactID.prototype.__constructor = function () {
18 | this.features._m_id = this;
19 | }
20 | b2ContactID.prototype.__varz = function(){
21 | this.features = new Features();
22 | }
23 | // static attributes
24 | // static methods
25 | // attributes
26 | b2ContactID.prototype.features = new Features();
27 | b2ContactID.prototype._key = 0;
28 | // methods
29 | b2ContactID.prototype.Set = function (id) {
30 | this.key = id._key;
31 | }
32 | b2ContactID.prototype.Copy = function () {
33 | var id = new b2ContactID();
34 | id.key = this._key;
35 | return id;
36 | }
37 |
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Contact_modified.js:
--------------------------------------------------------------------------------
1 | var b2ContactID = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactID.prototype = {
6 | get key() {
7 | return this._key;
8 | },
9 | set key(value) {
10 | this._key = value;
11 | this.features._referenceEdge = this._key & 0x000000ff;
12 | this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
13 | this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
14 | this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
15 | }
16 | }
17 | b2ContactID.prototype.__constructor = function () {
18 | this.features._m_id = this;
19 | }
20 | b2ContactID.prototype.__varz = function(){
21 | this.features = new Features();
22 | }
23 | // static attributes
24 | // static methods
25 | // attributes
26 | b2ContactID.prototype.features = new Features();
27 | b2ContactID.prototype._key = 0;
28 | // methods
29 | b2ContactID.prototype.Set = function (id) {
30 | this.key = id._key;
31 | }
32 | b2ContactID.prototype.Copy = function () {
33 | var id = new b2ContactID();
34 | id.key = this._key;
35 | return id;
36 | }
37 |
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2BoundValues.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | public class b2BoundValues{
23 | public var lowerValues:Array = [0,0];
24 | public var upperValues:Array = [0,0];
25 | }
26 |
27 |
28 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2BodyDef.js:
--------------------------------------------------------------------------------
1 | var b2BodyDef = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2BodyDef.prototype.__constructor = function () {
6 | this.massData.center.SetZero();
7 | this.massData.mass = 0.0;
8 | this.massData.I = 0.0;
9 | this.userData = null;
10 | this.position.Set(0.0, 0.0);
11 | this.angle = 0.0;
12 | this.linearDamping = 0.0;
13 | this.angularDamping = 0.0;
14 | this.allowSleep = true;
15 | this.isSleeping = false;
16 | this.fixedRotation = false;
17 | this.isBullet = false;
18 | }
19 | b2BodyDef.prototype.__varz = function(){
20 | this.massData = new b2MassData();
21 | this.position = new b2Vec2();
22 | }
23 | // static attributes
24 | // static methods
25 | // attributes
26 | b2BodyDef.prototype.massData = new b2MassData();
27 | b2BodyDef.prototype.userData = null;
28 | b2BodyDef.prototype.position = new b2Vec2();
29 | b2BodyDef.prototype.angle = null;
30 | b2BodyDef.prototype.linearDamping = null;
31 | b2BodyDef.prototype.angularDamping = null;
32 | b2BodyDef.prototype.allowSleep = null;
33 | b2BodyDef.prototype.isSleeping = null;
34 | b2BodyDef.prototype.fixedRotation = null;
35 | b2BodyDef.prototype.isBullet = null;
36 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2ContactConstraintPoint.js:
--------------------------------------------------------------------------------
1 | var b2ContactConstraintPoint = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ContactConstraintPoint.prototype.__constructor = function(){}
6 | b2ContactConstraintPoint.prototype.__varz = function(){
7 | this.localAnchor1 = new b2Vec2();
8 | this.localAnchor2 = new b2Vec2();
9 | this.r1 = new b2Vec2();
10 | this.r2 = new b2Vec2();
11 | }
12 | // static attributes
13 | // static methods
14 | // attributes
15 | b2ContactConstraintPoint.prototype.localAnchor1 = new b2Vec2();
16 | b2ContactConstraintPoint.prototype.localAnchor2 = new b2Vec2();
17 | b2ContactConstraintPoint.prototype.r1 = new b2Vec2();
18 | b2ContactConstraintPoint.prototype.r2 = new b2Vec2();
19 | b2ContactConstraintPoint.prototype.normalImpulse = null;
20 | b2ContactConstraintPoint.prototype.tangentImpulse = null;
21 | b2ContactConstraintPoint.prototype.positionImpulse = null;
22 | b2ContactConstraintPoint.prototype.normalMass = null;
23 | b2ContactConstraintPoint.prototype.tangentMass = null;
24 | b2ContactConstraintPoint.prototype.equalizedMass = null;
25 | b2ContactConstraintPoint.prototype.separation = null;
26 | b2ContactConstraintPoint.prototype.velocityBias = null;
27 | // methods
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2ContactRegister.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 |
22 | public class b2ContactRegister
23 | {
24 | public var createFcn:Function; // fcn pointer
25 | public var destroyFcn:Function;// fcn pointer
26 | public var primary:Boolean;
27 | };
28 |
29 |
30 |
31 | }
--------------------------------------------------------------------------------
/flash/General/FRateLimiter.as:
--------------------------------------------------------------------------------
1 | //===========================================================
2 | //=========================================================//
3 | // -=ANTHEM=-
4 | // file: frameLimiter.as
5 | //
6 | // copyright: Matthew Bush 2007
7 | //
8 | // notes: limits framerate
9 | //
10 | //=========================================================//
11 | //===========================================================
12 |
13 |
14 |
15 | //===========================================================
16 | // frame limiter
17 | //===========================================================
18 |
19 | package General{
20 |
21 |
22 | import flash.utils.getTimer;
23 |
24 |
25 | public class FRateLimiter{
26 |
27 |
28 | //======================
29 | // limit frame function
30 | //======================
31 | static public function limitFrame(maxFPS:uint):void{
32 |
33 | var fTime:uint = 1000 / maxFPS;
34 |
35 | while(Math.abs(newT - oldT) < fTime){
36 | newT = getTimer();
37 | }
38 | oldT = getTimer();
39 |
40 | }
41 |
42 | //======================
43 | // member vars
44 | //======================
45 | private static var oldT:uint = getTimer();
46 | private static var newT:uint = oldT;
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/ClipVertex.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Collision.*;
24 |
25 |
26 | public class ClipVertex
27 | {
28 | public var v:b2Vec2 = new b2Vec2();
29 | public var id:b2ContactID = new b2ContactID();
30 | };
31 |
32 |
33 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/b2Color.js:
--------------------------------------------------------------------------------
1 | var b2Color = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Color.prototype.__constructor = function (rr, gg, bb) {
6 | this._r = parseInt(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
7 | this._g = parseInt(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
8 | this._b = parseInt(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
9 | }
10 | b2Color.prototype.__varz = function(){
11 | }
12 | // static attributes
13 | // static methods
14 | // attributes
15 | b2Color.prototype._r = 0;
16 | b2Color.prototype._g = 0;
17 | b2Color.prototype._b = 0;
18 | // methods
19 | b2Color.prototype.Set = function (rr, gg, bb) {
20 | this._r = parseInt(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
21 | this._g = parseInt(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
22 | this._b = parseInt(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
23 | }
24 | b2Color.prototype.set = function (rr) {
25 | this._r = parseInt(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
26 | }
27 | b2Color.prototype.set = function (gg) {
28 | this._g = parseInt(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
29 | }
30 | b2Color.prototype.set = function (bb) {
31 | this._b = parseInt(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
32 | }
33 | b2Color.prototype.get = function () {
34 | return (this._r) | (this._g << 8) | (this._b << 16);
35 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2ManifoldPoint.js:
--------------------------------------------------------------------------------
1 | var b2ManifoldPoint = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2ManifoldPoint.prototype.__constructor = function(){}
6 | b2ManifoldPoint.prototype.__varz = function(){
7 | this.localPoint1 = new b2Vec2();
8 | this.localPoint2 = new b2Vec2();
9 | this.id = new b2ContactID();
10 | }
11 | // static attributes
12 | // static methods
13 | // attributes
14 | b2ManifoldPoint.prototype.localPoint1 = new b2Vec2();
15 | b2ManifoldPoint.prototype.localPoint2 = new b2Vec2();
16 | b2ManifoldPoint.prototype.separation = null;
17 | b2ManifoldPoint.prototype.normalImpulse = null;
18 | b2ManifoldPoint.prototype.tangentImpulse = null;
19 | b2ManifoldPoint.prototype.id = new b2ContactID();
20 | // methods
21 | b2ManifoldPoint.prototype.Reset = function () {
22 | this.localPoint1.SetZero();
23 | this.localPoint2.SetZero();
24 | this.separation = 0.0;
25 | this.normalImpulse = 0.0;
26 | this.tangentImpulse = 0.0;
27 | this.id.key = 0;
28 | }
29 | b2ManifoldPoint.prototype.Set = function (m) {
30 | this.localPoint1.SetV(m.localPoint1);
31 | this.localPoint2.SetV(m.localPoint2);
32 | this.separation = m.separation;
33 | this.normalImpulse = m.normalImpulse;
34 | this.tangentImpulse = m.tangentImpulse;
35 | this.id.key = m.id.key;
36 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2OBB.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Common.Math.*;
22 |
23 | /// An oriented bounding box.
24 | public class b2OBB
25 | {
26 | public var R:b2Mat22 = new b2Mat22(); ///< the rotation matrix
27 | public var center:b2Vec2 = new b2Vec2(); ///< the local centroid
28 | public var extents:b2Vec2 = new b2Vec2(); ///< the half-widths
29 | };
30 |
31 |
32 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2TimeStep.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | public class b2TimeStep
23 | {
24 | public var dt:Number; // time step
25 | public var inv_dt:Number; // inverse time step (0 if dt == 0).
26 | public var dtRatio:Number; // dt * inv_dt0
27 | public var maxIterations:int;
28 | public var warmStarting:Boolean;
29 | public var positionCorrection:Boolean;
30 | };
31 |
32 |
33 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2NullContact.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 |
22 | import Box2D.Collision.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 | public class b2NullContact extends b2Contact
27 | {
28 | public function b2NullContact() {}
29 | public override function Evaluate(l:b2ContactListener): void {}
30 | public override function GetManifolds():Array { return null; }
31 | };
32 |
33 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Shapes/b2CircleDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision.Shapes{
20 |
21 |
22 |
23 | import Box2D.Common.Math.*;
24 | import Box2D.Collision.Shapes.*;
25 |
26 |
27 | /// This structure is used to build circle shapes.
28 | public class b2CircleDef extends b2ShapeDef
29 | {
30 | public function b2CircleDef()
31 | {
32 | type = b2Shape.e_circleShape;
33 | radius = 1.0;
34 | }
35 |
36 | public var localPosition:b2Vec2 = new b2Vec2(0.0, 0.0);
37 | public var radius:Number;
38 | };
39 |
40 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Point.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*;
22 | import Box2D.Common.Math.*;
23 |
24 | // This is used for polygon-vs-circle distance.
25 | public class b2Point
26 | {
27 | public function Support(xf:b2XForm, vX:Number, vY:Number) : b2Vec2
28 | {
29 | return p;
30 | }
31 |
32 | public function GetFirstVertex(xf:b2XForm) : b2Vec2
33 | {
34 | return p;
35 | }
36 |
37 | public var p:b2Vec2 = new b2Vec2();
38 | };
39 |
40 |
41 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Shapes/b2MassData.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision.Shapes{
20 |
21 |
22 |
23 | import Box2D.Common.Math.*;
24 |
25 |
26 | /// This holds the mass data computed for a shape.
27 | public class b2MassData
28 | {
29 | /// The mass of the shape, usually in kilograms.
30 | public var mass:Number = 0.0;
31 | /// The position of the shape's centroid relative to the shape's origin.
32 | public var center:b2Vec2 = new b2Vec2(0,0);
33 | /// The rotational inertia of the shape.
34 | public var I:Number = 0.0;
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Features.js:
--------------------------------------------------------------------------------
1 | var Features = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | Features.prototype = {
6 | get referenceEdge() {
7 | return this._referenceEdge;
8 | },
9 | set referenceEdge(value) {
10 | this._referenceEdge = value;
11 | this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceEdge & 0x000000ff);
12 | },
13 | get incidentEdge() {
14 | return this._incidentEdge;
15 | },
16 | set incidentEdge(value) {
17 | this._incidentEdge = value;
18 | this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);
19 | },
20 | set incidentVertex(value) {
21 | this._incidentVertex = value;
22 | this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);
23 | },
24 | get incidentVertex() {
25 | return this._incidentVertex;
26 | },
27 | set flip(value) {
28 | this._flip = value;
29 | this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);
30 | },
31 | get flip() {
32 | return this._flip;
33 | }
34 | }
35 | Features.prototype.__constructor = function(){}
36 | Features.prototype.__varz = function(){
37 | }
38 | // static attributes
39 | // static methods
40 | // attributes
41 | Features.prototype._referenceEdge = 0;
42 | Features.prototype._incidentEdge = 0;
43 | Features.prototype._incidentVertex = 0;
44 | Features.prototype._flip = 0;
45 | Features.prototype._m_id = null;
46 |
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Features_edited.js:
--------------------------------------------------------------------------------
1 | var Features = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | Features.prototype = {
6 | get referenceEdge() {
7 | return this._referenceEdge;
8 | },
9 | set referenceEdge(value) {
10 | this._referenceEdge = value;
11 | this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceEdge & 0x000000ff);
12 | },
13 | get incidentEdge() {
14 | return this._incidentEdge;
15 | },
16 | set incidentEdge(value) {
17 | this._incidentEdge = value;
18 | this._m_id._key = (this._m_id._key & 0xffff00ff) | ((this._incidentEdge << 8) & 0x0000ff00);
19 | },
20 | set incidentVertex(value) {
21 | this._incidentVertex = value;
22 | this._m_id._key = (this._m_id._key & 0xff00ffff) | ((this._incidentVertex << 16) & 0x00ff0000);
23 | },
24 | get incidentVertex() {
25 | return this._incidentVertex;
26 | },
27 | set flip(value) {
28 | this._flip = value;
29 | this._m_id._key = (this._m_id._key & 0x00ffffff) | ((this._flip << 24) & 0xff000000);
30 | },
31 | get flip() {
32 | return this._flip;
33 | }
34 | }
35 | Features.prototype.__constructor = function(){}
36 | Features.prototype.__varz = function(){
37 | }
38 | // static attributes
39 | // static methods
40 | // attributes
41 | Features.prototype._referenceEdge = 0;
42 | Features.prototype._incidentEdge = 0;
43 | Features.prototype._incidentVertex = 0;
44 | Features.prototype._flip = 0;
45 | Features.prototype._m_id = null;
46 |
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2PairCallback.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | public class b2PairCallback
23 | {
24 | //virtual ~b2PairCallback() {}
25 |
26 | // This returns the new pair user data.
27 | public virtual function PairAdded(proxyUserData1:*, proxyUserData2:*):*{return null};
28 |
29 | // This should free the pair's user data. In extreme circumstances, it is possible
30 | // this will be called with null pairUserData because the pair never existed.
31 | public virtual function PairRemoved(proxyUserData1:*, proxyUserData2:*, pairUserData:*) : void{};
32 | };
33 |
34 |
35 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2DistanceJointDef.js:
--------------------------------------------------------------------------------
1 | var b2DistanceJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2DistanceJointDef.prototype, b2JointDef.prototype)
7 | b2DistanceJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2DistanceJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_distanceJoint;
10 |
11 |
12 | this.length = 1.0;
13 | this.frequencyHz = 0.0;
14 | this.dampingRatio = 0.0;
15 | }
16 | b2DistanceJointDef.prototype.__varz = function(){
17 | this.localAnchor1 = new b2Vec2();
18 | this.localAnchor2 = new b2Vec2();
19 | }
20 | // static attributes
21 | // static methods
22 | // attributes
23 | b2DistanceJointDef.prototype.localAnchor1 = new b2Vec2();
24 | b2DistanceJointDef.prototype.localAnchor2 = new b2Vec2();
25 | b2DistanceJointDef.prototype.length = null;
26 | b2DistanceJointDef.prototype.frequencyHz = null;
27 | b2DistanceJointDef.prototype.dampingRatio = null;
28 | // methods
29 | b2DistanceJointDef.prototype.Initialize = function (b1, b2,
30 | anchor1, anchor2) {
31 | this.body1 = b1;
32 | this.body2 = b2;
33 | this.localAnchor1.SetV( this.body1.GetLocalPoint(anchor1));
34 | this.localAnchor2.SetV( this.body2.GetLocalPoint(anchor2));
35 | var dX = anchor2.x - anchor1.x;
36 | var dY = anchor2.y - anchor1.y;
37 | this.length = Math.sqrt(dX*dX + dY*dY);
38 | this.frequencyHz = 0.0;
39 | this.dampingRatio = 0.0;
40 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/b2Settings.js:
--------------------------------------------------------------------------------
1 | var b2Settings = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Settings.prototype.__constructor = function(){}
6 | b2Settings.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | b2Settings.USHRT_MAX = 0x0000ffff;
10 | b2Settings.b2_pi = Math.PI;
11 | b2Settings.b2_maxManifoldPoints = 2;
12 | b2Settings.b2_maxPolygonVertices = 8;
13 | b2Settings.b2_maxProxies = 512;
14 | b2Settings.b2_maxPairs = 8 * b2Settings.b2_maxProxies;
15 | b2Settings.b2_linearSlop = 0.005;
16 | b2Settings.b2_angularSlop = 2.0 / 180.0 * b2Settings.b2_pi;
17 | b2Settings.b2_toiSlop = 8.0 * b2Settings.b2_linearSlop;
18 | b2Settings.b2_maxTOIContactsPerIsland = 32;
19 | b2Settings.b2_velocityThreshold = 1.0;
20 | b2Settings.b2_maxLinearCorrection = 0.2;
21 | b2Settings.b2_maxAngularCorrection = 8.0 / 180.0 * b2Settings.b2_pi;
22 | b2Settings.b2_maxLinearVelocity = 200.0;
23 | b2Settings.b2_maxLinearVelocitySquared = b2Settings.b2_maxLinearVelocity * b2Settings.b2_maxLinearVelocity;
24 | b2Settings.b2_maxAngularVelocity = 250.0;
25 | b2Settings.b2_maxAngularVelocitySquared = b2Settings.b2_maxAngularVelocity * b2Settings.b2_maxAngularVelocity;
26 | b2Settings.b2_contactBaumgarte = 0.2;
27 | b2Settings.b2_timeToSleep = 0.5;
28 | b2Settings.b2_linearSleepTolerance = 0.01;
29 | b2Settings.b2_angularSleepTolerance = 2.0 / 180.0;
30 | // static methods
31 | b2Settings.b2Assert = function (a) {
32 | if (!a){
33 | var nullVec;
34 | nullVec.x++;
35 | }
36 | }
37 | // attributes
38 | // methods
39 |
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Pair.js:
--------------------------------------------------------------------------------
1 | var b2Pair = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Pair.prototype.__constructor = function(){}
6 | b2Pair.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | b2Pair.b2_nullPair = b2Settings.USHRT_MAX;
10 | b2Pair.b2_nullProxy = b2Settings.USHRT_MAX;
11 | b2Pair.b2_tableCapacity = b2Settings.b2_maxPairs;
12 | b2Pair.b2_tableMask = b2Pair.b2_tableCapacity - 1;
13 | b2Pair.e_pairBuffered = 0x0001;
14 | b2Pair.e_pairRemoved = 0x0002;
15 | b2Pair.e_pairFinal = 0x0004;
16 | // static methods
17 | // attributes
18 | b2Pair.prototype.userData = null;
19 | b2Pair.prototype.proxyId1 = 0;
20 | b2Pair.prototype.proxyId2 = 0;
21 | b2Pair.prototype.next = 0;
22 | b2Pair.prototype.status = 0;
23 | // methods
24 | b2Pair.prototype.SetBuffered = function () { this.status |= b2Pair.e_pairBuffered; }
25 | b2Pair.prototype.ClearBuffered = function () { this.status &= ~b2Pair.e_pairBuffered; }
26 | b2Pair.prototype.IsBuffered = function () { return (this.status & b2Pair.e_pairBuffered) == b2Pair.e_pairBuffered; }
27 | b2Pair.prototype.SetRemoved = function () { this.status |= b2Pair.e_pairRemoved; }
28 | b2Pair.prototype.ClearRemoved = function () { this.status &= ~b2Pair.e_pairRemoved; }
29 | b2Pair.prototype.IsRemoved = function () { return (this.status & b2Pair.e_pairRemoved) == b2Pair.e_pairRemoved; }
30 | b2Pair.prototype.SetFinal = function () { this.status |= b2Pair.e_pairFinal; }
31 | b2Pair.prototype.IsFinal = function () { return (this.status & b2Pair.e_pairFinal) == b2Pair.e_pairFinal; }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Proxy.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | public class b2Proxy{
23 | public function GetNext():uint { return lowerBounds[0]; }
24 | public function SetNext(next:uint) : void { lowerBounds[0] = next & 0x0000ffff; }
25 |
26 | public function IsValid():Boolean { return overlapCount != b2BroadPhase.b2_invalid; }
27 |
28 | public var lowerBounds:Array = [uint(0), uint(0)];
29 | public var upperBounds:Array = [uint(0), uint(0)];
30 | public var overlapCount:uint;
31 | public var timeStamp:uint;
32 |
33 | public var userData:* = null;
34 | }
35 |
36 |
37 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2Segment.js:
--------------------------------------------------------------------------------
1 | var b2Segment = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Segment.prototype.__constructor = function(){}
6 | b2Segment.prototype.__varz = function(){
7 | this.p1 = new b2Vec2();
8 | this.p2 = new b2Vec2();
9 | }
10 | // static attributes
11 | // static methods
12 | // attributes
13 | b2Segment.prototype.p1 = new b2Vec2();
14 | b2Segment.prototype.p2 = new b2Vec2();
15 | // methods
16 | b2Segment.prototype.TestSegment = function (lambda,
17 | normal,
18 | segment,
19 | maxLambda) {
20 |
21 | var s = segment.p1;
22 |
23 | var rX = segment.p2.x - s.x;
24 | var rY = segment.p2.y - s.y;
25 |
26 | var dX = this.p2.x - this.p1.x;
27 | var dY = this.p2.y - this.p1.y;
28 |
29 | var nX = dY;
30 | var nY = -dX;
31 |
32 | var k_slop = 100.0 * Number.MIN_VALUE;
33 |
34 | var denom = -(rX*nX + rY*nY);
35 |
36 |
37 | if (denom > k_slop)
38 | {
39 |
40 |
41 | var bX = s.x - this.p1.x;
42 | var bY = s.y - this.p1.y;
43 |
44 | var a = (bX*nX + bY*nY);
45 |
46 | if (0.0 <= a && a <= maxLambda * denom)
47 | {
48 | var mu2 = -rX * bY + rY * bX;
49 |
50 |
51 | if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0 + k_slop))
52 | {
53 | a /= denom;
54 |
55 | var nLen = Math.sqrt(nX*nX + nY*nY);
56 | nX /= nLen;
57 | nY /= nLen;
58 |
59 | lambda[0] = a;
60 |
61 | normal.Set(nX, nY);
62 | return true;
63 | }
64 | }
65 | }
66 |
67 | return false;
68 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2BoundaryListener.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | import Box2D.Collision.*;
23 | import Box2D.Collision.Shapes.*;
24 | import Box2D.Dynamics.Contacts.*;
25 | import Box2D.Dynamics.*;
26 | import Box2D.Common.Math.*;
27 | import Box2D.Common.*;
28 |
29 |
30 | /// This is called when a body's shape passes outside of the world boundary.
31 | public class b2BoundaryListener
32 | {
33 |
34 | /// This is called for each body that leaves the world boundary.
35 | /// @warning you can't modify the world inside this callback.
36 | public virtual function Violation(body:b2Body) : void{};
37 |
38 | };
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2ContactConstraintPoint.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 |
24 |
25 | public class b2ContactConstraintPoint
26 | {
27 | public var localAnchor1:b2Vec2=new b2Vec2();
28 | public var localAnchor2:b2Vec2=new b2Vec2();
29 | public var r1:b2Vec2=new b2Vec2();
30 | public var r2:b2Vec2=new b2Vec2();
31 | public var normalImpulse:Number;
32 | public var tangentImpulse:Number;
33 | public var positionImpulse:Number;
34 | public var normalMass:Number;
35 | public var tangentMass:Number;
36 | public var equalizedMass:Number;
37 | public var separation:Number;
38 | public var velocityBias:Number;
39 | };
40 |
41 |
42 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2ContactEdge.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 |
22 | import Box2D.Dynamics.b2Body;
23 | import Box2D.Dynamics.Contacts.*;
24 |
25 | /// A contact edge is used to connect bodies and contacts together
26 | /// in a contact graph where each body is a node and each contact
27 | /// is an edge. A contact edge belongs to a doubly linked list
28 | /// maintained in each attached body. Each contact has two contact
29 | /// nodes, one for each attached body.
30 | public class b2ContactEdge
31 | {
32 | public var other:b2Body;
33 | public var contact:b2Contact;
34 | public var prev:b2ContactEdge;
35 | public var next:b2ContactEdge;
36 | };
37 |
38 |
39 |
40 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Bound.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 |
22 | public class b2Bound{
23 | public function IsLower():Boolean { return (value & 1) == 0; }
24 | public function IsUpper():Boolean { return (value & 1) == 1; }
25 | public function Swap(b:b2Bound) : void{
26 | var tempValue:uint = value;
27 | var tempProxyId:uint = proxyId;
28 | var tempStabbingCount:uint = stabbingCount;
29 |
30 | value = b.value;
31 | proxyId = b.proxyId;
32 | stabbingCount = b.stabbingCount;
33 |
34 | b.value = tempValue;
35 | b.proxyId = tempProxyId;
36 | b.stabbingCount = tempStabbingCount;
37 | }
38 |
39 | public var value:uint;
40 | public var proxyId:uint;
41 | public var stabbingCount:uint;
42 | }
43 |
44 |
45 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2AABB.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*;
22 | import Box2D.Common.Math.*;
23 |
24 | // A manifold for two touching convex shapes.
25 | public class b2AABB
26 | {
27 | /// Verify that the bounds are sorted.
28 | public function IsValid():Boolean{
29 | //b2Vec2 d = upperBound - lowerBound;;
30 | var dX:Number = upperBound.x - lowerBound.x;
31 | var dY:Number = upperBound.y - lowerBound.y;
32 | var valid:Boolean = dX >= 0.0 && dY >= 0.0;
33 | valid = valid && lowerBound.IsValid() && upperBound.IsValid();
34 | return valid;
35 | }
36 |
37 | public var lowerBound:b2Vec2 = new b2Vec2(); ///< the lower vertex
38 | public var upperBound:b2Vec2 = new b2Vec2(); ///< the upper vertex
39 | };
40 |
41 |
42 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2Sweep.js:
--------------------------------------------------------------------------------
1 | var b2Sweep = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Sweep.prototype.__constructor = function(){}
6 | b2Sweep.prototype.__varz = function(){
7 | this.localCenter = new b2Vec2();
8 | this.c0 = new b2Vec2;
9 | this.c = new b2Vec2();
10 | }
11 | // static attributes
12 | // static methods
13 | // attributes
14 | b2Sweep.prototype.localCenter = new b2Vec2();
15 | b2Sweep.prototype.c0 = new b2Vec2;
16 | b2Sweep.prototype.c = new b2Vec2();
17 | b2Sweep.prototype.a0 = null;
18 | b2Sweep.prototype.a = null;
19 | b2Sweep.prototype.t0 = null;
20 | // methods
21 | b2Sweep.prototype.GetXForm = function (xf, t) {
22 |
23 |
24 | if (1.0 - this.t0 > Number.MIN_VALUE)
25 | {
26 | var alpha = (t - this.t0) / (1.0 - this.t0);
27 | xf.position.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;
28 | xf.position.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;
29 | var angle = (1.0 - alpha) * this.a0 + alpha * this.a;
30 | xf.R.Set(angle);
31 | }
32 | else
33 | {
34 | xf.position.SetV(this.c);
35 | xf.R.Set(this.a);
36 | }
37 |
38 |
39 |
40 | var tMat = xf.R;
41 | xf.position.x -= (tMat.col1.x * this.localCenter.x + tMat.col2.x * this.localCenter.y);
42 | xf.position.y -= (tMat.col1.y * this.localCenter.x + tMat.col2.y * this.localCenter.y);
43 |
44 | }
45 | b2Sweep.prototype.Advance = function (t) {
46 | if (this.t0 < t && 1.0 - this.t0 > Number.MIN_VALUE)
47 | {
48 | var alpha = (t - this.t0) / (1.0 - this.t0);
49 |
50 | this.c0.x = (1.0 - alpha) * this.c0.x + alpha * this.c.x;
51 | this.c0.y = (1.0 - alpha) * this.c0.y + alpha * this.c.y;
52 | this.a0 = (1.0 - alpha) * this.a0 + alpha * this.a;
53 | this.t0 = t;
54 | }
55 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2ContactConstraint.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Collision.*;
24 | import Box2D.Dynamics.*;
25 | import Box2D.Common.*;
26 |
27 |
28 | public class b2ContactConstraint
29 | {
30 | public function b2ContactConstraint(){
31 | points = new Array(b2Settings.b2_maxManifoldPoints);
32 | for (var i:int = 0; i < b2Settings.b2_maxManifoldPoints; i++){
33 | points[i] = new b2ContactConstraintPoint();
34 | }
35 |
36 |
37 | }
38 | public var points:Array;
39 | public var normal:b2Vec2=new b2Vec2();
40 | public var manifold:b2Manifold;
41 | public var body1:b2Body;
42 | public var body2:b2Body;
43 | public var friction:Number;
44 | public var restitution:Number;
45 | public var pointCount:int;
46 | };
47 |
48 |
49 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Contacts/b2ContactResult.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Contacts{
20 |
21 | import Box2D.Collision.*;
22 | import Box2D.Collision.Shapes.*;
23 | import Box2D.Common.Math.*;
24 |
25 | /// This structure is used to report contact point results.
26 | public class b2ContactResult
27 | {
28 | public var shape1:b2Shape; ///< the first shape
29 | public var shape2:b2Shape; ///< the second shape
30 | public var position:b2Vec2 = new b2Vec2(); ///< position in world coordinates
31 | public var normal:b2Vec2 = new b2Vec2(); ///< points from shape1 to shape2
32 | public var normalImpulse:Number; ///< the normal impulse applied to body2
33 | public var tangentImpulse:Number; ///< the tangent impulse applied to body2
34 | public var id:b2ContactID = new b2ContactID(); ///< the contact id identifies the features in contact
35 | };
36 |
37 |
38 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2RevoluteJointDef.js:
--------------------------------------------------------------------------------
1 | var b2RevoluteJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2RevoluteJointDef.prototype, b2JointDef.prototype)
7 | b2RevoluteJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2RevoluteJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_revoluteJoint;
10 | this.localAnchor1.Set(0.0, 0.0);
11 | this.localAnchor2.Set(0.0, 0.0);
12 | this.referenceAngle = 0.0;
13 | this.lowerAngle = 0.0;
14 | this.upperAngle = 0.0;
15 | this.maxMotorTorque = 0.0;
16 | this.motorSpeed = 0.0;
17 | this.enableLimit = false;
18 | this.enableMotor = false;
19 | }
20 | b2RevoluteJointDef.prototype.__varz = function(){
21 | this.localAnchor1 = new b2Vec2();
22 | this.localAnchor2 = new b2Vec2();
23 | }
24 | // static attributes
25 | // static methods
26 | // attributes
27 | b2RevoluteJointDef.prototype.localAnchor1 = new b2Vec2();
28 | b2RevoluteJointDef.prototype.localAnchor2 = new b2Vec2();
29 | b2RevoluteJointDef.prototype.referenceAngle = null;
30 | b2RevoluteJointDef.prototype.enableLimit = null;
31 | b2RevoluteJointDef.prototype.lowerAngle = null;
32 | b2RevoluteJointDef.prototype.upperAngle = null;
33 | b2RevoluteJointDef.prototype.enableMotor = null;
34 | b2RevoluteJointDef.prototype.motorSpeed = null;
35 | b2RevoluteJointDef.prototype.maxMotorTorque = null;
36 | // methods
37 | b2RevoluteJointDef.prototype.Initialize = function (b1, b2, anchor) {
38 | this.body1 = b1;
39 | this.body2 = b2;
40 | this.localAnchor1 = this.body1.GetLocalPoint(anchor);
41 | this.localAnchor2 = this.body2.GetLocalPoint(anchor);
42 | this.referenceAngle = this.body2.GetAngle() - this.body1.GetAngle();
43 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2JointEdge.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 | /// A joint edge is used to connect bodies and joints together
27 | /// in a joint graph where each body is a node and each joint
28 | /// is an edge. A joint edge belongs to a doubly linked list
29 | /// maintained in each attached body. Each joint has two joint
30 | /// nodes, one for each attached body.
31 |
32 | public class b2JointEdge
33 | {
34 |
35 | public var other:b2Body; ///< provides quick access to the other body attached.
36 | public var joint:b2Joint; ///< the joint
37 | public var prev:b2JointEdge; ///< the previous joint edge in the body's joint list
38 | public var next:b2JointEdge; ///< the next joint edge in the body's joint list
39 |
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2GearJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 |
24 |
25 |
26 | /// Gear joint definition. This definition requires two existing
27 | /// revolute or prismatic joints (any combination will work).
28 | /// The provided joints must attach a dynamic body to a static body.
29 |
30 | public class b2GearJointDef extends b2JointDef
31 | {
32 | public function b2GearJointDef()
33 | {
34 | type = b2Joint.e_gearJoint;
35 | joint1 = null;
36 | joint2 = null;
37 | ratio = 1.0;
38 | }
39 |
40 | /// The first revolute/prismatic joint attached to the gear joint.
41 | public var joint1:b2Joint;
42 | /// The second revolute/prismatic joint attached to the gear joint.
43 | public var joint2:b2Joint;
44 | /// The gear ratio.
45 | /// @see b2GearJoint for explanation.
46 | public var ratio:Number;
47 | };
48 |
49 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2JointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 | /// Joint definitions are used to construct joints.
27 | public class b2JointDef
28 | {
29 |
30 | public function b2JointDef()
31 | {
32 | type = b2Joint.e_unknownJoint;
33 | userData = null;
34 | body1 = null;
35 | body2 = null;
36 | collideConnected = false;
37 | }
38 |
39 | /// The joint type is set automatically for concrete joint types.
40 | public var type:int;
41 | /// Use this to attach application specific data to your joints.
42 | public var userData:*;
43 | /// The first attached body.
44 | public var body1:b2Body;
45 | /// The second attached body.
46 | public var body2:b2Body;
47 | /// Set this flag to true if the attached bodies should collide.
48 | public var collideConnected:Boolean;
49 |
50 | }
51 |
52 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2DestructionListener.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | import Box2D.Collision.*;
23 | import Box2D.Collision.Shapes.*;
24 | import Box2D.Dynamics.Contacts.*;
25 | import Box2D.Dynamics.Joints.*;
26 | import Box2D.Common.Math.*;
27 | import Box2D.Common.*;
28 |
29 |
30 | /// Joints and shapes are destroyed when their associated
31 | /// body is destroyed. Implement this listener so that you
32 | /// may nullify references to these joints and shapes.
33 | public class b2DestructionListener
34 | {
35 |
36 | /// Called when any joint is about to be destroyed due
37 | /// to the destruction of one of its attached bodies.
38 | public virtual function SayGoodbyeJoint(joint:b2Joint) : void{};
39 |
40 | /// Called when any shape is about to be destroyed due
41 | /// to the destruction of its parent body.
42 | public virtual function SayGoodbyeShape(shape:b2Shape) : void{};
43 |
44 | };
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2Jacobian.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 |
24 |
25 | public class b2Jacobian
26 | {
27 | public var linear1:b2Vec2 = new b2Vec2();
28 | public var angular1:Number;
29 | public var linear2:b2Vec2 = new b2Vec2();
30 | public var angular2:Number;
31 |
32 | public function SetZero() : void{
33 | linear1.SetZero(); angular1 = 0.0;
34 | linear2.SetZero(); angular2 = 0.0;
35 | }
36 | public function Set(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number) : void{
37 | linear1.SetV(x1); angular1 = a1;
38 | linear2.SetV(x2); angular2 = a2;
39 | }
40 | public function Compute(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number):Number{
41 |
42 | //return b2Math.b2Dot(linear1, x1) + angular1 * a1 + b2Math.b2Dot(linear2, x2) + angular2 * a2;
43 | return (linear1.x*x1.x + linear1.y*x1.y) + angular1 * a1 + (linear2.x*x2.x + linear2.y*x2.y) + angular2 * a2;
44 | }
45 | };
46 |
47 |
48 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Shapes/b2FilterData.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision.Shapes{
20 |
21 |
22 |
23 | import Box2D.Common.Math.*;
24 |
25 |
26 | /// This holds contact filtering data.
27 | public class b2FilterData
28 | {
29 | public function Copy() : b2FilterData {
30 | var copy: b2FilterData = new b2FilterData();
31 | copy.categoryBits = categoryBits;
32 | copy.maskBits = maskBits;
33 | copy.groupIndex = groupIndex;
34 | return copy;
35 | }
36 |
37 | /// The collision category bits. Normally you would just set one bit.
38 | public var categoryBits: uint = 0x0001;
39 |
40 | /// The collision mask bits. This states the categories that this
41 | /// shape would accept for collision.
42 | public var maskBits: uint = 0xFFFF;
43 |
44 | /// Collision groups allow a certain group of objects to never collide (negative)
45 | /// or always collide (positive). Zero means no collision group. Non-zero group
46 | /// filtering always wins against the mask bits.
47 | public var groupIndex: int = 0;
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/Shapes/b2PolygonDef.js:
--------------------------------------------------------------------------------
1 | var b2PolygonDef = function() {
2 | b2ShapeDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2PolygonDef.prototype, b2ShapeDef.prototype)
7 | b2PolygonDef.prototype._super = function(){ b2ShapeDef.prototype.__constructor.apply(this, arguments) }
8 | b2PolygonDef.prototype.__constructor = function () {
9 | this.type = b2Shape.e_polygonShape;
10 | this.vertexCount = 0;
11 |
12 | for (var i = 0; i < b2Settings.b2_maxPolygonVertices; i++){
13 | this.vertices[i] = new b2Vec2();
14 | }
15 | }
16 | b2PolygonDef.prototype.__varz = function(){
17 | this.vertices = new Array(b2Settings.b2_maxPolygonVertices);
18 | }
19 | // static attributes
20 | b2PolygonDef.s_mat = new b2Mat22();
21 | // static methods
22 | // attributes
23 | b2PolygonDef.prototype.vertices = new Array(b2Settings.b2_maxPolygonVertices);
24 | b2PolygonDef.prototype.vertexCount = 0;
25 | // methods
26 | b2PolygonDef.prototype.SetAsBox = function (hx, hy) {
27 | this.vertexCount = 4;
28 | this.vertices[0].Set(-hx, -hy);
29 | this.vertices[1].Set( hx, -hy);
30 | this.vertices[2].Set( hx, hy);
31 | this.vertices[3].Set(-hx, hy);
32 | }
33 | b2PolygonDef.prototype.SetAsOrientedBox = function (hx, hy, center, angle) {
34 |
35 | {
36 | this.vertexCount = 4;
37 | this.vertices[0].Set(-hx, -hy);
38 | this.vertices[1].Set( hx, -hy);
39 | this.vertices[2].Set( hx, hy);
40 | this.vertices[3].Set(-hx, hy);
41 | }
42 |
43 | if (center){
44 |
45 |
46 | var xfPosition = center;
47 |
48 | var xfR = b2PolygonDef.s_mat;
49 | xfR.Set(angle);
50 |
51 | for (var i = 0; i < this.vertexCount; ++i)
52 | {
53 |
54 |
55 | center = this.vertices[i];
56 | hx = xfPosition.x + (xfR.col1.x * center.x + xfR.col2.x * center.y)
57 | center.y = xfPosition.y + (xfR.col1.y * center.x + xfR.col2.y * center.y)
58 | center.x = hx;
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2PrismaticJointDef.js:
--------------------------------------------------------------------------------
1 | var b2PrismaticJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2PrismaticJointDef.prototype, b2JointDef.prototype)
7 | b2PrismaticJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2PrismaticJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_prismaticJoint;
10 |
11 |
12 | this.localAxis1.Set(1.0, 0.0);
13 | this.referenceAngle = 0.0;
14 | this.enableLimit = false;
15 | this.lowerTranslation = 0.0;
16 | this.upperTranslation = 0.0;
17 | this.enableMotor = false;
18 | this.maxMotorForce = 0.0;
19 | this.motorSpeed = 0.0;
20 | }
21 | b2PrismaticJointDef.prototype.__varz = function(){
22 | this.localAnchor1 = new b2Vec2();
23 | this.localAnchor2 = new b2Vec2();
24 | this.localAxis1 = new b2Vec2();
25 | }
26 | // static attributes
27 | // static methods
28 | // attributes
29 | b2PrismaticJointDef.prototype.localAnchor1 = new b2Vec2();
30 | b2PrismaticJointDef.prototype.localAnchor2 = new b2Vec2();
31 | b2PrismaticJointDef.prototype.localAxis1 = new b2Vec2();
32 | b2PrismaticJointDef.prototype.referenceAngle = null;
33 | b2PrismaticJointDef.prototype.enableLimit = null;
34 | b2PrismaticJointDef.prototype.lowerTranslation = null;
35 | b2PrismaticJointDef.prototype.upperTranslation = null;
36 | b2PrismaticJointDef.prototype.enableMotor = null;
37 | b2PrismaticJointDef.prototype.maxMotorForce = null;
38 | b2PrismaticJointDef.prototype.motorSpeed = null;
39 | // methods
40 | b2PrismaticJointDef.prototype.Initialize = function (b1, b2, anchor, axis) {
41 | this.body1 = b1;
42 | this.body2 = b2;
43 | this.localAnchor1 = this.body1.GetLocalPoint(anchor);
44 | this.localAnchor2 = this.body2.GetLocalPoint(anchor);
45 | this.localAxis1 = this.body1.GetLocalVector(axis);
46 | this.referenceAngle = this.body2.GetAngle() - this.body1.GetAngle();
47 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2ContactPoint.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*;
22 | import Box2D.Collision.Shapes.*;
23 | import Box2D.Common.Math.*;
24 |
25 | /// This structure is used to report contact points.
26 | public class b2ContactPoint
27 | {
28 | public var shape1:b2Shape; ///< the first shape
29 | public var shape2:b2Shape; ///< the second shape
30 | public var position:b2Vec2 = new b2Vec2(); ///< position in world coordinates
31 | public var velocity:b2Vec2 = new b2Vec2(); ///< velocity of point on body2 relative to point on body1 (pre-solver)
32 | public var normal:b2Vec2 = new b2Vec2(); ///< points from shape1 to shape2
33 | public var separation:Number; ///< the separation is negative when shapes are touching
34 | public var friction:Number; ///< the combined friction coefficient
35 | public var restitution:Number; ///< the combined restitution coefficient
36 | public var id:b2ContactID = new b2ContactID(); ///< the contact id identifies the features in contact
37 | };
38 |
39 |
40 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2ContactID.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.Features;
22 |
23 | // We use contact ids to facilitate warm starting.
24 | public class b2ContactID
25 | {
26 | public function b2ContactID(){
27 | features._m_id = this;
28 |
29 | }
30 | public function Set(id:b2ContactID) : void{
31 | key = id._key;
32 | }
33 | public function Copy():b2ContactID{
34 | var id:b2ContactID = new b2ContactID();
35 | id.key = key;
36 | return id;
37 | }
38 | public function get key():uint {
39 | return _key;
40 | }
41 | public function set key(value:uint) : void {
42 | _key = value;
43 | features._referenceEdge = _key & 0x000000ff;
44 | features._incidentEdge = ((_key & 0x0000ff00) >> 8) & 0x000000ff;
45 | features._incidentVertex = ((_key & 0x00ff0000) >> 16) & 0x000000ff;
46 | features._flip = ((_key & 0xff000000) >> 24) & 0x000000ff;
47 | }
48 | public var features:Features = new Features();
49 | public var _key:uint;///< Used to quickly compare contact ids.
50 | };
51 |
52 |
53 | }
--------------------------------------------------------------------------------
/flash/Box2D/Common/Math/b2XForm.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common.Math{
20 |
21 |
22 | import Box2D.Common.*;
23 |
24 |
25 | /// A transform contains translation and rotation. It is used to represent
26 | /// the position and orientation of rigid frames.
27 | public class b2XForm
28 | {
29 | /// The default constructor does nothing (for performance).
30 | public function b2XForm(pos:b2Vec2=null, r:b2Mat22=null) : void
31 | {
32 | if (pos){
33 | position.SetV(pos);
34 | R.SetM(r);
35 |
36 | }
37 | }
38 |
39 | /// Initialize using a position vector and a rotation matrix.
40 | public function Initialize(pos:b2Vec2, r:b2Mat22) : void
41 | {
42 | position.SetV(pos);
43 | R.SetM(r);
44 | }
45 |
46 | /// Set this to the identity transform.
47 | public function SetIdentity() : void
48 | {
49 | position.SetZero();
50 | R.SetIdentity();
51 | }
52 |
53 |
54 |
55 | public function Set(x:b2XForm) : void{
56 |
57 | position.SetV(x.position);
58 |
59 | R.SetM(x.R);
60 |
61 | }
62 |
63 | public var position:b2Vec2 = new b2Vec2;
64 | public var R:b2Mat22 = new b2Mat22();
65 | };
66 |
67 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2MouseJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 |
24 |
25 | /// Mouse joint definition. This requires a world target point,
26 | /// tuning parameters, and the time step.
27 | public class b2MouseJointDef extends b2JointDef
28 | {
29 | public function b2MouseJointDef()
30 | {
31 | type = b2Joint.e_mouseJoint;
32 | maxForce = 0.0;
33 | frequencyHz = 5.0;
34 | dampingRatio = 0.7;
35 | timeStep = 1.0 / 60.0;
36 | }
37 |
38 | /// The initial world target point. This is assumed
39 | /// to coincide with the body anchor initially.
40 | public var target:b2Vec2 = new b2Vec2();
41 | /// The maximum constraint force that can be exerted
42 | /// to move the candidate body. Usually you will express
43 | /// as some multiple of the weight (multiplier * mass * gravity).
44 | public var maxForce:Number;
45 | /// The response speed.
46 | public var frequencyHz:Number;
47 | /// The damping ratio. 0 = no damping, 1 = critical damping.
48 | public var dampingRatio:Number;
49 | /// The time step used in the simulation.
50 | public var timeStep:Number;
51 | };
52 |
53 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Manifold.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*
22 | import Box2D.Common.Math.*
23 | import Box2D.Common.*
24 |
25 | // A manifold for two touching convex shapes.
26 | public class b2Manifold
27 | {
28 | public function b2Manifold(){
29 | points = new Array(b2Settings.b2_maxManifoldPoints);
30 | for (var i:int = 0; i < b2Settings.b2_maxManifoldPoints; i++){
31 | points[i] = new b2ManifoldPoint();
32 | }
33 | normal = new b2Vec2();
34 | }
35 | public function Reset() : void{
36 | for (var i:int = 0; i < b2Settings.b2_maxManifoldPoints; i++){
37 | (points[i] as b2ManifoldPoint).Reset();
38 | }
39 | normal.SetZero();
40 | pointCount = 0;
41 | }
42 | public function Set(m:b2Manifold) : void{
43 | pointCount = m.pointCount;
44 | for (var i:int = 0; i < b2Settings.b2_maxManifoldPoints; i++){
45 | (points[i] as b2ManifoldPoint).Set(m.points[i]);
46 | }
47 | normal.SetV(m.normal);
48 | }
49 | public var points:Array; ///< the points of contact
50 | public var normal:b2Vec2; ///< the shared unit normal vector
51 | public var pointCount:int = 0; ///< the number of manifold points
52 | };
53 |
54 |
55 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Shapes/b2ShapeDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision.Shapes{
20 |
21 |
22 |
23 | import Box2D.Common.Math.*;
24 | import Box2D.Common.*;
25 | import Box2D.Collision.Shapes.b2Shape;
26 |
27 |
28 |
29 | /// A shape definition is used to construct a shape. This class defines an
30 | /// abstract shape definition. You can reuse shape definitions safely.
31 | public class b2ShapeDef
32 | {
33 | /// Holds the shape type for down-casting.
34 | public var type:int = b2Shape.e_unknownShape;
35 |
36 | /// Use this to store application specify shape data.
37 | public var userData:* = null;
38 |
39 | /// The shape's friction coefficient, usually in the range [0,1].
40 | public var friction:Number = 0.2;
41 |
42 | /// The shape's restitution (elasticity) usually in the range [0,1].
43 | public var restitution:Number = 0.0;
44 |
45 | /// The shape's density, usually in kg/m^2.
46 | public var density:Number = 0.0;
47 |
48 | /// A sensor shape collects contact information but never generates a collision
49 | /// response.
50 | public var isSensor:Boolean = false;
51 |
52 | /// Contact filtering data.
53 | public var filter: b2FilterData = new b2FilterData();
54 | };
55 |
56 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2ManifoldPoint.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*
22 | import Box2D.Common.Math.*
23 |
24 | /// A manifold point is a contact point belonging to a contact
25 | /// manifold. It holds details related to the geometry and dynamics
26 | /// of the contact points.
27 | /// The point is stored in local coordinates because CCD
28 | /// requires sub-stepping in which the separation is stale.
29 | public class b2ManifoldPoint
30 | {
31 | public function Reset() : void{
32 | localPoint1.SetZero();
33 | localPoint2.SetZero();
34 | separation = 0.0;
35 | normalImpulse = 0.0;
36 | tangentImpulse = 0.0;
37 | id.key = 0;
38 | }
39 | public function Set(m:b2ManifoldPoint) : void{
40 | localPoint1.SetV(m.localPoint1);
41 | localPoint2.SetV(m.localPoint2);
42 | separation = m.separation;
43 | normalImpulse = m.normalImpulse;
44 | tangentImpulse = m.tangentImpulse;
45 | id.key = m.id.key;
46 | }
47 | public var localPoint1:b2Vec2 = new b2Vec2();
48 | public var localPoint2:b2Vec2 = new b2Vec2();
49 | public var separation:Number;
50 | public var normalImpulse:Number;
51 | public var tangentImpulse:Number;
52 | public var id:b2ContactID = new b2ContactID();
53 | };
54 |
55 |
56 | }
--------------------------------------------------------------------------------
/flash/Box2D/Common/b2Color.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common{
20 |
21 |
22 | import Box2D.Common.*;
23 | import Box2D.Common.Math.*;
24 |
25 |
26 | /// A 2D column vector.
27 |
28 | public class b2Color
29 | {
30 |
31 | public function b2Color(rr:Number, gg:Number, bb:Number){
32 | _r = uint(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
33 | _g = uint(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
34 | _b = uint(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
35 | }
36 |
37 | public function Set(rr:Number, gg:Number, bb:Number):void{
38 | _r = uint(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
39 | _g = uint(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
40 | _b = uint(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
41 | }
42 |
43 | // R
44 | public function set r(rr:Number) : void{
45 | _r = uint(255 * b2Math.b2Clamp(rr, 0.0, 1.0));
46 | }
47 | // G
48 | public function set g(gg:Number) : void{
49 | _g = uint(255 * b2Math.b2Clamp(gg, 0.0, 1.0));
50 | }
51 | // B
52 | public function set b(bb:Number) : void{
53 | _b = uint(255 * b2Math.b2Clamp(bb, 0.0, 1.0));
54 | }
55 |
56 | // Color
57 | public function get color() : uint{
58 | return (_r) | (_g << 8) | (_b << 16);
59 | }
60 |
61 | private var _r:uint = 0;
62 | private var _g:uint = 0;
63 | private var _b:uint = 0;
64 |
65 | };
66 |
67 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2ContactFilter.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | import Box2D.Collision.*;
23 | import Box2D.Collision.Shapes.*;
24 | import Box2D.Dynamics.Contacts.*;
25 | import Box2D.Dynamics.*;
26 | import Box2D.Common.Math.*;
27 | import Box2D.Common.*;
28 |
29 |
30 | /// Implement this class to provide collision filtering. In other words, you can implement
31 | /// this class if you want finer control over contact creation.
32 | public class b2ContactFilter
33 | {
34 |
35 | /// Return true if contact calculations should be performed between these two shapes.
36 | /// @warning for performance reasons this is only called when the AABBs begin to overlap.
37 | public virtual function ShouldCollide(shape1:b2Shape, shape2:b2Shape) : Boolean{
38 | var filter1:b2FilterData = shape1.GetFilterData();
39 | var filter2:b2FilterData = shape2.GetFilterData();
40 |
41 | if (filter1.groupIndex == filter2.groupIndex && filter1.groupIndex != 0)
42 | {
43 | return filter1.groupIndex > 0;
44 | }
45 |
46 | var collide:Boolean = (filter1.maskBits & filter2.categoryBits) != 0 && (filter1.categoryBits & filter2.maskBits) != 0;
47 | return collide;
48 | }
49 |
50 | static public var b2_defaultFilter:b2ContactFilter = new b2ContactFilter();
51 |
52 | };
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2PulleyJointDef.js:
--------------------------------------------------------------------------------
1 | var b2PulleyJointDef = function() {
2 | b2JointDef.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2PulleyJointDef.prototype, b2JointDef.prototype)
7 | b2PulleyJointDef.prototype._super = function(){ b2JointDef.prototype.__constructor.apply(this, arguments) }
8 | b2PulleyJointDef.prototype.__constructor = function () {
9 | this.type = b2Joint.e_pulleyJoint;
10 | this.groundAnchor1.Set(-1.0, 1.0);
11 | this.groundAnchor2.Set(1.0, 1.0);
12 | this.localAnchor1.Set(-1.0, 0.0);
13 | this.localAnchor2.Set(1.0, 0.0);
14 | this.length1 = 0.0;
15 | this.maxLength1 = 0.0;
16 | this.length2 = 0.0;
17 | this.maxLength2 = 0.0;
18 | this.ratio = 1.0;
19 | this.collideConnected = true;
20 | }
21 | b2PulleyJointDef.prototype.__varz = function(){
22 | this.groundAnchor1 = new b2Vec2();
23 | this.groundAnchor2 = new b2Vec2();
24 | this.localAnchor1 = new b2Vec2();
25 | this.localAnchor2 = new b2Vec2();
26 | }
27 | // static attributes
28 | // static methods
29 | // attributes
30 | b2PulleyJointDef.prototype.groundAnchor1 = new b2Vec2();
31 | b2PulleyJointDef.prototype.groundAnchor2 = new b2Vec2();
32 | b2PulleyJointDef.prototype.localAnchor1 = new b2Vec2();
33 | b2PulleyJointDef.prototype.localAnchor2 = new b2Vec2();
34 | b2PulleyJointDef.prototype.length1 = null;
35 | b2PulleyJointDef.prototype.maxLength1 = null;
36 | b2PulleyJointDef.prototype.length2 = null;
37 | b2PulleyJointDef.prototype.maxLength2 = null;
38 | b2PulleyJointDef.prototype.ratio = null;
39 | // methods
40 | b2PulleyJointDef.prototype.Initialize = function (b1, b2,
41 | ga1, ga2,
42 | anchor1, anchor2,
43 | r) {
44 | this.body1 = b1;
45 | this.body2 = b2;
46 | this.groundAnchor1.SetV( ga1 );
47 | this.groundAnchor2.SetV( ga2 );
48 | this.localAnchor1 = this.body1.GetLocalPoint(anchor1);
49 | this.localAnchor2 = this.body2.GetLocalPoint(anchor2);
50 |
51 | var d1X = anchor1.x - ga1.x;
52 | var d1Y = anchor1.y - ga1.y;
53 |
54 | this.length1 = Math.sqrt(d1X*d1X + d1Y*d1Y);
55 |
56 |
57 | var d2X = anchor2.x - ga2.x;
58 | var d2Y = anchor2.y - ga2.y;
59 |
60 | this.length2 = Math.sqrt(d2X*d2X + d2Y*d2Y);
61 |
62 | this.ratio = r;
63 |
64 | var C = this.length1 + this.ratio * this.length2;
65 | this.maxLength1 = C - this.ratio * b2PulleyJoint.b2_minPulleyLength;
66 | this.maxLength2 = (C - b2PulleyJoint.b2_minPulleyLength) / this.ratio;
67 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2Vec2.js:
--------------------------------------------------------------------------------
1 | var b2Vec2 = function(x_, y_) {
2 | if(arguments.length == 2) {
3 | this.x=x_; this.y=y_;
4 | }
5 | }
6 | // static attributes
7 | // static methods
8 | b2Vec2.Make = function (x_, y_) {
9 | return new b2Vec2(x_, y_);
10 | }
11 | // attributes
12 | b2Vec2.prototype.x = 0;
13 | b2Vec2.prototype.y = 0;
14 | // methods
15 | b2Vec2.prototype.SetZero = function () { this.x = 0.0; this.y = 0.0; }
16 | b2Vec2.prototype.Set = function (x_, y_) {this.x=x_; this.y=y_;}
17 | b2Vec2.prototype.SetV = function (v) {this.x=v.x; this.y=v.y;}
18 | b2Vec2.prototype.Negative = function () { return new b2Vec2(-this.x, -this.y); }
19 | b2Vec2.prototype.Copy = function () {
20 | return new b2Vec2(this.x,this.y);
21 | }
22 | b2Vec2.prototype.Add = function (v) {
23 | this.x += v.x; this.y += v.y;
24 | }
25 | b2Vec2.prototype.Subtract = function (v) {
26 | this.x -= v.x; this.y -= v.y;
27 | }
28 | b2Vec2.prototype.Multiply = function (a) {
29 | this.x *= a; this.y *= a;
30 | }
31 | b2Vec2.prototype.MulM = function (A) {
32 | var tX = this.x;
33 | this.x = A.col1.x * tX + A.col2.x * this.y;
34 | this.y = A.col1.y * tX + A.col2.y * this.y;
35 | }
36 | b2Vec2.prototype.MulTM = function (A) {
37 | var tX = b2Math.b2Dot(this, A.col1);
38 | this.y = b2Math.b2Dot(this, A.col2);
39 | this.x = tX;
40 | }
41 | b2Vec2.prototype.CrossVF = function (s) {
42 | var tX = this.x;
43 | this.x = s * this.y;
44 | this.y = -s * tX;
45 | }
46 | b2Vec2.prototype.CrossFV = function (s) {
47 | var tX = this.x;
48 | this.x = -s * this.y;
49 | this.y = s * tX;
50 | }
51 | b2Vec2.prototype.MinV = function (b) {
52 | this.x = this.x < b.x ? this.x : b.x;
53 | this.y = this.y < b.y ? this.y : b.y;
54 | }
55 | b2Vec2.prototype.MaxV = function (b) {
56 | this.x = this.x > b.x ? this.x : b.x;
57 | this.y = this.y > b.y ? this.y : b.y;
58 | }
59 | b2Vec2.prototype.Abs = function () {
60 | if (this.x < 0) this.x = -this.x;
61 | if (this.y < 0) this.y = -this.y;
62 | }
63 | b2Vec2.prototype.Length = function () {
64 | return Math.sqrt(this.x * this.x + this.y * this.y);
65 | }
66 | b2Vec2.prototype.LengthSquared = function () {
67 | return (this.x * this.x + this.y * this.y);
68 | }
69 | b2Vec2.prototype.Normalize = function () {
70 | var length = Math.sqrt(this.x * this.x + this.y * this.y);
71 | if (length < Number.MIN_VALUE)
72 | {
73 | return 0.0;
74 | }
75 | var invLength = 1.0 / length;
76 | this.x *= invLength;
77 | this.y *= invLength;
78 |
79 | return length;
80 | }
81 | b2Vec2.prototype.IsValid = function () {
82 | return b2Math.b2IsValid(this.x) && b2Math.b2IsValid(this.y);
83 | }
84 |
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Features.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | // We use contact ids to facilitate warm starting.
22 | public class Features
23 | {
24 | ///< The edge that defines the outward contact normal.
25 | public function set referenceEdge(value:int) : void{
26 | _referenceEdge = value;
27 | _m_id._key = (_m_id._key & 0xffffff00) | (_referenceEdge & 0x000000ff);
28 | }
29 | public function get referenceEdge():int{
30 | return _referenceEdge;
31 | }
32 | public var _referenceEdge:int;
33 |
34 | ///< The edge most anti-parallel to the reference edge.
35 | public function set incidentEdge(value:int) : void{
36 | _incidentEdge = value;
37 | _m_id._key = (_m_id._key & 0xffff00ff) | ((_incidentEdge << 8) & 0x0000ff00);
38 | }
39 | public function get incidentEdge():int{
40 | return _incidentEdge;
41 | }
42 | public var _incidentEdge:int;
43 |
44 | ///< The vertex (0 or 1) on the incident edge that was clipped.
45 | public function set incidentVertex(value:int) : void{
46 | _incidentVertex = value;
47 | _m_id._key = (_m_id._key & 0xff00ffff) | ((_incidentVertex << 16) & 0x00ff0000);
48 | }
49 | public function get incidentVertex():int{
50 | return _incidentVertex;
51 | }
52 | public var _incidentVertex:int;
53 |
54 | ///< A value of 1 indicates that the reference edge is on shape2.
55 | public function set flip(value:int) : void{
56 | _flip = value;
57 | _m_id._key = (_m_id._key & 0x00ffffff) | ((_flip << 24) & 0xff000000);
58 | }
59 | public function get flip():int{
60 | return _flip;
61 | }
62 | public var _flip:int;
63 |
64 |
65 | public var _m_id:b2ContactID;
66 | };
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2Mat22.js:
--------------------------------------------------------------------------------
1 | var b2Mat22 = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Mat22.prototype.__constructor = function (angle, c1, c2) {
6 | if (c1!=null && c2!=null){
7 | this.col1.SetV(c1);
8 | this.col2.SetV(c2);
9 | }
10 | else{
11 | var c = Math.cos(angle);
12 | var s = Math.sin(angle);
13 | this.col1.x = c; this.col2.x = -s;
14 | this.col1.y = s; this.col2.y = c;
15 | }
16 | }
17 | b2Mat22.prototype.__varz = function(){
18 | this.col1 = new b2Vec2();
19 | this.col2 = new b2Vec2();
20 | }
21 | // static attributes
22 | // static methods
23 | // attributes
24 | b2Mat22.prototype.col1 = new b2Vec2();
25 | b2Mat22.prototype.col2 = new b2Vec2();
26 | // methods
27 | b2Mat22.prototype.Set = function (angle) {
28 | var c = Math.cos(angle);
29 | var s = Math.sin(angle);
30 | this.col1.x = c; this.col2.x = -s;
31 | this.col1.y = s; this.col2.y = c;
32 | }
33 | b2Mat22.prototype.SetVV = function (c1, c2) {
34 | this.col1.SetV(c1);
35 | this.col2.SetV(c2);
36 | }
37 | b2Mat22.prototype.Copy = function () {
38 | return new b2Mat22(0, this.col1, this.col2);
39 | }
40 | b2Mat22.prototype.SetM = function (m) {
41 | this.col1.SetV(m.col1);
42 | this.col2.SetV(m.col2);
43 | }
44 | b2Mat22.prototype.AddM = function (m) {
45 | this.col1.x += m.col1.x;
46 | this.col1.y += m.col1.y;
47 | this.col2.x += m.col2.x;
48 | this.col2.y += m.col2.y;
49 | }
50 | b2Mat22.prototype.SetIdentity = function () {
51 | this.col1.x = 1.0; this.col2.x = 0.0;
52 | this.col1.y = 0.0; this.col2.y = 1.0;
53 | }
54 | b2Mat22.prototype.SetZero = function () {
55 | this.col1.x = 0.0; this.col2.x = 0.0;
56 | this.col1.y = 0.0; this.col2.y = 0.0;
57 | }
58 | b2Mat22.prototype.GetAngle = function () {
59 | return Math.atan2(this.col1.y, this.col1.x);
60 | }
61 | b2Mat22.prototype.Invert = function (out) {
62 | var a = this.col1.x;
63 | var b = this.col2.x;
64 | var c = this.col1.y;
65 | var d = this.col2.y;
66 |
67 | var det = a * d - b * c;
68 |
69 | det = 1.0 / det;
70 | out.col1.x = det * d; out.col2.x = -det * b;
71 | out.col1.y = -det * c; out.col2.y = det * a;
72 | return out;
73 | }
74 | b2Mat22.prototype.Solve = function (out, bX, bY) {
75 |
76 | var a11 = this.col1.x;
77 | var a12 = this.col2.x;
78 | var a21 = this.col1.y;
79 | var a22 = this.col2.y;
80 |
81 | var det = a11 * a22 - a12 * a21;
82 |
83 | det = 1.0 / det;
84 | out.x = det * (a22 * bX - a12 * bY);
85 | out.y = det * (a11 * bY - a21 * bX);
86 |
87 | return out;
88 | }
89 | b2Mat22.prototype.Abs = function () {
90 | this.col1.Abs();
91 | this.col2.Abs();
92 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2ContactListener.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | import Box2D.Collision.*;
23 | import Box2D.Collision.Shapes.*;
24 | import Box2D.Dynamics.Contacts.*;
25 | import Box2D.Dynamics.*;
26 | import Box2D.Common.Math.*;
27 | import Box2D.Common.*;
28 |
29 |
30 | /// Implement this class to get collision results. You can use these results for
31 | /// things like sounds and game logic. You can also get contact results by
32 | /// traversing the contact lists after the time step. However, you might miss
33 | /// some contacts because continuous physics leads to sub-stepping.
34 | /// Additionally you may receive multiple callbacks for the same contact in a
35 | /// single time step.
36 | /// You should strive to make your callbacks efficient because there may be
37 | /// many callbacks per time step.
38 | /// @warning The contact separation is the last computed value.
39 | /// @warning You cannot create/destroy Box2D entities inside these callbacks.
40 | public class b2ContactListener
41 | {
42 |
43 | /// Called when a contact point is added. This includes the geometry
44 | /// and the forces.
45 | public virtual function Add(point:b2ContactPoint) : void{};
46 |
47 | /// Called when a contact point persists. This includes the geometry
48 | /// and the forces.
49 | public virtual function Persist(point:b2ContactPoint) : void{};
50 |
51 | /// Called when a contact point is removed. This includes the last
52 | /// computed geometry and forces.
53 | public virtual function Remove(point:b2ContactPoint) : void{};
54 |
55 | /// Called after a contact point is solved.
56 | public virtual function Result(point:b2ContactResult) : void{};
57 | };
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Pair.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | // The pair manager is used by the broad-phase to quickly add/remove/find pairs
20 | // of overlapping proxies. It is based closely on code provided by Pierre Terdiman.
21 | // http://www.codercorner.com/IncrementalSAP.txt
22 |
23 | package Box2D.Collision{
24 |
25 |
26 | import Box2D.Common.*;
27 |
28 |
29 | public class b2Pair
30 | {
31 |
32 |
33 | public function SetBuffered() : void { status |= e_pairBuffered; }
34 | public function ClearBuffered() : void { status &= ~e_pairBuffered; }
35 | public function IsBuffered():Boolean { return (status & e_pairBuffered) == e_pairBuffered; }
36 |
37 | public function SetRemoved() : void { status |= e_pairRemoved; }
38 | public function ClearRemoved() : void { status &= ~e_pairRemoved; }
39 | public function IsRemoved():Boolean { return (status & e_pairRemoved) == e_pairRemoved; }
40 |
41 | public function SetFinal() : void { status |= e_pairFinal; }
42 | public function IsFinal():Boolean { return (status & e_pairFinal) == e_pairFinal; }
43 |
44 | public var userData:* = null;
45 | public var proxyId1:uint;
46 | public var proxyId2:uint;
47 | public var next:uint;
48 | public var status:uint;
49 |
50 | // STATIC
51 | static public var b2_nullPair:uint = b2Settings.USHRT_MAX;
52 | static public var b2_nullProxy:uint = b2Settings.USHRT_MAX;
53 | static public var b2_tableCapacity:int = b2Settings.b2_maxPairs; // must be a power of two
54 | static public var b2_tableMask:int = b2_tableCapacity - 1;
55 |
56 | // enum
57 | static public var e_pairBuffered:uint = 0x0001;
58 | static public var e_pairRemoved:uint = 0x0002;
59 | static public var e_pairFinal:uint = 0x0004;
60 |
61 | };
62 |
63 |
64 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2Vec2_edited.js:
--------------------------------------------------------------------------------
1 | var b2Vec2 = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Vec2.prototype.__constructor = function (x_, y_) {
6 | if(arguments.length == 2) {
7 | this.x=x_; this.y=y_;
8 | }
9 | }
10 | b2Vec2.prototype.__varz = function(){
11 | }
12 | // static attributes
13 | // static methods
14 | b2Vec2.Make = function (x_, y_) {
15 | return new b2Vec2(x_, y_);
16 | }
17 | // attributes
18 | b2Vec2.prototype.x = 0;
19 | b2Vec2.prototype.y = 0;
20 | // methods
21 | b2Vec2.prototype.SetZero = function () { this.x = 0.0; this.y = 0.0; }
22 | b2Vec2.prototype.Set = function (x_, y_) {this.x=x_; this.y=y_;}
23 | b2Vec2.prototype.SetV = function (v) {this.x=v.x; this.y=v.y;}
24 | b2Vec2.prototype.Negative = function () { return new b2Vec2(-this.x, -this.y); }
25 | b2Vec2.prototype.Copy = function () {
26 | return new b2Vec2(this.x,this.y);
27 | }
28 | b2Vec2.prototype.Add = function (v) {
29 | this.x += v.x; this.y += v.y;
30 | }
31 | b2Vec2.prototype.Subtract = function (v) {
32 | this.x -= v.x; this.y -= v.y;
33 | }
34 | b2Vec2.prototype.Multiply = function (a) {
35 | this.x *= a; this.y *= a;
36 | }
37 | b2Vec2.prototype.MulM = function (A) {
38 | var tX = this.x;
39 | this.x = A.col1.x * tX + A.col2.x * this.y;
40 | this.y = A.col1.y * tX + A.col2.y * this.y;
41 | }
42 | b2Vec2.prototype.MulTM = function (A) {
43 | var tX = b2Math.b2Dot(this, A.col1);
44 | this.y = b2Math.b2Dot(this, A.col2);
45 | this.x = tX;
46 | }
47 | b2Vec2.prototype.CrossVF = function (s) {
48 | var tX = this.x;
49 | this.x = s * this.y;
50 | this.y = -s * tX;
51 | }
52 | b2Vec2.prototype.CrossFV = function (s) {
53 | var tX = this.x;
54 | this.x = -s * this.y;
55 | this.y = s * tX;
56 | }
57 | b2Vec2.prototype.MinV = function (b) {
58 | this.x = this.x < b.x ? this.x : b.x;
59 | this.y = this.y < b.y ? this.y : b.y;
60 | }
61 | b2Vec2.prototype.MaxV = function (b) {
62 | this.x = this.x > b.x ? this.x : b.x;
63 | this.y = this.y > b.y ? this.y : b.y;
64 | }
65 | b2Vec2.prototype.Abs = function () {
66 | if (this.x < 0) this.x = -this.x;
67 | if (this.y < 0) this.y = -this.y;
68 | }
69 | b2Vec2.prototype.Length = function () {
70 | return Math.sqrt(this.x * this.x + this.y * this.y);
71 | }
72 | b2Vec2.prototype.LengthSquared = function () {
73 | return (this.x * this.x + this.y * this.y);
74 | }
75 | b2Vec2.prototype.Normalize = function () {
76 | var length = Math.sqrt(this.x * this.x + this.y * this.y);
77 | if (length < Number.MIN_VALUE)
78 | {
79 | return 0.0;
80 | }
81 | var invLength = 1.0 / length;
82 | this.x *= invLength;
83 | this.y *= invLength;
84 |
85 | return length;
86 | }
87 | b2Vec2.prototype.IsValid = function () {
88 | return b2Math.b2IsValid(this.x) && b2Math.b2IsValid(this.y);
89 | }
90 |
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2DistanceJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.Joints.*;
24 | import Box2D.Dynamics.*;
25 |
26 |
27 | /// Distance joint definition. This requires defining an
28 | /// anchor point on both bodies and the non-zero length of the
29 | /// distance joint. The definition uses local anchor points
30 | /// so that the initial configuration can violate the constraint
31 | /// slightly. This helps when saving and loading a game.
32 | /// @warning Do not use a zero or short length.
33 | public class b2DistanceJointDef extends b2JointDef
34 | {
35 | public function b2DistanceJointDef()
36 | {
37 | type = b2Joint.e_distanceJoint;
38 | //localAnchor1.Set(0.0, 0.0);
39 | //localAnchor2.Set(0.0, 0.0);
40 | length = 1.0;
41 | frequencyHz = 0.0;
42 | dampingRatio = 0.0;
43 | }
44 |
45 | /// Initialize the bodies, anchors, and length using the world
46 | /// anchors.
47 | public function Initialize(b1:b2Body, b2:b2Body,
48 | anchor1:b2Vec2, anchor2:b2Vec2) : void
49 | {
50 | body1 = b1;
51 | body2 = b2;
52 | localAnchor1.SetV( body1.GetLocalPoint(anchor1));
53 | localAnchor2.SetV( body2.GetLocalPoint(anchor2));
54 | var dX:Number = anchor2.x - anchor1.x;
55 | var dY:Number = anchor2.y - anchor1.y;
56 | length = Math.sqrt(dX*dX + dY*dY);
57 | frequencyHz = 0.0;
58 | dampingRatio = 0.0;
59 | }
60 |
61 | /// The local anchor point relative to body1's origin.
62 | public var localAnchor1:b2Vec2 = new b2Vec2();
63 |
64 | /// The local anchor point relative to body2's origin.
65 | public var localAnchor2:b2Vec2 = new b2Vec2();
66 |
67 | /// The equilibrium length between the anchor points.
68 | public var length:Number;
69 |
70 | /// The response speed.
71 | public var frequencyHz:Number;
72 |
73 | /// The damping ratio. 0 = no damping, 1 = critical damping.
74 | public var dampingRatio:Number;
75 | };
76 |
77 | }
--------------------------------------------------------------------------------
/flash/ReadMe.txt:
--------------------------------------------------------------------------------
1 |
2 | //
3 | Box2DFlashAS3
4 | Version 2.0.1
5 | //
6 |
7 | //
8 | Homepage:
9 | http://box2dflash.sourceforge.net
10 | //
11 |
12 | //
13 | Credits:
14 | Box2D - Erin Catto ( http://gphysics.com/ )
15 | Box2DFlashAS3 - Matthew Bush (Flash ActionScript 3.0 port of Erin Catto's work)
16 | Box2DFlashAS3 2.0.1 - John Nesky (2.0.0 -> 2.0.1 port and other changes)
17 | //
18 |
19 | //
20 | To compile the demo:
21 | //
22 | Flash: extract Box2DFlashAS3 and open PhysTest.fla in Flash CS3 (9) and hit Ctrl+Enter.
23 | Flex: Create a new ActionScript project and add all the files from the archive to the project. Set Main.as to the default application and hit Ctrl+F11.
24 |
25 | //
26 | Controls:
27 | //
28 | -Left and right arrows to change to previous/next example
29 | -Left mouse to drag objects
30 | -R to reset
31 |
32 | //
33 |
34 | Changes
35 | //
36 | List of general API changes from 1.4.3 can be found here
37 | http://box2d.org/forum/viewtopic.php?f=2&t=509
38 | Notes:
39 | -Past users note that b2BoxDef has been replaced by SetAsBox() function in b2PolygonDef
40 | (Refer to any of the PhysTest examples or the manual for more info and usage examples)
41 | -Debug rendering class included, see the constructor in Test.as in the PhysTest project for example usage
42 | -One of the major features of 2.0.0 is the inclusion of CCD, see here for more information:
43 | http://www.box2d.org/manual.html#bullets
44 | //
45 |
46 |
47 | //
48 | Getting started:
49 | //
50 | Please refer to the source code from the examples provided to get an idea of how to use Box2DFlash in your projects.
51 | For more detailed information about the Box2D, please refer to the online manual at http://www.box2d.org/manual.html
52 | Or the wiki at http://www.box2d.org/wiki/
53 | If you have any questions about Box2D, or have any problems, please visit the Box2D forums at http://www.box2d.org/forum/ and make a note that you are using this Flash port.
54 |
55 | Note: The 'General' folder contains some classes used in the test bed, such as for the frame rate counter and input, you don't have to include this folder to use Box2DFlashAS3 but you're welcome to use any of the code.
56 |
57 | If you make a commercial application using Box2DFlashAS3 and would like to pass on some of your earnings, I would like to request that you donate to Erin Catto's project here: http://sourceforge.net/donate/index.php?group_id=205387 since creating a physics engine is a much larger task than simply porting it to Flash.
58 | But if you really, really want to send me a donation, you can PayPal me at skatehead [at] gmail.com and I will be very grateful.
59 |
60 | Please report any bugs on the forums mentioned above, or if you like, you can contact me directly at the email address mentioned above.
61 |
62 | Thanks,
63 | If you do use Box2DFlashAS3 in any projects, I'd love to see them, so drop me an email or make a post on the Box2D forums in the 'Games and Applications' sections.
64 | All the best,
65 | -Matt
66 |
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2PrismaticJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 | public class b2PrismaticJointDef extends b2JointDef
27 | {
28 | public function b2PrismaticJointDef()
29 | {
30 | type = b2Joint.e_prismaticJoint;
31 | //localAnchor1.SetZero();
32 | //localAnchor2.SetZero();
33 | localAxis1.Set(1.0, 0.0);
34 | referenceAngle = 0.0;
35 | enableLimit = false;
36 | lowerTranslation = 0.0;
37 | upperTranslation = 0.0;
38 | enableMotor = false;
39 | maxMotorForce = 0.0;
40 | motorSpeed = 0.0;
41 | }
42 |
43 | public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2, axis:b2Vec2) : void
44 | {
45 | body1 = b1;
46 | body2 = b2;
47 | localAnchor1 = body1.GetLocalPoint(anchor);
48 | localAnchor2 = body2.GetLocalPoint(anchor);
49 | localAxis1 = body1.GetLocalVector(axis);
50 | referenceAngle = body2.GetAngle() - body1.GetAngle();
51 | }
52 |
53 | /// The local anchor point relative to body1's origin.
54 | public var localAnchor1:b2Vec2 = new b2Vec2();
55 |
56 | /// The local anchor point relative to body2's origin.
57 | public var localAnchor2:b2Vec2 = new b2Vec2();
58 |
59 | /// The local translation axis in body1.
60 | public var localAxis1:b2Vec2 = new b2Vec2();
61 |
62 | /// The constrained angle between the bodies: body2_angle - body1_angle.
63 | public var referenceAngle:Number;
64 |
65 | /// Enable/disable the joint limit.
66 | public var enableLimit:Boolean;
67 |
68 | /// The lower translation limit, usually in meters.
69 | public var lowerTranslation:Number;
70 |
71 | /// The upper translation limit, usually in meters.
72 | public var upperTranslation:Number;
73 |
74 | /// Enable/disable the joint motor.
75 | public var enableMotor:Boolean;
76 |
77 | /// The maximum motor torque, usually in N-m.
78 | public var maxMotorForce:Number;
79 |
80 | /// The desired motor speed in radians per second.
81 | public var motorSpeed:Number;
82 | };
83 |
84 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Collision/b2TimeOfImpact.js:
--------------------------------------------------------------------------------
1 | var b2TimeOfImpact = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2TimeOfImpact.prototype.__constructor = function(){}
6 | b2TimeOfImpact.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | b2TimeOfImpact.s_p1 = new b2Vec2();
10 | b2TimeOfImpact.s_p2 = new b2Vec2();
11 | b2TimeOfImpact.s_xf1 = new b2XForm();
12 | b2TimeOfImpact.s_xf2 = new b2XForm();
13 | // static methods
14 | b2TimeOfImpact.TimeOfImpact = function ( shape1, sweep1,
15 | shape2, sweep2) {
16 | var math1;
17 | var math2;
18 |
19 | var r1 = shape1.m_sweepRadius;
20 | var r2 = shape2.m_sweepRadius;
21 |
22 |
23 |
24 |
25 | var t0 = sweep1.t0;
26 |
27 | var v1X = sweep1.c.x - sweep1.c0.x;
28 | var v1Y = sweep1.c.y - sweep1.c0.y;
29 |
30 | var v2X = sweep2.c.x - sweep2.c0.x;
31 | var v2Y = sweep2.c.y - sweep2.c0.y;
32 | var omega1 = sweep1.a - sweep1.a0;
33 | var omega2 = sweep2.a - sweep2.a0;
34 |
35 | var alpha = 0.0;
36 |
37 | var p1 = b2TimeOfImpact.s_p1;
38 | var p2 = b2TimeOfImpact.s_p2;
39 | var k_maxIterations = 20;
40 | var iter = 0;
41 |
42 | var normalX = 0.0;
43 | var normalY = 0.0;
44 | var distance = 0.0;
45 | var targetDistance = 0.0;
46 | for(;;)
47 | {
48 | var t = (1.0 - alpha) * t0 + alpha;
49 |
50 | var xf1 = b2TimeOfImpact.s_xf1;
51 | var xf2 = b2TimeOfImpact.s_xf2;
52 | sweep1.GetXForm(xf1, t);
53 | sweep2.GetXForm(xf2, t);
54 |
55 |
56 | distance = b2Distance.Distance(p1, p2, shape1, xf1, shape2, xf2);
57 |
58 | if (iter == 0)
59 | {
60 |
61 |
62 | if (distance > 2.0 * b2Settings.b2_toiSlop)
63 | {
64 | targetDistance = 1.5 * b2Settings.b2_toiSlop;
65 | }
66 | else
67 | {
68 |
69 | math1 = 0.05 * b2Settings.b2_toiSlop;
70 | math2 = distance - 0.5 * b2Settings.b2_toiSlop;
71 | targetDistance = math1 > math2 ? math1 : math2;
72 | }
73 | }
74 |
75 | if (distance - targetDistance < 0.05 * b2Settings.b2_toiSlop || iter == k_maxIterations)
76 | {
77 | break;
78 | }
79 |
80 |
81 | normalX = p2.x - p1.x;
82 | normalY = p2.y - p1.y;
83 |
84 | var nLen = Math.sqrt(normalX*normalX + normalY*normalY);
85 | normalX /= nLen;
86 | normalY /= nLen;
87 |
88 |
89 |
90 | var approachVelocityBound = (normalX*(v1X - v2X) + normalY*(v1Y - v2Y))
91 | + (omega1 < 0 ? -omega1 : omega1) * r1
92 | + (omega2 < 0 ? -omega2 : omega2) * r2;
93 |
94 | if (approachVelocityBound == 0)
95 | {
96 | alpha = 1.0;
97 | break;
98 | }
99 |
100 |
101 | var dAlpha = (distance - targetDistance) / approachVelocityBound;
102 |
103 | var newAlpha = alpha + dAlpha;
104 |
105 |
106 | if (newAlpha < 0.0 || 1.0 < newAlpha)
107 | {
108 | alpha = 1.0;
109 | break;
110 | }
111 |
112 |
113 | if (newAlpha < (1.0 + 100.0 * Number.MIN_VALUE) * alpha)
114 | {
115 | break;
116 | }
117 |
118 | alpha = newAlpha;
119 |
120 | ++iter;
121 | }
122 |
123 | return alpha;
124 | }
125 | // attributes
126 | // methods
--------------------------------------------------------------------------------
/flash/Box2D/Common/Math/b2Sweep.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common.Math{
20 |
21 |
22 | import Box2D.Common.*;
23 |
24 |
25 | /// This describes the motion of a body/shape for TOI computation.
26 | /// Shapes are defined with respect to the body origin, which may
27 | /// no coincide with the center of mass. However, to support dynamics
28 | /// we must interpolate the center of mass position.
29 | public class b2Sweep
30 | {
31 | /// Get the interpolated transform at a specific time.
32 | /// @param t the normalized time in [0,1].
33 | public function GetXForm(xf:b2XForm, t:Number) : void{
34 |
35 | // center = p + R * localCenter
36 | if (1.0 - t0 > Number.MIN_VALUE)
37 | {
38 | var alpha:Number = (t - t0) / (1.0 - t0);
39 | xf.position.x = (1.0 - alpha) * c0.x + alpha * c.x;
40 | xf.position.y = (1.0 - alpha) * c0.y + alpha * c.y;
41 | var angle:Number = (1.0 - alpha) * a0 + alpha * a;
42 | xf.R.Set(angle);
43 | }
44 | else
45 | {
46 | xf.position.SetV(c);
47 | xf.R.Set(a);
48 | }
49 |
50 | // Shift to origin
51 | //xf->position -= b2Mul(xf->R, localCenter);
52 | var tMat:b2Mat22 = xf.R;
53 | xf.position.x -= (tMat.col1.x * localCenter.x + tMat.col2.x * localCenter.y);
54 | xf.position.y -= (tMat.col1.y * localCenter.x + tMat.col2.y * localCenter.y);
55 |
56 | }
57 |
58 | /// Advance the sweep forward, yielding a new initial state.
59 | /// @param t the new initial time.
60 | public function Advance(t:Number) : void{
61 | if (t0 < t && 1.0 - t0 > Number.MIN_VALUE)
62 | {
63 | var alpha:Number = (t - t0) / (1.0 - t0);
64 | //c0 = (1.0f - alpha) * c0 + alpha * c;
65 | c0.x = (1.0 - alpha) * c0.x + alpha * c.x;
66 | c0.y = (1.0 - alpha) * c0.y + alpha * c.y;
67 | a0 = (1.0 - alpha) * a0 + alpha * a;
68 | t0 = t;
69 | }
70 | }
71 |
72 | public var localCenter:b2Vec2 = new b2Vec2(); ///< local center of mass position
73 | public var c0:b2Vec2 = new b2Vec2; ///< center world positions
74 | public var c:b2Vec2 = new b2Vec2();
75 | public var a0:Number, a:Number; ///< world angles
76 | public var t0:Number; ///< time interval = [t0,1], where t0 is in [0,1]
77 | };
78 |
79 | }
--------------------------------------------------------------------------------
/flash/TestBed/TestCCD.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 |
20 | package TestBed{
21 |
22 |
23 |
24 | import Box2D.Dynamics.*;
25 | import Box2D.Collision.*;
26 | import Box2D.Collision.Shapes.*;
27 | import Box2D.Dynamics.Joints.*;
28 | import Box2D.Dynamics.Contacts.*;
29 | import Box2D.Common.*;
30 | import Box2D.Common.Math.*;
31 |
32 |
33 |
34 | public class TestCCD extends Test{
35 |
36 | public function TestCCD(){
37 |
38 | // Set Text field
39 | Main.m_aboutText.text = "Continuous Collision Detection";
40 |
41 | var bd:b2BodyDef;
42 | var body:b2Body;
43 | {
44 | var sd_bottom:b2PolygonDef = new b2PolygonDef();
45 | sd_bottom.SetAsBox( 45.0/m_physScale, 4.5/m_physScale );
46 | sd_bottom.density = 4.0;
47 | sd_bottom.restitution = 1.4;
48 |
49 | var sd_left:b2PolygonDef = new b2PolygonDef();
50 | sd_left.SetAsOrientedBox(4.5/m_physScale, 81.0/m_physScale, new b2Vec2(-43.5/m_physScale, -70.5/m_physScale), -0.2);
51 | sd_left.density = 4.0;
52 | sd_left.restitution = 1.4;
53 |
54 | var sd_right:b2PolygonDef = new b2PolygonDef();
55 | sd_right.SetAsOrientedBox(4.5/m_physScale, 81.0/m_physScale, new b2Vec2(43.5/m_physScale, -70.5/m_physScale), 0.2);
56 | sd_right.density = 4.0;
57 | sd_right.restitution = 1.4;
58 |
59 | bd = new b2BodyDef();
60 | bd.isBullet = true;
61 | bd.position.Set( 150.0/m_physScale, 100.0/m_physScale );
62 | body = m_world.CreateBody(bd);
63 | body.CreateShape(sd_bottom);
64 | body.CreateShape(sd_left);
65 | body.CreateShape(sd_right);
66 | body.SetMassFromShapes();
67 | }
68 |
69 | // add some small circles for effect
70 | for (var i:int = 0; i < 5; i++){
71 | var cd:b2CircleDef = new b2CircleDef();
72 | cd.radius = (Math.random() * 10 + 5) / m_physScale;
73 | cd.friction = 0.3;
74 | cd.density = 1.0;
75 | cd.restitution = 1.1;
76 | bd = new b2BodyDef();
77 | bd.isBullet = true;
78 | bd.position.Set( (Math.random()*300 + 250)/m_physScale, (Math.random()*320 + 20)/m_physScale );
79 | body = m_world.CreateBody(bd);
80 | body.CreateShape(cd);
81 | body.SetMassFromShapes();
82 | }
83 |
84 | }
85 |
86 |
87 | //======================
88 | // Member Data
89 | //======================
90 |
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/Shapes/b2PolygonDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision.Shapes{
20 |
21 |
22 |
23 | import Box2D.Common.Math.*;
24 | import Box2D.Common.*;
25 | import Box2D.Collision.Shapes.*;
26 |
27 |
28 |
29 | public class b2PolygonDef extends b2ShapeDef
30 | {
31 | public function b2PolygonDef()
32 | {
33 | type = b2Shape.e_polygonShape;
34 | vertexCount = 0;
35 |
36 | for (var i:int = 0; i < b2Settings.b2_maxPolygonVertices; i++){
37 | vertices[i] = new b2Vec2();
38 | }
39 | }
40 |
41 | /// Build vertices to represent an axis-aligned box.
42 | /// @param hx the half-width.
43 | /// @param hy the half-height.
44 | public function SetAsBox(hx:Number, hy:Number) : void{
45 | vertexCount = 4;
46 | vertices[0].Set(-hx, -hy);
47 | vertices[1].Set( hx, -hy);
48 | vertices[2].Set( hx, hy);
49 | vertices[3].Set(-hx, hy);
50 | }
51 |
52 | /// Build vertices to represent an oriented box.
53 | /// @param hx the half-width.
54 | /// @param hy the half-height.
55 | /// @param center the center of the box in local coordinates.
56 | /// @param angle the rotation of the box in local coordinates.
57 | static private var s_mat:b2Mat22 = new b2Mat22();
58 | public function SetAsOrientedBox(hx:Number, hy:Number, center:b2Vec2=null, angle:Number=0.0) : void{
59 | //SetAsBox(hx, hy);
60 | {
61 | vertexCount = 4;
62 | vertices[0].Set(-hx, -hy);
63 | vertices[1].Set( hx, -hy);
64 | vertices[2].Set( hx, hy);
65 | vertices[3].Set(-hx, hy);
66 | }
67 |
68 | if (center){
69 | //b2XForm xf;
70 | //xf.position = center;
71 | var xfPosition:b2Vec2 = center;
72 | //xf.R.Set(angle);
73 | var xfR:b2Mat22 = s_mat;
74 | xfR.Set(angle);
75 |
76 | for (var i:int = 0; i < vertexCount; ++i)
77 | {
78 | //vertices[i] = b2Mul(xf, vertices[i]);
79 | //var a:b2Vec2 = b2MulMV(T.R, v);
80 | center = vertices[i];
81 | hx = xfPosition.x + (xfR.col1.x * center.x + xfR.col2.x * center.y)
82 | center.y = xfPosition.y + (xfR.col1.y * center.x + xfR.col2.y * center.y)
83 | center.x = hx;
84 | }
85 | }
86 | }
87 |
88 | /// The polygon vertices in local coordinates.
89 | public var vertices:Array = new Array(b2Settings.b2_maxPolygonVertices);
90 | /// The number of polygon vertices.
91 | public var vertexCount:int;
92 | };
93 |
94 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2RevoluteJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 |
27 | /// Revolute joint definition. This requires defining an
28 | /// anchor point where the bodies are joined. The definition
29 | /// uses local anchor points so that the initial configuration
30 | /// can violate the constraint slightly. You also need to
31 | /// specify the initial relative angle for joint limits. This
32 | /// helps when saving and loading a game.
33 | /// The local anchor points are measured from the body's origin
34 | /// rather than the center of mass because:
35 | /// 1. you might not know where the center of mass will be.
36 | /// 2. if you add/remove shapes from a body and recompute the mass,
37 | /// the joints will be broken.
38 |
39 | public class b2RevoluteJointDef extends b2JointDef
40 | {
41 | public function b2RevoluteJointDef()
42 | {
43 | type = b2Joint.e_revoluteJoint;
44 | localAnchor1.Set(0.0, 0.0);
45 | localAnchor2.Set(0.0, 0.0);
46 | referenceAngle = 0.0;
47 | lowerAngle = 0.0;
48 | upperAngle = 0.0;
49 | maxMotorTorque = 0.0;
50 | motorSpeed = 0.0;
51 | enableLimit = false;
52 | enableMotor = false;
53 | }
54 |
55 | /// Initialize the bodies, anchors, and reference angle using the world
56 | /// anchor.
57 | public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2) : void{
58 | body1 = b1;
59 | body2 = b2;
60 | localAnchor1 = body1.GetLocalPoint(anchor);
61 | localAnchor2 = body2.GetLocalPoint(anchor);
62 | referenceAngle = body2.GetAngle() - body1.GetAngle();
63 | }
64 |
65 | /// The local anchor point relative to body1's origin.
66 | public var localAnchor1:b2Vec2 = new b2Vec2();
67 |
68 | /// The local anchor point relative to body2's origin.
69 | public var localAnchor2:b2Vec2 = new b2Vec2();
70 |
71 | /// The body2 angle minus body1 angle in the reference state (radians).
72 | public var referenceAngle:Number;
73 |
74 | /// A flag to enable joint limits.
75 | public var enableLimit:Boolean;
76 |
77 | /// The lower angle for the joint limit (radians).
78 | public var lowerAngle:Number;
79 |
80 | /// The upper angle for the joint limit (radians).
81 | public var upperAngle:Number;
82 |
83 | /// A flag to enable the joint motor.
84 | public var enableMotor:Boolean;
85 |
86 | /// The desired motor speed. Usually in radians per second.
87 | public var motorSpeed:Number;
88 |
89 | /// The maximum motor torque used to achieve the desired motor speed.
90 | /// Usually in N-m.
91 | public var maxMotorTorque:Number;
92 |
93 | };
94 |
95 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Joints/b2Joint.js:
--------------------------------------------------------------------------------
1 | var b2Joint = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Joint.prototype.__constructor = function (def) {
6 | this.m_type = def.type;
7 | this.m_prev = null;
8 | this.m_next = null;
9 | this.m_body1 = def.body1;
10 | this.m_body2 = def.body2;
11 | this.m_collideConnected = def.collideConnected;
12 | this.m_islandFlag = false;
13 | this.m_userData = def.userData;
14 | }
15 | b2Joint.prototype.__varz = function(){
16 | this.m_node1 = new b2JointEdge();
17 | this.m_node2 = new b2JointEdge();
18 | }
19 | // static attributes
20 | b2Joint.e_unknownJoint = 0;
21 | b2Joint.e_revoluteJoint = 1;
22 | b2Joint.e_prismaticJoint = 2;
23 | b2Joint.e_distanceJoint = 3;
24 | b2Joint.e_pulleyJoint = 4;
25 | b2Joint.e_mouseJoint = 5;
26 | b2Joint.e_gearJoint = 6;
27 | b2Joint.e_inactiveLimit = 0;
28 | b2Joint.e_atLowerLimit = 1;
29 | b2Joint.e_atUpperLimit = 2;
30 | b2Joint.e_equalLimits = 3;
31 | // static methods
32 | b2Joint.Create = function (def, allocator) {
33 | var joint = null;
34 |
35 | switch (def.type)
36 | {
37 | case b2Joint.e_distanceJoint:
38 | {
39 |
40 | joint = new b2DistanceJoint(def);
41 | }
42 | break;
43 |
44 | case b2Joint.e_mouseJoint:
45 | {
46 |
47 | joint = new b2MouseJoint(def);
48 | }
49 | break;
50 |
51 | case b2Joint.e_prismaticJoint:
52 | {
53 |
54 | joint = new b2PrismaticJoint(def);
55 | }
56 | break;
57 |
58 | case b2Joint.e_revoluteJoint:
59 | {
60 |
61 | joint = new b2RevoluteJoint(def);
62 | }
63 | break;
64 |
65 | case b2Joint.e_pulleyJoint:
66 | {
67 |
68 | joint = new b2PulleyJoint(def);
69 | }
70 | break;
71 |
72 | case b2Joint.e_gearJoint:
73 | {
74 |
75 | joint = new b2GearJoint(def);
76 | }
77 | break;
78 |
79 | default:
80 |
81 | break;
82 | }
83 |
84 | return joint;
85 | }
86 | b2Joint.Destroy = function (joint, allocator) {
87 |
88 | }
89 | // attributes
90 | b2Joint.prototype.m_type = 0;
91 | b2Joint.prototype.m_prev = null;
92 | b2Joint.prototype.m_next = null;
93 | b2Joint.prototype.m_node1 = new b2JointEdge();
94 | b2Joint.prototype.m_node2 = new b2JointEdge();
95 | b2Joint.prototype.m_body1 = null;
96 | b2Joint.prototype.m_body2 = null;
97 | b2Joint.prototype.m_inv_dt = null;
98 | b2Joint.prototype.m_islandFlag = null;
99 | b2Joint.prototype.m_collideConnected = null;
100 | b2Joint.prototype.m_userData = null;
101 | // methods
102 | b2Joint.prototype.GetType = function () {
103 | return this.m_type;
104 | }
105 | b2Joint.prototype.GetAnchor1 = function () {return null}
106 | b2Joint.prototype.GetAnchor2 = function () {return null}
107 | b2Joint.prototype.GetReactionForce = function () {return null}
108 | b2Joint.prototype.GetReactionTorque = function () {return 0.0}
109 | b2Joint.prototype.GetBody1 = function () {
110 | return this.m_body1;
111 | }
112 | b2Joint.prototype.GetBody2 = function () {
113 | return this.m_body2;
114 | }
115 | b2Joint.prototype.GetNext = function () {
116 | return this.m_next;
117 | }
118 | b2Joint.prototype.GetUserData = function () {
119 | return this.m_userData;
120 | }
121 | b2Joint.prototype.SetUserData = function (data) {
122 | this.m_userData = data;
123 | }
124 | b2Joint.prototype.InitVelocityConstraints = function (step) {}
125 | b2Joint.prototype.SolveVelocityConstraints = function (step) {}
126 | b2Joint.prototype.InitPositionConstraints = function () {}
127 | b2Joint.prototype.SolvePositionConstraints = function () {return false}
--------------------------------------------------------------------------------
/flash/TestBed/TestStack.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 |
20 | package TestBed{
21 |
22 |
23 |
24 | import Box2D.Dynamics.*;
25 | import Box2D.Collision.*;
26 | import Box2D.Collision.Shapes.*;
27 | import Box2D.Dynamics.Joints.*;
28 | import Box2D.Dynamics.Contacts.*;
29 | import Box2D.Common.*;
30 | import Box2D.Common.Math.*;
31 |
32 |
33 |
34 | public class TestStack extends Test{
35 |
36 | public function TestStack(){
37 |
38 | // Set Text field
39 | Main.m_aboutText.text = "Stacked Boxes";
40 |
41 | // Add bodies
42 | var sd:b2PolygonDef = new b2PolygonDef();
43 | var bd:b2BodyDef = new b2BodyDef();
44 | //bd.isBullet = true;
45 | var b:b2Body;
46 | sd.density = 1.0;
47 | sd.friction = 0.5;
48 | sd.restitution = 0.1;
49 |
50 | var i:int;
51 | // Create 3 stacks
52 | for (i = 0; i < 10; i++){
53 | sd.SetAsBox((10) / m_physScale, (10) / m_physScale);
54 | bd.position.Set((640/2+100+Math.random()*0.02 - 0.01) / m_physScale, (360-5-i*25) / m_physScale);
55 | b = m_world.CreateBody(bd);
56 | b.CreateShape(sd);
57 | b.SetMassFromShapes();
58 | }
59 | for (i = 0; i < 10; i++){
60 | sd.SetAsBox((10) / m_physScale, (10) / m_physScale);
61 | bd.position.Set((640/2-0+Math.random()*0.02 - 0.01) / m_physScale, (360-5-i*25) / m_physScale);
62 | b = m_world.CreateBody(bd);
63 | b.CreateShape(sd);
64 | b.SetMassFromShapes();
65 | }
66 | for (i = 0; i < 10; i++){
67 | sd.SetAsBox((10) / m_physScale, (10) / m_physScale);
68 | bd.position.Set((640/2+200+Math.random()*0.02 - 0.01) / m_physScale, (360-5-i*25) / m_physScale);
69 | b = m_world.CreateBody(bd);
70 | b.CreateShape(sd);
71 | b.SetMassFromShapes();
72 | }
73 |
74 |
75 | // Create ramp
76 | sd.vertexCount = 3;
77 | sd.density = 0;
78 | sd.vertices[0] = new b2Vec2(0,0);
79 | sd.vertices[1] = new b2Vec2(0,-100/m_physScale);
80 | sd.vertices[2] = new b2Vec2(200/m_physScale,0);
81 | bd.position.Set(0, 360 / m_physScale);
82 | b = m_world.CreateBody(bd);
83 | b.CreateShape(sd);
84 | b.SetMassFromShapes();
85 |
86 | // Create ball
87 | var cd:b2CircleDef = new b2CircleDef();
88 | cd.radius = 40/m_physScale;
89 | cd.density = 2;
90 | cd.restitution = 0.2;
91 | cd.friction = 0.5;
92 | bd.position.Set(50/m_physScale, 100 / m_physScale);
93 | b = m_world.CreateBody(bd);
94 | b.CreateShape(cd);
95 | b.SetMassFromShapes();
96 |
97 |
98 | }
99 |
100 |
101 | //======================
102 | // Member Data
103 | //======================
104 | }
105 |
106 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/b2BodyDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics{
20 |
21 |
22 | import Box2D.Dynamics.*;
23 | import Box2D.Dynamics.Joints.*;
24 | import Box2D.Dynamics.Contacts.*;
25 | import Box2D.Collision.*;
26 | import Box2D.Collision.Shapes.*;
27 | import Box2D.Common.b2Settings;
28 | import Box2D.Common.Math.*;
29 |
30 |
31 | /// A body definition holds all the data needed to construct a rigid body.
32 | /// You can safely re-use body definitions.
33 | public class b2BodyDef
34 | {
35 | /// This constructor sets the body definition default values.
36 | public function b2BodyDef()
37 | {
38 | massData.center.SetZero();
39 | massData.mass = 0.0;
40 | massData.I = 0.0;
41 | userData = null;
42 | position.Set(0.0, 0.0);
43 | angle = 0.0;
44 | linearDamping = 0.0;
45 | angularDamping = 0.0;
46 | allowSleep = true;
47 | isSleeping = false;
48 | fixedRotation = false;
49 | isBullet = false;
50 | }
51 |
52 | /// You can use this to initialized the mass properties of the body.
53 | /// If you prefer, you can set the mass properties after the shapes
54 | /// have been added using b2Body::SetMassFromShapes.
55 | public var massData:b2MassData = new b2MassData();
56 |
57 | /// Use this to store application specific body data.
58 | public var userData:*;
59 |
60 | /// The world position of the body. Avoid creating bodies at the origin
61 | /// since this can lead to many overlapping shapes.
62 | public var position:b2Vec2 = new b2Vec2();
63 |
64 | /// The world angle of the body in radians.
65 | public var angle:Number;
66 |
67 | /// Linear damping is use to reduce the linear velocity. The damping parameter
68 | /// can be larger than 1.0f but the damping effect becomes sensitive to the
69 | /// time step when the damping parameter is large.
70 | public var linearDamping:Number;
71 |
72 | /// Angular damping is use to reduce the angular velocity. The damping parameter
73 | /// can be larger than 1.0f but the damping effect becomes sensitive to the
74 | /// time step when the damping parameter is large.
75 | public var angularDamping:Number;
76 |
77 | /// Set this flag to false if this body should never fall asleep. Note that
78 | /// this increases CPU usage.
79 | public var allowSleep:Boolean;
80 |
81 | /// Is this body initially sleeping?
82 | public var isSleeping:Boolean;
83 |
84 | /// Should this body be prevented from rotating? Useful for characters.
85 | public var fixedRotation:Boolean;
86 |
87 | /// Is this a fast moving body that should be prevented from tunneling through
88 | /// other moving bodies? Note that all bodies are prevented from tunneling through
89 | /// static bodies.
90 | /// @warning You should use this flag sparingly since it increases processing time.
91 | public var isBullet:Boolean;
92 | };
93 |
94 |
95 | }
--------------------------------------------------------------------------------
/flash/Box2D/Collision/b2Segment.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Collision{
20 |
21 | import Box2D.Collision.*;
22 | import Box2D.Common.Math.*;
23 | import Box2D.Common.*;
24 |
25 | // A manifold for two touching convex shapes.
26 | public class b2Segment
27 | {
28 | /// Ray cast against this segment with another segment.
29 | // Collision Detection in Interactive 3D Environments by Gino van den Bergen
30 | // From Section 3.4.1
31 | // x = mu1 * p1 + mu2 * p2
32 | // mu1 + mu2 = 1 && mu1 >= 0 && mu2 >= 0
33 | // mu1 = 1 - mu2;
34 | // x = (1 - mu2) * p1 + mu2 * p2
35 | // = p1 + mu2 * (p2 - p1)
36 | // x = s + a * r (s := start, r := end - start)
37 | // s + a * r = p1 + mu2 * d (d := p2 - p1)
38 | // -a * r + mu2 * d = b (b := s - p1)
39 | // [-r d] * [a; mu2] = b
40 | // Cramer's rule:
41 | // denom = det[-r d]
42 | // a = det[b d] / denom
43 | // mu2 = det[-r b] / denom
44 | public function TestSegment(lambda:Array, // float pointer
45 | normal:b2Vec2, // pointer
46 | segment:b2Segment,
47 | maxLambda:Number) : Boolean{
48 | //b2Vec2 s = segment.p1;
49 | var s:b2Vec2 = segment.p1;
50 | //b2Vec2 r = segment.p2 - s;
51 | var rX:Number = segment.p2.x - s.x;
52 | var rY:Number = segment.p2.y - s.y;
53 | //b2Vec2 d = p2 - p1;
54 | var dX:Number = p2.x - p1.x;
55 | var dY:Number = p2.y - p1.y;
56 | //b2Vec2 n = b2Cross(d, 1.0f);
57 | var nX:Number = dY;
58 | var nY:Number = -dX;
59 |
60 | var k_slop:Number = 100.0 * Number.MIN_VALUE;
61 | //var denom:Number = -b2Dot(r, n);
62 | var denom:Number = -(rX*nX + rY*nY);
63 |
64 | // Cull back facing collision and ignore parallel segments.
65 | if (denom > k_slop)
66 | {
67 | // Does the segment intersect the infinite line associated with this segment?
68 | //b2Vec2 b = s - p1;
69 | var bX:Number = s.x - p1.x;
70 | var bY:Number = s.y - p1.y;
71 | //var a:Number = b2Dot(b, n);
72 | var a:Number = (bX*nX + bY*nY);
73 |
74 | if (0.0 <= a && a <= maxLambda * denom)
75 | {
76 | var mu2:Number = -rX * bY + rY * bX;
77 |
78 | // Does the segment intersect this segment?
79 | if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0 + k_slop))
80 | {
81 | a /= denom;
82 | //n.Normalize();
83 | var nLen:Number = Math.sqrt(nX*nX + nY*nY);
84 | nX /= nLen;
85 | nY /= nLen;
86 | //*lambda = a;
87 | lambda[0] = a;
88 | //*normal = n;
89 | normal.Set(nX, nY);
90 | return true;
91 | }
92 | }
93 | }
94 |
95 | return false;
96 | }
97 |
98 | public var p1:b2Vec2 = new b2Vec2(); ///< the starting point
99 | public var p2:b2Vec2 = new b2Vec2(); ///< the ending point
100 | };
101 |
102 |
103 | }
--------------------------------------------------------------------------------
/flash/Box2D/Common/Math/b2Vec2.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common.Math{
20 |
21 |
22 | import Box2D.Common.*;
23 |
24 |
25 | /// A 2D column vector.
26 |
27 | public class b2Vec2
28 | {
29 | public function b2Vec2(x_:Number=0, y_:Number=0) : void {x=x_; y=y_;};
30 |
31 | public function SetZero() : void { x = 0.0; y = 0.0; }
32 | public function Set(x_:Number=0, y_:Number=0) : void {x=x_; y=y_;};
33 | public function SetV(v:b2Vec2) : void {x=v.x; y=v.y;};
34 |
35 | public function Negative():b2Vec2 { return new b2Vec2(-x, -y); }
36 |
37 | static public function Make(x_:Number, y_:Number):b2Vec2
38 | {
39 | return new b2Vec2(x_, y_);
40 | }
41 |
42 | public function Copy():b2Vec2{
43 | return new b2Vec2(x,y);
44 | }
45 |
46 | public function Add(v:b2Vec2) : void
47 | {
48 | x += v.x; y += v.y;
49 | }
50 |
51 | public function Subtract(v:b2Vec2) : void
52 | {
53 | x -= v.x; y -= v.y;
54 | }
55 |
56 | public function Multiply(a:Number) : void
57 | {
58 | x *= a; y *= a;
59 | }
60 |
61 | public function MulM(A:b2Mat22) : void
62 | {
63 | var tX:Number = x;
64 | x = A.col1.x * tX + A.col2.x * y;
65 | y = A.col1.y * tX + A.col2.y * y;
66 | }
67 |
68 | public function MulTM(A:b2Mat22) : void
69 | {
70 | var tX:Number = b2Math.b2Dot(this, A.col1);
71 | y = b2Math.b2Dot(this, A.col2);
72 | x = tX;
73 | }
74 |
75 | public function CrossVF(s:Number) : void
76 | {
77 | var tX:Number = x;
78 | x = s * y;
79 | y = -s * tX;
80 | }
81 |
82 | public function CrossFV(s:Number) : void
83 | {
84 | var tX:Number = x;
85 | x = -s * y;
86 | y = s * tX;
87 | }
88 |
89 | public function MinV(b:b2Vec2) : void
90 | {
91 | x = x < b.x ? x : b.x;
92 | y = y < b.y ? y : b.y;
93 | }
94 |
95 | public function MaxV(b:b2Vec2) : void
96 | {
97 | x = x > b.x ? x : b.x;
98 | y = y > b.y ? y : b.y;
99 | }
100 |
101 | public function Abs() : void
102 | {
103 | if (x < 0) x = -x;
104 | if (y < 0) y = -y;
105 | }
106 |
107 | public function Length():Number
108 | {
109 | return Math.sqrt(x * x + y * y);
110 | }
111 |
112 | public function LengthSquared():Number
113 | {
114 | return (x * x + y * y);
115 | }
116 |
117 | public function Normalize():Number
118 | {
119 | var length:Number = Math.sqrt(x * x + y * y);
120 | if (length < Number.MIN_VALUE)
121 | {
122 | return 0.0;
123 | }
124 | var invLength:Number = 1.0 / length;
125 | x *= invLength;
126 | y *= invLength;
127 |
128 | return length;
129 | }
130 |
131 | public function IsValid():Boolean
132 | {
133 | return b2Math.b2IsValid(x) && b2Math.b2IsValid(y);
134 | }
135 |
136 | public var x:Number;
137 | public var y:Number;
138 | };
139 |
140 | }
--------------------------------------------------------------------------------
/flash/General/FpsCounter.as:
--------------------------------------------------------------------------------
1 | //===========================================================
2 | //=========================================================//
3 | // -=ANTHEM=-
4 | // file: .as
5 | //
6 | // copyright: Matthew Bush 2007
7 | //
8 | // notes:
9 | //
10 | //=========================================================//
11 | //===========================================================
12 |
13 |
14 |
15 | //===========================================================
16 | // FPS COUNTER CLASS
17 | //===========================================================
18 | package General{
19 |
20 | import flash.display.Sprite;
21 | import flash.text.*;
22 | import flash.utils.getTimer;
23 | import flash.events.*;
24 | import flash.system.System;
25 |
26 | public class FpsCounter extends Sprite{
27 |
28 | //======================
29 | // constructor
30 | //======================
31 | public function FpsCounter(){
32 |
33 | // create text field
34 | textBox = new TextField();
35 | textBox.text = "...";
36 | textBox.textColor = 0xaa1144;
37 | textBox.selectable = false;
38 |
39 | textBox2 = new TextField();
40 | textBox2.text = "...";
41 | textBox2.width = 150;
42 | textBox2.textColor = 0xaa1144;
43 | textBox2.selectable = false;
44 | textBox2.y = 15;
45 |
46 | textBox3 = new TextField();
47 | textBox3.text = "...";
48 | textBox3.textColor = 0xaa1144;
49 | textBox3.selectable = false;
50 | textBox3.y = 30;
51 |
52 | // set initial lastTime
53 | oldT = getTimer();
54 |
55 | addChild(textBox);
56 | addChild(textBox2);
57 | addChild(textBox3);
58 | }
59 |
60 | //======================
61 | // update function
62 | //======================
63 | public function update():void{
64 | var newT:uint = getTimer();
65 | var f1:uint = newT-oldT;
66 | mfpsCount += f1;
67 | if (avgCount < 1){
68 | textBox.text = String(Math.round(1000/(mfpsCount/30))+" fps average");
69 | avgCount = 30;
70 | mfpsCount = 0;
71 | }
72 | avgCount--;
73 | oldT = getTimer();
74 |
75 | textBox3.text = Math.round(System.totalMemory/(1024*1024)) + " MB used"
76 |
77 | }
78 |
79 |
80 | public function updatePhys(oldT2:uint):void{
81 | var newT:uint = getTimer();
82 | var f1:uint = newT-oldT2;
83 | mfpsCount2 += f1;
84 | if (avgCount2 < 1){
85 | textBox2.text = String("Physics step: "+Math.round(mfpsCount2/30)+" ms (" +Math.round(1000/(mfpsCount2/30))+" fps)");
86 | avgCount2 = 30;
87 | mfpsCount2 = 0;
88 | }
89 | avgCount2--;
90 | }
91 |
92 |
93 | //======================
94 | // updateend function
95 | //======================
96 | public function updateEnd():void{
97 | // wrong
98 | /*var newT:uint = getTimer();
99 | var f1:uint = newT-oldT;
100 | mfpsCount2 += f1;
101 | if (avgCount2 < 1){
102 | textBox2.text = String(Math.round(1000/(mfpsCount2/30))+" fps uncapped");
103 | avgCount2 = 30;
104 | mfpsCount2 = 0;
105 | }
106 | avgCount2--;*/
107 |
108 | }
109 |
110 |
111 | //======================
112 | // private variables
113 | //======================
114 | private var textBox:TextField;
115 | private var textBox2:TextField;
116 | private var textBox3:TextField;
117 | private var mfpsCount:int = 0;
118 | private var mfpsCount2:int = 0;
119 | private var avgCount:int = 30;
120 | private var avgCount2:int = 30;
121 | private var oldT:uint;
122 | }
123 | }
124 |
125 |
126 |
127 |
128 | // End of file
129 | //===========================================================
130 | //===========================================================
131 |
132 |
133 |
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2CircleContact.js:
--------------------------------------------------------------------------------
1 | var b2CircleContact = function() {
2 | b2Contact.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2CircleContact.prototype, b2Contact.prototype)
7 | b2CircleContact.prototype._super = function(){ b2Contact.prototype.__constructor.apply(this, arguments) }
8 | b2CircleContact.prototype.__constructor = function (shape1, shape2) {
9 | this._super(shape1, shape2);
10 |
11 | this.m_manifold = this.m_manifolds[0];
12 |
13 |
14 |
15 | this.m_manifold.pointCount = 0;
16 | var point = this.m_manifold.points[0];
17 | point.normalImpulse = 0.0;
18 | point.tangentImpulse = 0.0;
19 | }
20 | b2CircleContact.prototype.__varz = function(){
21 | this.m_manifolds = [new b2Manifold()];
22 | this.m0 = new b2Manifold();
23 | }
24 | // static attributes
25 | b2CircleContact.s_evalCP = new b2ContactPoint();
26 | // static methods
27 | b2CircleContact.Create = function (shape1, shape2, allocator) {
28 | return new b2CircleContact(shape1, shape2);
29 | }
30 | b2CircleContact.Destroy = function (contact, allocator) {
31 |
32 | }
33 | // attributes
34 | b2CircleContact.prototype.m_manifolds = [new b2Manifold()];
35 | b2CircleContact.prototype.m0 = new b2Manifold();
36 | b2CircleContact.prototype.m_manifold = null;
37 | // methods
38 | b2CircleContact.prototype.Evaluate = function (listener) {
39 | var v1;
40 | var v2;
41 | var mp0;
42 |
43 | var b1 = this.m_shape1.m_body;
44 | var b2 = this.m_shape2.m_body;
45 |
46 |
47 |
48 |
49 | this.m0.Set(this.m_manifold);
50 |
51 | b2Collision.b2CollideCircles(this.m_manifold, this.m_shape1, b1.m_xf, this.m_shape2, b2.m_xf);
52 |
53 | var cp = b2CircleContact.s_evalCP;
54 | cp.shape1 = this.m_shape1;
55 | cp.shape2 = this.m_shape2;
56 | cp.friction = this.m_friction;
57 | cp.restitution = this.m_restitution;
58 |
59 | if (this.m_manifold.pointCount > 0)
60 | {
61 | this.m_manifoldCount = 1;
62 | var mp = this.m_manifold.points[ 0 ];
63 |
64 | if (this.m0.pointCount == 0)
65 | {
66 | mp.normalImpulse = 0.0;
67 | mp.tangentImpulse = 0.0;
68 |
69 | if (listener)
70 | {
71 | cp.position = b1.GetWorldPoint(mp.localPoint1);
72 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
73 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
74 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
75 | cp.normal.SetV(this.m_manifold.normal);
76 | cp.separation = mp.separation;
77 | cp.id.key = mp.id._key;
78 | listener.Add(cp);
79 | }
80 | } else
81 | {
82 | mp0 = this.m0.points[ 0 ];
83 | mp.normalImpulse = mp0.normalImpulse;
84 | mp.tangentImpulse = mp0.tangentImpulse;
85 |
86 | if (listener)
87 | {
88 | cp.position = b1.GetWorldPoint(mp.localPoint1);
89 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
90 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
91 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
92 | cp.normal.SetV(this.m_manifold.normal);
93 | cp.separation = mp.separation;
94 | cp.id.key = mp.id._key;
95 | listener.Persist(cp);
96 | }
97 | }
98 | }
99 | else
100 | {
101 | this.m_manifoldCount = 0;
102 | if (this.m0.pointCount > 0 && listener)
103 | {
104 | mp0 = this.m0.points[ 0 ];
105 | cp.position = b1.GetWorldPoint(mp0.localPoint1);
106 | v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
107 | v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
108 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
109 | cp.normal.SetV(this.m0.normal);
110 | cp.separation = mp0.separation;
111 | cp.id.key = mp0.id._key;
112 | listener.Remove(cp);
113 | }
114 | }
115 | }
116 | b2CircleContact.prototype.GetManifolds = function () {
117 | return this.m_manifolds;
118 | }
--------------------------------------------------------------------------------
/flash/Box2D/Dynamics/Joints/b2PulleyJointDef.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Dynamics.Joints{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 | import Box2D.Dynamics.*;
24 |
25 |
26 |
27 | /// Pulley joint definition. This requires two ground anchors,
28 | /// two dynamic body anchor points, max lengths for each side,
29 | /// and a pulley ratio.
30 |
31 | public class b2PulleyJointDef extends b2JointDef
32 | {
33 | public function b2PulleyJointDef()
34 | {
35 | type = b2Joint.e_pulleyJoint;
36 | groundAnchor1.Set(-1.0, 1.0);
37 | groundAnchor2.Set(1.0, 1.0);
38 | localAnchor1.Set(-1.0, 0.0);
39 | localAnchor2.Set(1.0, 0.0);
40 | length1 = 0.0;
41 | maxLength1 = 0.0;
42 | length2 = 0.0;
43 | maxLength2 = 0.0;
44 | ratio = 1.0;
45 | collideConnected = true;
46 | }
47 |
48 | public function Initialize(b1:b2Body, b2:b2Body,
49 | ga1:b2Vec2, ga2:b2Vec2,
50 | anchor1:b2Vec2, anchor2:b2Vec2,
51 | r:Number) : void
52 | {
53 | body1 = b1;
54 | body2 = b2;
55 | groundAnchor1.SetV( ga1 );
56 | groundAnchor2.SetV( ga2 );
57 | localAnchor1 = body1.GetLocalPoint(anchor1);
58 | localAnchor2 = body2.GetLocalPoint(anchor2);
59 | //b2Vec2 d1 = anchor1 - ga1;
60 | var d1X:Number = anchor1.x - ga1.x;
61 | var d1Y:Number = anchor1.y - ga1.y;
62 | //length1 = d1.Length();
63 | length1 = Math.sqrt(d1X*d1X + d1Y*d1Y);
64 |
65 | //b2Vec2 d2 = anchor2 - ga2;
66 | var d2X:Number = anchor2.x - ga2.x;
67 | var d2Y:Number = anchor2.y - ga2.y;
68 | //length2 = d2.Length();
69 | length2 = Math.sqrt(d2X*d2X + d2Y*d2Y);
70 |
71 | ratio = r;
72 | //b2Settings.b2Assert(ratio > Number.MIN_VALUE);
73 | var C:Number = length1 + ratio * length2;
74 | maxLength1 = C - ratio * b2PulleyJoint.b2_minPulleyLength;
75 | maxLength2 = (C - b2PulleyJoint.b2_minPulleyLength) / ratio;
76 | }
77 |
78 | /// The first ground anchor in world coordinates. This point never moves.
79 | public var groundAnchor1:b2Vec2 = new b2Vec2();
80 |
81 | /// The second ground anchor in world coordinates. This point never moves.
82 | public var groundAnchor2:b2Vec2 = new b2Vec2();
83 |
84 | /// The local anchor point relative to body1's origin.
85 | public var localAnchor1:b2Vec2 = new b2Vec2();
86 |
87 | /// The local anchor point relative to body2's origin.
88 | public var localAnchor2:b2Vec2 = new b2Vec2();
89 |
90 | /// The a reference length for the segment attached to body1.
91 | public var length1:Number;
92 |
93 | /// The maximum length of the segment attached to body1.
94 | public var maxLength1:Number;
95 |
96 | /// The a reference length for the segment attached to body2.
97 | public var length2:Number;
98 |
99 | /// The maximum length of the segment attached to body2.
100 | public var maxLength2:Number;
101 |
102 | /// The pulley ratio, used to simulate a block-and-tackle.
103 | public var ratio:Number;
104 |
105 | };
106 |
107 | }
--------------------------------------------------------------------------------
/flash/Box2D/Common/Math/b2Mat22.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common.Math{
20 |
21 |
22 | import Box2D.Common.*;
23 |
24 |
25 | /// A 2-by-2 matrix. Stored in column-major order.
26 | public class b2Mat22
27 | {
28 | public function b2Mat22(angle:Number=0, c1:b2Vec2=null, c2:b2Vec2=null)
29 | {
30 | if (c1!=null && c2!=null){
31 | col1.SetV(c1);
32 | col2.SetV(c2);
33 | }
34 | else{
35 | var c:Number = Math.cos(angle);
36 | var s:Number = Math.sin(angle);
37 | col1.x = c; col2.x = -s;
38 | col1.y = s; col2.y = c;
39 | }
40 | }
41 |
42 | public function Set(angle:Number) : void
43 | {
44 | var c:Number = Math.cos(angle);
45 | var s:Number = Math.sin(angle);
46 | col1.x = c; col2.x = -s;
47 | col1.y = s; col2.y = c;
48 | }
49 |
50 | public function SetVV(c1:b2Vec2, c2:b2Vec2) : void
51 | {
52 | col1.SetV(c1);
53 | col2.SetV(c2);
54 | }
55 |
56 | public function Copy():b2Mat22{
57 | return new b2Mat22(0, col1, col2);
58 | }
59 |
60 | public function SetM(m:b2Mat22) : void
61 | {
62 | col1.SetV(m.col1);
63 | col2.SetV(m.col2);
64 | }
65 |
66 | public function AddM(m:b2Mat22) : void
67 | {
68 | col1.x += m.col1.x;
69 | col1.y += m.col1.y;
70 | col2.x += m.col2.x;
71 | col2.y += m.col2.y;
72 | }
73 |
74 | public function SetIdentity() : void
75 | {
76 | col1.x = 1.0; col2.x = 0.0;
77 | col1.y = 0.0; col2.y = 1.0;
78 | }
79 |
80 | public function SetZero() : void
81 | {
82 | col1.x = 0.0; col2.x = 0.0;
83 | col1.y = 0.0; col2.y = 0.0;
84 | }
85 |
86 | public function GetAngle() :Number
87 | {
88 | return Math.atan2(col1.y, col1.x);
89 | }
90 |
91 | public function Invert(out:b2Mat22):b2Mat22
92 | {
93 | var a:Number = col1.x;
94 | var b:Number = col2.x;
95 | var c:Number = col1.y;
96 | var d:Number = col2.y;
97 | //var B:b2Mat22 = new b2Mat22();
98 | var det:Number = a * d - b * c;
99 | //b2Settings.b2Assert(det != 0.0);
100 | det = 1.0 / det;
101 | out.col1.x = det * d; out.col2.x = -det * b;
102 | out.col1.y = -det * c; out.col2.y = det * a;
103 | return out;
104 | }
105 |
106 | // Solve A * x = b
107 | public function Solve(out:b2Vec2, bX:Number, bY:Number):b2Vec2
108 | {
109 | //float32 a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y;
110 | var a11:Number = col1.x;
111 | var a12:Number = col2.x;
112 | var a21:Number = col1.y;
113 | var a22:Number = col2.y;
114 | //float32 det = a11 * a22 - a12 * a21;
115 | var det:Number = a11 * a22 - a12 * a21;
116 | //b2Settings.b2Assert(det != 0.0);
117 | det = 1.0 / det;
118 | out.x = det * (a22 * bX - a12 * bY);
119 | out.y = det * (a11 * bY - a21 * bX);
120 |
121 | return out;
122 | }
123 |
124 | public function Abs() : void
125 | {
126 | col1.Abs();
127 | col2.Abs();
128 | }
129 |
130 | public var col1:b2Vec2 = new b2Vec2();
131 | public var col2:b2Vec2 = new b2Vec2();
132 | };
133 |
134 | }
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | jQuery(function($){
2 |
3 | var canvas = document.getElementById('canvas');
4 | var ctx = canvas.getContext('2d');
5 | var c_width = 55.0;
6 | var ppm = canvas.width/c_width;
7 | var c_height = canvas.height/ppm;
8 | ctx.setTransform(ppm, 0, 0, -ppm, 0, canvas.height);
9 |
10 | var worldAABB = new b2AABB();
11 | worldAABB.lowerBound.Set(-10000.0, -10000.0);
12 | worldAABB.upperBound.Set(10000.0, 10000.0);
13 | var gravity = new b2Vec2(0.0, -9.8);
14 | var world = new b2World(worldAABB, gravity, true);
15 | window.world = world;
16 |
17 | var groundBodyDef = new b2BodyDef();
18 | groundBodyDef.position.Set(c_width/2.0, 3.0);
19 | var groundBody = world.CreateBody(groundBodyDef);
20 | var groundShapeDef = new b2PolygonDef();
21 | groundShapeDef.restitution = 0.0;
22 | groundShapeDef.friction = 0.5;
23 | groundShapeDef.density = 1.0;
24 | groundBody.w = c_width*1.0
25 | groundBody.h = 5.0
26 | groundShapeDef.SetAsBox(groundBody.w, groundBody.h);
27 | groundBody.CreateShape(groundShapeDef);
28 | groundBody.SynchronizeShapes();
29 |
30 | var bodies = [groundBody];
31 | var explosionParticles = [];
32 |
33 | function spawn(x, y) {
34 | var bodyDef = new b2BodyDef();
35 | bodyDef.position.Set(x, y);
36 | var body = world.CreateBody(bodyDef);
37 | var shapeDef = new b2PolygonDef();
38 | shapeDef.SetAsBox(1.0, 1.0);
39 | body.w = 1.0;
40 | body.h = 1.0;
41 | shapeDef.restitution = 0.0;
42 | shapeDef.density = 2.0;
43 | shapeDef.friction = 0.9;
44 | body.CreateShape(shapeDef);
45 | body.SetMassFromShapes();
46 | bodies.push(body);
47 | }
48 |
49 | function explode(x, y) {
50 | for(var i = 0; i < 10; i++) {
51 | var a = Math.PI/5*i;
52 | var vx = Math.cos(a);
53 | var vy = Math.sin(a);
54 | var bodyDef = new b2BodyDef();
55 | bodyDef.position.Set(x+vx, y+vy);
56 | bodyDef.isBullet = true;
57 | var body = world.CreateBody(bodyDef);
58 | var shapeDef = new b2CircleDef();
59 | shapeDef.radius = 0.1;
60 | //var shapeDef = new b2PolygonDef();
61 | //shapeDef.SetAsBox(1.0, 1.0);
62 | shapeDef.restitution = 0.0;
63 | shapeDef.density = 50.0;
64 | shapeDef.friction = 0.0;
65 | body.CreateShape(shapeDef);
66 | body.SetMassFromShapes();
67 | body.ApplyImpulse({x: vx*500, y:vy*500}, {x:x, y:y});
68 | body.w = 1.0;
69 | body.h = 1.0;
70 | explosionParticles.push(body);
71 | }
72 | }
73 | $(canvas).click(function (e){
74 | var o = $(canvas).offset();
75 | var x = (e.pageX-o.left)/ppm;
76 | var y = (canvas.height-e.pageY+o.top)/ppm;
77 | explode(x, y);
78 | // spawn((e.pageX-o.left)/ppm, (canvas.height-e.pageY+o.top)/ppm);
79 | });
80 | //debugger;
81 |
82 | for(var i = 0; i < 20; i ++) {
83 | spawn(c_width/2, c_height);
84 | }
85 |
86 | var frame = 0;
87 | var fps = new Engine.FPSCounter(ctx);
88 | window.setInterval(function() {
89 | frame ++;
90 | if(frame%20 == 0) {
91 | // spawn(c_width/2, c_height);
92 | }
93 | // debugger;
94 | world.Step(1.0/60.0, 10);
95 | //ctx.clearRect(0.0, 0.0, canvas.width, canvas.height);
96 | ctx.fillStyle = 'white';
97 | ctx.fillRect(0, 0, c_width, c_height);
98 | ctx.fillStyle = 'black';
99 | for(var i = 0; i < bodies.length; i++){
100 | var body = bodies[i];
101 | var t = body.m_xf;
102 | ctx.translate(t.position.x, t.position.y)
103 | ctx.rotate(body.GetAngle());
104 | ctx.fillRect(-body.w, -body.h, body.w*2, body.h*2);
105 | ctx.rotate(-body.GetAngle());
106 | ctx.translate(-t.position.x, -t.position.y)
107 | }
108 | ctx.fillStyle = 'red';
109 | for(var i = 0; i < explosionParticles.length; i++){
110 | var body = explosionParticles[i];
111 | var t = body.m_xf;
112 | ctx.translate(t.position.x, t.position.y)
113 | ctx.beginPath();
114 | ctx.arc(0, 0, 0.1, 0, Math.PI*2, true);
115 | ctx.closePath();
116 | ctx.fill();
117 | ctx.translate(-t.position.x, -t.position.y)
118 | }
119 | ctx.save();
120 | ctx.setTransform(1,0,0,1,0,0);
121 | fps.draw();
122 | ctx.restore();
123 | }, 1000/30);
124 |
125 |
126 |
127 | });
128 | jQuery.noConflict();
129 |
--------------------------------------------------------------------------------
/flash/HelloWorld.as:
--------------------------------------------------------------------------------
1 | package{
2 |
3 | import flash.display.Sprite;
4 | import flash.events.Event;
5 | // Classes used in this example
6 | import Box2D.Dynamics.*;
7 | import Box2D.Collision.*;
8 | import Box2D.Collision.Shapes.*;
9 | import Box2D.Common.Math.*;
10 |
11 | public class HelloWorld extends Sprite{
12 |
13 | public function HelloWorld(){
14 |
15 |
16 |
17 | // Add event for main loop
18 | addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
19 |
20 |
21 |
22 | // Creat world AABB
23 | var worldAABB:b2AABB = new b2AABB();
24 | worldAABB.lowerBound.Set(-100.0, -100.0);
25 | worldAABB.upperBound.Set(100.0, 100.0);
26 |
27 | // Define the gravity vector
28 | var gravity:b2Vec2 = new b2Vec2(0.0, 10.0);
29 |
30 | // Allow bodies to sleep
31 | var doSleep:Boolean = true;
32 |
33 | // Construct a world object
34 | m_world = new b2World(worldAABB, gravity, doSleep);
35 |
36 | // set debug draw
37 | /*var dbgDraw:b2DebugDraw = new b2DebugDraw();
38 | var dbgSprite:Sprite = new Sprite();
39 | addChild(dbgSprite);
40 | dbgDraw.m_sprite = dbgSprite;
41 | dbgDraw.m_drawScale = 30.0;
42 | dbgDraw.m_fillAlpha = 0.0;
43 | dbgDraw.m_lineThickness = 1.0;
44 | dbgDraw.m_drawFlags = 0xFFFFFFFF;
45 | m_world.SetDebugDraw(dbgDraw);*/
46 |
47 |
48 |
49 | // Vars used to create bodies
50 | var body:b2Body;
51 | var bodyDef:b2BodyDef;
52 | var boxDef:b2PolygonDef;
53 | var circleDef:b2CircleDef;
54 |
55 |
56 |
57 | // Add ground body
58 | bodyDef = new b2BodyDef();
59 | //bodyDef.position.Set(15, 19);
60 | bodyDef.position.Set(10, 12);
61 | //bodyDef.angle = 0.1;
62 | boxDef = new b2PolygonDef();
63 | boxDef.SetAsBox(30, 3);
64 | boxDef.friction = 0.3;
65 | boxDef.density = 0; // static bodies require zero density
66 | /*circleDef = new b2CircleDef();
67 | circleDef.radius = 10;
68 | circleDef.restitution = 0.2*/
69 | // Add sprite to body userData
70 | bodyDef.userData = new PhysGround();
71 | //bodyDef.userData = new PhysCircle();
72 | bodyDef.userData.width = 30 * 2 * 30;
73 | bodyDef.userData.height = 30 * 2 * 3;
74 | addChild(bodyDef.userData);
75 | body = m_world.CreateBody(bodyDef);
76 | body.CreateShape(boxDef);
77 | //body.CreateShape(circleDef);
78 | body.SetMassFromShapes();
79 |
80 | // Add some objects
81 | for (var i:int = 1; i < 10; i++){
82 | bodyDef = new b2BodyDef();
83 | bodyDef.position.x = Math.random() * 15 + 5;
84 | bodyDef.position.y = Math.random() * 10;
85 | var rX:Number = Math.random() + 0.5;
86 | var rY:Number = Math.random() + 0.5;
87 | // Box
88 | if (Math.random() < 0.5){
89 | boxDef = new b2PolygonDef();
90 | boxDef.SetAsBox(rX, rY);
91 | boxDef.density = 1.0;
92 | boxDef.friction = 0.5;
93 | boxDef.restitution = 0.2;
94 | bodyDef.userData = new PhysBox();
95 | bodyDef.userData.width = rX * 2 * 30;
96 | bodyDef.userData.height = rY * 2 * 30;
97 | body = m_world.CreateBody(bodyDef);
98 | body.CreateShape(boxDef);
99 | }
100 | // Circle
101 | else {
102 | circleDef = new b2CircleDef();
103 | circleDef.radius = rX;
104 | circleDef.density = 1.0;
105 | circleDef.friction = 0.5;
106 | circleDef.restitution = 0.2
107 | bodyDef.userData = new PhysCircle();
108 | bodyDef.userData.width = rX * 2 * 30;
109 | bodyDef.userData.height = rX * 2 * 30;
110 | body = m_world.CreateBody(bodyDef);
111 | body.CreateShape(circleDef);
112 | }
113 | body.SetMassFromShapes();
114 | addChild(bodyDef.userData);
115 | }
116 |
117 | }
118 |
119 | public function Update(e:Event):void{
120 |
121 | m_world.Step(m_timeStep, m_iterations);
122 |
123 | // Go through body list and update sprite positions/rotations
124 | for (var bb:b2Body = m_world.m_bodyList; bb; bb = bb.m_next){
125 | if (bb.m_userData is Sprite){
126 | bb.m_userData.x = bb.GetPosition().x * 30;
127 | bb.m_userData.y = bb.GetPosition().y * 30;
128 | bb.m_userData.rotation = bb.GetAngle() * (180/Math.PI);
129 | }
130 | }
131 |
132 | }
133 |
134 | public var m_world:b2World;
135 | public var m_iterations:int = 10;
136 | public var m_timeStep:Number = 1.0/30.0;
137 |
138 | }
139 |
140 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2PolygonContact.js:
--------------------------------------------------------------------------------
1 | var b2PolygonContact = function() {
2 | b2Contact.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2PolygonContact.prototype, b2Contact.prototype)
7 | b2PolygonContact.prototype._super = function(){ b2Contact.prototype.__constructor.apply(this, arguments) }
8 | b2PolygonContact.prototype.__constructor = function (shape1, shape2) {
9 | this._super(shape1, shape2);
10 | this.m_manifold = this.m_manifolds[0];
11 |
12 |
13 | this.m_manifold.pointCount = 0;
14 | }
15 | b2PolygonContact.prototype.__varz = function(){
16 | this.m0 = new b2Manifold();
17 | this.m_manifolds = [new b2Manifold()];
18 | }
19 | // static attributes
20 | b2PolygonContact.s_evalCP = new b2ContactPoint();
21 | // static methods
22 | b2PolygonContact.Create = function (shape1, shape2, allocator) {
23 |
24 | return new b2PolygonContact(shape1, shape2);
25 | }
26 | b2PolygonContact.Destroy = function (contact, allocator) {
27 |
28 |
29 | }
30 | // attributes
31 | b2PolygonContact.prototype.m0 = new b2Manifold();
32 | b2PolygonContact.prototype.m_manifolds = [new b2Manifold()];
33 | b2PolygonContact.prototype.m_manifold = null;
34 | // methods
35 | b2PolygonContact.prototype.Evaluate = function (listener) {
36 | var v1;
37 | var v2;
38 | var mp0;
39 |
40 | var b1 = this.m_shape1.m_body;
41 | var b2 = this.m_shape2.m_body;
42 |
43 | var cp;
44 | var i = 0;
45 |
46 |
47 |
48 |
49 | this.m0.Set(this.m_manifold);
50 |
51 | b2Collision.b2CollidePolygons(this.m_manifold, this.m_shape1, b1.m_xf, this.m_shape2, b2.m_xf);
52 | var persisted = [false, false];
53 |
54 | cp = b2PolygonContact.s_evalCP;
55 | cp.shape1 = this.m_shape1;
56 | cp.shape2 = this.m_shape2;
57 | cp.friction = this.m_friction;
58 | cp.restitution = this.m_restitution;
59 |
60 |
61 | if (this.m_manifold.pointCount > 0)
62 | {
63 |
64 |
65 |
66 | for (i = 0; i < this.m_manifold.pointCount; ++i)
67 | {
68 | var mp = this.m_manifold.points[ i ];
69 | mp.normalImpulse = 0.0;
70 | mp.tangentImpulse = 0.0;
71 | var found = false;
72 | var idKey = mp.id._key;
73 |
74 | for (var j = 0; j < this.m0.pointCount; ++j)
75 | {
76 | if (persisted[j] == true)
77 | {
78 | continue;
79 | }
80 |
81 | mp0 = this.m0.points[ j ];
82 |
83 | if (mp0.id._key == idKey)
84 | {
85 | persisted[j] = true;
86 | mp.normalImpulse = mp0.normalImpulse;
87 | mp.tangentImpulse = mp0.tangentImpulse;
88 |
89 |
90 | found = true;
91 |
92 |
93 | if (listener != null)
94 | {
95 | cp.position = b1.GetWorldPoint(mp.localPoint1);
96 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
97 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
98 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
99 | cp.normal.SetV(this.m_manifold.normal);
100 | cp.separation = mp.separation;
101 | cp.id.key = idKey;
102 | listener.Persist(cp);
103 | }
104 | break;
105 | }
106 | }
107 |
108 |
109 | if (found == false && listener != null)
110 | {
111 | cp.position = b1.GetWorldPoint(mp.localPoint1);
112 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
113 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
114 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
115 | cp.normal.SetV(this.m_manifold.normal);
116 | cp.separation = mp.separation;
117 | cp.id.key = idKey;
118 | listener.Add(cp);
119 | }
120 | }
121 |
122 | this.m_manifoldCount = 1;
123 | }
124 | else
125 | {
126 | this.m_manifoldCount = 0;
127 | }
128 |
129 | if (listener == null)
130 | {
131 | return;
132 | }
133 |
134 |
135 | for (i = 0; i < this.m0.pointCount; ++i)
136 | {
137 | if (persisted[i])
138 | {
139 | continue;
140 | }
141 |
142 | mp0 = this.m0.points[ i ];
143 | cp.position = b1.GetWorldPoint(mp0.localPoint1);
144 | v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
145 | v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
146 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
147 | cp.normal.SetV(this.m0.normal);
148 | cp.separation = mp0.separation;
149 | cp.id.key = mp0.id._key;
150 | listener.Remove(cp);
151 | }
152 | }
153 | b2PolygonContact.prototype.GetManifolds = function () {
154 | return this.m_manifolds;
155 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Common/Math/b2Math.js:
--------------------------------------------------------------------------------
1 | var b2Math = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2Math.prototype.__constructor = function(){}
6 | b2Math.prototype.__varz = function(){
7 | }
8 | // static attributes
9 | b2Math.b2Vec2_zero = new b2Vec2(0.0, 0.0);
10 | b2Math.b2Mat22_identity = new b2Mat22(0, new b2Vec2(1.0, 0.0), new b2Vec2(0.0, 1.0));
11 | b2Math.b2XForm_identity = new b2XForm(b2Math.b2Vec2_zero, b2Math.b2Mat22_identity);
12 | // static methods
13 | b2Math.b2IsValid = function (x) {
14 | return isFinite(x);
15 | }
16 | b2Math.b2Dot = function (a, b) {
17 | return a.x * b.x + a.y * b.y;
18 | }
19 | b2Math.b2CrossVV = function (a, b) {
20 | return a.x * b.y - a.y * b.x;
21 | }
22 | b2Math.b2CrossVF = function (a, s) {
23 | var v = new b2Vec2(s * a.y, -s * a.x);
24 | return v;
25 | }
26 | b2Math.b2CrossFV = function (s, a) {
27 | var v = new b2Vec2(-s * a.y, s * a.x);
28 | return v;
29 | }
30 | b2Math.b2MulMV = function (A, v) {
31 |
32 |
33 | var u = new b2Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y);
34 | return u;
35 | }
36 | b2Math.b2MulTMV = function (A, v) {
37 |
38 |
39 | var u = new b2Vec2(b2Math.b2Dot(v, A.col1), b2Math.b2Dot(v, A.col2));
40 | return u;
41 | }
42 | b2Math.b2MulX = function (T, v) {
43 | var a = b2Math.b2MulMV(T.R, v);
44 | a.x += T.position.x;
45 | a.y += T.position.y;
46 |
47 | return a;
48 | }
49 | b2Math.b2MulXT = function (T, v) {
50 | var a = b2Math.SubtractVV(v, T.position);
51 |
52 | var tX = (a.x * T.R.col1.x + a.y * T.R.col1.y );
53 | a.y = (a.x * T.R.col2.x + a.y * T.R.col2.y );
54 | a.x = tX;
55 | return a;
56 | }
57 | b2Math.AddVV = function (a, b) {
58 | var v = new b2Vec2(a.x + b.x, a.y + b.y);
59 | return v;
60 | }
61 | b2Math.SubtractVV = function (a, b) {
62 | var v = new b2Vec2(a.x - b.x, a.y - b.y);
63 | return v;
64 | }
65 | b2Math.b2Distance = function (a, b) {
66 | var cX = a.x-b.x;
67 | var cY = a.y-b.y;
68 | return Math.sqrt(cX*cX + cY*cY);
69 | }
70 | b2Math.b2DistanceSquared = function (a, b) {
71 | var cX = a.x-b.x;
72 | var cY = a.y-b.y;
73 | return (cX*cX + cY*cY);
74 | }
75 | b2Math.MulFV = function (s, a) {
76 | var v = new b2Vec2(s * a.x, s * a.y);
77 | return v;
78 | }
79 | b2Math.AddMM = function (A, B) {
80 | var C = new b2Mat22(0, b2Math.AddVV(A.col1, B.col1), b2Math.AddVV(A.col2, B.col2));
81 | return C;
82 | }
83 | b2Math.b2MulMM = function (A, B) {
84 | var C = new b2Mat22(0, b2Math.b2MulMV(A, B.col1), b2Math.b2MulMV(A, B.col2));
85 | return C;
86 | }
87 | b2Math.b2MulTMM = function (A, B) {
88 | var c1 = new b2Vec2(b2Math.b2Dot(A.col1, B.col1), b2Math.b2Dot(A.col2, B.col1));
89 | var c2 = new b2Vec2(b2Math.b2Dot(A.col1, B.col2), b2Math.b2Dot(A.col2, B.col2));
90 | var C = new b2Mat22(0, c1, c2);
91 | return C;
92 | }
93 | b2Math.b2Abs = function (a) {
94 | return a > 0.0 ? a : -a;
95 | }
96 | b2Math.b2AbsV = function (a) {
97 | var b = new b2Vec2(b2Math.b2Abs(a.x), b2Math.b2Abs(a.y));
98 | return b;
99 | }
100 | b2Math.b2AbsM = function (A) {
101 | var B = new b2Mat22(0, b2Math.b2AbsV(A.col1), b2Math.b2AbsV(A.col2));
102 | return B;
103 | }
104 | b2Math.b2Min = function (a, b) {
105 | return a < b ? a : b;
106 | }
107 | b2Math.b2MinV = function (a, b) {
108 | var c = new b2Vec2(b2Math.b2Min(a.x, b.x), b2Math.b2Min(a.y, b.y));
109 | return c;
110 | }
111 | b2Math.b2Max = function (a, b) {
112 | return a > b ? a : b;
113 | }
114 | b2Math.b2MaxV = function (a, b) {
115 | var c = new b2Vec2(b2Math.b2Max(a.x, b.x), b2Math.b2Max(a.y, b.y));
116 | return c;
117 | }
118 | b2Math.b2Clamp = function (a, low, high) {
119 | return b2Math.b2Max(low, b2Math.b2Min(a, high));
120 | }
121 | b2Math.b2ClampV = function (a, low, high) {
122 | return b2Math.b2MaxV(low, b2Math.b2MinV(a, high));
123 | }
124 | b2Math.b2Swap = function (a, b) {
125 | var tmp = a[0];
126 | a[0] = b[0];
127 | b[0] = tmp;
128 | }
129 | b2Math.b2Random = function () {
130 | return Math.random() * 2 - 1;
131 | }
132 | b2Math.b2RandomRange = function (lo, hi) {
133 | var r = Math.random();
134 | r = (hi - lo) * r + lo;
135 | return r;
136 | }
137 | b2Math.b2NextPowerOfTwo = function (x) {
138 | x |= (x >> 1) & 0x7FFFFFFF;
139 | x |= (x >> 2) & 0x3FFFFFFF;
140 | x |= (x >> 4) & 0x0FFFFFFF;
141 | x |= (x >> 8) & 0x00FFFFFF;
142 | x |= (x >> 16)& 0x0000FFFF;
143 | return x + 1;
144 | }
145 | b2Math.b2IsPowerOfTwo = function (x) {
146 | var result = x > 0 && (x & (x - 1)) == 0;
147 | return result;
148 | }
149 | // attributes
150 | // methods
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/b2DebugDraw.js:
--------------------------------------------------------------------------------
1 | var b2DebugDraw = function() {
2 | this.__varz();
3 | this.__constructor.apply(this, arguments);
4 | }
5 | b2DebugDraw.prototype.__constructor = function () {
6 | this.m_drawFlags = 0;
7 | }
8 | b2DebugDraw.prototype.__varz = function(){
9 | }
10 | // static attributes
11 | b2DebugDraw.e_shapeBit = 0x0001;
12 | b2DebugDraw.e_jointBit = 0x0002;
13 | b2DebugDraw.e_coreShapeBit = 0x0004;
14 | b2DebugDraw.e_aabbBit = 0x0008;
15 | b2DebugDraw.e_obbBit = 0x0010;
16 | b2DebugDraw.e_pairBit = 0x0020;
17 | b2DebugDraw.e_centerOfMassBit = 0x0040;
18 | // static methods
19 | // attributes
20 | b2DebugDraw.prototype.m_drawFlags = 0;
21 | b2DebugDraw.prototype.m_sprite = null;
22 | b2DebugDraw.prototype.m_drawScale = 1.0;
23 | b2DebugDraw.prototype.m_lineThickness = 1.0;
24 | b2DebugDraw.prototype.m_alpha = 1.0;
25 | b2DebugDraw.prototype.m_fillAlpha = 1.0;
26 | b2DebugDraw.prototype.m_xformScale = 1.0;
27 | // methods
28 | b2DebugDraw.prototype.SetFlags = function (flags) {
29 | this.m_drawFlags = flags;
30 | }
31 | b2DebugDraw.prototype.GetFlags = function () {
32 | return this.m_drawFlags;
33 | }
34 | b2DebugDraw.prototype.AppendFlags = function (flags) {
35 | this.m_drawFlags |= flags;
36 | }
37 | b2DebugDraw.prototype.ClearFlags = function (flags) {
38 | this.m_drawFlags &= ~flags;
39 | }
40 | b2DebugDraw.prototype.DrawPolygon = function (vertices, vertexCount, color) {
41 |
42 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
43 | this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale);
44 | for (var i = 1; i < vertexCount; i++){
45 | this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale);
46 | }
47 | this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale);
48 |
49 | }
50 | b2DebugDraw.prototype.DrawSolidPolygon = function (vertices, vertexCount, color) {
51 |
52 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
53 | this.m_sprite.graphics.moveTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale);
54 | this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha);
55 | for (var i = 1; i < vertexCount; i++){
56 | this.m_sprite.graphics.lineTo(vertices[i].x * this.m_drawScale, vertices[i].y * this.m_drawScale);
57 | }
58 | this.m_sprite.graphics.lineTo(vertices[0].x * this.m_drawScale, vertices[0].y * this.m_drawScale);
59 | this.m_sprite.graphics.endFill();
60 |
61 | }
62 | b2DebugDraw.prototype.DrawCircle = function (center, radius, color) {
63 |
64 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
65 | this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale);
66 |
67 | }
68 | b2DebugDraw.prototype.DrawSolidCircle = function (center, radius, axis, color) {
69 |
70 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
71 | this.m_sprite.graphics.moveTo(0,0);
72 | this.m_sprite.graphics.beginFill(color.color, this.m_fillAlpha);
73 | this.m_sprite.graphics.drawCircle(center.x * this.m_drawScale, center.y * this.m_drawScale, radius * this.m_drawScale);
74 | this.m_sprite.graphics.endFill();
75 | this.m_sprite.graphics.moveTo(center.x * this.m_drawScale, center.y * this.m_drawScale);
76 | this.m_sprite.graphics.lineTo((center.x + axis.x*radius) * this.m_drawScale, (center.y + axis.y*radius) * this.m_drawScale);
77 |
78 | }
79 | b2DebugDraw.prototype.DrawSegment = function (p1, p2, color) {
80 |
81 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, color.color, this.m_alpha);
82 | this.m_sprite.graphics.moveTo(p1.x * this.m_drawScale, p1.y * this.m_drawScale);
83 | this.m_sprite.graphics.lineTo(p2.x * this.m_drawScale, p2.y * this.m_drawScale);
84 |
85 | }
86 | b2DebugDraw.prototype.DrawXForm = function (xf) {
87 |
88 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0xff0000, this.m_alpha);
89 | this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale);
90 | this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale*xf.R.col1.x) * this.m_drawScale, (xf.position.y + this.m_xformScale*xf.R.col1.y) * this.m_drawScale);
91 |
92 | this.m_sprite.graphics.lineStyle(this.m_lineThickness, 0x00ff00, this.m_alpha);
93 | this.m_sprite.graphics.moveTo(xf.position.x * this.m_drawScale, xf.position.y * this.m_drawScale);
94 | this.m_sprite.graphics.lineTo((xf.position.x + this.m_xformScale*xf.R.col2.x) * this.m_drawScale, (xf.position.y + this.m_xformScale*xf.R.col2.y) * this.m_drawScale);
95 |
96 | }
--------------------------------------------------------------------------------
/javascript/Box2D/Dynamics/Contacts/b2PolyAndCircleContact.js:
--------------------------------------------------------------------------------
1 | var b2PolyAndCircleContact = function() {
2 | b2Contact.prototype.__varz.call(this)
3 | this.__varz();
4 | this.__constructor.apply(this, arguments);
5 | }
6 | extend(b2PolyAndCircleContact.prototype, b2Contact.prototype)
7 | b2PolyAndCircleContact.prototype._super = function(){ b2Contact.prototype.__constructor.apply(this, arguments) }
8 | b2PolyAndCircleContact.prototype.__constructor = function (shape1, shape2) {
9 | this._super(shape1, shape2);
10 |
11 | this.m_manifold = this.m_manifolds[0];
12 |
13 | b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_polygonShape);
14 | b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_circleShape);
15 | this.m_manifold.pointCount = 0;
16 | var point = this.m_manifold.points[0];
17 | point.normalImpulse = 0.0;
18 | point.tangentImpulse = 0.0;
19 | }
20 | b2PolyAndCircleContact.prototype.__varz = function(){
21 | this.m_manifolds = [new b2Manifold()];
22 | this.m0 = new b2Manifold();
23 | }
24 | // static attributes
25 | b2PolyAndCircleContact.s_evalCP = new b2ContactPoint();
26 | // static methods
27 | b2PolyAndCircleContact.Create = function (shape1, shape2, allocator) {
28 | return new b2PolyAndCircleContact(shape1, shape2);
29 | }
30 | b2PolyAndCircleContact.Destroy = function (contact, allocator) {
31 | }
32 | // attributes
33 | b2PolyAndCircleContact.prototype.m_manifolds = [new b2Manifold()];
34 | b2PolyAndCircleContact.prototype.m0 = new b2Manifold();
35 | b2PolyAndCircleContact.prototype.m_manifold = null;
36 | // methods
37 | b2PolyAndCircleContact.prototype.Evaluate = function (listener) {
38 | var i = 0;
39 | var v1;
40 | var v2;
41 | var mp0;
42 |
43 | var b1 = this.m_shape1.m_body;
44 | var b2 = this.m_shape2.m_body;
45 |
46 |
47 |
48 |
49 | this.m0.Set(this.m_manifold);
50 |
51 | b2Collision.b2CollidePolygonAndCircle(this.m_manifold, this.m_shape1, b1.m_xf, this.m_shape2, b2.m_xf);
52 |
53 | var persisted = [false, false];
54 |
55 | var cp = b2PolyAndCircleContact.s_evalCP;
56 | cp.shape1 = this.m_shape1;
57 | cp.shape2 = this.m_shape2;
58 | cp.friction = this.m_friction;
59 | cp.restitution = this.m_restitution;
60 |
61 |
62 | if (this.m_manifold.pointCount > 0)
63 | {
64 |
65 |
66 | for (i = 0; i < this.m_manifold.pointCount; ++i)
67 | {
68 | var mp = this.m_manifold.points[ i ];
69 | mp.normalImpulse = 0.0;
70 | mp.tangentImpulse = 0.0;
71 | var found = false;
72 | var idKey = mp.id._key;
73 |
74 | for (var j = 0; j < this.m0.pointCount; ++j)
75 | {
76 | if (persisted[j] == true)
77 | {
78 | continue;
79 | }
80 |
81 | mp0 = this.m0.points[ j ];
82 |
83 | if (mp0.id._key == idKey)
84 | {
85 | persisted[j] = true;
86 | mp.normalImpulse = mp0.normalImpulse;
87 | mp.tangentImpulse = mp0.tangentImpulse;
88 |
89 |
90 | found = true;
91 |
92 |
93 | if (listener != null)
94 | {
95 | cp.position = b1.GetWorldPoint(mp.localPoint1);
96 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
97 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
98 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
99 | cp.normal.SetV(this.m_manifold.normal);
100 | cp.separation = mp.separation;
101 | cp.id.key = idKey;
102 | listener.Persist(cp);
103 | }
104 | break;
105 | }
106 | }
107 |
108 |
109 | if (found == false && listener != null)
110 | {
111 | cp.position = b1.GetWorldPoint(mp.localPoint1);
112 | v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
113 | v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
114 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
115 | cp.normal.SetV(this.m_manifold.normal);
116 | cp.separation = mp.separation;
117 | cp.id.key = idKey;
118 | listener.Add(cp);
119 | }
120 | }
121 |
122 | this.m_manifoldCount = 1;
123 | }
124 | else
125 | {
126 | this.m_manifoldCount = 0;
127 | }
128 |
129 | if (listener == null)
130 | {
131 | return;
132 | }
133 |
134 |
135 | for (i = 0; i < this.m0.pointCount; ++i)
136 | {
137 | if (persisted[i])
138 | {
139 | continue;
140 | }
141 |
142 | mp0 = this.m0.points[ i ];
143 | cp.position = b1.GetWorldPoint(mp0.localPoint1);
144 | v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
145 | v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
146 | cp.velocity.Set(v2.x - v1.x, v2.y - v1.y);
147 | cp.normal.SetV(this.m0.normal);
148 | cp.separation = mp0.separation;
149 | cp.id.key = mp0.id._key;
150 | listener.Remove(cp);
151 | }
152 | }
153 | b2PolyAndCircleContact.prototype.GetManifolds = function () {
154 | return this.m_manifolds;
155 | }
--------------------------------------------------------------------------------
/flash/Box2D/Common/b2Settings.as:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
3 | *
4 | * This software is provided 'as-is', without any express or implied
5 | * warranty. In no event will the authors be held liable for any damages
6 | * arising from the use of this software.
7 | * Permission is granted to anyone to use this software for any purpose,
8 | * including commercial applications, and to alter it and redistribute it
9 | * freely, subject to the following restrictions:
10 | * 1. The origin of this software must not be misrepresented; you must not
11 | * claim that you wrote the original software. If you use this software
12 | * in a product, an acknowledgment in the product documentation would be
13 | * appreciated but is not required.
14 | * 2. Altered source versions must be plainly marked as such, and must not be
15 | * misrepresented as being the original software.
16 | * 3. This notice may not be removed or altered from any source distribution.
17 | */
18 |
19 | package Box2D.Common{
20 |
21 |
22 | import Box2D.Common.Math.*;
23 |
24 |
25 | public class b2Settings{
26 |
27 | static public const USHRT_MAX:int = 0x0000ffff;
28 |
29 | static public const b2_pi:Number = Math.PI;
30 |
31 |
32 |
33 | // Collision
34 | static public const b2_maxManifoldPoints:int = 2;
35 | static public const b2_maxPolygonVertices:int = 8;
36 | static public const b2_maxProxies:int = 512; // this must be a power of two
37 | static public const b2_maxPairs:int = 8 * b2_maxProxies; // this must be a power of two
38 |
39 |
40 |
41 | // Dynamics
42 |
43 | /// A small length used as a collision and constraint tolerance. Usually it is
44 | /// chosen to be numerically significant, but visually insignificant.
45 | static public const b2_linearSlop:Number = 0.005; // 0.5 cm
46 |
47 | /// A small angle used as a collision and constraint tolerance. Usually it is
48 | /// chosen to be numerically significant, but visually insignificant.
49 | static public const b2_angularSlop:Number = 2.0 / 180.0 * b2_pi; // 2 degrees
50 |
51 | /// Continuous collision detection (CCD) works with core, shrunken shapes. This is the
52 | /// amount by which shapes are automatically shrunk to work with CCD. This must be
53 | /// larger than b2_linearSlop.
54 | static public const b2_toiSlop:Number = 8.0 * b2_linearSlop;
55 |
56 | /// Maximum number of contacts to be handled to solve a TOI island.
57 | static public const b2_maxTOIContactsPerIsland:int = 32;
58 |
59 | /// A velocity threshold for elastic collisions. Any collision with a relative linear
60 | /// velocity below this threshold will be treated as inelastic.
61 | static public const b2_velocityThreshold:Number = 1.0; // 1 m/s
62 |
63 | /// The maximum linear position correction used when solving constraints. This helps to
64 | /// prevent overshoot.
65 | static public const b2_maxLinearCorrection:Number = 0.2; // 20 cm
66 |
67 | /// The maximum angular position correction used when solving constraints. This helps to
68 | /// prevent overshoot.
69 | static public const b2_maxAngularCorrection:Number = 8.0 / 180.0 * b2_pi; // 8 degrees
70 |
71 | /// The maximum linear velocity of a body. This limit is very large and is used
72 | /// to prevent numerical problems. You shouldn't need to adjust this.
73 | static public const b2_maxLinearVelocity:Number = 200.0;
74 | static public const b2_maxLinearVelocitySquared:Number = b2_maxLinearVelocity * b2_maxLinearVelocity;
75 |
76 | /// The maximum angular velocity of a body. This limit is very large and is used
77 | /// to prevent numerical problems. You shouldn't need to adjust this.
78 | static public const b2_maxAngularVelocity:Number = 250.0;
79 | static public const b2_maxAngularVelocitySquared:Number = b2_maxAngularVelocity * b2_maxAngularVelocity;
80 |
81 | /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
82 | /// that overlap is removed in one time step. However using values close to 1 often lead
83 | /// to overshoot.
84 | static public const b2_contactBaumgarte:Number = 0.2;
85 |
86 |
87 |
88 | // Sleep
89 |
90 | /// The time that a body must be still before it will go to sleep.
91 | static public const b2_timeToSleep:Number = 0.5; // half a second
92 | /// A body cannot sleep if its linear velocity is above this tolerance.
93 | static public const b2_linearSleepTolerance:Number = 0.01; // 1 cm/s
94 | /// A body cannot sleep if its angular velocity is above this tolerance.
95 | static public const b2_angularSleepTolerance:Number = 2.0 / 180.0; // 2 degrees/s
96 |
97 | // assert
98 | static public function b2Assert(a:Boolean) : void
99 | {
100 | if (!a){
101 | var nullVec:b2Vec2;
102 | nullVec.x++;
103 | }
104 | }
105 | }
106 |
107 | }
--------------------------------------------------------------------------------