box2d-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,65 @@
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 b2NullContact = Class.create();
24
+ Object.extend(b2NullContact.prototype, b2Contact.prototype);
25
+ Object.extend(b2NullContact.prototype,
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
+ Evaluate: function() {},
64
+ GetManifolds: function(){ return null; }});
65
+
@@ -0,0 +1,103 @@
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 b2PolyAndCircleContact = Class.create();
24
+ Object.extend(b2PolyAndCircleContact.prototype, b2Contact.prototype);
25
+ Object.extend(b2PolyAndCircleContact.prototype, {
26
+
27
+
28
+ initialize: function(s1, s2) {
29
+ // The constructor for b2Contact
30
+ // initialize instance variables for references
31
+ this.m_node1 = new b2ContactNode();
32
+ this.m_node2 = new b2ContactNode();
33
+ //
34
+ this.m_flags = 0;
35
+
36
+ if (!s1 || !s2){
37
+ this.m_shape1 = null;
38
+ this.m_shape2 = null;
39
+ return;
40
+ }
41
+
42
+ this.m_shape1 = s1;
43
+ this.m_shape2 = s2;
44
+
45
+ this.m_manifoldCount = 0;
46
+
47
+ this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction);
48
+ this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution);
49
+
50
+ this.m_prev = null;
51
+ this.m_next = null;
52
+
53
+ this.m_node1.contact = null;
54
+ this.m_node1.prev = null;
55
+ this.m_node1.next = null;
56
+ this.m_node1.other = null;
57
+
58
+ this.m_node2.contact = null;
59
+ this.m_node2.prev = null;
60
+ this.m_node2.next = null;
61
+ this.m_node2.other = null;
62
+ //
63
+
64
+ // initialize instance variables for references
65
+ this.m_manifold = [new b2Manifold()];
66
+ //
67
+
68
+ //super(shape1, shape2);
69
+
70
+ b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_polyShape);
71
+ b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_circleShape);
72
+ this.m_manifold[0].pointCount = 0;
73
+ this.m_manifold[0].points[0].normalImpulse = 0.0;
74
+ this.m_manifold[0].points[0].tangentImpulse = 0.0;
75
+ },
76
+ //~b2PolyAndCircleContact() {}
77
+
78
+ Evaluate: function(){
79
+ b2Collision.b2CollidePolyAndCircle(this.m_manifold[0], this.m_shape1, this.m_shape2, false);
80
+
81
+ if (this.m_manifold[0].pointCount > 0)
82
+ {
83
+ this.m_manifoldCount = 1;
84
+ }
85
+ else
86
+ {
87
+ this.m_manifoldCount = 0;
88
+ }
89
+ },
90
+
91
+ GetManifolds: function()
92
+ {
93
+ return this.m_manifold;
94
+ },
95
+
96
+ m_manifold: [new b2Manifold()]})
97
+
98
+ b2PolyAndCircleContact.Create = function(shape1, shape2, allocator){
99
+ return new b2PolyAndCircleContact(shape1, shape2);
100
+ };
101
+ b2PolyAndCircleContact.Destroy = function(contact, allocator){
102
+ //
103
+ };
@@ -0,0 +1,163 @@
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 b2PolyContact = Class.create();
24
+ Object.extend(b2PolyContact.prototype, b2Contact.prototype);
25
+ Object.extend(b2PolyContact.prototype,
26
+ {
27
+
28
+ initialize: function(s1, s2) {
29
+ // The constructor for b2Contact
30
+ // initialize instance variables for references
31
+ this.m_node1 = new b2ContactNode();
32
+ this.m_node2 = new b2ContactNode();
33
+ //
34
+ this.m_flags = 0;
35
+
36
+ if (!s1 || !s2){
37
+ this.m_shape1 = null;
38
+ this.m_shape2 = null;
39
+ return;
40
+ }
41
+
42
+ this.m_shape1 = s1;
43
+ this.m_shape2 = s2;
44
+
45
+ this.m_manifoldCount = 0;
46
+
47
+ this.m_friction = Math.sqrt(this.m_shape1.m_friction * this.m_shape2.m_friction);
48
+ this.m_restitution = b2Math.b2Max(this.m_shape1.m_restitution, this.m_shape2.m_restitution);
49
+
50
+ this.m_prev = null;
51
+ this.m_next = null;
52
+
53
+ this.m_node1.contact = null;
54
+ this.m_node1.prev = null;
55
+ this.m_node1.next = null;
56
+ this.m_node1.other = null;
57
+
58
+ this.m_node2.contact = null;
59
+ this.m_node2.prev = null;
60
+ this.m_node2.next = null;
61
+ this.m_node2.other = null;
62
+ //
63
+
64
+ // initialize instance variables for references
65
+ this.m0 = new b2Manifold();
66
+ this.m_manifold = [new b2Manifold()];
67
+ //
68
+
69
+ //super(shape1, shape2);
70
+ //b2Settings.b2Assert(this.m_shape1.m_type == b2Shape.e_polyShape);
71
+ //b2Settings.b2Assert(this.m_shape2.m_type == b2Shape.e_polyShape);
72
+ this.m_manifold[0].pointCount = 0;
73
+ },
74
+ //~b2PolyContact() {}
75
+
76
+ // store temp manifold to reduce calls to new
77
+ m0: new b2Manifold(),
78
+
79
+ Evaluate: function(){
80
+ var tMani = this.m_manifold[0];
81
+ // replace memcpy
82
+ // memcpy(&this.m0, &this.m_manifold, sizeof(b2Manifold));
83
+ //this.m0.points = new Array(tMani.pointCount);
84
+ var tPoints = this.m0.points;
85
+
86
+ for (var k = 0; k < tMani.pointCount; k++){
87
+ var tPoint = tPoints[k];
88
+ var tPoint0 = tMani.points[k];
89
+ //tPoint.separation = tPoint0.separation;
90
+ tPoint.normalImpulse = tPoint0.normalImpulse;
91
+ tPoint.tangentImpulse = tPoint0.tangentImpulse;
92
+ //tPoint.position.SetV( tPoint0.position );
93
+
94
+ tPoint.id = tPoint0.id.Copy();
95
+
96
+ /*this.m0.points[k].id.features = new Features();
97
+ this.m0.points[k].id.features.referenceFace = this.m_manifold[0].points[k].id.features.referenceFace;
98
+ this.m0.points[k].id.features.incidentEdge = this.m_manifold[0].points[k].id.features.incidentEdge;
99
+ this.m0.points[k].id.features.incidentVertex = this.m_manifold[0].points[k].id.features.incidentVertex;
100
+ this.m0.points[k].id.features.flip = this.m_manifold[0].points[k].id.features.flip;*/
101
+ }
102
+ //this.m0.normal.SetV( tMani.normal );
103
+ this.m0.pointCount = tMani.pointCount;
104
+
105
+ b2Collision.b2CollidePoly(tMani, this.m_shape1, this.m_shape2, false);
106
+
107
+ // Match contact ids to facilitate warm starting.
108
+ if (tMani.pointCount > 0)
109
+ {
110
+ var match = [false, false];
111
+
112
+ // Match old contact ids to new contact ids and copy the
113
+ // stored impulses to warm start the solver.
114
+ for (var i = 0; i < tMani.pointCount; ++i)
115
+ {
116
+ var cp = tMani.points[ i ];
117
+
118
+ cp.normalImpulse = 0.0;
119
+ cp.tangentImpulse = 0.0;
120
+ var idKey = cp.id.key;
121
+
122
+ for (var j = 0; j < this.m0.pointCount; ++j)
123
+ {
124
+
125
+ if (match[j] == true)
126
+ continue;
127
+
128
+ var cp0 = this.m0.points[j];
129
+ var id0 = cp0.id;
130
+
131
+ if (id0.key == idKey)
132
+ {
133
+ match[j] = true;
134
+ cp.normalImpulse = cp0.normalImpulse;
135
+ cp.tangentImpulse = cp0.tangentImpulse;
136
+ break;
137
+ }
138
+ }
139
+ }
140
+
141
+ this.m_manifoldCount = 1;
142
+ }
143
+ else
144
+ {
145
+ this.m_manifoldCount = 0;
146
+ }
147
+ },
148
+
149
+ GetManifolds: function()
150
+ {
151
+ return this.m_manifold;
152
+ },
153
+
154
+ m_manifold: [new b2Manifold()]});
155
+
156
+ b2PolyContact.Create = function(shape1, shape2, allocator){
157
+ //void* mem = allocator->Allocate(sizeof(b2PolyContact));
158
+ return new b2PolyContact(shape1, shape2);
159
+ };
160
+ b2PolyContact.Destroy = function(contact, allocator){
161
+ //((b2PolyContact*)contact)->~b2PolyContact();
162
+ //allocator->Free(contact, sizeof(b2PolyContact));
163
+ };
@@ -0,0 +1,264 @@
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
+ // C = norm(p2 - p1) - L
22
+ // u = (p2 - p1) / norm(p2 - p1)
23
+ // Cdot = dot(u, v2 + cross(w2, r2) - v1 - cross(w1, r1))
24
+ // J = [-u -cross(r1, u) u cross(r2, u)]
25
+ // K = J * invM * JT
26
+ // = invMass1 + invI1 * cross(r1, u)^2 + invMass2 + invI2 * cross(r2, u)^2
27
+
28
+ var b2DistanceJoint = Class.create();
29
+ Object.extend(b2DistanceJoint.prototype, b2Joint.prototype);
30
+ Object.extend(b2DistanceJoint.prototype,
31
+ {
32
+ //--------------- Internals Below -------------------
33
+
34
+ initialize: function(def){
35
+ // The constructor for b2Joint
36
+ // initialize instance variables for references
37
+ this.m_node1 = new b2JointNode();
38
+ this.m_node2 = new b2JointNode();
39
+ //
40
+ this.m_type = def.type;
41
+ this.m_prev = null;
42
+ this.m_next = null;
43
+ this.m_body1 = def.body1;
44
+ this.m_body2 = def.body2;
45
+ this.m_collideConnected = def.collideConnected;
46
+ this.m_islandFlag = false;
47
+ this.m_userData = def.userData;
48
+ //
49
+
50
+ // initialize instance variables for references
51
+ this.m_localAnchor1 = new b2Vec2();
52
+ this.m_localAnchor2 = new b2Vec2();
53
+ this.m_u = new b2Vec2();
54
+ //
55
+
56
+ //super(def);
57
+
58
+ var tMat;
59
+ var tX;
60
+ var tY;
61
+ //this.m_localAnchor1 = b2MulT(this.m_body1->m_R, def->anchorPoint1 - this.m_body1->m_position);
62
+ tMat = this.m_body1.m_R;
63
+ tX = def.anchorPoint1.x - this.m_body1.m_position.x;
64
+ tY = def.anchorPoint1.y - this.m_body1.m_position.y;
65
+ this.m_localAnchor1.x = tX*tMat.col1.x + tY*tMat.col1.y;
66
+ this.m_localAnchor1.y = tX*tMat.col2.x + tY*tMat.col2.y;
67
+ //this.m_localAnchor2 = b2MulT(this.m_body2->m_R, def->anchorPoint2 - this.m_body2->m_position);
68
+ tMat = this.m_body2.m_R;
69
+ tX = def.anchorPoint2.x - this.m_body2.m_position.x;
70
+ tY = def.anchorPoint2.y - this.m_body2.m_position.y;
71
+ this.m_localAnchor2.x = tX*tMat.col1.x + tY*tMat.col1.y;
72
+ this.m_localAnchor2.y = tX*tMat.col2.x + tY*tMat.col2.y;
73
+
74
+ //b2Vec2 d = def->anchorPoint2 - def->anchorPoint1;
75
+ tX = def.anchorPoint2.x - def.anchorPoint1.x;
76
+ tY = def.anchorPoint2.y - def.anchorPoint1.y;
77
+ //this.m_length = d.Length();
78
+ this.m_length = Math.sqrt(tX*tX + tY*tY);
79
+ this.m_impulse = 0.0;
80
+ },
81
+
82
+ PrepareVelocitySolver: function(){
83
+
84
+ var tMat;
85
+
86
+ // Compute the effective mass matrix.
87
+ //b2Vec2 r1 = b2Mul(this.m_body1->m_R, this.m_localAnchor1);
88
+ tMat = this.m_body1.m_R;
89
+ var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
90
+ var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
91
+ //b2Vec2 r2 = b2Mul(this.m_body2->m_R, this.m_localAnchor2);
92
+ tMat = this.m_body2.m_R;
93
+ var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
94
+ var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
95
+ //this.m_u = this.m_body2->m_position + r2 - this.m_body1->m_position - r1;
96
+ this.m_u.x = this.m_body2.m_position.x + r2X - this.m_body1.m_position.x - r1X;
97
+ this.m_u.y = this.m_body2.m_position.y + r2Y - this.m_body1.m_position.y - r1Y;
98
+
99
+ // Handle singularity.
100
+ //float32 length = this.m_u.Length();
101
+ var length = Math.sqrt(this.m_u.x*this.m_u.x + this.m_u.y*this.m_u.y);
102
+ if (length > b2Settings.b2_linearSlop)
103
+ {
104
+ //this.m_u *= 1.0 / length;
105
+ this.m_u.Multiply( 1.0 / length );
106
+ }
107
+ else
108
+ {
109
+ this.m_u.SetZero();
110
+ }
111
+
112
+ //float32 cr1u = b2Cross(r1, this.m_u);
113
+ var cr1u = (r1X * this.m_u.y - r1Y * this.m_u.x);
114
+ //float32 cr2u = b2Cross(r2, this.m_u);
115
+ var cr2u = (r2X * this.m_u.y - r2Y * this.m_u.x);
116
+ //this.m_mass = this.m_body1->m_invMass + this.m_body1->m_invI * cr1u * cr1u + this.m_body2->m_invMass + this.m_body2->m_invI * cr2u * cr2u;
117
+ this.m_mass = this.m_body1.m_invMass + this.m_body1.m_invI * cr1u * cr1u + this.m_body2.m_invMass + this.m_body2.m_invI * cr2u * cr2u;
118
+ //b2Settings.b2Assert(this.m_mass > Number.MIN_VALUE);
119
+ this.m_mass = 1.0 / this.m_mass;
120
+
121
+ if (b2World.s_enableWarmStarting)
122
+ {
123
+ //b2Vec2 P = this.m_impulse * this.m_u;
124
+ var PX = this.m_impulse * this.m_u.x;
125
+ var PY = this.m_impulse * this.m_u.y;
126
+ //this.m_body1.m_linearVelocity -= this.m_body1.m_invMass * P;
127
+ this.m_body1.m_linearVelocity.x -= this.m_body1.m_invMass * PX;
128
+ this.m_body1.m_linearVelocity.y -= this.m_body1.m_invMass * PY;
129
+ //this.m_body1.m_angularVelocity -= this.m_body1.m_invI * b2Cross(r1, P);
130
+ this.m_body1.m_angularVelocity -= this.m_body1.m_invI * (r1X * PY - r1Y * PX);
131
+ //this.m_body2.m_linearVelocity += this.m_body2.m_invMass * P;
132
+ this.m_body2.m_linearVelocity.x += this.m_body2.m_invMass * PX;
133
+ this.m_body2.m_linearVelocity.y += this.m_body2.m_invMass * PY;
134
+ //this.m_body2.m_angularVelocity += this.m_body2.m_invI * b2Cross(r2, P);
135
+ this.m_body2.m_angularVelocity += this.m_body2.m_invI * (r2X * PY - r2Y * PX);
136
+ }
137
+ else
138
+ {
139
+ this.m_impulse = 0.0;
140
+ }
141
+
142
+ },
143
+
144
+
145
+
146
+ SolveVelocityConstraints: function(step){
147
+
148
+ var tMat;
149
+
150
+ //b2Vec2 r1 = b2Mul(this.m_body1->m_R, this.m_localAnchor1);
151
+ tMat = this.m_body1.m_R;
152
+ var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
153
+ var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
154
+ //b2Vec2 r2 = b2Mul(this.m_body2->m_R, this.m_localAnchor2);
155
+ tMat = this.m_body2.m_R;
156
+ var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
157
+ var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
158
+
159
+ // Cdot = dot(u, v + cross(w, r))
160
+ //b2Vec2 v1 = this.m_body1->m_linearVelocity + b2Cross(this.m_body1->m_angularVelocity, r1);
161
+ var v1X = this.m_body1.m_linearVelocity.x + (-this.m_body1.m_angularVelocity * r1Y);
162
+ var v1Y = this.m_body1.m_linearVelocity.y + (this.m_body1.m_angularVelocity * r1X);
163
+ //b2Vec2 v2 = this.m_body2->m_linearVelocity + b2Cross(this.m_body2->m_angularVelocity, r2);
164
+ var v2X = this.m_body2.m_linearVelocity.x + (-this.m_body2.m_angularVelocity * r2Y);
165
+ var v2Y = this.m_body2.m_linearVelocity.y + (this.m_body2.m_angularVelocity * r2X);
166
+ //float32 Cdot = b2Dot(this.m_u, v2 - v1);
167
+ var Cdot = (this.m_u.x * (v2X - v1X) + this.m_u.y * (v2Y - v1Y));
168
+ //float32 impulse = -this.m_mass * Cdot;
169
+ var impulse = -this.m_mass * Cdot;
170
+ this.m_impulse += impulse;
171
+
172
+ //b2Vec2 P = impulse * this.m_u;
173
+ var PX = impulse * this.m_u.x;
174
+ var PY = impulse * this.m_u.y;
175
+ //this.m_body1->m_linearVelocity -= this.m_body1->m_invMass * P;
176
+ this.m_body1.m_linearVelocity.x -= this.m_body1.m_invMass * PX;
177
+ this.m_body1.m_linearVelocity.y -= this.m_body1.m_invMass * PY;
178
+ //this.m_body1->m_angularVelocity -= this.m_body1->m_invI * b2Cross(r1, P);
179
+ this.m_body1.m_angularVelocity -= this.m_body1.m_invI * (r1X * PY - r1Y * PX);
180
+ //this.m_body2->m_linearVelocity += this.m_body2->m_invMass * P;
181
+ this.m_body2.m_linearVelocity.x += this.m_body2.m_invMass * PX;
182
+ this.m_body2.m_linearVelocity.y += this.m_body2.m_invMass * PY;
183
+ //this.m_body2->m_angularVelocity += this.m_body2->m_invI * b2Cross(r2, P);
184
+ this.m_body2.m_angularVelocity += this.m_body2.m_invI * (r2X * PY - r2Y * PX);
185
+ },
186
+
187
+ SolvePositionConstraints: function(){
188
+
189
+ var tMat;
190
+
191
+ //b2Vec2 r1 = b2Mul(this.m_body1->m_R, this.m_localAnchor1);
192
+ tMat = this.m_body1.m_R;
193
+ var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
194
+ var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
195
+ //b2Vec2 r2 = b2Mul(this.m_body2->m_R, this.m_localAnchor2);
196
+ tMat = this.m_body2.m_R;
197
+ var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
198
+ var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
199
+ //b2Vec2 d = this.m_body2->m_position + r2 - this.m_body1->m_position - r1;
200
+ var dX = this.m_body2.m_position.x + r2X - this.m_body1.m_position.x - r1X;
201
+ var dY = this.m_body2.m_position.y + r2Y - this.m_body1.m_position.y - r1Y;
202
+
203
+ //float32 length = d.Normalize();
204
+ var length = Math.sqrt(dX*dX + dY*dY);
205
+ dX /= length;
206
+ dY /= length;
207
+ //float32 C = length - this.m_length;
208
+ var C = length - this.m_length;
209
+ C = b2Math.b2Clamp(C, -b2Settings.b2_maxLinearCorrection, b2Settings.b2_maxLinearCorrection);
210
+
211
+ var impulse = -this.m_mass * C;
212
+ //this.m_u = d;
213
+ this.m_u.Set(dX, dY);
214
+ //b2Vec2 P = impulse * this.m_u;
215
+ var PX = impulse * this.m_u.x;
216
+ var PY = impulse * this.m_u.y;
217
+
218
+ //this.m_body1->m_position -= this.m_body1->m_invMass * P;
219
+ this.m_body1.m_position.x -= this.m_body1.m_invMass * PX;
220
+ this.m_body1.m_position.y -= this.m_body1.m_invMass * PY;
221
+ //this.m_body1->m_rotation -= this.m_body1->m_invI * b2Cross(r1, P);
222
+ this.m_body1.m_rotation -= this.m_body1.m_invI * (r1X * PY - r1Y * PX);
223
+ //this.m_body2->m_position += this.m_body2->m_invMass * P;
224
+ this.m_body2.m_position.x += this.m_body2.m_invMass * PX;
225
+ this.m_body2.m_position.y += this.m_body2.m_invMass * PY;
226
+ //this.m_body2->m_rotation -= this.m_body2->m_invI * b2Cross(r2, P);
227
+ this.m_body2.m_rotation += this.m_body2.m_invI * (r2X * PY - r2Y * PX);
228
+
229
+ this.m_body1.m_R.Set(this.m_body1.m_rotation);
230
+ this.m_body2.m_R.Set(this.m_body2.m_rotation);
231
+
232
+ return b2Math.b2Abs(C) < b2Settings.b2_linearSlop;
233
+
234
+ },
235
+
236
+ GetAnchor1: function(){
237
+ return b2Math.AddVV(this.m_body1.m_position , b2Math.b2MulMV(this.m_body1.m_R, this.m_localAnchor1));
238
+ },
239
+ GetAnchor2: function(){
240
+ return b2Math.AddVV(this.m_body2.m_position , b2Math.b2MulMV(this.m_body2.m_R, this.m_localAnchor2));
241
+ },
242
+
243
+ GetReactionForce: function(invTimeStep)
244
+ {
245
+ //var F = (this.m_impulse * invTimeStep) * this.m_u;
246
+ var F = new b2Vec2();
247
+ F.SetV(this.m_u);
248
+ F.Multiply(this.m_impulse * invTimeStep);
249
+ return F;
250
+ },
251
+
252
+ GetReactionTorque: function(invTimeStep)
253
+ {
254
+ //NOT_USED(invTimeStep);
255
+ return 0.0;
256
+ },
257
+
258
+ m_localAnchor1: new b2Vec2(),
259
+ m_localAnchor2: new b2Vec2(),
260
+ m_u: new b2Vec2(),
261
+ m_impulse: null,
262
+ m_mass: null,
263
+ m_length: null});
264
+