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,200 @@
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 b2Joint = Class.create();
24
+ b2Joint.prototype =
25
+ {
26
+ GetType: function(){
27
+ return this.m_type;
28
+ },
29
+
30
+ GetAnchor1: function(){return null},
31
+ GetAnchor2: function(){return null},
32
+
33
+ GetReactionForce: function(invTimeStep){return null},
34
+ GetReactionTorque: function(invTimeStep){return 0.0},
35
+
36
+ GetBody1: function()
37
+ {
38
+ return this.m_body1;
39
+ },
40
+
41
+ GetBody2: function()
42
+ {
43
+ return this.m_body2;
44
+ },
45
+
46
+ GetNext: function(){
47
+ return this.m_next;
48
+ },
49
+
50
+ GetUserData: function(){
51
+ return this.m_userData;
52
+ },
53
+
54
+ //--------------- Internals Below -------------------
55
+
56
+
57
+
58
+ initialize: function(def){
59
+ // initialize instance variables for references
60
+ this.m_node1 = new b2JointNode();
61
+ this.m_node2 = new b2JointNode();
62
+ //
63
+
64
+ this.m_type = def.type;
65
+ this.m_prev = null;
66
+ this.m_next = null;
67
+ this.m_body1 = def.body1;
68
+ this.m_body2 = def.body2;
69
+ this.m_collideConnected = def.collideConnected;
70
+ this.m_islandFlag = false;
71
+ this.m_userData = def.userData;
72
+ },
73
+ //virtual ~b2Joint() {}
74
+
75
+ PrepareVelocitySolver: function(){},
76
+ SolveVelocityConstraints: function(step){},
77
+
78
+ // This returns true if the position errors are within tolerance.
79
+ PreparePositionSolver: function(){},
80
+ SolvePositionConstraints: function(){return false},
81
+
82
+ m_type: 0,
83
+ m_prev: null,
84
+ m_next: null,
85
+ m_node1: new b2JointNode(),
86
+ m_node2: new b2JointNode(),
87
+ m_body1: null,
88
+ m_body2: null,
89
+
90
+ m_islandFlag: null,
91
+ m_collideConnected: null,
92
+
93
+ m_userData: null
94
+
95
+
96
+ // ENUMS
97
+
98
+ // enum b2JointType
99
+
100
+ // enum b2LimitState
101
+
102
+ };
103
+ b2Joint.Create = function(def, allocator){
104
+ var joint = null;
105
+
106
+ switch (def.type)
107
+ {
108
+ case b2Joint.e_distanceJoint:
109
+ {
110
+ //void* mem = allocator->Allocate(sizeof(b2DistanceJoint));
111
+ joint = new b2DistanceJoint(def);
112
+ }
113
+ break;
114
+
115
+ case b2Joint.e_mouseJoint:
116
+ {
117
+ //void* mem = allocator->Allocate(sizeof(b2MouseJoint));
118
+ joint = new b2MouseJoint(def);
119
+ }
120
+ break;
121
+
122
+ case b2Joint.e_prismaticJoint:
123
+ {
124
+ //void* mem = allocator->Allocate(sizeof(b2PrismaticJoint));
125
+ joint = new b2PrismaticJoint(def);
126
+ }
127
+ break;
128
+
129
+ case b2Joint.e_revoluteJoint:
130
+ {
131
+ //void* mem = allocator->Allocate(sizeof(b2RevoluteJoint));
132
+ joint = new b2RevoluteJoint(def);
133
+ }
134
+ break;
135
+
136
+ case b2Joint.e_pulleyJoint:
137
+ {
138
+ //void* mem = allocator->Allocate(sizeof(b2PulleyJoint));
139
+ joint = new b2PulleyJoint(def);
140
+ }
141
+ break;
142
+
143
+ case b2Joint.e_gearJoint:
144
+ {
145
+ //void* mem = allocator->Allocate(sizeof(b2GearJoint));
146
+ joint = new b2GearJoint(def);
147
+ }
148
+ break;
149
+
150
+ default:
151
+ //b2Settings.b2Assert(false);
152
+ break;
153
+ }
154
+
155
+ return joint;
156
+ };
157
+ b2Joint.Destroy = function(joint, allocator){
158
+ /*joint->~b2Joint();
159
+ switch (joint.m_type)
160
+ {
161
+ case b2Joint.e_distanceJoint:
162
+ allocator->Free(joint, sizeof(b2DistanceJoint));
163
+ break;
164
+
165
+ case b2Joint.e_mouseJoint:
166
+ allocator->Free(joint, sizeof(b2MouseJoint));
167
+ break;
168
+
169
+ case b2Joint.e_prismaticJoint:
170
+ allocator->Free(joint, sizeof(b2PrismaticJoint));
171
+ break;
172
+
173
+ case b2Joint.e_revoluteJoint:
174
+ allocator->Free(joint, sizeof(b2RevoluteJoint));
175
+ break;
176
+
177
+ case b2Joint.e_pulleyJoint:
178
+ allocator->Free(joint, sizeof(b2PulleyJoint));
179
+ break;
180
+
181
+ case b2Joint.e_gearJoint:
182
+ allocator->Free(joint, sizeof(b2GearJoint));
183
+ break;
184
+
185
+ default:
186
+ b2Assert(false);
187
+ break;
188
+ }*/
189
+ };
190
+ b2Joint.e_unknownJoint = 0;
191
+ b2Joint.e_revoluteJoint = 1;
192
+ b2Joint.e_prismaticJoint = 2;
193
+ b2Joint.e_distanceJoint = 3;
194
+ b2Joint.e_pulleyJoint = 4;
195
+ b2Joint.e_mouseJoint = 5;
196
+ b2Joint.e_gearJoint = 6;
197
+ b2Joint.e_inactiveLimit = 0;
198
+ b2Joint.e_atLowerLimit = 1;
199
+ b2Joint.e_atUpperLimit = 2;
200
+ b2Joint.e_equalLimits = 3;
@@ -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 b2JointDef = Class.create();
24
+ b2JointDef.prototype =
25
+ {
26
+
27
+ initialize: function()
28
+ {
29
+ this.type = b2Joint.e_unknownJoint;
30
+ this.userData = null;
31
+ this.body1 = null;
32
+ this.body2 = null;
33
+ this.collideConnected = false;
34
+ },
35
+
36
+ type: 0,
37
+ userData: null,
38
+ body1: null,
39
+ body2: null,
40
+ collideConnected: null}
@@ -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 b2JointNode = Class.create();
24
+ b2JointNode.prototype =
25
+ {
26
+
27
+ other: null,
28
+ joint: null,
29
+ prev: null,
30
+ next: null,
31
+
32
+
33
+ initialize: function() {}}
@@ -0,0 +1,234 @@
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
+ // p = attached point, m = mouse point
24
+ // C = p - m
25
+ // Cdot = v
26
+ // = v + cross(w, r)
27
+ // J = [I r_skew]
28
+ // Identity used:
29
+ // w k % (rx i + ry j) = w * (-ry i + rx j)
30
+
31
+ var b2MouseJoint = Class.create();
32
+ Object.extend(b2MouseJoint.prototype, b2Joint.prototype);
33
+ Object.extend(b2MouseJoint.prototype,
34
+ {
35
+ GetAnchor1: function(){
36
+ return this.m_target;
37
+ },
38
+ GetAnchor2: function(){
39
+ var tVec = b2Math.b2MulMV(this.m_body2.m_R, this.m_localAnchor);
40
+ tVec.Add(this.m_body2.m_position);
41
+ return tVec;
42
+ },
43
+
44
+ GetReactionForce: function(invTimeStep)
45
+ {
46
+ //b2Vec2 F = invTimeStep * this.m_impulse;
47
+ var F = new b2Vec2();
48
+ F.SetV(this.m_impulse);
49
+ F.Multiply(invTimeStep);
50
+ return F;
51
+ },
52
+
53
+ GetReactionTorque: function(invTimeStep)
54
+ {
55
+ //NOT_USED(invTimeStep);
56
+ return 0.0;
57
+ },
58
+
59
+ SetTarget: function(target){
60
+ this.m_body2.WakeUp();
61
+ this.m_target = target;
62
+ },
63
+
64
+ //--------------- Internals Below -------------------
65
+
66
+ initialize: function(def){
67
+ // The constructor for b2Joint
68
+ // initialize instance variables for references
69
+ this.m_node1 = new b2JointNode();
70
+ this.m_node2 = new b2JointNode();
71
+ //
72
+ this.m_type = def.type;
73
+ this.m_prev = null;
74
+ this.m_next = null;
75
+ this.m_body1 = def.body1;
76
+ this.m_body2 = def.body2;
77
+ this.m_collideConnected = def.collideConnected;
78
+ this.m_islandFlag = false;
79
+ this.m_userData = def.userData;
80
+ //
81
+
82
+ // initialize instance variables for references
83
+ this.K = new b2Mat22();
84
+ this.K1 = new b2Mat22();
85
+ this.K2 = new b2Mat22();
86
+ this.m_localAnchor = new b2Vec2();
87
+ this.m_target = new b2Vec2();
88
+ this.m_impulse = new b2Vec2();
89
+ this.m_ptpMass = new b2Mat22();
90
+ this.m_C = new b2Vec2();
91
+ //
92
+
93
+ //super(def);
94
+
95
+ this.m_target.SetV(def.target);
96
+ //this.m_localAnchor = b2Math.b2MulTMV(this.m_body2.m_R, b2Math.SubtractVV( this.m_target, this.m_body2.m_position ) );
97
+ var tX = this.m_target.x - this.m_body2.m_position.x;
98
+ var tY = this.m_target.y - this.m_body2.m_position.y;
99
+ this.m_localAnchor.x = (tX * this.m_body2.m_R.col1.x + tY * this.m_body2.m_R.col1.y);
100
+ this.m_localAnchor.y = (tX * this.m_body2.m_R.col2.x + tY * this.m_body2.m_R.col2.y);
101
+
102
+ this.m_maxForce = def.maxForce;
103
+ this.m_impulse.SetZero();
104
+
105
+ var mass = this.m_body2.m_mass;
106
+
107
+ // Frequency
108
+ var omega = 2.0 * b2Settings.b2_pi * def.frequencyHz;
109
+
110
+ // Damping coefficient
111
+ var d = 2.0 * mass * def.dampingRatio * omega;
112
+
113
+ // Spring stiffness
114
+ var k = mass * omega * omega;
115
+
116
+ // magic formulas
117
+ this.m_gamma = 1.0 / (d + def.timeStep * k);
118
+ this.m_beta = def.timeStep * k / (d + def.timeStep * k);
119
+ },
120
+
121
+ // Presolve vars
122
+ K: new b2Mat22(),
123
+ K1: new b2Mat22(),
124
+ K2: new b2Mat22(),
125
+ PrepareVelocitySolver: function(){
126
+ var b = this.m_body2;
127
+
128
+ var tMat;
129
+
130
+ // Compute the effective mass matrix.
131
+ //b2Vec2 r = b2Mul(b.m_R, this.m_localAnchor);
132
+ tMat = b.m_R;
133
+ var rX = tMat.col1.x * this.m_localAnchor.x + tMat.col2.x * this.m_localAnchor.y;
134
+ var rY = tMat.col1.y * this.m_localAnchor.x + tMat.col2.y * this.m_localAnchor.y;
135
+
136
+ // this.K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
137
+ // = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
138
+ // [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
139
+ var invMass = b.m_invMass;
140
+ var invI = b.m_invI;
141
+
142
+ //b2Mat22 this.K1;
143
+ this.K1.col1.x = invMass; this.K1.col2.x = 0.0;
144
+ this.K1.col1.y = 0.0; this.K1.col2.y = invMass;
145
+
146
+ //b2Mat22 this.K2;
147
+ this.K2.col1.x = invI * rY * rY; this.K2.col2.x = -invI * rX * rY;
148
+ this.K2.col1.y = -invI * rX * rY; this.K2.col2.y = invI * rX * rX;
149
+
150
+ //b2Mat22 this.K = this.K1 + this.K2;
151
+ this.K.SetM(this.K1);
152
+ this.K.AddM(this.K2);
153
+ this.K.col1.x += this.m_gamma;
154
+ this.K.col2.y += this.m_gamma;
155
+
156
+ //this.m_ptpMass = this.K.Invert();
157
+ this.K.Invert(this.m_ptpMass);
158
+
159
+ //this.m_C = b.m_position + r - this.m_target;
160
+ this.m_C.x = b.m_position.x + rX - this.m_target.x;
161
+ this.m_C.y = b.m_position.y + rY - this.m_target.y;
162
+
163
+ // Cheat with some damping
164
+ b.m_angularVelocity *= 0.98;
165
+
166
+ // Warm starting.
167
+ //b2Vec2 P = this.m_impulse;
168
+ var PX = this.m_impulse.x;
169
+ var PY = this.m_impulse.y;
170
+ //b.m_linearVelocity += invMass * P;
171
+ b.m_linearVelocity.x += invMass * PX;
172
+ b.m_linearVelocity.y += invMass * PY;
173
+ //b.m_angularVelocity += invI * b2Cross(r, P);
174
+ b.m_angularVelocity += invI * (rX * PY - rY * PX);
175
+ },
176
+
177
+
178
+ SolveVelocityConstraints: function(step){
179
+ var body = this.m_body2;
180
+
181
+ var tMat;
182
+
183
+ // Compute the effective mass matrix.
184
+ //b2Vec2 r = b2Mul(body.m_R, this.m_localAnchor);
185
+ tMat = body.m_R;
186
+ var rX = tMat.col1.x * this.m_localAnchor.x + tMat.col2.x * this.m_localAnchor.y;
187
+ var rY = tMat.col1.y * this.m_localAnchor.x + tMat.col2.y * this.m_localAnchor.y;
188
+
189
+ // Cdot = v + cross(w, r)
190
+ //b2Vec2 Cdot = body->m_linearVelocity + b2Cross(body->m_angularVelocity, r);
191
+ var CdotX = body.m_linearVelocity.x + (-body.m_angularVelocity * rY);
192
+ var CdotY = body.m_linearVelocity.y + (body.m_angularVelocity * rX);
193
+ //b2Vec2 impulse = -b2Mul(this.m_ptpMass, Cdot + (this.m_beta * step->inv_dt) * this.m_C + this.m_gamma * this.m_impulse);
194
+ tMat = this.m_ptpMass;
195
+ var tX = CdotX + (this.m_beta * step.inv_dt) * this.m_C.x + this.m_gamma * this.m_impulse.x;
196
+ var tY = CdotY + (this.m_beta * step.inv_dt) * this.m_C.y + this.m_gamma * this.m_impulse.y;
197
+ var impulseX = -(tMat.col1.x * tX + tMat.col2.x * tY);
198
+ var impulseY = -(tMat.col1.y * tX + tMat.col2.y * tY);
199
+
200
+ var oldImpulseX = this.m_impulse.x;
201
+ var oldImpulseY = this.m_impulse.y;
202
+ //this.m_impulse += impulse;
203
+ this.m_impulse.x += impulseX;
204
+ this.m_impulse.y += impulseY;
205
+ var length = this.m_impulse.Length();
206
+ if (length > step.dt * this.m_maxForce)
207
+ {
208
+ //this.m_impulse *= step.dt * this.m_maxForce / length;
209
+ this.m_impulse.Multiply(step.dt * this.m_maxForce / length);
210
+ }
211
+ //impulse = this.m_impulse - oldImpulse;
212
+ impulseX = this.m_impulse.x - oldImpulseX;
213
+ impulseY = this.m_impulse.y - oldImpulseY;
214
+
215
+ //body.m_linearVelocity += body->m_invMass * impulse;
216
+ body.m_linearVelocity.x += body.m_invMass * impulseX;
217
+ body.m_linearVelocity.y += body.m_invMass * impulseY;
218
+ //body.m_angularVelocity += body->m_invI * b2Cross(r, impulse);
219
+ body.m_angularVelocity += body.m_invI * (rX * impulseY - rY * impulseX);
220
+ },
221
+ SolvePositionConstraints: function(){
222
+ return true;
223
+ },
224
+
225
+ m_localAnchor: new b2Vec2(),
226
+ m_target: new b2Vec2(),
227
+ m_impulse: new b2Vec2(),
228
+
229
+ m_ptpMass: new b2Mat22(),
230
+ m_C: new b2Vec2(),
231
+ m_maxForce: null,
232
+ m_beta: null,
233
+ m_gamma: null});
234
+