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.
- 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,53 @@
|
|
|
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 b2MouseJointDef = Class.create();
|
|
24
|
+
Object.extend(b2MouseJointDef.prototype, b2JointDef.prototype);
|
|
25
|
+
Object.extend(b2MouseJointDef.prototype,
|
|
26
|
+
{
|
|
27
|
+
initialize: function()
|
|
28
|
+
{
|
|
29
|
+
// The constructor for b2JointDef
|
|
30
|
+
this.type = b2Joint.e_unknownJoint;
|
|
31
|
+
this.userData = null;
|
|
32
|
+
this.body1 = null;
|
|
33
|
+
this.body2 = null;
|
|
34
|
+
this.collideConnected = false;
|
|
35
|
+
//
|
|
36
|
+
|
|
37
|
+
// initialize instance variables for references
|
|
38
|
+
this.target = new b2Vec2();
|
|
39
|
+
//
|
|
40
|
+
|
|
41
|
+
this.type = b2Joint.e_mouseJoint;
|
|
42
|
+
this.maxForce = 0.0;
|
|
43
|
+
this.frequencyHz = 5.0;
|
|
44
|
+
this.dampingRatio = 0.7;
|
|
45
|
+
this.timeStep = 1.0 / 60.0;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
target: new b2Vec2(),
|
|
49
|
+
maxForce: null,
|
|
50
|
+
frequencyHz: null,
|
|
51
|
+
dampingRatio: null,
|
|
52
|
+
timeStep: null});
|
|
53
|
+
|
|
@@ -0,0 +1,676 @@
|
|
|
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
|
+
// Linear constraint (point-to-line)
|
|
24
|
+
// d = p2 - p1 = x2 + r2 - x1 - r1
|
|
25
|
+
// C = dot(ay1, d)
|
|
26
|
+
// Cdot = dot(d, cross(w1, ay1)) + dot(ay1, v2 + cross(w2, r2) - v1 - cross(w1, r1))
|
|
27
|
+
// = -dot(ay1, v1) - dot(cross(d + r1, ay1), w1) + dot(ay1, v2) + dot(cross(r2, ay1), v2)
|
|
28
|
+
// J = [-ay1 -cross(d+r1,ay1) ay1 cross(r2,ay1)]
|
|
29
|
+
//
|
|
30
|
+
// Angular constraint
|
|
31
|
+
// C = a2 - a1 + a_initial
|
|
32
|
+
// Cdot = w2 - w1
|
|
33
|
+
// J = [0 0 -1 0 0 1]
|
|
34
|
+
|
|
35
|
+
// Motor/Limit linear constraint
|
|
36
|
+
// C = dot(ax1, d)
|
|
37
|
+
// Cdot = = -dot(ax1, v1) - dot(cross(d + r1, ax1), w1) + dot(ax1, v2) + dot(cross(r2, ax1), v2)
|
|
38
|
+
// J = [-ax1 -cross(d+r1,ax1) ax1 cross(r2,ax1)]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var b2PrismaticJoint = Class.create();
|
|
42
|
+
Object.extend(b2PrismaticJoint.prototype, b2Joint.prototype);
|
|
43
|
+
Object.extend(b2PrismaticJoint.prototype,
|
|
44
|
+
{
|
|
45
|
+
GetAnchor1: function(){
|
|
46
|
+
var b1 = this.m_body1;
|
|
47
|
+
//return b2Math.AddVV(b1.m_position, b2Math.b2MulMV(b1.m_R, this.m_localAnchor1));
|
|
48
|
+
var tVec = new b2Vec2();
|
|
49
|
+
tVec.SetV(this.m_localAnchor1);
|
|
50
|
+
tVec.MulM(b1.m_R);
|
|
51
|
+
tVec.Add(b1.m_position);
|
|
52
|
+
return tVec;
|
|
53
|
+
},
|
|
54
|
+
GetAnchor2: function(){
|
|
55
|
+
var b2 = this.m_body2;
|
|
56
|
+
//return b2Math.AddVV(b2.m_position, b2Math.b2MulMV(b2.m_R, this.m_localAnchor2));
|
|
57
|
+
var tVec = new b2Vec2();
|
|
58
|
+
tVec.SetV(this.m_localAnchor2);
|
|
59
|
+
tVec.MulM(b2.m_R);
|
|
60
|
+
tVec.Add(b2.m_position);
|
|
61
|
+
return tVec;
|
|
62
|
+
},
|
|
63
|
+
GetJointTranslation: function(){
|
|
64
|
+
var b1 = this.m_body1;
|
|
65
|
+
var b2 = this.m_body2;
|
|
66
|
+
|
|
67
|
+
var tMat;
|
|
68
|
+
|
|
69
|
+
//var r1 = b2Math.b2MulMV(b1.m_R, this.m_localAnchor1);
|
|
70
|
+
tMat = b1.m_R;
|
|
71
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
72
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
73
|
+
//var r2 = b2Math.b2MulMV(b2.m_R, this.m_localAnchor2);
|
|
74
|
+
tMat = b2.m_R;
|
|
75
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
76
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
77
|
+
//var p1 = b2Math.AddVV(b1.m_position , r1);
|
|
78
|
+
var p1X = b1.m_position.x + r1X;
|
|
79
|
+
var p1Y = b1.m_position.y + r1Y;
|
|
80
|
+
//var p2 = b2Math.AddVV(b2.m_position , r2);
|
|
81
|
+
var p2X = b2.m_position.x + r2X;
|
|
82
|
+
var p2Y = b2.m_position.y + r2Y;
|
|
83
|
+
//var d = b2Math.SubtractVV(p2, p1);
|
|
84
|
+
var dX = p2X - p1X;
|
|
85
|
+
var dY = p2Y - p1Y;
|
|
86
|
+
//var ax1 = b2Math.b2MulMV(b1.m_R, this.m_localXAxis1);
|
|
87
|
+
tMat = b1.m_R;
|
|
88
|
+
var ax1X = tMat.col1.x * this.m_localXAxis1.x + tMat.col2.x * this.m_localXAxis1.y;
|
|
89
|
+
var ax1Y = tMat.col1.y * this.m_localXAxis1.x + tMat.col2.y * this.m_localXAxis1.y;
|
|
90
|
+
|
|
91
|
+
//var translation = b2Math.b2Dot(ax1, d);
|
|
92
|
+
var translation = ax1X*dX + ax1Y*dY;
|
|
93
|
+
return translation;
|
|
94
|
+
},
|
|
95
|
+
GetJointSpeed: function(){
|
|
96
|
+
var b1 = this.m_body1;
|
|
97
|
+
var b2 = this.m_body2;
|
|
98
|
+
|
|
99
|
+
var tMat;
|
|
100
|
+
|
|
101
|
+
//var r1 = b2Math.b2MulMV(b1.m_R, this.m_localAnchor1);
|
|
102
|
+
tMat = b1.m_R;
|
|
103
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
104
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
105
|
+
//var r2 = b2Math.b2MulMV(b2.m_R, this.m_localAnchor2);
|
|
106
|
+
tMat = b2.m_R;
|
|
107
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
108
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
109
|
+
//var p1 = b2Math.AddVV(b1.m_position , r1);
|
|
110
|
+
var p1X = b1.m_position.x + r1X;
|
|
111
|
+
var p1Y = b1.m_position.y + r1Y;
|
|
112
|
+
//var p2 = b2Math.AddVV(b2.m_position , r2);
|
|
113
|
+
var p2X = b2.m_position.x + r2X;
|
|
114
|
+
var p2Y = b2.m_position.y + r2Y;
|
|
115
|
+
//var d = b2Math.SubtractVV(p2, p1);
|
|
116
|
+
var dX = p2X - p1X;
|
|
117
|
+
var dY = p2Y - p1Y;
|
|
118
|
+
//var ax1 = b2Math.b2MulMV(b1.m_R, this.m_localXAxis1);
|
|
119
|
+
tMat = b1.m_R;
|
|
120
|
+
var ax1X = tMat.col1.x * this.m_localXAxis1.x + tMat.col2.x * this.m_localXAxis1.y;
|
|
121
|
+
var ax1Y = tMat.col1.y * this.m_localXAxis1.x + tMat.col2.y * this.m_localXAxis1.y;
|
|
122
|
+
|
|
123
|
+
var v1 = b1.m_linearVelocity;
|
|
124
|
+
var v2 = b2.m_linearVelocity;
|
|
125
|
+
var w1 = b1.m_angularVelocity;
|
|
126
|
+
var w2 = b2.m_angularVelocity;
|
|
127
|
+
|
|
128
|
+
//var speed = b2Math.b2Dot(d, b2Math.b2CrossFV(w1, ax1)) + b2Math.b2Dot(ax1, b2Math.SubtractVV( b2Math.SubtractVV( b2Math.AddVV( v2 , b2Math.b2CrossFV(w2, r2)) , v1) , b2Math.b2CrossFV(w1, r1)));
|
|
129
|
+
//var b2D = (dX*(-w1 * ax1Y) + dY*(w1 * ax1X));
|
|
130
|
+
//var b2D2 = (ax1X * ((( v2.x + (-w2 * r2Y)) - v1.x) - (-w1 * r1Y)) + ax1Y * ((( v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)));
|
|
131
|
+
var speed = (dX*(-w1 * ax1Y) + dY*(w1 * ax1X)) + (ax1X * ((( v2.x + (-w2 * r2Y)) - v1.x) - (-w1 * r1Y)) + ax1Y * ((( v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)));
|
|
132
|
+
|
|
133
|
+
return speed;
|
|
134
|
+
},
|
|
135
|
+
GetMotorForce: function(invTimeStep){
|
|
136
|
+
return invTimeStep * this.m_motorImpulse;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
SetMotorSpeed: function(speed)
|
|
140
|
+
{
|
|
141
|
+
this.m_motorSpeed = speed;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
SetMotorForce: function(force)
|
|
145
|
+
{
|
|
146
|
+
this.m_maxMotorForce = force;
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
GetReactionForce: function(invTimeStep)
|
|
150
|
+
{
|
|
151
|
+
var tImp = invTimeStep * this.m_limitImpulse;
|
|
152
|
+
var tMat;
|
|
153
|
+
|
|
154
|
+
//var ax1 = b2Math.b2MulMV(this.m_body1.m_R, this.m_localXAxis1);
|
|
155
|
+
tMat = this.m_body1.m_R;
|
|
156
|
+
var ax1X = tImp * (tMat.col1.x * this.m_localXAxis1.x + tMat.col2.x * this.m_localXAxis1.y);
|
|
157
|
+
var ax1Y = tImp * (tMat.col1.y * this.m_localXAxis1.x + tMat.col2.y * this.m_localXAxis1.y);
|
|
158
|
+
//var ay1 = b2Math.b2MulMV(this.m_body1.m_R, this.m_localYAxis1);
|
|
159
|
+
var ay1X = tImp * (tMat.col1.x * this.m_localYAxis1.x + tMat.col2.x * this.m_localYAxis1.y);
|
|
160
|
+
var ay1Y = tImp * (tMat.col1.y * this.m_localYAxis1.x + tMat.col2.y * this.m_localYAxis1.y);
|
|
161
|
+
|
|
162
|
+
//return (invTimeStep * this.m_limitImpulse) * ax1 + (invTimeStep * this.m_linearImpulse) * ay1;
|
|
163
|
+
|
|
164
|
+
return new b2Vec2(ax1X+ay1X, ax1Y+ay1Y);
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
GetReactionTorque: function(invTimeStep)
|
|
168
|
+
{
|
|
169
|
+
return invTimeStep * this.m_angularImpulse;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
//--------------- Internals Below -------------------
|
|
174
|
+
|
|
175
|
+
initialize: function(def){
|
|
176
|
+
// The constructor for b2Joint
|
|
177
|
+
// initialize instance variables for references
|
|
178
|
+
this.m_node1 = new b2JointNode();
|
|
179
|
+
this.m_node2 = new b2JointNode();
|
|
180
|
+
//
|
|
181
|
+
this.m_type = def.type;
|
|
182
|
+
this.m_prev = null;
|
|
183
|
+
this.m_next = null;
|
|
184
|
+
this.m_body1 = def.body1;
|
|
185
|
+
this.m_body2 = def.body2;
|
|
186
|
+
this.m_collideConnected = def.collideConnected;
|
|
187
|
+
this.m_islandFlag = false;
|
|
188
|
+
this.m_userData = def.userData;
|
|
189
|
+
//
|
|
190
|
+
|
|
191
|
+
// initialize instance variables for references
|
|
192
|
+
this.m_localAnchor1 = new b2Vec2();
|
|
193
|
+
this.m_localAnchor2 = new b2Vec2();
|
|
194
|
+
this.m_localXAxis1 = new b2Vec2();
|
|
195
|
+
this.m_localYAxis1 = new b2Vec2();
|
|
196
|
+
this.m_linearJacobian = new b2Jacobian();
|
|
197
|
+
this.m_motorJacobian = new b2Jacobian();
|
|
198
|
+
//
|
|
199
|
+
|
|
200
|
+
//super(def);
|
|
201
|
+
|
|
202
|
+
var tMat;
|
|
203
|
+
var tX;
|
|
204
|
+
var tY;
|
|
205
|
+
|
|
206
|
+
//this.m_localAnchor1 = b2Math.b2MulTMV(this.m_body1.m_R, b2Math.SubtractVV(def.anchorPoint , this.m_body1.m_position));
|
|
207
|
+
tMat = this.m_body1.m_R;
|
|
208
|
+
tX = (def.anchorPoint.x - this.m_body1.m_position.x);
|
|
209
|
+
tY = (def.anchorPoint.y - this.m_body1.m_position.y);
|
|
210
|
+
this.m_localAnchor1.Set((tX*tMat.col1.x + tY*tMat.col1.y), (tX*tMat.col2.x + tY*tMat.col2.y));
|
|
211
|
+
|
|
212
|
+
//this.m_localAnchor2 = b2Math.b2MulTMV(this.m_body2.m_R, b2Math.SubtractVV(def.anchorPoint , this.m_body2.m_position));
|
|
213
|
+
tMat = this.m_body2.m_R;
|
|
214
|
+
tX = (def.anchorPoint.x - this.m_body2.m_position.x);
|
|
215
|
+
tY = (def.anchorPoint.y - this.m_body2.m_position.y);
|
|
216
|
+
this.m_localAnchor2.Set((tX*tMat.col1.x + tY*tMat.col1.y), (tX*tMat.col2.x + tY*tMat.col2.y));
|
|
217
|
+
|
|
218
|
+
//this.m_localXAxis1 = b2Math.b2MulTMV(this.m_body1.m_R, def.axis);
|
|
219
|
+
tMat = this.m_body1.m_R;
|
|
220
|
+
tX = def.axis.x;
|
|
221
|
+
tY = def.axis.y;
|
|
222
|
+
this.m_localXAxis1.Set((tX*tMat.col1.x + tY*tMat.col1.y), (tX*tMat.col2.x + tY*tMat.col2.y));
|
|
223
|
+
|
|
224
|
+
//this.m_localYAxis1 = b2Math.b2CrossFV(1.0, this.m_localXAxis1);
|
|
225
|
+
this.m_localYAxis1.x = -this.m_localXAxis1.y;
|
|
226
|
+
this.m_localYAxis1.y = this.m_localXAxis1.x;
|
|
227
|
+
|
|
228
|
+
this.m_initialAngle = this.m_body2.m_rotation - this.m_body1.m_rotation;
|
|
229
|
+
|
|
230
|
+
this.m_linearJacobian.SetZero();
|
|
231
|
+
this.m_linearMass = 0.0;
|
|
232
|
+
this.m_linearImpulse = 0.0;
|
|
233
|
+
|
|
234
|
+
this.m_angularMass = 0.0;
|
|
235
|
+
this.m_angularImpulse = 0.0;
|
|
236
|
+
|
|
237
|
+
this.m_motorJacobian.SetZero();
|
|
238
|
+
this.m_motorMass = 0.0;
|
|
239
|
+
this.m_motorImpulse = 0.0;
|
|
240
|
+
this.m_limitImpulse = 0.0;
|
|
241
|
+
this.m_limitPositionImpulse = 0.0;
|
|
242
|
+
|
|
243
|
+
this.m_lowerTranslation = def.lowerTranslation;
|
|
244
|
+
this.m_upperTranslation = def.upperTranslation;
|
|
245
|
+
this.m_maxMotorForce = def.motorForce;
|
|
246
|
+
this.m_motorSpeed = def.motorSpeed;
|
|
247
|
+
this.m_enableLimit = def.enableLimit;
|
|
248
|
+
this.m_enableMotor = def.enableMotor;
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
PrepareVelocitySolver: function(){
|
|
252
|
+
var b1 = this.m_body1;
|
|
253
|
+
var b2 = this.m_body2;
|
|
254
|
+
|
|
255
|
+
var tMat;
|
|
256
|
+
|
|
257
|
+
// Compute the effective masses.
|
|
258
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
|
259
|
+
tMat = b1.m_R;
|
|
260
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
261
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
262
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
|
263
|
+
tMat = b2.m_R;
|
|
264
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
265
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
266
|
+
|
|
267
|
+
//float32 invMass1 = b1->m_invMass, invMass2 = b2->m_invMass;
|
|
268
|
+
var invMass1 = b1.m_invMass;
|
|
269
|
+
var invMass2 = b2.m_invMass;
|
|
270
|
+
//float32 invI1 = b1->m_invI, invI2 = b2->m_invI;
|
|
271
|
+
var invI1 = b1.m_invI;
|
|
272
|
+
var invI2 = b2.m_invI;
|
|
273
|
+
|
|
274
|
+
// Compute point to line constraint effective mass.
|
|
275
|
+
// J = [-ay1 -cross(d+r1,ay1) ay1 cross(r2,ay1)]
|
|
276
|
+
//b2Vec2 ay1 = b2Mul(b1->m_R, this.m_localYAxis1);
|
|
277
|
+
tMat = b1.m_R;
|
|
278
|
+
var ay1X = tMat.col1.x * this.m_localYAxis1.x + tMat.col2.x * this.m_localYAxis1.y;
|
|
279
|
+
var ay1Y = tMat.col1.y * this.m_localYAxis1.x + tMat.col2.y * this.m_localYAxis1.y;
|
|
280
|
+
//b2Vec2 e = b2->m_position + r2 - b1->m_position;
|
|
281
|
+
var eX = b2.m_position.x + r2X - b1.m_position.x;
|
|
282
|
+
var eY = b2.m_position.y + r2Y - b1.m_position.y;
|
|
283
|
+
|
|
284
|
+
//this.m_linearJacobian.Set(-ay1, -b2Math.b2Cross(e, ay1), ay1, b2Math.b2Cross(r2, ay1));
|
|
285
|
+
this.m_linearJacobian.linear1.x = -ay1X;
|
|
286
|
+
this.m_linearJacobian.linear1.y = -ay1Y;
|
|
287
|
+
this.m_linearJacobian.linear2.x = ay1X;
|
|
288
|
+
this.m_linearJacobian.linear2.y = ay1Y;
|
|
289
|
+
this.m_linearJacobian.angular1 = -(eX * ay1Y - eY * ay1X);
|
|
290
|
+
this.m_linearJacobian.angular2 = r2X * ay1Y - r2Y * ay1X;
|
|
291
|
+
|
|
292
|
+
this.m_linearMass = invMass1 + invI1 * this.m_linearJacobian.angular1 * this.m_linearJacobian.angular1 +
|
|
293
|
+
invMass2 + invI2 * this.m_linearJacobian.angular2 * this.m_linearJacobian.angular2;
|
|
294
|
+
//b2Settings.b2Assert(this.m_linearMass > Number.MIN_VALUE);
|
|
295
|
+
this.m_linearMass = 1.0 / this.m_linearMass;
|
|
296
|
+
|
|
297
|
+
// Compute angular constraint effective mass.
|
|
298
|
+
this.m_angularMass = 1.0 / (invI1 + invI2);
|
|
299
|
+
|
|
300
|
+
// Compute motor and limit terms.
|
|
301
|
+
if (this.m_enableLimit || this.m_enableMotor)
|
|
302
|
+
{
|
|
303
|
+
// The motor and limit share a Jacobian and effective mass.
|
|
304
|
+
//b2Vec2 ax1 = b2Mul(b1->m_R, this.m_localXAxis1);
|
|
305
|
+
tMat = b1.m_R;
|
|
306
|
+
var ax1X = tMat.col1.x * this.m_localXAxis1.x + tMat.col2.x * this.m_localXAxis1.y;
|
|
307
|
+
var ax1Y = tMat.col1.y * this.m_localXAxis1.x + tMat.col2.y * this.m_localXAxis1.y;
|
|
308
|
+
//this.m_motorJacobian.Set(-ax1, -b2Cross(e, ax1), ax1, b2Cross(r2, ax1));
|
|
309
|
+
this.m_motorJacobian.linear1.x = -ax1X; this.m_motorJacobian.linear1.y = -ax1Y;
|
|
310
|
+
this.m_motorJacobian.linear2.x = ax1X; this.m_motorJacobian.linear2.y = ax1Y;
|
|
311
|
+
this.m_motorJacobian.angular1 = -(eX * ax1Y - eY * ax1X);
|
|
312
|
+
this.m_motorJacobian.angular2 = r2X * ax1Y - r2Y * ax1X;
|
|
313
|
+
|
|
314
|
+
this.m_motorMass = invMass1 + invI1 * this.m_motorJacobian.angular1 * this.m_motorJacobian.angular1 +
|
|
315
|
+
invMass2 + invI2 * this.m_motorJacobian.angular2 * this.m_motorJacobian.angular2;
|
|
316
|
+
//b2Settings.b2Assert(this.m_motorMass > Number.MIN_VALUE);
|
|
317
|
+
this.m_motorMass = 1.0 / this.m_motorMass;
|
|
318
|
+
|
|
319
|
+
if (this.m_enableLimit)
|
|
320
|
+
{
|
|
321
|
+
//b2Vec2 d = e - r1;
|
|
322
|
+
var dX = eX - r1X;
|
|
323
|
+
var dY = eY - r1Y;
|
|
324
|
+
//float32 jointTranslation = b2Dot(ax1, d);
|
|
325
|
+
var jointTranslation = ax1X * dX + ax1Y * dY;
|
|
326
|
+
if (b2Math.b2Abs(this.m_upperTranslation - this.m_lowerTranslation) < 2.0 * b2Settings.b2_linearSlop)
|
|
327
|
+
{
|
|
328
|
+
this.m_limitState = b2Joint.e_equalLimits;
|
|
329
|
+
}
|
|
330
|
+
else if (jointTranslation <= this.m_lowerTranslation)
|
|
331
|
+
{
|
|
332
|
+
if (this.m_limitState != b2Joint.e_atLowerLimit)
|
|
333
|
+
{
|
|
334
|
+
this.m_limitImpulse = 0.0;
|
|
335
|
+
}
|
|
336
|
+
this.m_limitState = b2Joint.e_atLowerLimit;
|
|
337
|
+
}
|
|
338
|
+
else if (jointTranslation >= this.m_upperTranslation)
|
|
339
|
+
{
|
|
340
|
+
if (this.m_limitState != b2Joint.e_atUpperLimit)
|
|
341
|
+
{
|
|
342
|
+
this.m_limitImpulse = 0.0;
|
|
343
|
+
}
|
|
344
|
+
this.m_limitState = b2Joint.e_atUpperLimit;
|
|
345
|
+
}
|
|
346
|
+
else
|
|
347
|
+
{
|
|
348
|
+
this.m_limitState = b2Joint.e_inactiveLimit;
|
|
349
|
+
this.m_limitImpulse = 0.0;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (this.m_enableMotor == false)
|
|
355
|
+
{
|
|
356
|
+
this.m_motorImpulse = 0.0;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (this.m_enableLimit == false)
|
|
360
|
+
{
|
|
361
|
+
this.m_limitImpulse = 0.0;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (b2World.s_enableWarmStarting)
|
|
365
|
+
{
|
|
366
|
+
//b2Vec2 P1 = this.m_linearImpulse * this.m_linearJacobian.linear1 + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear1;
|
|
367
|
+
var P1X = this.m_linearImpulse * this.m_linearJacobian.linear1.x + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear1.x;
|
|
368
|
+
var P1Y = this.m_linearImpulse * this.m_linearJacobian.linear1.y + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear1.y;
|
|
369
|
+
//b2Vec2 P2 = this.m_linearImpulse * this.m_linearJacobian.linear2 + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear2;
|
|
370
|
+
var P2X = this.m_linearImpulse * this.m_linearJacobian.linear2.x + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear2.x;
|
|
371
|
+
var P2Y = this.m_linearImpulse * this.m_linearJacobian.linear2.y + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.linear2.y;
|
|
372
|
+
//float32 L1 = this.m_linearImpulse * this.m_linearJacobian.angular1 - this.m_angularImpulse + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.angular1;
|
|
373
|
+
var L1 = this.m_linearImpulse * this.m_linearJacobian.angular1 - this.m_angularImpulse + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.angular1;
|
|
374
|
+
//float32 L2 = this.m_linearImpulse * this.m_linearJacobian.angular2 + this.m_angularImpulse + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.angular2;
|
|
375
|
+
var L2 = this.m_linearImpulse * this.m_linearJacobian.angular2 + this.m_angularImpulse + (this.m_motorImpulse + this.m_limitImpulse) * this.m_motorJacobian.angular2;
|
|
376
|
+
|
|
377
|
+
//b1->m_linearVelocity += invMass1 * P1;
|
|
378
|
+
b1.m_linearVelocity.x += invMass1 * P1X;
|
|
379
|
+
b1.m_linearVelocity.y += invMass1 * P1Y;
|
|
380
|
+
//b1->m_angularVelocity += invI1 * L1;
|
|
381
|
+
b1.m_angularVelocity += invI1 * L1;
|
|
382
|
+
|
|
383
|
+
//b2->m_linearVelocity += invMass2 * P2;
|
|
384
|
+
b2.m_linearVelocity.x += invMass2 * P2X;
|
|
385
|
+
b2.m_linearVelocity.y += invMass2 * P2Y;
|
|
386
|
+
//b2->m_angularVelocity += invI2 * L2;
|
|
387
|
+
b2.m_angularVelocity += invI2 * L2;
|
|
388
|
+
}
|
|
389
|
+
else
|
|
390
|
+
{
|
|
391
|
+
this.m_linearImpulse = 0.0;
|
|
392
|
+
this.m_angularImpulse = 0.0;
|
|
393
|
+
this.m_limitImpulse = 0.0;
|
|
394
|
+
this.m_motorImpulse = 0.0;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
this.m_limitPositionImpulse = 0.0;
|
|
398
|
+
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
SolveVelocityConstraints: function(step){
|
|
402
|
+
var b1 = this.m_body1;
|
|
403
|
+
var b2 = this.m_body2;
|
|
404
|
+
|
|
405
|
+
var invMass1 = b1.m_invMass;
|
|
406
|
+
var invMass2 = b2.m_invMass;
|
|
407
|
+
var invI1 = b1.m_invI;
|
|
408
|
+
var invI2 = b2.m_invI;
|
|
409
|
+
|
|
410
|
+
var oldLimitImpulse;
|
|
411
|
+
|
|
412
|
+
// Solve linear constraint.
|
|
413
|
+
var linearCdot = this.m_linearJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
|
|
414
|
+
var linearImpulse = -this.m_linearMass * linearCdot;
|
|
415
|
+
this.m_linearImpulse += linearImpulse;
|
|
416
|
+
|
|
417
|
+
//b1->m_linearVelocity += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1;
|
|
418
|
+
b1.m_linearVelocity.x += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1.x;
|
|
419
|
+
b1.m_linearVelocity.y += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1.y;
|
|
420
|
+
//b1->m_angularVelocity += invI1 * linearImpulse * this.m_linearJacobian.angular1;
|
|
421
|
+
b1.m_angularVelocity += invI1 * linearImpulse * this.m_linearJacobian.angular1;
|
|
422
|
+
|
|
423
|
+
//b2->m_linearVelocity += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2;
|
|
424
|
+
b2.m_linearVelocity.x += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2.x;
|
|
425
|
+
b2.m_linearVelocity.y += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2.y;
|
|
426
|
+
//b2.m_angularVelocity += invI2 * linearImpulse * this.m_linearJacobian.angular2;
|
|
427
|
+
b2.m_angularVelocity += invI2 * linearImpulse * this.m_linearJacobian.angular2;
|
|
428
|
+
|
|
429
|
+
// Solve angular constraint.
|
|
430
|
+
var angularCdot = b2.m_angularVelocity - b1.m_angularVelocity;
|
|
431
|
+
var angularImpulse = -this.m_angularMass * angularCdot;
|
|
432
|
+
this.m_angularImpulse += angularImpulse;
|
|
433
|
+
|
|
434
|
+
b1.m_angularVelocity -= invI1 * angularImpulse;
|
|
435
|
+
b2.m_angularVelocity += invI2 * angularImpulse;
|
|
436
|
+
|
|
437
|
+
// Solve linear motor constraint.
|
|
438
|
+
if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits)
|
|
439
|
+
{
|
|
440
|
+
var motorCdot = this.m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity) - this.m_motorSpeed;
|
|
441
|
+
var motorImpulse = -this.m_motorMass * motorCdot;
|
|
442
|
+
var oldMotorImpulse = this.m_motorImpulse;
|
|
443
|
+
this.m_motorImpulse = b2Math.b2Clamp(this.m_motorImpulse + motorImpulse, -step.dt * this.m_maxMotorForce, step.dt * this.m_maxMotorForce);
|
|
444
|
+
motorImpulse = this.m_motorImpulse - oldMotorImpulse;
|
|
445
|
+
|
|
446
|
+
//b1.m_linearVelocity += (invMass1 * motorImpulse) * this.m_motorJacobian.linear1;
|
|
447
|
+
b1.m_linearVelocity.x += (invMass1 * motorImpulse) * this.m_motorJacobian.linear1.x;
|
|
448
|
+
b1.m_linearVelocity.y += (invMass1 * motorImpulse) * this.m_motorJacobian.linear1.y;
|
|
449
|
+
//b1.m_angularVelocity += invI1 * motorImpulse * this.m_motorJacobian.angular1;
|
|
450
|
+
b1.m_angularVelocity += invI1 * motorImpulse * this.m_motorJacobian.angular1;
|
|
451
|
+
|
|
452
|
+
//b2->m_linearVelocity += (invMass2 * motorImpulse) * this.m_motorJacobian.linear2;
|
|
453
|
+
b2.m_linearVelocity.x += (invMass2 * motorImpulse) * this.m_motorJacobian.linear2.x;
|
|
454
|
+
b2.m_linearVelocity.y += (invMass2 * motorImpulse) * this.m_motorJacobian.linear2.y;
|
|
455
|
+
//b2->m_angularVelocity += invI2 * motorImpulse * this.m_motorJacobian.angular2;
|
|
456
|
+
b2.m_angularVelocity += invI2 * motorImpulse * this.m_motorJacobian.angular2;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Solve linear limit constraint.
|
|
460
|
+
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit)
|
|
461
|
+
{
|
|
462
|
+
var limitCdot = this.m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
|
|
463
|
+
var limitImpulse = -this.m_motorMass * limitCdot;
|
|
464
|
+
|
|
465
|
+
if (this.m_limitState == b2Joint.e_equalLimits)
|
|
466
|
+
{
|
|
467
|
+
this.m_limitImpulse += limitImpulse;
|
|
468
|
+
}
|
|
469
|
+
else if (this.m_limitState == b2Joint.e_atLowerLimit)
|
|
470
|
+
{
|
|
471
|
+
oldLimitImpulse = this.m_limitImpulse;
|
|
472
|
+
this.m_limitImpulse = b2Math.b2Max(this.m_limitImpulse + limitImpulse, 0.0);
|
|
473
|
+
limitImpulse = this.m_limitImpulse - oldLimitImpulse;
|
|
474
|
+
}
|
|
475
|
+
else if (this.m_limitState == b2Joint.e_atUpperLimit)
|
|
476
|
+
{
|
|
477
|
+
oldLimitImpulse = this.m_limitImpulse;
|
|
478
|
+
this.m_limitImpulse = b2Math.b2Min(this.m_limitImpulse + limitImpulse, 0.0);
|
|
479
|
+
limitImpulse = this.m_limitImpulse - oldLimitImpulse;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
//b1->m_linearVelocity += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1;
|
|
483
|
+
b1.m_linearVelocity.x += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1.x;
|
|
484
|
+
b1.m_linearVelocity.y += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1.y;
|
|
485
|
+
//b1->m_angularVelocity += invI1 * limitImpulse * this.m_motorJacobian.angular1;
|
|
486
|
+
b1.m_angularVelocity += invI1 * limitImpulse * this.m_motorJacobian.angular1;
|
|
487
|
+
|
|
488
|
+
//b2->m_linearVelocity += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2;
|
|
489
|
+
b2.m_linearVelocity.x += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2.x;
|
|
490
|
+
b2.m_linearVelocity.y += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2.y;
|
|
491
|
+
//b2->m_angularVelocity += invI2 * limitImpulse * this.m_motorJacobian.angular2;
|
|
492
|
+
b2.m_angularVelocity += invI2 * limitImpulse * this.m_motorJacobian.angular2;
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
SolvePositionConstraints: function(){
|
|
499
|
+
|
|
500
|
+
var limitC;
|
|
501
|
+
var oldLimitImpulse;
|
|
502
|
+
|
|
503
|
+
var b1 = this.m_body1;
|
|
504
|
+
var b2 = this.m_body2;
|
|
505
|
+
|
|
506
|
+
var invMass1 = b1.m_invMass;
|
|
507
|
+
var invMass2 = b2.m_invMass;
|
|
508
|
+
var invI1 = b1.m_invI;
|
|
509
|
+
var invI2 = b2.m_invI;
|
|
510
|
+
|
|
511
|
+
var tMat;
|
|
512
|
+
|
|
513
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
|
514
|
+
tMat = b1.m_R;
|
|
515
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
516
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
517
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
|
518
|
+
tMat = b2.m_R;
|
|
519
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
520
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
521
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
|
522
|
+
var p1X = b1.m_position.x + r1X;
|
|
523
|
+
var p1Y = b1.m_position.y + r1Y;
|
|
524
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
|
525
|
+
var p2X = b2.m_position.x + r2X;
|
|
526
|
+
var p2Y = b2.m_position.y + r2Y;
|
|
527
|
+
//b2Vec2 d = p2 - p1;
|
|
528
|
+
var dX = p2X - p1X;
|
|
529
|
+
var dY = p2Y - p1Y;
|
|
530
|
+
//b2Vec2 ay1 = b2Mul(b1->m_R, this.m_localYAxis1);
|
|
531
|
+
tMat = b1.m_R;
|
|
532
|
+
var ay1X = tMat.col1.x * this.m_localYAxis1.x + tMat.col2.x * this.m_localYAxis1.y;
|
|
533
|
+
var ay1Y = tMat.col1.y * this.m_localYAxis1.x + tMat.col2.y * this.m_localYAxis1.y;
|
|
534
|
+
|
|
535
|
+
// Solve linear (point-to-line) constraint.
|
|
536
|
+
//float32 linearC = b2Dot(ay1, d);
|
|
537
|
+
var linearC = ay1X*dX + ay1Y*dY;
|
|
538
|
+
// Prevent overly large corrections.
|
|
539
|
+
linearC = b2Math.b2Clamp(linearC, -b2Settings.b2_maxLinearCorrection, b2Settings.b2_maxLinearCorrection);
|
|
540
|
+
var linearImpulse = -this.m_linearMass * linearC;
|
|
541
|
+
|
|
542
|
+
//b1->m_position += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1;
|
|
543
|
+
b1.m_position.x += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1.x;
|
|
544
|
+
b1.m_position.y += (invMass1 * linearImpulse) * this.m_linearJacobian.linear1.y;
|
|
545
|
+
//b1->m_rotation += invI1 * linearImpulse * this.m_linearJacobian.angular1;
|
|
546
|
+
b1.m_rotation += invI1 * linearImpulse * this.m_linearJacobian.angular1;
|
|
547
|
+
//b1->m_R.Set(b1->m_rotation);
|
|
548
|
+
//b2->m_position += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2;
|
|
549
|
+
b2.m_position.x += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2.x;
|
|
550
|
+
b2.m_position.y += (invMass2 * linearImpulse) * this.m_linearJacobian.linear2.y;
|
|
551
|
+
b2.m_rotation += invI2 * linearImpulse * this.m_linearJacobian.angular2;
|
|
552
|
+
//b2->m_R.Set(b2->m_rotation);
|
|
553
|
+
|
|
554
|
+
var positionError = b2Math.b2Abs(linearC);
|
|
555
|
+
|
|
556
|
+
// Solve angular constraint.
|
|
557
|
+
var angularC = b2.m_rotation - b1.m_rotation - this.m_initialAngle;
|
|
558
|
+
// Prevent overly large corrections.
|
|
559
|
+
angularC = b2Math.b2Clamp(angularC, -b2Settings.b2_maxAngularCorrection, b2Settings.b2_maxAngularCorrection);
|
|
560
|
+
var angularImpulse = -this.m_angularMass * angularC;
|
|
561
|
+
|
|
562
|
+
b1.m_rotation -= b1.m_invI * angularImpulse;
|
|
563
|
+
b1.m_R.Set(b1.m_rotation);
|
|
564
|
+
b2.m_rotation += b2.m_invI * angularImpulse;
|
|
565
|
+
b2.m_R.Set(b2.m_rotation);
|
|
566
|
+
|
|
567
|
+
var angularError = b2Math.b2Abs(angularC);
|
|
568
|
+
|
|
569
|
+
// Solve linear limit constraint.
|
|
570
|
+
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit)
|
|
571
|
+
{
|
|
572
|
+
|
|
573
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
|
574
|
+
tMat = b1.m_R;
|
|
575
|
+
r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
576
|
+
r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
577
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
|
578
|
+
tMat = b2.m_R;
|
|
579
|
+
r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
580
|
+
r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
581
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
|
582
|
+
p1X = b1.m_position.x + r1X;
|
|
583
|
+
p1Y = b1.m_position.y + r1Y;
|
|
584
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
|
585
|
+
p2X = b2.m_position.x + r2X;
|
|
586
|
+
p2Y = b2.m_position.y + r2Y;
|
|
587
|
+
//b2Vec2 d = p2 - p1;
|
|
588
|
+
dX = p2X - p1X;
|
|
589
|
+
dY = p2Y - p1Y;
|
|
590
|
+
//b2Vec2 ax1 = b2Mul(b1->m_R, this.m_localXAxis1);
|
|
591
|
+
tMat = b1.m_R;
|
|
592
|
+
var ax1X = tMat.col1.x * this.m_localXAxis1.x + tMat.col2.x * this.m_localXAxis1.y;
|
|
593
|
+
var ax1Y = tMat.col1.y * this.m_localXAxis1.x + tMat.col2.y * this.m_localXAxis1.y;
|
|
594
|
+
|
|
595
|
+
//float32 translation = b2Dot(ax1, d);
|
|
596
|
+
var translation = (ax1X*dX + ax1Y*dY);
|
|
597
|
+
var limitImpulse = 0.0;
|
|
598
|
+
|
|
599
|
+
if (this.m_limitState == b2Joint.e_equalLimits)
|
|
600
|
+
{
|
|
601
|
+
// Prevent large angular corrections
|
|
602
|
+
limitC = b2Math.b2Clamp(translation, -b2Settings.b2_maxLinearCorrection, b2Settings.b2_maxLinearCorrection);
|
|
603
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
604
|
+
positionError = b2Math.b2Max(positionError, b2Math.b2Abs(angularC));
|
|
605
|
+
}
|
|
606
|
+
else if (this.m_limitState == b2Joint.e_atLowerLimit)
|
|
607
|
+
{
|
|
608
|
+
limitC = translation - this.m_lowerTranslation;
|
|
609
|
+
positionError = b2Math.b2Max(positionError, -limitC);
|
|
610
|
+
|
|
611
|
+
// Prevent large linear corrections and allow some slop.
|
|
612
|
+
limitC = b2Math.b2Clamp(limitC + b2Settings.b2_linearSlop, -b2Settings.b2_maxLinearCorrection, 0.0);
|
|
613
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
614
|
+
oldLimitImpulse = this.m_limitPositionImpulse;
|
|
615
|
+
this.m_limitPositionImpulse = b2Math.b2Max(this.m_limitPositionImpulse + limitImpulse, 0.0);
|
|
616
|
+
limitImpulse = this.m_limitPositionImpulse - oldLimitImpulse;
|
|
617
|
+
}
|
|
618
|
+
else if (this.m_limitState == b2Joint.e_atUpperLimit)
|
|
619
|
+
{
|
|
620
|
+
limitC = translation - this.m_upperTranslation;
|
|
621
|
+
positionError = b2Math.b2Max(positionError, limitC);
|
|
622
|
+
|
|
623
|
+
// Prevent large linear corrections and allow some slop.
|
|
624
|
+
limitC = b2Math.b2Clamp(limitC - b2Settings.b2_linearSlop, 0.0, b2Settings.b2_maxLinearCorrection);
|
|
625
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
626
|
+
oldLimitImpulse = this.m_limitPositionImpulse;
|
|
627
|
+
this.m_limitPositionImpulse = b2Math.b2Min(this.m_limitPositionImpulse + limitImpulse, 0.0);
|
|
628
|
+
limitImpulse = this.m_limitPositionImpulse - oldLimitImpulse;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
//b1->m_position += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1;
|
|
632
|
+
b1.m_position.x += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1.x;
|
|
633
|
+
b1.m_position.y += (invMass1 * limitImpulse) * this.m_motorJacobian.linear1.y;
|
|
634
|
+
//b1->m_rotation += invI1 * limitImpulse * this.m_motorJacobian.angular1;
|
|
635
|
+
b1.m_rotation += invI1 * limitImpulse * this.m_motorJacobian.angular1;
|
|
636
|
+
b1.m_R.Set(b1.m_rotation);
|
|
637
|
+
//b2->m_position += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2;
|
|
638
|
+
b2.m_position.x += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2.x;
|
|
639
|
+
b2.m_position.y += (invMass2 * limitImpulse) * this.m_motorJacobian.linear2.y;
|
|
640
|
+
//b2->m_rotation += invI2 * limitImpulse * this.m_motorJacobian.angular2;
|
|
641
|
+
b2.m_rotation += invI2 * limitImpulse * this.m_motorJacobian.angular2;
|
|
642
|
+
b2.m_R.Set(b2.m_rotation);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
return positionError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;
|
|
646
|
+
|
|
647
|
+
},
|
|
648
|
+
|
|
649
|
+
m_localAnchor1: new b2Vec2(),
|
|
650
|
+
m_localAnchor2: new b2Vec2(),
|
|
651
|
+
m_localXAxis1: new b2Vec2(),
|
|
652
|
+
m_localYAxis1: new b2Vec2(),
|
|
653
|
+
m_initialAngle: null,
|
|
654
|
+
|
|
655
|
+
m_linearJacobian: new b2Jacobian(),
|
|
656
|
+
m_linearMass: null,
|
|
657
|
+
m_linearImpulse: null,
|
|
658
|
+
|
|
659
|
+
m_angularMass: null,
|
|
660
|
+
m_angularImpulse: null,
|
|
661
|
+
|
|
662
|
+
m_motorJacobian: new b2Jacobian(),
|
|
663
|
+
m_motorMass: null,
|
|
664
|
+
m_motorImpulse: null,
|
|
665
|
+
m_limitImpulse: null,
|
|
666
|
+
m_limitPositionImpulse: null,
|
|
667
|
+
|
|
668
|
+
m_lowerTranslation: null,
|
|
669
|
+
m_upperTranslation: null,
|
|
670
|
+
m_maxMotorForce: null,
|
|
671
|
+
m_motorSpeed: null,
|
|
672
|
+
|
|
673
|
+
m_enableLimit: null,
|
|
674
|
+
m_enableMotor: null,
|
|
675
|
+
m_limitState: 0});
|
|
676
|
+
|