box2d-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/box2d-rails.gemspec +20 -0
- data/lib/box2d-rails.rb +8 -0
- data/lib/box2d-rails/version.rb +5 -0
- data/vendor/assets/javascripts/box2d/collision/ClipVertex.js +35 -0
- data/vendor/assets/javascripts/box2d/collision/Features.js +61 -0
- data/vendor/assets/javascripts/box2d/collision/b2AABB.js +45 -0
- data/vendor/assets/javascripts/box2d/collision/b2Bound.js +43 -0
- data/vendor/assets/javascripts/box2d/collision/b2BoundValues.js +31 -0
- data/vendor/assets/javascripts/box2d/collision/b2BroadPhase.js +898 -0
- data/vendor/assets/javascripts/box2d/collision/b2BufferedPair.js +26 -0
- data/vendor/assets/javascripts/box2d/collision/b2Collision.js +738 -0
- data/vendor/assets/javascripts/box2d/collision/b2ContactID.js +52 -0
- data/vendor/assets/javascripts/box2d/collision/b2ContactPoint.js +35 -0
- data/vendor/assets/javascripts/box2d/collision/b2Distance.js +333 -0
- data/vendor/assets/javascripts/box2d/collision/b2Manifold.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2OBB.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2Pair.js +60 -0
- data/vendor/assets/javascripts/box2d/collision/b2PairCallback.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2PairManager.js +386 -0
- data/vendor/assets/javascripts/box2d/collision/b2Proxy.js +40 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2BoxDef.js +49 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleDef.js +49 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleShape.js +198 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2MassData.js +36 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyDef.js +58 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyShape.js +492 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2Shape.js +339 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2ShapeDef.js +109 -0
- data/vendor/assets/javascripts/box2d/common/b2Settings.js +72 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Mat22.js +130 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Math.js +218 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Vec2.js +131 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2Body.js +469 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2BodyDef.js +69 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2CollisionFilter.js +42 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2ContactManager.js +337 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2Island.js +331 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2TimeStep.js +27 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2World.js +522 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2WorldListener.js +52 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2CircleContact.js +102 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Conservative.js +228 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Contact.js +201 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraint.js +45 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraintPoint.js +40 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactNode.js +33 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactRegister.js +30 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactSolver.js +537 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2NullContact.js +65 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyAndCircleContact.js +103 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyContact.js +163 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJoint.js +264 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJointDef.js +49 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJoint.js +307 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJointDef.js +50 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2Jacobian.js +49 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2Joint.js +200 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointDef.js +40 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointNode.js +33 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJoint.js +234 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJointDef.js +53 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJoint.js +676 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJointDef.js +56 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJoint.js +618 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJointDef.js +70 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJoint.js +491 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJointDef.js +55 -0
- metadata +133 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
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, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
var b2ContactConstraint = Class.create();
|
24
|
+
b2ContactConstraint.prototype =
|
25
|
+
{
|
26
|
+
initialize: function(){
|
27
|
+
// initialize instance variables for references
|
28
|
+
this.normal = new b2Vec2();
|
29
|
+
//
|
30
|
+
|
31
|
+
this.points = new Array(b2Settings.b2_maxManifoldPoints);
|
32
|
+
for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
|
33
|
+
this.points[i] = new b2ContactConstraintPoint();
|
34
|
+
}
|
35
|
+
|
36
|
+
|
37
|
+
},
|
38
|
+
points: null,
|
39
|
+
normal: new b2Vec2(),
|
40
|
+
manifold: null,
|
41
|
+
body1: null,
|
42
|
+
body2: null,
|
43
|
+
friction: null,
|
44
|
+
restitution: null,
|
45
|
+
pointCount: 0};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
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, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
var b2ContactConstraintPoint = Class.create();
|
24
|
+
b2ContactConstraintPoint.prototype =
|
25
|
+
{
|
26
|
+
localAnchor1: new b2Vec2(),
|
27
|
+
localAnchor2: new b2Vec2(),
|
28
|
+
normalImpulse: null,
|
29
|
+
tangentImpulse: null,
|
30
|
+
positionImpulse: null,
|
31
|
+
normalMass: null,
|
32
|
+
tangentMass: null,
|
33
|
+
separation: null,
|
34
|
+
velocityBias: null,
|
35
|
+
initialize: function() {
|
36
|
+
// initialize instance variables for references
|
37
|
+
this.localAnchor1 = new b2Vec2();
|
38
|
+
this.localAnchor2 = new b2Vec2();
|
39
|
+
//
|
40
|
+
}};
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
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, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
var b2ContactNode = Class.create();
|
24
|
+
b2ContactNode.prototype =
|
25
|
+
{
|
26
|
+
other: null,
|
27
|
+
contact: null,
|
28
|
+
prev: null,
|
29
|
+
next: null,
|
30
|
+
initialize: function() {}};
|
31
|
+
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
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, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
var b2ContactRegister = Class.create();
|
22
|
+
b2ContactRegister.prototype =
|
23
|
+
{
|
24
|
+
createFcn: null,
|
25
|
+
destroyFcn: null,
|
26
|
+
primary: null,
|
27
|
+
initialize: function() {}};
|
28
|
+
|
29
|
+
|
30
|
+
|
@@ -0,0 +1,537 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
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, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
var b2ContactSolver = Class.create();
|
24
|
+
b2ContactSolver.prototype =
|
25
|
+
{
|
26
|
+
initialize: function(contacts, contactCount, allocator){
|
27
|
+
// initialize instance variables for references
|
28
|
+
this.m_constraints = new Array();
|
29
|
+
//
|
30
|
+
|
31
|
+
this.m_allocator = allocator;
|
32
|
+
|
33
|
+
var i = 0;
|
34
|
+
var tVec;
|
35
|
+
var tMat;
|
36
|
+
|
37
|
+
this.m_constraintCount = 0;
|
38
|
+
for (i = 0; i < contactCount; ++i)
|
39
|
+
{
|
40
|
+
this.m_constraintCount += contacts[i].GetManifoldCount();
|
41
|
+
}
|
42
|
+
|
43
|
+
// fill array
|
44
|
+
for (i = 0; i < this.m_constraintCount; i++){
|
45
|
+
this.m_constraints[i] = new b2ContactConstraint();
|
46
|
+
}
|
47
|
+
|
48
|
+
var count = 0;
|
49
|
+
for (i = 0; i < contactCount; ++i)
|
50
|
+
{
|
51
|
+
var contact = contacts[i];
|
52
|
+
var b1 = contact.m_shape1.m_body;
|
53
|
+
var b2 = contact.m_shape2.m_body;
|
54
|
+
var manifoldCount = contact.GetManifoldCount();
|
55
|
+
var manifolds = contact.GetManifolds();
|
56
|
+
var friction = contact.m_friction;
|
57
|
+
var restitution = contact.m_restitution;
|
58
|
+
|
59
|
+
//var v1 = b1.m_linearVelocity.Copy();
|
60
|
+
var v1X = b1.m_linearVelocity.x;
|
61
|
+
var v1Y = b1.m_linearVelocity.y;
|
62
|
+
//var v2 = b2.m_linearVelocity.Copy();
|
63
|
+
var v2X = b2.m_linearVelocity.x;
|
64
|
+
var v2Y = b2.m_linearVelocity.y;
|
65
|
+
var w1 = b1.m_angularVelocity;
|
66
|
+
var w2 = b2.m_angularVelocity;
|
67
|
+
|
68
|
+
for (var j = 0; j < manifoldCount; ++j)
|
69
|
+
{
|
70
|
+
var manifold = manifolds[ j ];
|
71
|
+
|
72
|
+
//b2Settings.b2Assert(manifold.pointCount > 0);
|
73
|
+
|
74
|
+
//var normal = manifold.normal.Copy();
|
75
|
+
var normalX = manifold.normal.x;
|
76
|
+
var normalY = manifold.normal.y;
|
77
|
+
|
78
|
+
//b2Settings.b2Assert(count < this.m_constraintCount);
|
79
|
+
var c = this.m_constraints[ count ];
|
80
|
+
c.body1 = b1;
|
81
|
+
c.body2 = b2;
|
82
|
+
c.manifold = manifold;
|
83
|
+
//c.normal = normal;
|
84
|
+
c.normal.x = normalX;
|
85
|
+
c.normal.y = normalY;
|
86
|
+
c.pointCount = manifold.pointCount;
|
87
|
+
c.friction = friction;
|
88
|
+
c.restitution = restitution;
|
89
|
+
|
90
|
+
for (var k = 0; k < c.pointCount; ++k)
|
91
|
+
{
|
92
|
+
var cp = manifold.points[ k ];
|
93
|
+
var ccp = c.points[ k ];
|
94
|
+
|
95
|
+
ccp.normalImpulse = cp.normalImpulse;
|
96
|
+
ccp.tangentImpulse = cp.tangentImpulse;
|
97
|
+
ccp.separation = cp.separation;
|
98
|
+
|
99
|
+
//var r1 = b2Math.SubtractVV( cp.position, b1.m_position );
|
100
|
+
var r1X = cp.position.x - b1.m_position.x;
|
101
|
+
var r1Y = cp.position.y - b1.m_position.y;
|
102
|
+
//var r2 = b2Math.SubtractVV( cp.position, b2.m_position );
|
103
|
+
var r2X = cp.position.x - b2.m_position.x;
|
104
|
+
var r2Y = cp.position.y - b2.m_position.y;
|
105
|
+
|
106
|
+
//ccp.localAnchor1 = b2Math.b2MulTMV(b1.m_R, r1);
|
107
|
+
tVec = ccp.localAnchor1;
|
108
|
+
tMat = b1.m_R;
|
109
|
+
tVec.x = r1X * tMat.col1.x + r1Y * tMat.col1.y;
|
110
|
+
tVec.y = r1X * tMat.col2.x + r1Y * tMat.col2.y;
|
111
|
+
|
112
|
+
//ccp.localAnchor2 = b2Math.b2MulTMV(b2.m_R, r2);
|
113
|
+
tVec = ccp.localAnchor2;
|
114
|
+
tMat = b2.m_R;
|
115
|
+
tVec.x = r2X * tMat.col1.x + r2Y * tMat.col1.y;
|
116
|
+
tVec.y = r2X * tMat.col2.x + r2Y * tMat.col2.y;
|
117
|
+
|
118
|
+
var r1Sqr = r1X * r1X + r1Y * r1Y;
|
119
|
+
var r2Sqr = r2X * r2X + r2Y * r2Y;
|
120
|
+
|
121
|
+
//var rn1 = b2Math.b2Dot(r1, normal);
|
122
|
+
var rn1 = r1X*normalX + r1Y*normalY;
|
123
|
+
//var rn2 = b2Math.b2Dot(r2, normal);
|
124
|
+
var rn2 = r2X*normalX + r2Y*normalY;
|
125
|
+
var kNormal = b1.m_invMass + b2.m_invMass;
|
126
|
+
kNormal += b1.m_invI * (r1Sqr - rn1 * rn1) + b2.m_invI * (r2Sqr - rn2 * rn2);
|
127
|
+
//b2Settings.b2Assert(kNormal > Number.MIN_VALUE);
|
128
|
+
ccp.normalMass = 1.0 / kNormal;
|
129
|
+
|
130
|
+
//var tangent = b2Math.b2CrossVF(normal, 1.0);
|
131
|
+
var tangentX = normalY
|
132
|
+
var tangentY = -normalX;
|
133
|
+
|
134
|
+
//var rt1 = b2Math.b2Dot(r1, tangent);
|
135
|
+
var rt1 = r1X*tangentX + r1Y*tangentY;
|
136
|
+
//var rt2 = b2Math.b2Dot(r2, tangent);
|
137
|
+
var rt2 = r2X*tangentX + r2Y*tangentY;
|
138
|
+
var kTangent = b1.m_invMass + b2.m_invMass;
|
139
|
+
kTangent += b1.m_invI * (r1Sqr - rt1 * rt1) + b2.m_invI * (r2Sqr - rt2 * rt2);
|
140
|
+
//b2Settings.b2Assert(kTangent > Number.MIN_VALUE);
|
141
|
+
ccp.tangentMass = 1.0 / kTangent;
|
142
|
+
|
143
|
+
// Setup a velocity bias for restitution.
|
144
|
+
ccp.velocityBias = 0.0;
|
145
|
+
if (ccp.separation > 0.0)
|
146
|
+
{
|
147
|
+
ccp.velocityBias = -60.0 * ccp.separation;
|
148
|
+
}
|
149
|
+
//var vRel = b2Math.b2Dot(c.normal, b2Math.SubtractVV( b2Math.SubtractVV( b2Math.AddVV( v2, b2Math.b2CrossFV(w2, r2)), v1 ), b2Math.b2CrossFV(w1, r1)));
|
150
|
+
var tX = v2X + (-w2*r2Y) - v1X - (-w1*r1Y);
|
151
|
+
var tY = v2Y + (w2*r2X) - v1Y - (w1*r1X);
|
152
|
+
//var vRel = b2Dot(c.normal, tX/Y);
|
153
|
+
var vRel = c.normal.x*tX + c.normal.y*tY;
|
154
|
+
if (vRel < -b2Settings.b2_velocityThreshold)
|
155
|
+
{
|
156
|
+
ccp.velocityBias += -c.restitution * vRel;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
|
160
|
+
++count;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
//b2Settings.b2Assert(count == this.m_constraintCount);
|
165
|
+
},
|
166
|
+
//~b2ContactSolver();
|
167
|
+
|
168
|
+
PreSolve: function(){
|
169
|
+
var tVec;
|
170
|
+
var tVec2;
|
171
|
+
var tMat;
|
172
|
+
|
173
|
+
// Warm start.
|
174
|
+
for (var i = 0; i < this.m_constraintCount; ++i)
|
175
|
+
{
|
176
|
+
var c = this.m_constraints[ i ];
|
177
|
+
|
178
|
+
var b1 = c.body1;
|
179
|
+
var b2 = c.body2;
|
180
|
+
var invMass1 = b1.m_invMass;
|
181
|
+
var invI1 = b1.m_invI;
|
182
|
+
var invMass2 = b2.m_invMass;
|
183
|
+
var invI2 = b2.m_invI;
|
184
|
+
//var normal = new b2Vec2(c.normal.x, c.normal.y);
|
185
|
+
var normalX = c.normal.x;
|
186
|
+
var normalY = c.normal.y;
|
187
|
+
//var tangent = b2Math.b2CrossVF(normal, 1.0);
|
188
|
+
var tangentX = normalY;
|
189
|
+
var tangentY = -normalX;
|
190
|
+
|
191
|
+
var j = 0;
|
192
|
+
var tCount = 0;
|
193
|
+
if (b2World.s_enableWarmStarting)
|
194
|
+
{
|
195
|
+
tCount = c.pointCount;
|
196
|
+
for (j = 0; j < tCount; ++j)
|
197
|
+
{
|
198
|
+
var ccp = c.points[ j ];
|
199
|
+
//var P = b2Math.AddVV( b2Math.MulFV(ccp.normalImpulse, normal), b2Math.MulFV(ccp.tangentImpulse, tangent));
|
200
|
+
var PX = ccp.normalImpulse*normalX + ccp.tangentImpulse*tangentX;
|
201
|
+
var PY = ccp.normalImpulse*normalY + ccp.tangentImpulse*tangentY;
|
202
|
+
|
203
|
+
//var r1 = b2Math.b2MulMV(b1.m_R, ccp.localAnchor1);
|
204
|
+
tMat = b1.m_R;
|
205
|
+
tVec = ccp.localAnchor1;
|
206
|
+
var r1X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
|
207
|
+
var r1Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
|
208
|
+
|
209
|
+
//var r2 = b2Math.b2MulMV(b2.m_R, ccp.localAnchor2);
|
210
|
+
tMat = b2.m_R;
|
211
|
+
tVec = ccp.localAnchor2;
|
212
|
+
var r2X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
|
213
|
+
var r2Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
|
214
|
+
|
215
|
+
//b1.m_angularVelocity -= invI1 * b2Math.b2CrossVV(r1, P);
|
216
|
+
b1.m_angularVelocity -= invI1 * (r1X * PY - r1Y * PX);
|
217
|
+
//b1.m_linearVelocity.Subtract( b2Math.MulFV(invMass1, P) );
|
218
|
+
b1.m_linearVelocity.x -= invMass1 * PX;
|
219
|
+
b1.m_linearVelocity.y -= invMass1 * PY;
|
220
|
+
//b2.m_angularVelocity += invI2 * b2Math.b2CrossVV(r2, P);
|
221
|
+
b2.m_angularVelocity += invI2 * (r2X * PY - r2Y * PX);
|
222
|
+
//b2.m_linearVelocity.Add( b2Math.MulFV(invMass2, P) );
|
223
|
+
b2.m_linearVelocity.x += invMass2 * PX;
|
224
|
+
b2.m_linearVelocity.y += invMass2 * PY;
|
225
|
+
|
226
|
+
ccp.positionImpulse = 0.0;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
else{
|
230
|
+
tCount = c.pointCount;
|
231
|
+
for (j = 0; j < tCount; ++j)
|
232
|
+
{
|
233
|
+
var ccp2 = c.points[ j ];
|
234
|
+
ccp2.normalImpulse = 0.0;
|
235
|
+
ccp2.tangentImpulse = 0.0;
|
236
|
+
|
237
|
+
ccp2.positionImpulse = 0.0;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}
|
241
|
+
},
|
242
|
+
SolveVelocityConstraints: function(){
|
243
|
+
var j = 0;
|
244
|
+
var ccp;
|
245
|
+
var r1X;
|
246
|
+
var r1Y;
|
247
|
+
var r2X;
|
248
|
+
var r2Y;
|
249
|
+
var dvX;
|
250
|
+
var dvY;
|
251
|
+
var lambda;
|
252
|
+
var newImpulse;
|
253
|
+
var PX;
|
254
|
+
var PY;
|
255
|
+
|
256
|
+
var tMat;
|
257
|
+
var tVec;
|
258
|
+
|
259
|
+
for (var i = 0; i < this.m_constraintCount; ++i)
|
260
|
+
{
|
261
|
+
var c = this.m_constraints[ i ];
|
262
|
+
var b1 = c.body1;
|
263
|
+
var b2 = c.body2;
|
264
|
+
var b1_angularVelocity = b1.m_angularVelocity;
|
265
|
+
var b1_linearVelocity = b1.m_linearVelocity;
|
266
|
+
var b2_angularVelocity = b2.m_angularVelocity;
|
267
|
+
var b2_linearVelocity = b2.m_linearVelocity;
|
268
|
+
|
269
|
+
var invMass1 = b1.m_invMass;
|
270
|
+
var invI1 = b1.m_invI;
|
271
|
+
var invMass2 = b2.m_invMass;
|
272
|
+
var invI2 = b2.m_invI;
|
273
|
+
//var normal = new b2Vec2(c.normal.x, c.normal.y);
|
274
|
+
var normalX = c.normal.x;
|
275
|
+
var normalY = c.normal.y;
|
276
|
+
//var tangent = b2Math.b2CrossVF(normal, 1.0);
|
277
|
+
var tangentX = normalY;
|
278
|
+
var tangentY = -normalX;
|
279
|
+
|
280
|
+
// Solver normal constraints
|
281
|
+
var tCount = c.pointCount;
|
282
|
+
for (j = 0; j < tCount; ++j)
|
283
|
+
{
|
284
|
+
ccp = c.points[ j ];
|
285
|
+
|
286
|
+
//r1 = b2Math.b2MulMV(b1.m_R, ccp.localAnchor1);
|
287
|
+
tMat = b1.m_R;
|
288
|
+
tVec = ccp.localAnchor1;
|
289
|
+
r1X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
290
|
+
r1Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
291
|
+
//r2 = b2Math.b2MulMV(b2.m_R, ccp.localAnchor2);
|
292
|
+
tMat = b2.m_R;
|
293
|
+
tVec = ccp.localAnchor2;
|
294
|
+
r2X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
295
|
+
r2Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
296
|
+
|
297
|
+
// Relative velocity at contact
|
298
|
+
//var dv = b2Math.SubtractVV( b2Math.AddVV( b2.m_linearVelocity, b2Math.b2CrossFV(b2.m_angularVelocity, r2)), b2Math.SubtractVV(b1.m_linearVelocity, b2Math.b2CrossFV(b1.m_angularVelocity, r1)));
|
299
|
+
//dv = b2Math.SubtractVV(b2Math.SubtractVV( b2Math.AddVV( b2.m_linearVelocity, b2Math.b2CrossFV(b2.m_angularVelocity, r2)), b1.m_linearVelocity), b2Math.b2CrossFV(b1.m_angularVelocity, r1));
|
300
|
+
dvX = b2_linearVelocity.x + (-b2_angularVelocity * r2Y) - b1_linearVelocity.x - (-b1_angularVelocity * r1Y);
|
301
|
+
dvY = b2_linearVelocity.y + (b2_angularVelocity * r2X) - b1_linearVelocity.y - (b1_angularVelocity * r1X);
|
302
|
+
|
303
|
+
// Compute normal impulse
|
304
|
+
//var vn = b2Math.b2Dot(dv, normal);
|
305
|
+
var vn = dvX * normalX + dvY * normalY;
|
306
|
+
lambda = -ccp.normalMass * (vn - ccp.velocityBias);
|
307
|
+
|
308
|
+
// b2Clamp the accumulated impulse
|
309
|
+
newImpulse = b2Math.b2Max(ccp.normalImpulse + lambda, 0.0);
|
310
|
+
lambda = newImpulse - ccp.normalImpulse;
|
311
|
+
|
312
|
+
// Apply contact impulse
|
313
|
+
//P = b2Math.MulFV(lambda, normal);
|
314
|
+
PX = lambda * normalX;
|
315
|
+
PY = lambda * normalY;
|
316
|
+
|
317
|
+
//b1.m_linearVelocity.Subtract( b2Math.MulFV( invMass1, P ) );
|
318
|
+
b1_linearVelocity.x -= invMass1 * PX;
|
319
|
+
b1_linearVelocity.y -= invMass1 * PY;
|
320
|
+
b1_angularVelocity -= invI1 * (r1X * PY - r1Y * PX);
|
321
|
+
|
322
|
+
//b2.m_linearVelocity.Add( b2Math.MulFV( invMass2, P ) );
|
323
|
+
b2_linearVelocity.x += invMass2 * PX;
|
324
|
+
b2_linearVelocity.y += invMass2 * PY;
|
325
|
+
b2_angularVelocity += invI2 * (r2X * PY - r2Y * PX);
|
326
|
+
|
327
|
+
ccp.normalImpulse = newImpulse;
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
// MOVED FROM BELOW
|
332
|
+
// Relative velocity at contact
|
333
|
+
//var dv = b2.m_linearVelocity + b2Cross(b2.m_angularVelocity, r2) - b1.m_linearVelocity - b2Cross(b1.m_angularVelocity, r1);
|
334
|
+
//dv = b2Math.SubtractVV(b2Math.SubtractVV(b2Math.AddVV(b2.m_linearVelocity, b2Math.b2CrossFV(b2.m_angularVelocity, r2)), b1.m_linearVelocity), b2Math.b2CrossFV(b1.m_angularVelocity, r1));
|
335
|
+
dvX = b2_linearVelocity.x + (-b2_angularVelocity * r2Y) - b1_linearVelocity.x - (-b1_angularVelocity * r1Y);
|
336
|
+
dvY = b2_linearVelocity.y + (b2_angularVelocity * r2X) - b1_linearVelocity.y - (b1_angularVelocity * r1X);
|
337
|
+
|
338
|
+
// Compute tangent impulse
|
339
|
+
var vt = dvX*tangentX + dvY*tangentY;
|
340
|
+
lambda = ccp.tangentMass * (-vt);
|
341
|
+
|
342
|
+
// b2Clamp the accumulated impulse
|
343
|
+
var maxFriction = c.friction * ccp.normalImpulse;
|
344
|
+
newImpulse = b2Math.b2Clamp(ccp.tangentImpulse + lambda, -maxFriction, maxFriction);
|
345
|
+
lambda = newImpulse - ccp.tangentImpulse;
|
346
|
+
|
347
|
+
// Apply contact impulse
|
348
|
+
//P = b2Math.MulFV(lambda, tangent);
|
349
|
+
PX = lambda * tangentX;
|
350
|
+
PY = lambda * tangentY;
|
351
|
+
|
352
|
+
//b1.m_linearVelocity.Subtract( b2Math.MulFV( invMass1, P ) );
|
353
|
+
b1_linearVelocity.x -= invMass1 * PX;
|
354
|
+
b1_linearVelocity.y -= invMass1 * PY;
|
355
|
+
b1_angularVelocity -= invI1 * (r1X * PY - r1Y * PX);
|
356
|
+
|
357
|
+
//b2.m_linearVelocity.Add( b2Math.MulFV( invMass2, P ) );
|
358
|
+
b2_linearVelocity.x += invMass2 * PX;
|
359
|
+
b2_linearVelocity.y += invMass2 * PY;
|
360
|
+
b2_angularVelocity += invI2 * (r2X * PY - r2Y * PX);
|
361
|
+
|
362
|
+
ccp.tangentImpulse = newImpulse;
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
// Solver tangent constraints
|
368
|
+
// MOVED ABOVE FOR EFFICIENCY
|
369
|
+
/*for (j = 0; j < tCount; ++j)
|
370
|
+
{
|
371
|
+
ccp = c.points[ j ];
|
372
|
+
|
373
|
+
//r1 = b2Math.b2MulMV(b1.m_R, ccp.localAnchor1);
|
374
|
+
tMat = b1.m_R;
|
375
|
+
tVec = ccp.localAnchor1;
|
376
|
+
r1X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
377
|
+
r1Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
378
|
+
//r2 = b2Math.b2MulMV(b2.m_R, ccp.localAnchor2);
|
379
|
+
tMat = b2.m_R;
|
380
|
+
tVec = ccp.localAnchor2;
|
381
|
+
r2X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
382
|
+
r2Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
383
|
+
|
384
|
+
// Relative velocity at contact
|
385
|
+
//var dv = b2.m_linearVelocity + b2Cross(b2.m_angularVelocity, r2) - b1.m_linearVelocity - b2Cross(b1.m_angularVelocity, r1);
|
386
|
+
//dv = b2Math.SubtractVV(b2Math.SubtractVV(b2Math.AddVV(b2.m_linearVelocity, b2Math.b2CrossFV(b2.m_angularVelocity, r2)), b1.m_linearVelocity), b2Math.b2CrossFV(b1.m_angularVelocity, r1));
|
387
|
+
dvX = b2_linearVelocity.x + (-b2_angularVelocity * r2Y) - b1_linearVelocity.x - (-b1_angularVelocity * r1Y);
|
388
|
+
dvY = b2_linearVelocity.y + (b2_angularVelocity * r2X) - b1_linearVelocity.y - (b1_angularVelocity * r1X);
|
389
|
+
|
390
|
+
// Compute tangent impulse
|
391
|
+
var vt = dvX*tangentX + dvY*tangentY;
|
392
|
+
lambda = ccp.tangentMass * (-vt);
|
393
|
+
|
394
|
+
// b2Clamp the accumulated impulse
|
395
|
+
var maxFriction = c.friction * ccp.normalImpulse;
|
396
|
+
newImpulse = b2Math.b2Clamp(ccp.tangentImpulse + lambda, -maxFriction, maxFriction);
|
397
|
+
lambda = newImpulse - ccp.tangentImpulse;
|
398
|
+
|
399
|
+
// Apply contact impulse
|
400
|
+
//P = b2Math.MulFV(lambda, tangent);
|
401
|
+
PX = lambda * tangentX;
|
402
|
+
PY = lambda * tangentY;
|
403
|
+
|
404
|
+
//b1.m_linearVelocity.Subtract( b2Math.MulFV( invMass1, P ) );
|
405
|
+
b1_linearVelocity.x -= invMass1 * PX;
|
406
|
+
b1_linearVelocity.y -= invMass1 * PY;
|
407
|
+
b1_angularVelocity -= invI1 * (r1X * PY - r1Y * PX);
|
408
|
+
|
409
|
+
//b2.m_linearVelocity.Add( b2Math.MulFV( invMass2, P ) );
|
410
|
+
b2_linearVelocity.x += invMass2 * PX;
|
411
|
+
b2_linearVelocity.y += invMass2 * PY;
|
412
|
+
b2_angularVelocity += invI2 * (r2X * PY - r2Y * PX);
|
413
|
+
|
414
|
+
ccp.tangentImpulse = newImpulse;
|
415
|
+
}*/
|
416
|
+
|
417
|
+
// Update angular velocity
|
418
|
+
b1.m_angularVelocity = b1_angularVelocity;
|
419
|
+
b2.m_angularVelocity = b2_angularVelocity;
|
420
|
+
}
|
421
|
+
},
|
422
|
+
SolvePositionConstraints: function(beta){
|
423
|
+
var minSeparation = 0.0;
|
424
|
+
|
425
|
+
var tMat;
|
426
|
+
var tVec;
|
427
|
+
|
428
|
+
for (var i = 0; i < this.m_constraintCount; ++i)
|
429
|
+
{
|
430
|
+
var c = this.m_constraints[ i ];
|
431
|
+
var b1 = c.body1;
|
432
|
+
var b2 = c.body2;
|
433
|
+
var b1_position = b1.m_position;
|
434
|
+
var b1_rotation = b1.m_rotation;
|
435
|
+
var b2_position = b2.m_position;
|
436
|
+
var b2_rotation = b2.m_rotation;
|
437
|
+
|
438
|
+
var invMass1 = b1.m_invMass;
|
439
|
+
var invI1 = b1.m_invI;
|
440
|
+
var invMass2 = b2.m_invMass;
|
441
|
+
var invI2 = b2.m_invI;
|
442
|
+
//var normal = new b2Vec2(c.normal.x, c.normal.y);
|
443
|
+
var normalX = c.normal.x;
|
444
|
+
var normalY = c.normal.y;
|
445
|
+
//var tangent = b2Math.b2CrossVF(normal, 1.0);
|
446
|
+
var tangentX = normalY;
|
447
|
+
var tangentY = -normalX;
|
448
|
+
|
449
|
+
// Solver normal constraints
|
450
|
+
var tCount = c.pointCount;
|
451
|
+
for (var j = 0; j < tCount; ++j)
|
452
|
+
{
|
453
|
+
var ccp = c.points[ j ];
|
454
|
+
|
455
|
+
//r1 = b2Math.b2MulMV(b1.m_R, ccp.localAnchor1);
|
456
|
+
tMat = b1.m_R;
|
457
|
+
tVec = ccp.localAnchor1;
|
458
|
+
var r1X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
459
|
+
var r1Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
460
|
+
//r2 = b2Math.b2MulMV(b2.m_R, ccp.localAnchor2);
|
461
|
+
tMat = b2.m_R;
|
462
|
+
tVec = ccp.localAnchor2;
|
463
|
+
var r2X = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y
|
464
|
+
var r2Y = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y
|
465
|
+
|
466
|
+
//var p1 = b2Math.AddVV(b1.m_position, r1);
|
467
|
+
var p1X = b1_position.x + r1X;
|
468
|
+
var p1Y = b1_position.y + r1Y;
|
469
|
+
|
470
|
+
//var p2 = b2Math.AddVV(b2.m_position, r2);
|
471
|
+
var p2X = b2_position.x + r2X;
|
472
|
+
var p2Y = b2_position.y + r2Y;
|
473
|
+
|
474
|
+
//var dp = b2Math.SubtractVV(p2, p1);
|
475
|
+
var dpX = p2X - p1X;
|
476
|
+
var dpY = p2Y - p1Y;
|
477
|
+
|
478
|
+
// Approximate the current separation.
|
479
|
+
//var separation = b2Math.b2Dot(dp, normal) + ccp.separation;
|
480
|
+
var separation = (dpX*normalX + dpY*normalY) + ccp.separation;
|
481
|
+
|
482
|
+
// Track max constraint error.
|
483
|
+
minSeparation = b2Math.b2Min(minSeparation, separation);
|
484
|
+
|
485
|
+
// Prevent large corrections and allow slop.
|
486
|
+
var C = beta * b2Math.b2Clamp(separation + b2Settings.b2_linearSlop, -b2Settings.b2_maxLinearCorrection, 0.0);
|
487
|
+
|
488
|
+
// Compute normal impulse
|
489
|
+
var dImpulse = -ccp.normalMass * C;
|
490
|
+
|
491
|
+
// b2Clamp the accumulated impulse
|
492
|
+
var impulse0 = ccp.positionImpulse;
|
493
|
+
ccp.positionImpulse = b2Math.b2Max(impulse0 + dImpulse, 0.0);
|
494
|
+
dImpulse = ccp.positionImpulse - impulse0;
|
495
|
+
|
496
|
+
//var impulse = b2Math.MulFV( dImpulse, normal );
|
497
|
+
var impulseX = dImpulse * normalX;
|
498
|
+
var impulseY = dImpulse * normalY;
|
499
|
+
|
500
|
+
//b1.m_position.Subtract( b2Math.MulFV( invMass1, impulse ) );
|
501
|
+
b1_position.x -= invMass1 * impulseX;
|
502
|
+
b1_position.y -= invMass1 * impulseY;
|
503
|
+
b1_rotation -= invI1 * (r1X * impulseY - r1Y * impulseX);
|
504
|
+
b1.m_R.Set(b1_rotation);
|
505
|
+
|
506
|
+
//b2.m_position.Add( b2Math.MulFV( invMass2, impulse ) );
|
507
|
+
b2_position.x += invMass2 * impulseX;
|
508
|
+
b2_position.y += invMass2 * impulseY;
|
509
|
+
b2_rotation += invI2 * (r2X * impulseY - r2Y * impulseX);
|
510
|
+
b2.m_R.Set(b2_rotation);
|
511
|
+
}
|
512
|
+
// Update body rotations
|
513
|
+
b1.m_rotation = b1_rotation;
|
514
|
+
b2.m_rotation = b2_rotation;
|
515
|
+
}
|
516
|
+
|
517
|
+
return minSeparation >= -b2Settings.b2_linearSlop;
|
518
|
+
},
|
519
|
+
PostSolve: function(){
|
520
|
+
for (var i = 0; i < this.m_constraintCount; ++i)
|
521
|
+
{
|
522
|
+
var c = this.m_constraints[ i ];
|
523
|
+
var m = c.manifold;
|
524
|
+
|
525
|
+
for (var j = 0; j < c.pointCount; ++j)
|
526
|
+
{
|
527
|
+
var mPoint = m.points[j];
|
528
|
+
var cPoint = c.points[j];
|
529
|
+
mPoint.normalImpulse = cPoint.normalImpulse;
|
530
|
+
mPoint.tangentImpulse = cPoint.tangentImpulse;
|
531
|
+
}
|
532
|
+
}
|
533
|
+
},
|
534
|
+
|
535
|
+
m_allocator: null,
|
536
|
+
m_constraints: new Array(),
|
537
|
+
m_constraintCount: 0};
|