box2d-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,52 @@
|
|
|
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
|
+
// We use contact ids to facilitate warm starting.
|
|
22
|
+
var b2ContactID = Class.create();
|
|
23
|
+
b2ContactID.prototype =
|
|
24
|
+
{
|
|
25
|
+
initialize: function(){
|
|
26
|
+
// initialize instance variables for references
|
|
27
|
+
this.features = new Features();
|
|
28
|
+
//
|
|
29
|
+
|
|
30
|
+
this.features._m_id = this;
|
|
31
|
+
|
|
32
|
+
},
|
|
33
|
+
Set: function(id){
|
|
34
|
+
this.set_key(id._key);
|
|
35
|
+
},
|
|
36
|
+
Copy: function(){
|
|
37
|
+
var id = new b2ContactID();
|
|
38
|
+
id.set_key(this._key);
|
|
39
|
+
return id;
|
|
40
|
+
},
|
|
41
|
+
get_key: function(){
|
|
42
|
+
return this._key;
|
|
43
|
+
},
|
|
44
|
+
set_key: function(value) {
|
|
45
|
+
this._key = value;
|
|
46
|
+
this.features._referenceFace = this._key & 0x000000ff;
|
|
47
|
+
this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
|
|
48
|
+
this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
|
|
49
|
+
this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
|
|
50
|
+
},
|
|
51
|
+
features: new Features(),
|
|
52
|
+
_key: 0};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
// We use contact ids to facilitate warm starting.
|
|
22
|
+
var b2ContactPoint = Class.create();
|
|
23
|
+
b2ContactPoint.prototype =
|
|
24
|
+
{
|
|
25
|
+
position: new b2Vec2(),
|
|
26
|
+
separation: null,
|
|
27
|
+
normalImpulse: null,
|
|
28
|
+
tangentImpulse: null,
|
|
29
|
+
id: new b2ContactID(),
|
|
30
|
+
initialize: function() {
|
|
31
|
+
// initialize instance variables for references
|
|
32
|
+
this.position = new b2Vec2();
|
|
33
|
+
this.id = new b2ContactID();
|
|
34
|
+
//
|
|
35
|
+
}};
|
|
@@ -0,0 +1,333 @@
|
|
|
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 b2Distance = Class.create();
|
|
22
|
+
b2Distance.prototype =
|
|
23
|
+
{
|
|
24
|
+
|
|
25
|
+
// GJK using Voronoi regions (Christer Ericson) and region selection
|
|
26
|
+
// optimizations (Casey Muratori).
|
|
27
|
+
|
|
28
|
+
// The origin is either in the region of points[1] or in the edge region. The origin is
|
|
29
|
+
// not in region of points[0] because that is the old point.
|
|
30
|
+
|
|
31
|
+
// Possible regions:
|
|
32
|
+
// - points[2]
|
|
33
|
+
// - edge points[0]-points[2]
|
|
34
|
+
// - edge points[1]-points[2]
|
|
35
|
+
// - inside the triangle
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
initialize: function() {}};
|
|
43
|
+
b2Distance.ProcessTwo = function(p1Out, p2Out, p1s, p2s, points)
|
|
44
|
+
{
|
|
45
|
+
// If in point[1] region
|
|
46
|
+
//b2Vec2 r = -points[1];
|
|
47
|
+
var rX = -points[1].x;
|
|
48
|
+
var rY = -points[1].y;
|
|
49
|
+
//b2Vec2 d = points[1] - points[0];
|
|
50
|
+
var dX = points[0].x - points[1].x;
|
|
51
|
+
var dY = points[0].y - points[1].y;
|
|
52
|
+
//float32 length = d.Normalize();
|
|
53
|
+
var length = Math.sqrt(dX*dX + dY*dY);
|
|
54
|
+
dX /= length;
|
|
55
|
+
dY /= length;
|
|
56
|
+
|
|
57
|
+
//float32 lambda = b2Dot(r, d);
|
|
58
|
+
var lambda = rX * dX + rY * dY;
|
|
59
|
+
if (lambda <= 0.0 || length < Number.MIN_VALUE)
|
|
60
|
+
{
|
|
61
|
+
// The simplex is reduced to a point.
|
|
62
|
+
//*p1Out = p1s[1];
|
|
63
|
+
p1Out.SetV(p1s[1]);
|
|
64
|
+
//*p2Out = p2s[1];
|
|
65
|
+
p2Out.SetV(p2s[1]);
|
|
66
|
+
//p1s[0] = p1s[1];
|
|
67
|
+
p1s[0].SetV(p1s[1]);
|
|
68
|
+
//p2s[0] = p2s[1];
|
|
69
|
+
p2s[0].SetV(p2s[1]);
|
|
70
|
+
points[0].SetV(points[1]);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Else in edge region
|
|
75
|
+
lambda /= length;
|
|
76
|
+
//*p1Out = p1s[1] + lambda * (p1s[0] - p1s[1]);
|
|
77
|
+
p1Out.x = p1s[1].x + lambda * (p1s[0].x - p1s[1].x);
|
|
78
|
+
p1Out.y = p1s[1].y + lambda * (p1s[0].y - p1s[1].y);
|
|
79
|
+
//*p2Out = p2s[1] + lambda * (p2s[0] - p2s[1]);
|
|
80
|
+
p2Out.x = p2s[1].x + lambda * (p2s[0].x - p2s[1].x);
|
|
81
|
+
p2Out.y = p2s[1].y + lambda * (p2s[0].y - p2s[1].y);
|
|
82
|
+
return 2;
|
|
83
|
+
};
|
|
84
|
+
b2Distance.ProcessThree = function(p1Out, p2Out, p1s, p2s, points)
|
|
85
|
+
{
|
|
86
|
+
//b2Vec2 a = points[0];
|
|
87
|
+
var aX = points[0].x;
|
|
88
|
+
var aY = points[0].y;
|
|
89
|
+
//b2Vec2 b = points[1];
|
|
90
|
+
var bX = points[1].x;
|
|
91
|
+
var bY = points[1].y;
|
|
92
|
+
//b2Vec2 c = points[2];
|
|
93
|
+
var cX = points[2].x;
|
|
94
|
+
var cY = points[2].y;
|
|
95
|
+
|
|
96
|
+
//b2Vec2 ab = b - a;
|
|
97
|
+
var abX = bX - aX;
|
|
98
|
+
var abY = bY - aY;
|
|
99
|
+
//b2Vec2 ac = c - a;
|
|
100
|
+
var acX = cX - aX;
|
|
101
|
+
var acY = cY - aY;
|
|
102
|
+
//b2Vec2 bc = c - b;
|
|
103
|
+
var bcX = cX - bX;
|
|
104
|
+
var bcY = cY - bY;
|
|
105
|
+
|
|
106
|
+
//float32 sn = -b2Dot(a, ab), sd = b2Dot(b, ab);
|
|
107
|
+
var sn = -(aX * abX + aY * abY);
|
|
108
|
+
var sd = (bX * abX + bY * abY);
|
|
109
|
+
//float32 tn = -b2Dot(a, ac), td = b2Dot(c, ac);
|
|
110
|
+
var tn = -(aX * acX + aY * acY);
|
|
111
|
+
var td = (cX * acX + cY * acY);
|
|
112
|
+
//float32 un = -b2Dot(b, bc), ud = b2Dot(c, bc);
|
|
113
|
+
var un = -(bX * bcX + bY * bcY);
|
|
114
|
+
var ud = (cX * bcX + cY * bcY);
|
|
115
|
+
|
|
116
|
+
// In vertex c region?
|
|
117
|
+
if (td <= 0.0 && ud <= 0.0)
|
|
118
|
+
{
|
|
119
|
+
// Single point
|
|
120
|
+
//*p1Out = p1s[2];
|
|
121
|
+
p1Out.SetV(p1s[2]);
|
|
122
|
+
//*p2Out = p2s[2];
|
|
123
|
+
p2Out.SetV(p2s[2]);
|
|
124
|
+
//p1s[0] = p1s[2];
|
|
125
|
+
p1s[0].SetV(p1s[2]);
|
|
126
|
+
//p2s[0] = p2s[2];
|
|
127
|
+
p2s[0].SetV(p2s[2]);
|
|
128
|
+
points[0].SetV(points[2]);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Should not be in vertex a or b region.
|
|
133
|
+
//b2Settings.b2Assert(sn > 0.0 || tn > 0.0);
|
|
134
|
+
//b2Settings.b2Assert(sd > 0.0 || un > 0.0);
|
|
135
|
+
|
|
136
|
+
//float32 n = b2Cross(ab, ac);
|
|
137
|
+
var n = abX * acY - abY * acX;
|
|
138
|
+
|
|
139
|
+
// Should not be in edge ab region.
|
|
140
|
+
//float32 vc = n * b2Cross(a, b);
|
|
141
|
+
var vc = n * (aX * bY - aY * bX);
|
|
142
|
+
//b2Settings.b2Assert(vc > 0.0 || sn > 0.0 || sd > 0.0);
|
|
143
|
+
|
|
144
|
+
// In edge bc region?
|
|
145
|
+
//float32 va = n * b2Cross(b, c);
|
|
146
|
+
var va = n * (bX * cY - bY * cX);
|
|
147
|
+
if (va <= 0.0 && un >= 0.0 && ud >= 0.0)
|
|
148
|
+
{
|
|
149
|
+
//b2Settings.b2Assert(un + ud > 0.0);
|
|
150
|
+
|
|
151
|
+
//float32 lambda = un / (un + ud);
|
|
152
|
+
var lambda = un / (un + ud);
|
|
153
|
+
//*p1Out = p1s[1] + lambda * (p1s[2] - p1s[1]);
|
|
154
|
+
p1Out.x = p1s[1].x + lambda * (p1s[2].x - p1s[1].x);
|
|
155
|
+
p1Out.y = p1s[1].y + lambda * (p1s[2].y - p1s[1].y);
|
|
156
|
+
//*p2Out = p2s[1] + lambda * (p2s[2] - p2s[1]);
|
|
157
|
+
p2Out.x = p2s[1].x + lambda * (p2s[2].x - p2s[1].x);
|
|
158
|
+
p2Out.y = p2s[1].y + lambda * (p2s[2].y - p2s[1].y);
|
|
159
|
+
//p1s[0] = p1s[2];
|
|
160
|
+
p1s[0].SetV(p1s[2]);
|
|
161
|
+
//p2s[0] = p2s[2];
|
|
162
|
+
p2s[0].SetV(p2s[2]);
|
|
163
|
+
//points[0] = points[2];
|
|
164
|
+
points[0].SetV(points[2]);
|
|
165
|
+
return 2;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// In edge ac region?
|
|
169
|
+
//float32 vb = n * b2Cross(c, a);
|
|
170
|
+
var vb = n * (cX * aY - cY * aX);
|
|
171
|
+
if (vb <= 0.0 && tn >= 0.0 && td >= 0.0)
|
|
172
|
+
{
|
|
173
|
+
//b2Settings.b2Assert(tn + td > 0.0);
|
|
174
|
+
|
|
175
|
+
//float32 lambda = tn / (tn + td);
|
|
176
|
+
var lambda = tn / (tn + td);
|
|
177
|
+
//*p1Out = p1s[0] + lambda * (p1s[2] - p1s[0]);
|
|
178
|
+
p1Out.x = p1s[0].x + lambda * (p1s[2].x - p1s[0].x);
|
|
179
|
+
p1Out.y = p1s[0].y + lambda * (p1s[2].y - p1s[0].y);
|
|
180
|
+
//*p2Out = p2s[0] + lambda * (p2s[2] - p2s[0]);
|
|
181
|
+
p2Out.x = p2s[0].x + lambda * (p2s[2].x - p2s[0].x);
|
|
182
|
+
p2Out.y = p2s[0].y + lambda * (p2s[2].y - p2s[0].y);
|
|
183
|
+
//p1s[1] = p1s[2];
|
|
184
|
+
p1s[1].SetV(p1s[2]);
|
|
185
|
+
//p2s[1] = p2s[2];
|
|
186
|
+
p2s[1].SetV(p2s[2]);
|
|
187
|
+
//points[1] = points[2];
|
|
188
|
+
points[1].SetV(points[2]);
|
|
189
|
+
return 2;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Inside the triangle, compute barycentric coordinates
|
|
193
|
+
//float32 denom = va + vb + vc;
|
|
194
|
+
var denom = va + vb + vc;
|
|
195
|
+
//b2Settings.b2Assert(denom > 0.0);
|
|
196
|
+
denom = 1.0 / denom;
|
|
197
|
+
//float32 u = va * denom;
|
|
198
|
+
var u = va * denom;
|
|
199
|
+
//float32 v = vb * denom;
|
|
200
|
+
var v = vb * denom;
|
|
201
|
+
//float32 w = 1.0f - u - v;
|
|
202
|
+
var w = 1.0 - u - v;
|
|
203
|
+
//*p1Out = u * p1s[0] + v * p1s[1] + w * p1s[2];
|
|
204
|
+
p1Out.x = u * p1s[0].x + v * p1s[1].x + w * p1s[2].x;
|
|
205
|
+
p1Out.y = u * p1s[0].y + v * p1s[1].y + w * p1s[2].y;
|
|
206
|
+
//*p2Out = u * p2s[0] + v * p2s[1] + w * p2s[2];
|
|
207
|
+
p2Out.x = u * p2s[0].x + v * p2s[1].x + w * p2s[2].x;
|
|
208
|
+
p2Out.y = u * p2s[0].y + v * p2s[1].y + w * p2s[2].y;
|
|
209
|
+
return 3;
|
|
210
|
+
};
|
|
211
|
+
b2Distance.InPoinsts = function(w, points, pointCount)
|
|
212
|
+
{
|
|
213
|
+
for (var i = 0; i < pointCount; ++i)
|
|
214
|
+
{
|
|
215
|
+
if (w.x == points[i].x && w.y == points[i].y)
|
|
216
|
+
{
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return false;
|
|
222
|
+
};
|
|
223
|
+
b2Distance.Distance = function(p1Out, p2Out, shape1, shape2)
|
|
224
|
+
{
|
|
225
|
+
//b2Vec2 p1s[3], p2s[3];
|
|
226
|
+
var p1s = new Array(3);
|
|
227
|
+
var p2s = new Array(3);
|
|
228
|
+
//b2Vec2 points[3];
|
|
229
|
+
var points = new Array(3);
|
|
230
|
+
//int32 pointCount = 0;
|
|
231
|
+
var pointCount = 0;
|
|
232
|
+
|
|
233
|
+
//*p1Out = shape1->m_position;
|
|
234
|
+
p1Out.SetV(shape1.m_position);
|
|
235
|
+
//*p2Out = shape2->m_position;
|
|
236
|
+
p2Out.SetV(shape2.m_position);
|
|
237
|
+
|
|
238
|
+
var vSqr = 0.0;
|
|
239
|
+
var maxIterations = 20;
|
|
240
|
+
for (var iter = 0; iter < maxIterations; ++iter)
|
|
241
|
+
{
|
|
242
|
+
//b2Vec2 v = *p2Out - *p1Out;
|
|
243
|
+
var vX = p2Out.x - p1Out.x;
|
|
244
|
+
var vY = p2Out.y - p1Out.y;
|
|
245
|
+
//b2Vec2 w1 = shape1->Support(v);
|
|
246
|
+
var w1 = shape1.Support(vX, vY);
|
|
247
|
+
//b2Vec2 w2 = shape2->Support(-v);
|
|
248
|
+
var w2 = shape2.Support(-vX, -vY);
|
|
249
|
+
//float32 vSqr = b2Dot(v, v);
|
|
250
|
+
vSqr = (vX*vX + vY*vY);
|
|
251
|
+
//b2Vec2 w = w2 - w1;
|
|
252
|
+
var wX = w2.x - w1.x;
|
|
253
|
+
var wY = w2.y - w1.y;
|
|
254
|
+
//float32 vw = b2Dot(v, w);
|
|
255
|
+
var vw = (vX*wX + vY*wY);
|
|
256
|
+
//if (vSqr - b2Dot(v, w) <= 0.01f * vSqr)
|
|
257
|
+
if (vSqr - b2Dot(vX * wX + vY * wY) <= 0.01 * vSqr)
|
|
258
|
+
{
|
|
259
|
+
if (pointCount == 0)
|
|
260
|
+
{
|
|
261
|
+
//*p1Out = w1;
|
|
262
|
+
p1Out.SetV(w1);
|
|
263
|
+
//*p2Out = w2;
|
|
264
|
+
p2Out.SetV(w2);
|
|
265
|
+
}
|
|
266
|
+
b2Distance.g_GJK_Iterations = iter;
|
|
267
|
+
return Math.sqrt(vSqr);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
switch (pointCount)
|
|
271
|
+
{
|
|
272
|
+
case 0:
|
|
273
|
+
//p1s[0] = w1;
|
|
274
|
+
p1s[0].SetV(w1);
|
|
275
|
+
//p2s[0] = w2;
|
|
276
|
+
p2s[0].SetV(w2);
|
|
277
|
+
points[0] = w;
|
|
278
|
+
//*p1Out = p1s[0];
|
|
279
|
+
p1Out.SetV(p1s[0]);
|
|
280
|
+
//*p2Out = p2s[0];
|
|
281
|
+
p2Out.SetV(p2s[0]);
|
|
282
|
+
++pointCount;
|
|
283
|
+
break;
|
|
284
|
+
|
|
285
|
+
case 1:
|
|
286
|
+
//p1s[1] = w1;
|
|
287
|
+
p1s[1].SetV(w1);
|
|
288
|
+
//p2s[1] = w2;
|
|
289
|
+
p2s[1].SetV(w2);
|
|
290
|
+
//points[1] = w;
|
|
291
|
+
points[1].x = wX;
|
|
292
|
+
points[1].y = wY;
|
|
293
|
+
pointCount = b2Distance.ProcessTwo(p1Out, p2Out, p1s, p2s, points);
|
|
294
|
+
break;
|
|
295
|
+
|
|
296
|
+
case 2:
|
|
297
|
+
//p1s[2] = w1;
|
|
298
|
+
p1s[2].SetV(w1);
|
|
299
|
+
//p2s[2] = w2;
|
|
300
|
+
p2s[2].SetV(w2);
|
|
301
|
+
//points[2] = w;
|
|
302
|
+
points[2].x = wX;
|
|
303
|
+
points[2].y = wY;
|
|
304
|
+
pointCount = b2Distance.ProcessThree(p1Out, p2Out, p1s, p2s, points);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// If we have three points, then the origin is in the corresponding triangle.
|
|
309
|
+
if (pointCount == 3)
|
|
310
|
+
{
|
|
311
|
+
b2Distance.g_GJK_Iterations = iter;
|
|
312
|
+
return 0.0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
//float32 maxSqr = -FLT_MAX;
|
|
316
|
+
var maxSqr = -Number.MAX_VALUE;
|
|
317
|
+
for (var i = 0; i < pointCount; ++i)
|
|
318
|
+
{
|
|
319
|
+
//maxSqr = b2Math.b2Max(maxSqr, b2Dot(points[i], points[i]));
|
|
320
|
+
maxSqr = b2Math.b2Max(maxSqr, (points[i].x*points[i].x + points[i].y*points[i].y));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (pointCount == 3 || vSqr <= 100.0 * Number.MIN_VALUE * maxSqr)
|
|
324
|
+
{
|
|
325
|
+
b2Distance.g_GJK_Iterations = iter;
|
|
326
|
+
return Math.sqrt(vSqr);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
b2Distance.g_GJK_Iterations = maxIterations;
|
|
331
|
+
return Math.sqrt(vSqr);
|
|
332
|
+
};
|
|
333
|
+
b2Distance.g_GJK_Iterations = 0;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
// A manifold for two touching convex shapes.
|
|
22
|
+
var b2Manifold = Class.create();
|
|
23
|
+
b2Manifold.prototype =
|
|
24
|
+
{
|
|
25
|
+
initialize: function(){
|
|
26
|
+
this.points = new Array(b2Settings.b2_maxManifoldPoints);
|
|
27
|
+
for (var i = 0; i < b2Settings.b2_maxManifoldPoints; i++){
|
|
28
|
+
this.points[i] = new b2ContactPoint();
|
|
29
|
+
}
|
|
30
|
+
this.normal = new b2Vec2();
|
|
31
|
+
},
|
|
32
|
+
points: null,
|
|
33
|
+
normal: null,
|
|
34
|
+
pointCount: 0};
|