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.
Files changed (73) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +1 -0
  6. data/box2d-rails.gemspec +20 -0
  7. data/lib/box2d-rails.rb +8 -0
  8. data/lib/box2d-rails/version.rb +5 -0
  9. data/vendor/assets/javascripts/box2d/collision/ClipVertex.js +35 -0
  10. data/vendor/assets/javascripts/box2d/collision/Features.js +61 -0
  11. data/vendor/assets/javascripts/box2d/collision/b2AABB.js +45 -0
  12. data/vendor/assets/javascripts/box2d/collision/b2Bound.js +43 -0
  13. data/vendor/assets/javascripts/box2d/collision/b2BoundValues.js +31 -0
  14. data/vendor/assets/javascripts/box2d/collision/b2BroadPhase.js +898 -0
  15. data/vendor/assets/javascripts/box2d/collision/b2BufferedPair.js +26 -0
  16. data/vendor/assets/javascripts/box2d/collision/b2Collision.js +738 -0
  17. data/vendor/assets/javascripts/box2d/collision/b2ContactID.js +52 -0
  18. data/vendor/assets/javascripts/box2d/collision/b2ContactPoint.js +35 -0
  19. data/vendor/assets/javascripts/box2d/collision/b2Distance.js +333 -0
  20. data/vendor/assets/javascripts/box2d/collision/b2Manifold.js +34 -0
  21. data/vendor/assets/javascripts/box2d/collision/b2OBB.js +34 -0
  22. data/vendor/assets/javascripts/box2d/collision/b2Pair.js +60 -0
  23. data/vendor/assets/javascripts/box2d/collision/b2PairCallback.js +34 -0
  24. data/vendor/assets/javascripts/box2d/collision/b2PairManager.js +386 -0
  25. data/vendor/assets/javascripts/box2d/collision/b2Proxy.js +40 -0
  26. data/vendor/assets/javascripts/box2d/collision/shapes/b2BoxDef.js +49 -0
  27. data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleDef.js +49 -0
  28. data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleShape.js +198 -0
  29. data/vendor/assets/javascripts/box2d/collision/shapes/b2MassData.js +36 -0
  30. data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyDef.js +58 -0
  31. data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyShape.js +492 -0
  32. data/vendor/assets/javascripts/box2d/collision/shapes/b2Shape.js +339 -0
  33. data/vendor/assets/javascripts/box2d/collision/shapes/b2ShapeDef.js +109 -0
  34. data/vendor/assets/javascripts/box2d/common/b2Settings.js +72 -0
  35. data/vendor/assets/javascripts/box2d/common/math/b2Mat22.js +130 -0
  36. data/vendor/assets/javascripts/box2d/common/math/b2Math.js +218 -0
  37. data/vendor/assets/javascripts/box2d/common/math/b2Vec2.js +131 -0
  38. data/vendor/assets/javascripts/box2d/dynamics/b2Body.js +469 -0
  39. data/vendor/assets/javascripts/box2d/dynamics/b2BodyDef.js +69 -0
  40. data/vendor/assets/javascripts/box2d/dynamics/b2CollisionFilter.js +42 -0
  41. data/vendor/assets/javascripts/box2d/dynamics/b2ContactManager.js +337 -0
  42. data/vendor/assets/javascripts/box2d/dynamics/b2Island.js +331 -0
  43. data/vendor/assets/javascripts/box2d/dynamics/b2TimeStep.js +27 -0
  44. data/vendor/assets/javascripts/box2d/dynamics/b2World.js +522 -0
  45. data/vendor/assets/javascripts/box2d/dynamics/b2WorldListener.js +52 -0
  46. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2CircleContact.js +102 -0
  47. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Conservative.js +228 -0
  48. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Contact.js +201 -0
  49. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraint.js +45 -0
  50. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraintPoint.js +40 -0
  51. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactNode.js +33 -0
  52. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactRegister.js +30 -0
  53. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactSolver.js +537 -0
  54. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2NullContact.js +65 -0
  55. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyAndCircleContact.js +103 -0
  56. data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyContact.js +163 -0
  57. data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJoint.js +264 -0
  58. data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJointDef.js +49 -0
  59. data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJoint.js +307 -0
  60. data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJointDef.js +50 -0
  61. data/vendor/assets/javascripts/box2d/dynamics/joints/b2Jacobian.js +49 -0
  62. data/vendor/assets/javascripts/box2d/dynamics/joints/b2Joint.js +200 -0
  63. data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointDef.js +40 -0
  64. data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointNode.js +33 -0
  65. data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJoint.js +234 -0
  66. data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJointDef.js +53 -0
  67. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJoint.js +676 -0
  68. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJointDef.js +56 -0
  69. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJoint.js +618 -0
  70. data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJointDef.js +70 -0
  71. data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJoint.js +491 -0
  72. data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJointDef.js +55 -0
  73. metadata +133 -0
