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,339 @@
|
|
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
|
+
|
26
|
+
// Shapes are created automatically when a body is created.
|
27
|
+
// Client code does not normally interact with shapes.
|
28
|
+
var b2Shape = Class.create();
|
29
|
+
b2Shape.prototype =
|
30
|
+
{
|
31
|
+
TestPoint: function(p){return false},
|
32
|
+
|
33
|
+
GetUserData: function(){return this.m_userData;},
|
34
|
+
|
35
|
+
GetType: function(){
|
36
|
+
return this.m_type;
|
37
|
+
},
|
38
|
+
|
39
|
+
// Get the parent body of this shape.
|
40
|
+
GetBody: function(){
|
41
|
+
return this.m_body;
|
42
|
+
},
|
43
|
+
|
44
|
+
GetPosition: function(){
|
45
|
+
return this.m_position;
|
46
|
+
},
|
47
|
+
GetRotationMatrix: function(){
|
48
|
+
return this.m_R;
|
49
|
+
},
|
50
|
+
|
51
|
+
// Remove and then add proxy from the broad-phase.
|
52
|
+
// This is used to refresh the collision filters.
|
53
|
+
ResetProxy: function(broadPhase){},
|
54
|
+
|
55
|
+
// Get the next shape in the parent body's shape list.
|
56
|
+
GetNext: function(){
|
57
|
+
return this.m_next;
|
58
|
+
},
|
59
|
+
|
60
|
+
//--------------- Internals Below -------------------
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
initialize: function(def, body){
|
66
|
+
// initialize instance variables for references
|
67
|
+
this.m_R = new b2Mat22();
|
68
|
+
this.m_position = new b2Vec2();
|
69
|
+
//
|
70
|
+
|
71
|
+
this.m_userData = def.userData;
|
72
|
+
|
73
|
+
this.m_friction = def.friction;
|
74
|
+
this.m_restitution = def.restitution;
|
75
|
+
this.m_body = body;
|
76
|
+
|
77
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
78
|
+
|
79
|
+
this.m_maxRadius = 0.0;
|
80
|
+
|
81
|
+
this.m_categoryBits = def.categoryBits;
|
82
|
+
this.m_maskBits = def.maskBits;
|
83
|
+
this.m_groupIndex = def.groupIndex;
|
84
|
+
},
|
85
|
+
|
86
|
+
// Internal use only. Do not call.
|
87
|
+
//b2Shape::~b2Shape()
|
88
|
+
//{
|
89
|
+
// this.m_body->m_world->m_broadPhase->this.DestroyProxy(this.m_proxyId);
|
90
|
+
//}
|
91
|
+
|
92
|
+
|
93
|
+
DestroyProxy: function()
|
94
|
+
{
|
95
|
+
if (this.m_proxyId != b2Pair.b2_nullProxy)
|
96
|
+
{
|
97
|
+
this.m_body.m_world.m_broadPhase.DestroyProxy(this.m_proxyId);
|
98
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
99
|
+
}
|
100
|
+
},
|
101
|
+
|
102
|
+
|
103
|
+
// Internal use only. Do not call.
|
104
|
+
Synchronize: function(position1, R1, position2, R2){},
|
105
|
+
QuickSync: function(position, R){},
|
106
|
+
Support: function(dX, dY, out){},
|
107
|
+
GetMaxRadius: function(){
|
108
|
+
return this.m_maxRadius;
|
109
|
+
},
|
110
|
+
|
111
|
+
m_next: null,
|
112
|
+
|
113
|
+
m_R: new b2Mat22(),
|
114
|
+
m_position: new b2Vec2(),
|
115
|
+
|
116
|
+
m_type: 0,
|
117
|
+
|
118
|
+
m_userData: null,
|
119
|
+
|
120
|
+
m_body: null,
|
121
|
+
|
122
|
+
m_friction: null,
|
123
|
+
m_restitution: null,
|
124
|
+
|
125
|
+
m_maxRadius: null,
|
126
|
+
|
127
|
+
m_proxyId: 0,
|
128
|
+
m_categoryBits: 0,
|
129
|
+
m_maskBits: 0,
|
130
|
+
m_groupIndex: 0
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
// b2ShapeType
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
b2Shape.Create = function(def, body, center){
|
151
|
+
switch (def.type)
|
152
|
+
{
|
153
|
+
case b2Shape.e_circleShape:
|
154
|
+
{
|
155
|
+
//void* mem = body->m_world->m_blockAllocator.Allocate(sizeof(b2CircleShape));
|
156
|
+
return new b2CircleShape(def, body, center);
|
157
|
+
}
|
158
|
+
|
159
|
+
case b2Shape.e_boxShape:
|
160
|
+
case b2Shape.e_polyShape:
|
161
|
+
{
|
162
|
+
//void* mem = body->m_world->m_blockAllocator.Allocate(sizeof(b2PolyShape));
|
163
|
+
return new b2PolyShape(def, body, center);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
//b2Settings.b2Assert(false);
|
168
|
+
return null;
|
169
|
+
};
|
170
|
+
b2Shape.Destroy = function(shape)
|
171
|
+
{
|
172
|
+
/*b2BlockAllocator& allocator = shape->m_body->m_world->m_blockAllocator;
|
173
|
+
|
174
|
+
switch (shape.m_type)
|
175
|
+
{
|
176
|
+
case b2Shape.e_circleShape:
|
177
|
+
shape->~b2Shape();
|
178
|
+
allocator.Free(shape, sizeof(b2CircleShape));
|
179
|
+
break;
|
180
|
+
|
181
|
+
case b2Shape.e_polyShape:
|
182
|
+
shape->~b2Shape();
|
183
|
+
allocator.Free(shape, sizeof(b2PolyShape));
|
184
|
+
break;
|
185
|
+
|
186
|
+
default:
|
187
|
+
b2Assert(false);
|
188
|
+
}
|
189
|
+
|
190
|
+
shape = NULL;*/
|
191
|
+
|
192
|
+
// FROM DESTRUCTOR
|
193
|
+
if (shape.m_proxyId != b2Pair.b2_nullProxy)
|
194
|
+
shape.m_body.m_world.m_broadPhase.DestroyProxy(shape.m_proxyId);
|
195
|
+
};
|
196
|
+
b2Shape.e_unknownShape = -1;
|
197
|
+
b2Shape.e_circleShape = 0;
|
198
|
+
b2Shape.e_boxShape = 1;
|
199
|
+
b2Shape.e_polyShape = 2;
|
200
|
+
b2Shape.e_meshShape = 3;
|
201
|
+
b2Shape.e_shapeTypeCount = 4;
|
202
|
+
b2Shape.PolyMass = function(massData, vs, count, rho)
|
203
|
+
{
|
204
|
+
//b2Settings.b2Assert(count >= 3);
|
205
|
+
|
206
|
+
//var center = new b2Vec2(0.0, 0.0);
|
207
|
+
var center = new b2Vec2();
|
208
|
+
center.SetZero();
|
209
|
+
|
210
|
+
var area = 0.0;
|
211
|
+
var I = 0.0;
|
212
|
+
|
213
|
+
// pRef is the reference point for forming triangles.
|
214
|
+
// It's location doesn't change the result (except for rounding error).
|
215
|
+
var pRef = new b2Vec2(0.0, 0.0);
|
216
|
+
|
217
|
+
var inv3 = 1.0 / 3.0;
|
218
|
+
|
219
|
+
for (var i = 0; i < count; ++i)
|
220
|
+
{
|
221
|
+
// Triangle vertices.
|
222
|
+
var p1 = pRef;
|
223
|
+
var p2 = vs[i];
|
224
|
+
var p3 = i + 1 < count ? vs[i+1] : vs[0];
|
225
|
+
|
226
|
+
var e1 = b2Math.SubtractVV(p2, p1);
|
227
|
+
var e2 = b2Math.SubtractVV(p3, p1);
|
228
|
+
|
229
|
+
var D = b2Math.b2CrossVV(e1, e2);
|
230
|
+
|
231
|
+
var triangleArea = 0.5 * D;
|
232
|
+
area += triangleArea;
|
233
|
+
|
234
|
+
// Area weighted centroid
|
235
|
+
// center += triangleArea * inv3 * (p1 + p2 + p3);
|
236
|
+
var tVec = new b2Vec2();
|
237
|
+
tVec.SetV(p1);
|
238
|
+
tVec.Add(p2);
|
239
|
+
tVec.Add(p3);
|
240
|
+
tVec.Multiply(inv3*triangleArea);
|
241
|
+
center.Add(tVec);
|
242
|
+
|
243
|
+
var px = p1.x;
|
244
|
+
var py = p1.y;
|
245
|
+
var ex1 = e1.x;
|
246
|
+
var ey1 = e1.y;
|
247
|
+
var ex2 = e2.x;
|
248
|
+
var ey2 = e2.y;
|
249
|
+
|
250
|
+
var intx2 = inv3 * (0.25 * (ex1*ex1 + ex2*ex1 + ex2*ex2) + (px*ex1 + px*ex2)) + 0.5*px*px;
|
251
|
+
var inty2 = inv3 * (0.25 * (ey1*ey1 + ey2*ey1 + ey2*ey2) + (py*ey1 + py*ey2)) + 0.5*py*py;
|
252
|
+
|
253
|
+
I += D * (intx2 + inty2);
|
254
|
+
}
|
255
|
+
|
256
|
+
// Total mass
|
257
|
+
massData.mass = rho * area;
|
258
|
+
|
259
|
+
// Center of mass
|
260
|
+
//b2Settings.b2Assert(area > Number.MIN_VALUE);
|
261
|
+
center.Multiply( 1.0 / area );
|
262
|
+
massData.center = center;
|
263
|
+
|
264
|
+
// Inertia tensor relative to the center.
|
265
|
+
I = rho * (I - area * b2Math.b2Dot(center, center));
|
266
|
+
massData.I = I;
|
267
|
+
};
|
268
|
+
b2Shape.PolyCentroid = function(vs, count, out)
|
269
|
+
{
|
270
|
+
//b2Settings.b2Assert(count >= 3);
|
271
|
+
|
272
|
+
//b2Vec2 c; c.Set(0.0f, 0.0f);
|
273
|
+
var cX = 0.0;
|
274
|
+
var cY = 0.0;
|
275
|
+
//float32 area = 0.0f;
|
276
|
+
var area = 0.0;
|
277
|
+
|
278
|
+
// pRef is the reference point for forming triangles.
|
279
|
+
// It's location doesn't change the result (except for rounding error).
|
280
|
+
//b2Vec2 pRef(0.0f, 0.0f);
|
281
|
+
var pRefX = 0.0;
|
282
|
+
var pRefY = 0.0;
|
283
|
+
/*
|
284
|
+
// This code would put the reference point inside the polygon.
|
285
|
+
for (var i = 0; i < count; ++i)
|
286
|
+
{
|
287
|
+
//pRef += vs[i];
|
288
|
+
pRef.x += vs[i].x;
|
289
|
+
pRef.y += vs[i].y;
|
290
|
+
}
|
291
|
+
pRef.x *= 1.0 / count;
|
292
|
+
pRef.y *= 1.0 / count;
|
293
|
+
*/
|
294
|
+
|
295
|
+
//const float32 inv3 = 1.0f / 3.0f;
|
296
|
+
var inv3 = 1.0 / 3.0;
|
297
|
+
|
298
|
+
for (var i = 0; i < count; ++i)
|
299
|
+
{
|
300
|
+
// Triangle vertices.
|
301
|
+
//b2Vec2 p1 = pRef;
|
302
|
+
var p1X = pRefX;
|
303
|
+
var p1Y = pRefY;
|
304
|
+
//b2Vec2 p2 = vs[i];
|
305
|
+
var p2X = vs[i].x;
|
306
|
+
var p2Y = vs[i].y;
|
307
|
+
//b2Vec2 p3 = i + 1 < count ? vs[i+1] : vs[0];
|
308
|
+
var p3X = i + 1 < count ? vs[i+1].x : vs[0].x;
|
309
|
+
var p3Y = i + 1 < count ? vs[i+1].y : vs[0].y;
|
310
|
+
|
311
|
+
//b2Vec2 e1 = p2 - p1;
|
312
|
+
var e1X = p2X - p1X;
|
313
|
+
var e1Y = p2Y - p1Y;
|
314
|
+
//b2Vec2 e2 = p3 - p1;
|
315
|
+
var e2X = p3X - p1X;
|
316
|
+
var e2Y = p3Y - p1Y;
|
317
|
+
|
318
|
+
//float32 D = b2Cross(e1, e2);
|
319
|
+
var D = (e1X * e2Y - e1Y * e2X);
|
320
|
+
|
321
|
+
//float32 triangleArea = 0.5f * D;
|
322
|
+
var triangleArea = 0.5 * D;
|
323
|
+
area += triangleArea;
|
324
|
+
|
325
|
+
// Area weighted centroid
|
326
|
+
//c += triangleArea * inv3 * (p1 + p2 + p3);
|
327
|
+
cX += triangleArea * inv3 * (p1X + p2X + p3X);
|
328
|
+
cY += triangleArea * inv3 * (p1Y + p2Y + p3Y);
|
329
|
+
}
|
330
|
+
|
331
|
+
// Centroid
|
332
|
+
//b2Settings.b2Assert(area > Number.MIN_VALUE);
|
333
|
+
cX *= 1.0 / area;
|
334
|
+
cY *= 1.0 / area;
|
335
|
+
|
336
|
+
// Replace return with 'out' vector
|
337
|
+
//return c;
|
338
|
+
out.Set(cX, cY);
|
339
|
+
};
|
@@ -0,0 +1,109 @@
|
|
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 b2ShapeDef = Class.create();
|
26
|
+
b2ShapeDef.prototype =
|
27
|
+
{
|
28
|
+
initialize: function()
|
29
|
+
{
|
30
|
+
this.type = b2Shape.e_unknownShape;
|
31
|
+
this.userData = null;
|
32
|
+
this.localPosition = new b2Vec2(0.0, 0.0);
|
33
|
+
this.localRotation = 0.0;
|
34
|
+
this.friction = 0.2;
|
35
|
+
this.restitution = 0.0;
|
36
|
+
this.density = 0.0;
|
37
|
+
this.categoryBits = 0x0001;
|
38
|
+
this.maskBits = 0xFFFF;
|
39
|
+
this.groupIndex = 0;
|
40
|
+
},
|
41
|
+
|
42
|
+
//virtual ~b2ShapeDef() {}
|
43
|
+
|
44
|
+
ComputeMass: function(massData)
|
45
|
+
{
|
46
|
+
|
47
|
+
massData.center = new b2Vec2(0.0, 0.0)
|
48
|
+
|
49
|
+
if (this.density == 0.0)
|
50
|
+
{
|
51
|
+
massData.mass = 0.0;
|
52
|
+
massData.center.Set(0.0, 0.0);
|
53
|
+
massData.I = 0.0;
|
54
|
+
};
|
55
|
+
|
56
|
+
switch (this.type)
|
57
|
+
{
|
58
|
+
case b2Shape.e_circleShape:
|
59
|
+
{
|
60
|
+
var circle = this;
|
61
|
+
massData.mass = this.density * b2Settings.b2_pi * circle.radius * circle.radius;
|
62
|
+
massData.center.Set(0.0, 0.0);
|
63
|
+
massData.I = 0.5 * (massData.mass) * circle.radius * circle.radius;
|
64
|
+
}
|
65
|
+
break;
|
66
|
+
|
67
|
+
case b2Shape.e_boxShape:
|
68
|
+
{
|
69
|
+
var box = this;
|
70
|
+
massData.mass = 4.0 * this.density * box.extents.x * box.extents.y;
|
71
|
+
massData.center.Set(0.0, 0.0);
|
72
|
+
massData.I = massData.mass / 3.0 * b2Math.b2Dot(box.extents, box.extents);
|
73
|
+
}
|
74
|
+
break;
|
75
|
+
|
76
|
+
case b2Shape.e_polyShape:
|
77
|
+
{
|
78
|
+
var poly = this;
|
79
|
+
b2Shape.PolyMass(massData, poly.vertices, poly.vertexCount, this.density);
|
80
|
+
}
|
81
|
+
break;
|
82
|
+
|
83
|
+
default:
|
84
|
+
massData.mass = 0.0;
|
85
|
+
massData.center.Set(0.0, 0.0);
|
86
|
+
massData.I = 0.0;
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
type: 0,
|
92
|
+
userData: null,
|
93
|
+
localPosition: null,
|
94
|
+
localRotation: null,
|
95
|
+
friction: null,
|
96
|
+
restitution: null,
|
97
|
+
density: null,
|
98
|
+
|
99
|
+
// The collision category bits. Normally you would just set one bit.
|
100
|
+
categoryBits: 0,
|
101
|
+
|
102
|
+
// The collision mask bits. This states the categories that this
|
103
|
+
// shape would accept for collision.
|
104
|
+
maskBits: 0,
|
105
|
+
|
106
|
+
// Collision groups allow a certain group of objects to never collide (negative)
|
107
|
+
// or always collide (positive). Zero means no collision group. Non-zero group
|
108
|
+
// filtering always wins against the mask bits.
|
109
|
+
groupIndex: 0};
|
@@ -0,0 +1,72 @@
|
|
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 b2Settings = Class.create();
|
24
|
+
b2Settings.prototype = {
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
// Define your unit system here. The default system is
|
29
|
+
// meters-kilograms-seconds. For the tuning to work well,
|
30
|
+
// your dynamic objects should be bigger than a pebble and smaller
|
31
|
+
// than a house.
|
32
|
+
//static public const b2Settings.b2_lengthUnitsPerMeter = 1.0;
|
33
|
+
|
34
|
+
// Use this for pixels:
|
35
|
+
|
36
|
+
// Global tuning constants based on MKS units.
|
37
|
+
|
38
|
+
// Collision
|
39
|
+
|
40
|
+
// Dynamics
|
41
|
+
|
42
|
+
// Sleep
|
43
|
+
|
44
|
+
// assert
|
45
|
+
|
46
|
+
initialize: function() {}}
|
47
|
+
b2Settings.USHRT_MAX = 0x0000ffff;
|
48
|
+
b2Settings.b2_pi = Math.PI;
|
49
|
+
b2Settings.b2_massUnitsPerKilogram = 1.0;
|
50
|
+
b2Settings.b2_timeUnitsPerSecond = 1.0;
|
51
|
+
b2Settings.b2_lengthUnitsPerMeter = 30.0;
|
52
|
+
b2Settings.b2_maxManifoldPoints = 2;
|
53
|
+
b2Settings.b2_maxShapesPerBody = 64;
|
54
|
+
b2Settings.b2_maxPolyVertices = 8;
|
55
|
+
b2Settings.b2_maxProxies = 1024;
|
56
|
+
b2Settings.b2_maxPairs = 8 * b2Settings.b2_maxProxies;
|
57
|
+
b2Settings.b2_linearSlop = 0.005 * b2Settings.b2_lengthUnitsPerMeter;
|
58
|
+
b2Settings.b2_angularSlop = 2.0 / 180.0 * b2Settings.b2_pi;
|
59
|
+
b2Settings.b2_velocityThreshold = 1.0 * b2Settings.b2_lengthUnitsPerMeter / b2Settings.b2_timeUnitsPerSecond;
|
60
|
+
b2Settings.b2_maxLinearCorrection = 0.2 * b2Settings.b2_lengthUnitsPerMeter;
|
61
|
+
b2Settings.b2_maxAngularCorrection = 8.0 / 180.0 * b2Settings.b2_pi;
|
62
|
+
b2Settings.b2_contactBaumgarte = 0.2;
|
63
|
+
b2Settings.b2_timeToSleep = 0.5 * b2Settings.b2_timeUnitsPerSecond;
|
64
|
+
b2Settings.b2_linearSleepTolerance = 0.01 * b2Settings.b2_lengthUnitsPerMeter / b2Settings.b2_timeUnitsPerSecond;
|
65
|
+
b2Settings.b2_angularSleepTolerance = 2.0 / 180.0 / b2Settings.b2_timeUnitsPerSecond;
|
66
|
+
b2Settings.b2Assert = function(a)
|
67
|
+
{
|
68
|
+
if (!a){
|
69
|
+
var nullVec;
|
70
|
+
nullVec.x++;
|
71
|
+
}
|
72
|
+
};
|