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,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
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
var b2WorldListener = Class.create();
|
26
|
+
b2WorldListener.prototype =
|
27
|
+
{
|
28
|
+
|
29
|
+
// If a body is destroyed, then any joints attached to it are also destroyed.
|
30
|
+
// This prevents memory leaks, but you may unexpectedly be left with an
|
31
|
+
// orphaned joint pointer.
|
32
|
+
// Box2D will notify you when a joint is implicitly destroyed.
|
33
|
+
// It is NOT called if you directly destroy a joint.
|
34
|
+
// Implement this abstract class and provide it to b2World via
|
35
|
+
// b2World::SetListener().
|
36
|
+
// DO NOT modify the Box2D world inside this callback.
|
37
|
+
NotifyJointDestroyed: function(joint){},
|
38
|
+
|
39
|
+
// This is called when a body's shape passes outside of the world boundary. If you
|
40
|
+
// override this and pass back e_destroyBody, you must nullify your copies of the
|
41
|
+
// body pointer.
|
42
|
+
NotifyBoundaryViolated: function(body)
|
43
|
+
{
|
44
|
+
//NOT_USED(body);
|
45
|
+
return b2WorldListener.b2_freezeBody;
|
46
|
+
},
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
initialize: function() {}};
|
51
|
+
b2WorldListener.b2_freezeBody = 0;
|
52
|
+
b2WorldListener.b2_destroyBody = 1;
|
@@ -0,0 +1,102 @@
|
|
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
|
+
var b2CircleContact = Class.create();
|
23
|
+
Object.extend(b2CircleContact.prototype, b2Contact.prototype);
|
24
|
+
Object.extend(b2CircleContact.prototype,
|
25
|
+
{
|
26
|
+
|
27
|
+
initialize: function(s1, s2) {
|
28
|
+
// The constructor for b2Contact
|
29
|
+
// initialize instance variables for references
|
30
|
+
this.m_node1 = new b2ContactNode();
|
31
|
+
this.m_node2 = new b2ContactNode();
|
32
|
+
//
|
33
|
+
this.m_flags = 0;
|
34
|
+
|
35
|
+
if (!s1 || !s2){
|
36
|
+
this.m_shape1 = null;
|
37
|
+
this.m_shape2 = null;
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
this.m_shape1 = s1;
|
42
|
+
this.m_shape2 = s2;
|
43
|
+
|
44
|
+
this.m_manifoldCount = 0;
|
45
|
+
|
46
|
+
this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction);
|
47
|
+
this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution);
|
48
|
+
|
49
|
+
this.m_prev = null;
|
50
|
+
this.m_next = null;
|
51
|
+
|
52
|
+
this.m_node1.contact = null;
|
53
|
+
this.m_node1.prev = null;
|
54
|
+
this.m_node1.next = null;
|
55
|
+
this.m_node1.other = null;
|
56
|
+
|
57
|
+
this.m_node2.contact = null;
|
58
|
+
this.m_node2.prev = null;
|
59
|
+
this.m_node2.next = null;
|
60
|
+
this.m_node2.other = null;
|
61
|
+
//
|
62
|
+
|
63
|
+
// initialize instance variables for references
|
64
|
+
this.m_manifold = [new b2Manifold()];
|
65
|
+
//
|
66
|
+
|
67
|
+
//super(shape1, shape2);
|
68
|
+
|
69
|
+
//b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_circleShape);
|
70
|
+
//b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_circleShape);
|
71
|
+
this.m_manifold[0].pointCount = 0;
|
72
|
+
this.m_manifold[0].points[0].normalImpulse = 0.0;
|
73
|
+
this.m_manifold[0].points[0].tangentImpulse = 0.0;
|
74
|
+
},
|
75
|
+
//~b2CircleContact() {}
|
76
|
+
|
77
|
+
Evaluate: function(){
|
78
|
+
b2Collision.b2CollideCircle(this.m_manifold[0], this.m_shape1, this.m_shape2, false);
|
79
|
+
|
80
|
+
if (this.m_manifold[0].pointCount > 0)
|
81
|
+
{
|
82
|
+
this.m_manifoldCount = 1;
|
83
|
+
}
|
84
|
+
else
|
85
|
+
{
|
86
|
+
this.m_manifoldCount = 0;
|
87
|
+
}
|
88
|
+
},
|
89
|
+
|
90
|
+
GetManifolds: function()
|
91
|
+
{
|
92
|
+
return this.m_manifold;
|
93
|
+
},
|
94
|
+
|
95
|
+
m_manifold: [new b2Manifold()]});
|
96
|
+
|
97
|
+
b2CircleContact.Create = function(shape1, shape2, allocator){
|
98
|
+
return new b2CircleContact(shape1, shape2);
|
99
|
+
};
|
100
|
+
b2CircleContact.Destroy = function(contact, allocator){
|
101
|
+
//
|
102
|
+
};
|
@@ -0,0 +1,228 @@
|
|
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 b2Conservative = Class.create();
|
24
|
+
b2Conservative.prototype = {
|
25
|
+
|
26
|
+
// Temp vars
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
initialize: function() {}}
|
31
|
+
b2Conservative.R1 = new b2Mat22();
|
32
|
+
b2Conservative.R2 = new b2Mat22();
|
33
|
+
b2Conservative.x1 = new b2Vec2();
|
34
|
+
b2Conservative.x2 = new b2Vec2();
|
35
|
+
b2Conservative.Conservative = function(shape1, shape2){
|
36
|
+
var body1 = shape1.GetBody();
|
37
|
+
var body2 = shape2.GetBody();
|
38
|
+
|
39
|
+
//b2Vec2 v1 = body1->m_position - body1->m_position0;
|
40
|
+
var v1X = body1.m_position.x - body1.m_position0.x;
|
41
|
+
var v1Y = body1.m_position.y - body1.m_position0.y;
|
42
|
+
//float32 omega1 = body1->m_rotation - body1->m_rotation0;
|
43
|
+
var omega1 = body1.m_rotation - body1.m_rotation0;
|
44
|
+
//b2Vec2 v2 = body2->m_position - body2->m_position0;
|
45
|
+
var v2X = body2.m_position.x - body2.m_position0.x;
|
46
|
+
var v2Y = body2.m_position.y - body2.m_position0.y;
|
47
|
+
//float32 omega2 = body2->m_rotation - body2->m_rotation0;
|
48
|
+
var omega2 = body2.m_rotation - body2.m_rotation0;
|
49
|
+
|
50
|
+
//float32 r1 = shape1->GetMaxRadius();
|
51
|
+
var r1 = shape1.GetMaxRadius();
|
52
|
+
//float32 r2 = shape2->GetMaxRadius();
|
53
|
+
var r2 = shape2.GetMaxRadius();
|
54
|
+
|
55
|
+
//b2Vec2 p1Start = body1->m_position0;
|
56
|
+
var p1StartX = body1.m_position0.x;
|
57
|
+
var p1StartY = body1.m_position0.y;
|
58
|
+
//float32 a1Start = body1->m_rotation0;
|
59
|
+
var a1Start = body1.m_rotation0;
|
60
|
+
|
61
|
+
//b2Vec2 p2Start = body2->m_position0;
|
62
|
+
var p2StartX = body2.m_position0.x;
|
63
|
+
var p2StartY = body2.m_position0.y;
|
64
|
+
//float32 a2Start = body2->m_rotation0;
|
65
|
+
var a2Start = body2.m_rotation0;
|
66
|
+
|
67
|
+
//b2Vec2 p1 = p1Start;
|
68
|
+
var p1X = p1StartX;
|
69
|
+
var p1Y = p1StartY;
|
70
|
+
//float32 a1 = a1Start;
|
71
|
+
var a1 = a1Start;
|
72
|
+
//b2Vec2 p2 = p2Start;
|
73
|
+
var p2X = p2StartX;
|
74
|
+
var p2Y = p2StartY;
|
75
|
+
//float32 a2 = a2Start;
|
76
|
+
var a2 = a2Start;
|
77
|
+
|
78
|
+
//b2Mat22 b2Conservative.R1(a1), b2Conservative.R2(a2);
|
79
|
+
b2Conservative.R1.Set(a1);
|
80
|
+
b2Conservative.R2.Set(a2);
|
81
|
+
|
82
|
+
//shape1->QuickSync(p1, b2Conservative.R1);
|
83
|
+
shape1.QuickSync(p1, b2Conservative.R1);
|
84
|
+
//shape2->QuickSync(p2, b2Conservative.R2);
|
85
|
+
shape2.QuickSync(p2, b2Conservative.R2);
|
86
|
+
|
87
|
+
//float32 s1 = 0.0f;
|
88
|
+
var s1 = 0.0;
|
89
|
+
//const int32 maxIterations = 10;
|
90
|
+
var maxIterations = 10;
|
91
|
+
//b2Vec2 d;
|
92
|
+
var dX;
|
93
|
+
var dY;
|
94
|
+
//float32 invRelativeVelocity = 0.0f;
|
95
|
+
var invRelativeVelocity = 0.0;
|
96
|
+
//bool hit = true;
|
97
|
+
var hit = true;
|
98
|
+
//b2Vec2 b2Conservative.x1, b2Conservative.x2; moved to static var
|
99
|
+
for (var iter = 0; iter < maxIterations; ++iter)
|
100
|
+
{
|
101
|
+
// Get the accurate distance between shapes.
|
102
|
+
//float32 distance = b2Distance.Distance(&b2Conservative.x1, &b2Conservative.x2, shape1, shape2);
|
103
|
+
var distance = b2Distance.Distance(b2Conservative.x1, b2Conservative.x2, shape1, shape2);
|
104
|
+
if (distance < b2Settings.b2_linearSlop)
|
105
|
+
{
|
106
|
+
if (iter == 0)
|
107
|
+
{
|
108
|
+
hit = false;
|
109
|
+
}
|
110
|
+
else
|
111
|
+
{
|
112
|
+
hit = true;
|
113
|
+
}
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
|
117
|
+
if (iter == 0)
|
118
|
+
{
|
119
|
+
//b2Vec2 d = b2Conservative.x2 - b2Conservative.x1;
|
120
|
+
dX = b2Conservative.x2.x - b2Conservative.x1.x;
|
121
|
+
dY = b2Conservative.x2.y - b2Conservative.x1.y;
|
122
|
+
//d.Normalize();
|
123
|
+
var dLen = Math.sqrt(dX*dX + dY*dY);
|
124
|
+
//float32 relativeVelocity = b2Dot(d, v1 - v2) + b2Abs(omega1) * r1 + b2Abs(omega2) * r2;
|
125
|
+
var relativeVelocity = (dX*(v1X-v2X) + dY*(v1Y - v2Y)) + Math.abs(omega1) * r1 + Math.abs(omega2) * r2;
|
126
|
+
if (Math.abs(relativeVelocity) < Number.MIN_VALUE)
|
127
|
+
{
|
128
|
+
hit = false;
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
|
132
|
+
invRelativeVelocity = 1.0 / relativeVelocity;
|
133
|
+
}
|
134
|
+
|
135
|
+
// Get the conservative movement.
|
136
|
+
//float32 ds = distance * invRelativeVelocity;
|
137
|
+
var ds = distance * invRelativeVelocity;
|
138
|
+
//float32 s2 = s1 + ds;
|
139
|
+
var s2 = s1 + ds;
|
140
|
+
|
141
|
+
if (s2 < 0.0 || 1.0 < s2)
|
142
|
+
{
|
143
|
+
hit = false;
|
144
|
+
break;
|
145
|
+
}
|
146
|
+
|
147
|
+
if (s2 < (1.0 + 100.0 * Number.MIN_VALUE) * s1)
|
148
|
+
{
|
149
|
+
hit = true;
|
150
|
+
break;
|
151
|
+
}
|
152
|
+
|
153
|
+
s1 = s2;
|
154
|
+
|
155
|
+
// Move forward conservatively.
|
156
|
+
//p1 = p1Start + s1 * v1;
|
157
|
+
p1X = p1StartX + s1 * v1.x;
|
158
|
+
p1Y = p1StartY + s1 * v1.y;
|
159
|
+
//a1 = a1Start + s1 * omega1;
|
160
|
+
a1 = a1Start + s1 * omega1;
|
161
|
+
//p2 = p2Start + s1 * v2;
|
162
|
+
p2X = p2StartX + s1 * v2.x;
|
163
|
+
p2Y = p2StartY + s1 * v2.y;
|
164
|
+
//a2 = a2Start + s1 * omega2;
|
165
|
+
a2 = a2Start + s1 * omega2;
|
166
|
+
|
167
|
+
b2Conservative.R1.Set(a1);
|
168
|
+
b2Conservative.R2.Set(a2);
|
169
|
+
shape1.QuickSync(p1, b2Conservative.R1);
|
170
|
+
shape2.QuickSync(p2, b2Conservative.R2);
|
171
|
+
}
|
172
|
+
|
173
|
+
if (hit)
|
174
|
+
{
|
175
|
+
// Hit, move bodies to safe position and re-sync shapes.
|
176
|
+
//b2Vec2 d = b2Conservative.x2 - b2Conservative.x1;
|
177
|
+
dX = b2Conservative.x2.x - b2Conservative.x1.x;
|
178
|
+
dY = b2Conservative.x2.y - b2Conservative.x1.y;
|
179
|
+
//float32 length = d.Length();
|
180
|
+
var length = Math.sqrt(dX*dX + dY*dY);
|
181
|
+
if (length > FLT_EPSILON)
|
182
|
+
{
|
183
|
+
d *= b2_linearSlop / length;
|
184
|
+
}
|
185
|
+
|
186
|
+
if (body1.IsStatic())
|
187
|
+
{
|
188
|
+
//body1.m_position = p1;
|
189
|
+
body1.m_position.x = p1X;
|
190
|
+
body1.m_position.y = p1Y;
|
191
|
+
}
|
192
|
+
else
|
193
|
+
{
|
194
|
+
//body1.m_position = p1 - d;
|
195
|
+
body1.m_position.x = p1X - dX;
|
196
|
+
body1.m_position.y = p1Y - dY;
|
197
|
+
}
|
198
|
+
body1.m_rotation = a1;
|
199
|
+
body1.m_R.Set(a1);
|
200
|
+
body1.QuickSyncShapes();
|
201
|
+
|
202
|
+
if (body2.IsStatic())
|
203
|
+
{
|
204
|
+
//body2->m_position = p2;
|
205
|
+
body2.m_position.x = p2X;
|
206
|
+
body2.m_position.y = p2Y;
|
207
|
+
}
|
208
|
+
else
|
209
|
+
{
|
210
|
+
//body2->m_position = p2 + d;
|
211
|
+
body2.m_position.x = p2X + dX;
|
212
|
+
body2.m_position.y = p2Y + dY;
|
213
|
+
}
|
214
|
+
//body2.m_position = p2 + d;
|
215
|
+
body2.m_position.x = p2X + dX;
|
216
|
+
body2.m_position.y = p2Y + dY;
|
217
|
+
body2.m_rotation = a2;
|
218
|
+
body2.m_R.Set(a2);
|
219
|
+
body2.QuickSyncShapes();
|
220
|
+
|
221
|
+
return true;
|
222
|
+
}
|
223
|
+
|
224
|
+
// No hit, restore shapes.
|
225
|
+
shape1.QuickSync(body1.m_position, body1.m_R);
|
226
|
+
shape2.QuickSync(body2.m_position, body2.m_R);
|
227
|
+
return false;
|
228
|
+
};
|
@@ -0,0 +1,201 @@
|
|
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
|
+
//typedef b2Contact* b2ContactCreateFcn(b2Shape* shape1, b2Shape* shape2, b2BlockAllocator* allocator);
|
24
|
+
//typedef void b2ContactDestroyFcn(b2Contact* contact, b2BlockAllocator* allocator);
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
var b2Contact = Class.create();
|
29
|
+
b2Contact.prototype =
|
30
|
+
{
|
31
|
+
GetManifolds: function(){return null},
|
32
|
+
GetManifoldCount: function()
|
33
|
+
{
|
34
|
+
return this.m_manifoldCount;
|
35
|
+
},
|
36
|
+
|
37
|
+
GetNext: function(){
|
38
|
+
return this.m_next;
|
39
|
+
},
|
40
|
+
|
41
|
+
GetShape1: function(){
|
42
|
+
return this.m_shape1;
|
43
|
+
},
|
44
|
+
|
45
|
+
GetShape2: function(){
|
46
|
+
return this.m_shape2;
|
47
|
+
},
|
48
|
+
|
49
|
+
//--------------- Internals Below -------------------
|
50
|
+
|
51
|
+
// this.m_flags
|
52
|
+
// enum
|
53
|
+
|
54
|
+
|
55
|
+
initialize: function(s1, s2)
|
56
|
+
{
|
57
|
+
// initialize instance variables for references
|
58
|
+
this.m_node1 = new b2ContactNode();
|
59
|
+
this.m_node2 = new b2ContactNode();
|
60
|
+
//
|
61
|
+
|
62
|
+
this.m_flags = 0;
|
63
|
+
|
64
|
+
if (!s1 || !s2){
|
65
|
+
this.m_shape1 = null;
|
66
|
+
this.m_shape2 = null;
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
|
70
|
+
this.m_shape1 = s1;
|
71
|
+
this.m_shape2 = s2;
|
72
|
+
|
73
|
+
this.m_manifoldCount = 0;
|
74
|
+
|
75
|
+
this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction);
|
76
|
+
this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution);
|
77
|
+
|
78
|
+
this.m_prev = null;
|
79
|
+
this.m_next = null;
|
80
|
+
|
81
|
+
this.m_node1.contact = null;
|
82
|
+
this.m_node1.prev = null;
|
83
|
+
this.m_node1.next = null;
|
84
|
+
this.m_node1.other = null;
|
85
|
+
|
86
|
+
this.m_node2.contact = null;
|
87
|
+
this.m_node2.prev = null;
|
88
|
+
this.m_node2.next = null;
|
89
|
+
this.m_node2.other = null;
|
90
|
+
},
|
91
|
+
|
92
|
+
//virtual ~b2Contact() {}
|
93
|
+
|
94
|
+
Evaluate: function(){},
|
95
|
+
|
96
|
+
m_flags: 0,
|
97
|
+
|
98
|
+
// World pool and list pointers.
|
99
|
+
m_prev: null,
|
100
|
+
m_next: null,
|
101
|
+
|
102
|
+
// Nodes for connecting bodies.
|
103
|
+
m_node1: new b2ContactNode(),
|
104
|
+
m_node2: new b2ContactNode(),
|
105
|
+
|
106
|
+
m_shape1: null,
|
107
|
+
m_shape2: null,
|
108
|
+
|
109
|
+
m_manifoldCount: 0,
|
110
|
+
|
111
|
+
// Combined friction
|
112
|
+
m_friction: null,
|
113
|
+
m_restitution: null};
|
114
|
+
b2Contact.e_islandFlag = 0x0001;
|
115
|
+
b2Contact.e_destroyFlag = 0x0002;
|
116
|
+
b2Contact.AddType = function(createFcn, destroyFcn, type1, type2)
|
117
|
+
{
|
118
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type1 && type1 < b2Shape.e_shapeTypeCount);
|
119
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type2 && type2 < b2Shape.e_shapeTypeCount);
|
120
|
+
|
121
|
+
b2Contact.s_registers[type1][type2].createFcn = createFcn;
|
122
|
+
b2Contact.s_registers[type1][type2].destroyFcn = destroyFcn;
|
123
|
+
b2Contact.s_registers[type1][type2].primary = true;
|
124
|
+
|
125
|
+
if (type1 != type2)
|
126
|
+
{
|
127
|
+
b2Contact.s_registers[type2][type1].createFcn = createFcn;
|
128
|
+
b2Contact.s_registers[type2][type1].destroyFcn = destroyFcn;
|
129
|
+
b2Contact.s_registers[type2][type1].primary = false;
|
130
|
+
}
|
131
|
+
};
|
132
|
+
b2Contact.InitializeRegisters = function(){
|
133
|
+
b2Contact.s_registers = new Array(b2Shape.e_shapeTypeCount);
|
134
|
+
for (var i = 0; i < b2Shape.e_shapeTypeCount; i++){
|
135
|
+
b2Contact.s_registers[i] = new Array(b2Shape.e_shapeTypeCount);
|
136
|
+
for (var j = 0; j < b2Shape.e_shapeTypeCount; j++){
|
137
|
+
b2Contact.s_registers[i][j] = new b2ContactRegister();
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
b2Contact.AddType(b2CircleContact.Create, b2CircleContact.Destroy, b2Shape.e_circleShape, b2Shape.e_circleShape);
|
142
|
+
b2Contact.AddType(b2PolyAndCircleContact.Create, b2PolyAndCircleContact.Destroy, b2Shape.e_polyShape, b2Shape.e_circleShape);
|
143
|
+
b2Contact.AddType(b2PolyContact.Create, b2PolyContact.Destroy, b2Shape.e_polyShape, b2Shape.e_polyShape);
|
144
|
+
|
145
|
+
};
|
146
|
+
b2Contact.Create = function(shape1, shape2, allocator){
|
147
|
+
if (b2Contact.s_initialized == false)
|
148
|
+
{
|
149
|
+
b2Contact.InitializeRegisters();
|
150
|
+
b2Contact.s_initialized = true;
|
151
|
+
}
|
152
|
+
|
153
|
+
var type1 = shape1.m_type;
|
154
|
+
var type2 = shape2.m_type;
|
155
|
+
|
156
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type1 && type1 < b2Shape.e_shapeTypeCount);
|
157
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type2 && type2 < b2Shape.e_shapeTypeCount);
|
158
|
+
|
159
|
+
var createFcn = b2Contact.s_registers[type1][type2].createFcn;
|
160
|
+
if (createFcn)
|
161
|
+
{
|
162
|
+
if (b2Contact.s_registers[type1][type2].primary)
|
163
|
+
{
|
164
|
+
return createFcn(shape1, shape2, allocator);
|
165
|
+
}
|
166
|
+
else
|
167
|
+
{
|
168
|
+
var c = createFcn(shape2, shape1, allocator);
|
169
|
+
for (var i = 0; i < c.GetManifoldCount(); ++i)
|
170
|
+
{
|
171
|
+
var m = c.GetManifolds()[ i ];
|
172
|
+
m.normal = m.normal.Negative();
|
173
|
+
}
|
174
|
+
return c;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
else
|
178
|
+
{
|
179
|
+
return null;
|
180
|
+
}
|
181
|
+
};
|
182
|
+
b2Contact.Destroy = function(contact, allocator){
|
183
|
+
//b2Settings.b2Assert(b2Contact.s_initialized == true);
|
184
|
+
|
185
|
+
if (contact.GetManifoldCount() > 0)
|
186
|
+
{
|
187
|
+
contact.m_shape1.m_body.WakeUp();
|
188
|
+
contact.m_shape2.m_body.WakeUp();
|
189
|
+
}
|
190
|
+
|
191
|
+
var type1 = contact.m_shape1.m_type;
|
192
|
+
var type2 = contact.m_shape2.m_type;
|
193
|
+
|
194
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type1 && type1 < b2Shape.e_shapeTypeCount);
|
195
|
+
//b2Settings.b2Assert(b2Shape.e_unknownShape < type2 && type2 < b2Shape.e_shapeTypeCount);
|
196
|
+
|
197
|
+
var destroyFcn = b2Contact.s_registers[type1][type2].destroyFcn;
|
198
|
+
destroyFcn(contact, allocator);
|
199
|
+
};
|
200
|
+
b2Contact.s_registers = null;
|
201
|
+
b2Contact.s_initialized = false;
|