@@ -0,0 +1,130 @@
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 b2Mat22 = Class.create();
24
+ b2Mat22.prototype =
25
+ {
26
+ initialize: function(angle, c1, c2)
27
+ {
28
+ if (angle==null) angle = 0;
29
+ // initialize instance variables for references
30
+ this.col1 = new b2Vec2();
31
+ this.col2 = new b2Vec2();
32
+ //
33
+
34
+ if (c1!=null && c2!=null){
35
+ this.col1.SetV(c1);
36
+ this.col2.SetV(c2);
37
+ }
38
+ else{
39
+ var c = Math.cos(angle);
40
+ var s = Math.sin(angle);
41
+ this.col1.x = c; this.col2.x = -s;
42
+ this.col1.y = s; this.col2.y = c;
43
+ }
44
+ },
45
+
46
+ Set: function(angle)
47
+ {
48
+ var c = Math.cos(angle);
49
+ var s = Math.sin(angle);
50
+ this.col1.x = c; this.col2.x = -s;
51
+ this.col1.y = s; this.col2.y = c;
52
+ },
53
+
54
+ SetVV: function(c1, c2)
55
+ {
56
+ this.col1.SetV(c1);
57
+ this.col2.SetV(c2);
58
+ },
59
+
60
+ Copy: function(){
61
+ return new b2Mat22(0, this.col1, this.col2);
62
+ },
63
+
64
+ SetM: function(m)
65
+ {
66
+ this.col1.SetV(m.col1);
67
+ this.col2.SetV(m.col2);
68
+ },
69
+
70
+ AddM: function(m)
71
+ {
72
+ this.col1.x += m.col1.x;
73
+ this.col1.y += m.col1.y;
74
+ this.col2.x += m.col2.x;
75
+ this.col2.y += m.col2.y;
76
+ },
77
+
78
+ SetIdentity: function()
79
+ {
80
+ this.col1.x = 1.0; this.col2.x = 0.0;
81
+ this.col1.y = 0.0; this.col2.y = 1.0;
82
+ },
83
+
84
+ SetZero: function()
85
+ {
86
+ this.col1.x = 0.0; this.col2.x = 0.0;
87
+ this.col1.y = 0.0; this.col2.y = 0.0;
88
+ },
89
+
90
+ Invert: function(out)
91
+ {
92
+ var a = this.col1.x;
93
+ var b = this.col2.x;
94
+ var c = this.col1.y;
95
+ var d = this.col2.y;
96
+ //var B = new b2Mat22();
97
+ var det = a * d - b * c;
98
+ //b2Settings.b2Assert(det != 0.0);
99
+ det = 1.0 / det;
100
+ out.col1.x = det * d; out.col2.x = -det * b;
101
+ out.col1.y = -det * c; out.col2.y = det * a;
102
+ return out;
103
+ },
104
+
105
+ // this.Solve A * x = b
106
+ Solve: function(out, bX, bY)
107
+ {
108
+ //float32 a11 = this.col1.x, a12 = this.col2.x, a21 = this.col1.y, a22 = this.col2.y;
109
+ var a11 = this.col1.x;
110
+ var a12 = this.col2.x;
111
+ var a21 = this.col1.y;
112
+ var a22 = this.col2.y;
113
+ //float32 det = a11 * a22 - a12 * a21;
114
+ var det = a11 * a22 - a12 * a21;
115
+ //b2Settings.b2Assert(det != 0.0);
116
+ det = 1.0 / det;
117
+ out.x = det * (a22 * bX - a12 * bY);
118
+ out.y = det * (a11 * bY - a21 * bX);
119
+
120
+ return out;
121
+ },
122
+
123
+ Abs: function()
124
+ {
125
+ this.col1.Abs();
126
+ this.col2.Abs();
127
+ },
128
+
129
+ col1: new b2Vec2(),
130
+ col2: new b2Vec2()};
@@ -0,0 +1,218 @@
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 b2Math = Class.create();
22
+ b2Math.prototype = {
23
+
24
+
25
+ /*static public function b2InvSqrt(x)
26
+ {
27
+ float32 xhalf = 0.5f * x;
28
+ int32 i = *(int32*)&x;
29
+ i = 0x5f3759df - (i >> 1);
30
+ x = *(float32*)&i;
31
+ x = x * (1.5f - xhalf * x * x);
32
+ return x;
33
+ }*/
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ // A * B
46
+
47
+ // A^T * B
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ // b2Math.b2Random number in range [-1,1]
60
+
61
+ /*inline float32 b2Math.b2Random(float32 lo, float32 hi)
62
+ {
63
+ float32 r = (float32)rand();
64
+ r /= RAND_MAX;
65
+ r = (hi - lo) * r + lo;
66
+ return r;
67
+ }*/
68
+
69
+ // "Next Largest Power of 2
70
+ // Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm
71
+ // that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with
72
+ // the same most significant 1, but all 1's below it. Adding 1 to that value yields the next
73
+ // largest power of 2. For a 32-bit value:"
74
+
75
+
76
+
77
+ // Temp vector functions to reduce calls to 'new'
78
+ /*static public var tempVec = new b2Vec2();
79
+
80
+
81
+ static public var tempAABB = new b2AABB(); */
82
+
83
+
84
+
85
+ initialize: function() {}}
86
+ b2Math.b2IsValid = function(x)
87
+ {
88
+ return isFinite(x);
89
+ };
90
+ b2Math.b2Dot = function(a, b)
91
+ {
92
+ return a.x * b.x + a.y * b.y;
93
+ };
94
+ b2Math.b2CrossVV = function(a, b)
95
+ {
96
+ return a.x * b.y - a.y * b.x;
97
+ };
98
+ b2Math.b2CrossVF = function(a, s)
99
+ {
100
+ var v = new b2Vec2(s * a.y, -s * a.x);
101
+ return v;
102
+ };
103
+ b2Math.b2CrossFV = function(s, a)
104
+ {
105
+ var v = new b2Vec2(-s * a.y, s * a.x);
106
+ return v;
107
+ };
108
+ b2Math.b2MulMV = function(A, v)
109
+ {
110
+ var u = new b2Vec2(A.col1.x * v.x + A.col2.x * v.y, A.col1.y * v.x + A.col2.y * v.y);
111
+ return u;
112
+ };
113
+ b2Math.b2MulTMV = function(A, v)
114
+ {
115
+ var u = new b2Vec2(b2Math.b2Dot(v, A.col1), b2Math.b2Dot(v, A.col2));
116
+ return u;
117
+ };
118
+ b2Math.AddVV = function(a, b)
119
+ {
120
+ var v = new b2Vec2(a.x + b.x, a.y + b.y);
121
+ return v;
122
+ };
123
+ b2Math.SubtractVV = function(a, b)
124
+ {
125
+ var v = new b2Vec2(a.x - b.x, a.y - b.y);
126
+ return v;
127
+ };
128
+ b2Math.MulFV = function(s, a)
129
+ {
130
+ var v = new b2Vec2(s * a.x, s * a.y);
131
+ return v;
132
+ };
133
+ b2Math.AddMM = function(A, B)
134
+ {
135
+ var C = new b2Mat22(0, b2Math.AddVV(A.col1, B.col1), b2Math.AddVV(A.col2, B.col2));
136
+ return C;
137
+ };
138
+ b2Math.b2MulMM = function(A, B)
139
+ {
140
+ var C = new b2Mat22(0, b2Math.b2MulMV(A, B.col1), b2Math.b2MulMV(A, B.col2));
141
+ return C;
142
+ };
143
+ b2Math.b2MulTMM = function(A, B)
144
+ {
145
+ var c1 = new b2Vec2(b2Math.b2Dot(A.col1, B.col1), b2Math.b2Dot(A.col2, B.col1));
146
+ var c2 = new b2Vec2(b2Math.b2Dot(A.col1, B.col2), b2Math.b2Dot(A.col2, B.col2));
147
+ var C = new b2Mat22(0, c1, c2);
148
+ return C;
149
+ };
150
+ b2Math.b2Abs = function(a)
151
+ {
152
+ return a > 0.0 ? a : -a;
153
+ };
154
+ b2Math.b2AbsV = function(a)
155
+ {
156
+ var b = new b2Vec2(b2Math.b2Abs(a.x), b2Math.b2Abs(a.y));
157
+ return b;
158
+ };
159
+ b2Math.b2AbsM = function(A)
160
+ {
161
+ var B = new b2Mat22(0, b2Math.b2AbsV(A.col1), b2Math.b2AbsV(A.col2));
162
+ return B;
163
+ };
164
+ b2Math.b2Min = function(a, b)
165
+ {
166
+ return a < b ? a : b;
167
+ };
168
+ b2Math.b2MinV = function(a, b)
169
+ {
170
+ var c = new b2Vec2(b2Math.b2Min(a.x, b.x), b2Math.b2Min(a.y, b.y));
171
+ return c;
172
+ };
173
+ b2Math.b2Max = function(a, b)
174
+ {
175
+ return a > b ? a : b;
176
+ };
177
+ b2Math.b2MaxV = function(a, b)
178
+ {
179
+ var c = new b2Vec2(b2Math.b2Max(a.x, b.x), b2Math.b2Max(a.y, b.y));
180
+ return c;
181
+ };
182
+ b2Math.b2Clamp = function(a, low, high)
183
+ {
184
+ return b2Math.b2Max(low, b2Math.b2Min(a, high));
185
+ };
186
+ b2Math.b2ClampV = function(a, low, high)
187
+ {
188
+ return b2Math.b2MaxV(low, b2Math.b2MinV(a, high));
189
+ };
190
+ b2Math.b2Swap = function(a, b)
191
+ {
192
+ var tmp = a[0];
193
+ a[0] = b[0];
194
+ b[0] = tmp;
195
+ };
196
+ b2Math.b2Random = function()
197
+ {
198
+ return Math.random() * 2 - 1;
199
+ };
200
+ b2Math.b2NextPowerOfTwo = function(x)
201
+ {
202
+ x |= (x >> 1) & 0x7FFFFFFF;
203
+ x |= (x >> 2) & 0x3FFFFFFF;
204
+ x |= (x >> 4) & 0x0FFFFFFF;
205
+ x |= (x >> 8) & 0x00FFFFFF;
206
+ x |= (x >> 16)& 0x0000FFFF;
207
+ return x + 1;
208
+ };
209
+ b2Math.b2IsPowerOfTwo = function(x)
210
+ {
211
+ var result = x > 0 && (x & (x - 1)) == 0;
212
+ return result;
213
+ };
214
+ b2Math.tempVec2 = new b2Vec2();
215
+ b2Math.tempVec3 = new b2Vec2();
216
+ b2Math.tempVec4 = new b2Vec2();
217
+ b2Math.tempVec5 = new b2Vec2();
218
+ b2Math.tempMat = new b2Mat22();
@@ -0,0 +1,131 @@
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
+ // b2Vec2 has no constructor so that it
24
+ // can be placed in a union.
25
+ var b2Vec2 = Class.create();
26
+ b2Vec2.prototype =
27
+ {
28
+ initialize: function(x_, y_) {this.x=x_; this.y=y_;},
29
+
30
+ SetZero: function() { this.x = 0.0; this.y = 0.0; },
31
+ Set: function(x_, y_) {this.x=x_; this.y=y_;},
32
+ SetV: function(v) {this.x=v.x; this.y=v.y;},
33
+
34
+ Negative: function(){ return new b2Vec2(-this.x, -this.y); },
35
+
36
+
37
+ Copy: function(){
38
+ return new b2Vec2(this.x,this.y);
39
+ },
40
+
41
+ Add: function(v)
42
+ {
43
+ this.x += v.x; this.y += v.y;
44
+ },
45
+
46
+ Subtract: function(v)
47
+ {
48
+ this.x -= v.x; this.y -= v.y;
49
+ },
50
+
51
+ Multiply: function(a)
52
+ {
53
+ this.x *= a; this.y *= a;
54
+ },
55
+
56
+ MulM: function(A)
57
+ {
58
+ var tX = this.x;
59
+ this.x = A.col1.x * tX + A.col2.x * this.y;
60
+ this.y = A.col1.y * tX + A.col2.y * this.y;
61
+ },
62
+
63
+ MulTM: function(A)
64
+ {
65
+ var tX = b2Math.b2Dot(this, A.col1);
66
+ this.y = b2Math.b2Dot(this, A.col2);
67
+ this.x = tX;
68
+ },
69
+
70
+ CrossVF: function(s)
71
+ {
72
+ var tX = this.x;
73
+ this.x = s * this.y;
74
+ this.y = -s * tX;
75
+ },
76
+
77
+ CrossFV: function(s)
78
+ {
79
+ var tX = this.x;
80
+ this.x = -s * this.y;
81
+ this.y = s * tX;
82
+ },
83
+
84
+ MinV: function(b)
85
+ {
86
+ this.x = this.x < b.x ? this.x : b.x;
87
+ this.y = this.y < b.y ? this.y : b.y;
88
+ },
89
+
90
+ MaxV: function(b)
91
+ {
92
+ this.x = this.x > b.x ? this.x : b.x;
93
+ this.y = this.y > b.y ? this.y : b.y;
94
+ },
95
+
96
+ Abs: function()
97
+ {
98
+ this.x = Math.abs(this.x);
99
+ this.y = Math.abs(this.y);
100
+ },
101
+
102
+ Length: function()
103
+ {
104
+ return Math.sqrt(this.x * this.x + this.y * this.y);
105
+ },
106
+
107
+ Normalize: function()
108
+ {
109
+ var length = this.Length();
110
+ if (length < Number.MIN_VALUE)
111
+ {
112
+ return 0.0;
113
+ }
114
+ var invLength = 1.0 / length;
115
+ this.x *= invLength;
116
+ this.y *= invLength;
117
+
118
+ return length;
119
+ },
120
+
121
+ IsValid: function()
122
+ {
123
+ return b2Math.b2IsValid(this.x) && b2Math.b2IsValid(this.y);
124
+ },
125
+
126
+ x: null,
127
+ y: null};
128
+ b2Vec2.Make = function(x_, y_)
129
+ {
130
+ return new b2Vec2(x_, y_);
131
+ };