box2d-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/box2d-rails.gemspec +20 -0
- data/lib/box2d-rails.rb +8 -0
- data/lib/box2d-rails/version.rb +5 -0
- data/vendor/assets/javascripts/box2d/collision/ClipVertex.js +35 -0
- data/vendor/assets/javascripts/box2d/collision/Features.js +61 -0
- data/vendor/assets/javascripts/box2d/collision/b2AABB.js +45 -0
- data/vendor/assets/javascripts/box2d/collision/b2Bound.js +43 -0
- data/vendor/assets/javascripts/box2d/collision/b2BoundValues.js +31 -0
- data/vendor/assets/javascripts/box2d/collision/b2BroadPhase.js +898 -0
- data/vendor/assets/javascripts/box2d/collision/b2BufferedPair.js +26 -0
- data/vendor/assets/javascripts/box2d/collision/b2Collision.js +738 -0
- data/vendor/assets/javascripts/box2d/collision/b2ContactID.js +52 -0
- data/vendor/assets/javascripts/box2d/collision/b2ContactPoint.js +35 -0
- data/vendor/assets/javascripts/box2d/collision/b2Distance.js +333 -0
- data/vendor/assets/javascripts/box2d/collision/b2Manifold.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2OBB.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2Pair.js +60 -0
- data/vendor/assets/javascripts/box2d/collision/b2PairCallback.js +34 -0
- data/vendor/assets/javascripts/box2d/collision/b2PairManager.js +386 -0
- data/vendor/assets/javascripts/box2d/collision/b2Proxy.js +40 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2BoxDef.js +49 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleDef.js +49 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2CircleShape.js +198 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2MassData.js +36 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyDef.js +58 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2PolyShape.js +492 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2Shape.js +339 -0
- data/vendor/assets/javascripts/box2d/collision/shapes/b2ShapeDef.js +109 -0
- data/vendor/assets/javascripts/box2d/common/b2Settings.js +72 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Mat22.js +130 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Math.js +218 -0
- data/vendor/assets/javascripts/box2d/common/math/b2Vec2.js +131 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2Body.js +469 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2BodyDef.js +69 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2CollisionFilter.js +42 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2ContactManager.js +337 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2Island.js +331 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2TimeStep.js +27 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2World.js +522 -0
- data/vendor/assets/javascripts/box2d/dynamics/b2WorldListener.js +52 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2CircleContact.js +102 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Conservative.js +228 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2Contact.js +201 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraint.js +45 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactConstraintPoint.js +40 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactNode.js +33 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactRegister.js +30 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2ContactSolver.js +537 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2NullContact.js +65 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyAndCircleContact.js +103 -0
- data/vendor/assets/javascripts/box2d/dynamics/contacts/b2PolyContact.js +163 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJoint.js +264 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2DistanceJointDef.js +49 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJoint.js +307 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2GearJointDef.js +50 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2Jacobian.js +49 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2Joint.js +200 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointDef.js +40 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2JointNode.js +33 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJoint.js +234 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2MouseJointDef.js +53 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJoint.js +676 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PrismaticJointDef.js +56 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJoint.js +618 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2PulleyJointDef.js +70 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJoint.js +491 -0
- data/vendor/assets/javascripts/box2d/dynamics/joints/b2RevoluteJointDef.js +55 -0
- metadata +133 -0
@@ -0,0 +1,56 @@
|
|
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 b2PrismaticJointDef = Class.create();
|
24
|
+
Object.extend(b2PrismaticJointDef.prototype, b2JointDef.prototype);
|
25
|
+
Object.extend(b2PrismaticJointDef.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
|
+
this.type = b2Joint.e_prismaticJoint;
|
38
|
+
this.anchorPoint = new b2Vec2(0.0, 0.0);
|
39
|
+
this.axis = new b2Vec2(0.0, 0.0);
|
40
|
+
this.lowerTranslation = 0.0;
|
41
|
+
this.upperTranslation = 0.0;
|
42
|
+
this.motorForce = 0.0;
|
43
|
+
this.motorSpeed = 0.0;
|
44
|
+
this.enableLimit = false;
|
45
|
+
this.enableMotor = false;
|
46
|
+
},
|
47
|
+
|
48
|
+
anchorPoint: null,
|
49
|
+
axis: null,
|
50
|
+
lowerTranslation: null,
|
51
|
+
upperTranslation: null,
|
52
|
+
motorForce: null,
|
53
|
+
motorSpeed: null,
|
54
|
+
enableLimit: null,
|
55
|
+
enableMotor: null});
|
56
|
+
|
@@ -0,0 +1,618 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2007 Erin Catto http:
|
3
|
+
*
|
4
|
+
* This software is provided 'as-is', without any express or implied
|
5
|
+
* warranty. In no event will the authors be held liable for any damages
|
6
|
+
* arising from the use of this software.
|
7
|
+
* Permission is granted to anyone to use this software for any purpose,
|
8
|
+
* including commercial applications, and to alter it and redistribute it
|
9
|
+
* freely, subject to the following restrictions:
|
10
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
11
|
+
* claim that you wrote the original software. If you use this software
|
12
|
+
* in a product, an acknowledgment in the product documentation would be
|
13
|
+
* appreciated but is not required.
|
14
|
+
* 2. Altered source versions must be plainly marked, and must not be
|
15
|
+
* misrepresented the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
var b2PulleyJoint = Class.create();
|
26
|
+
Object.extend(b2PulleyJoint.prototype, b2Joint.prototype);
|
27
|
+
Object.extend(b2PulleyJoint.prototype,
|
28
|
+
{
|
29
|
+
GetAnchor1: function(){
|
30
|
+
//return this.m_body1->m_position + b2Mul(this.m_body1->m_R, this.m_localAnchor1);
|
31
|
+
var tMat = this.m_body1.m_R;
|
32
|
+
return new b2Vec2( this.m_body1.m_position.x + (tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y),
|
33
|
+
this.m_body1.m_position.y + (tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y));
|
34
|
+
},
|
35
|
+
GetAnchor2: function(){
|
36
|
+
//return this.m_body2->m_position + b2Mul(this.m_body2->m_R, this.m_localAnchor2);
|
37
|
+
var tMat = this.m_body2.m_R;
|
38
|
+
return new b2Vec2( this.m_body2.m_position.x + (tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y),
|
39
|
+
this.m_body2.m_position.y + (tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y));
|
40
|
+
},
|
41
|
+
|
42
|
+
GetGroundPoint1: function(){
|
43
|
+
//return this.m_ground->m_position + this.m_groundAnchor1;
|
44
|
+
return new b2Vec2(this.m_ground.m_position.x + this.m_groundAnchor1.x, this.m_ground.m_position.y + this.m_groundAnchor1.y);
|
45
|
+
},
|
46
|
+
GetGroundPoint2: function(){
|
47
|
+
return new b2Vec2(this.m_ground.m_position.x + this.m_groundAnchor2.x, this.m_ground.m_position.y + this.m_groundAnchor2.y);
|
48
|
+
},
|
49
|
+
|
50
|
+
GetReactionForce: function(invTimeStep){
|
51
|
+
//b2Vec2 F(0.0f, 0.0f);
|
52
|
+
return new b2Vec2();
|
53
|
+
},
|
54
|
+
GetReactionTorque: function(invTimeStep){
|
55
|
+
return 0.0;
|
56
|
+
},
|
57
|
+
|
58
|
+
GetLength1: function(){
|
59
|
+
var tMat;
|
60
|
+
//b2Vec2 p = this.m_body1->m_position + b2Mul(this.m_body1->m_R, this.m_localAnchor1);
|
61
|
+
tMat = this.m_body1.m_R;
|
62
|
+
var pX = this.m_body1.m_position.x + (tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y);
|
63
|
+
var pY = this.m_body1.m_position.y + (tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y);
|
64
|
+
//b2Vec2 s = this.m_ground->m_position + this.m_groundAnchor1;
|
65
|
+
//b2Vec2 d = p - s;
|
66
|
+
var dX = pX - (this.m_ground.m_position.x + this.m_groundAnchor1.x);
|
67
|
+
var dY = pY - (this.m_ground.m_position.y + this.m_groundAnchor1.y);
|
68
|
+
return Math.sqrt(dX*dX + dY*dY);
|
69
|
+
},
|
70
|
+
GetLength2: function(){
|
71
|
+
var tMat;
|
72
|
+
//b2Vec2 p = this.m_body2->m_position + b2Mul(this.m_body2->m_R, this.m_localAnchor2);
|
73
|
+
tMat = this.m_body2.m_R;
|
74
|
+
var pX = this.m_body2.m_position.x + (tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y);
|
75
|
+
var pY = this.m_body2.m_position.y + (tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y);
|
76
|
+
//b2Vec2 s = this.m_ground->m_position + this.m_groundAnchor2;
|
77
|
+
//b2Vec2 d = p - s;
|
78
|
+
var dX = pX - (this.m_ground.m_position.x + this.m_groundAnchor2.x);
|
79
|
+
var dY = pY - (this.m_ground.m_position.y + this.m_groundAnchor2.y);
|
80
|
+
return Math.sqrt(dX*dX + dY*dY);
|
81
|
+
},
|
82
|
+
|
83
|
+
GetRatio: function(){
|
84
|
+
return this.m_ratio;
|
85
|
+
},
|
86
|
+
|
87
|
+
//--------------- Internals Below -------------------
|
88
|
+
|
89
|
+
initialize: function(def){
|
90
|
+
// The constructor for b2Joint
|
91
|
+
// initialize instance variables for references
|
92
|
+
this.m_node1 = new b2JointNode();
|
93
|
+
this.m_node2 = new b2JointNode();
|
94
|
+
//
|
95
|
+
this.m_type = def.type;
|
96
|
+
this.m_prev = null;
|
97
|
+
this.m_next = null;
|
98
|
+
this.m_body1 = def.body1;
|
99
|
+
this.m_body2 = def.body2;
|
100
|
+
this.m_collideConnected = def.collideConnected;
|
101
|
+
this.m_islandFlag = false;
|
102
|
+
this.m_userData = def.userData;
|
103
|
+
//
|
104
|
+
|
105
|
+
// initialize instance variables for references
|
106
|
+
this.m_groundAnchor1 = new b2Vec2();
|
107
|
+
this.m_groundAnchor2 = new b2Vec2();
|
108
|
+
this.m_localAnchor1 = new b2Vec2();
|
109
|
+
this.m_localAnchor2 = new b2Vec2();
|
110
|
+
this.m_u1 = new b2Vec2();
|
111
|
+
this.m_u2 = new b2Vec2();
|
112
|
+
//
|
113
|
+
|
114
|
+
|
115
|
+
// parent
|
116
|
+
//super(def);
|
117
|
+
|
118
|
+
var tMat;
|
119
|
+
var tX;
|
120
|
+
var tY;
|
121
|
+
|
122
|
+
this.m_ground = this.m_body1.m_world.m_groundBody;
|
123
|
+
//this.m_groundAnchor1 = def.groundPoint1 - this.m_ground.m_position;
|
124
|
+
this.m_groundAnchor1.x = def.groundPoint1.x - this.m_ground.m_position.x;
|
125
|
+
this.m_groundAnchor1.y = def.groundPoint1.y - this.m_ground.m_position.y;
|
126
|
+
//this.m_groundAnchor2 = def.groundPoint2 - this.m_ground.m_position;
|
127
|
+
this.m_groundAnchor2.x = def.groundPoint2.x - this.m_ground.m_position.x;
|
128
|
+
this.m_groundAnchor2.y = def.groundPoint2.y - this.m_ground.m_position.y;
|
129
|
+
//this.m_localAnchor1 = b2MulT(this.m_body1.m_R, def.anchorPoint1 - this.m_body1.m_position);
|
130
|
+
tMat = this.m_body1.m_R;
|
131
|
+
tX = def.anchorPoint1.x - this.m_body1.m_position.x;
|
132
|
+
tY = def.anchorPoint1.y - this.m_body1.m_position.y;
|
133
|
+
this.m_localAnchor1.x = tX*tMat.col1.x + tY*tMat.col1.y;
|
134
|
+
this.m_localAnchor1.y = tX*tMat.col2.x + tY*tMat.col2.y;
|
135
|
+
//this.m_localAnchor2 = b2MulT(this.m_body2.m_R, def.anchorPoint2 - this.m_body2.m_position);
|
136
|
+
tMat = this.m_body2.m_R;
|
137
|
+
tX = def.anchorPoint2.x - this.m_body2.m_position.x;
|
138
|
+
tY = def.anchorPoint2.y - this.m_body2.m_position.y;
|
139
|
+
this.m_localAnchor2.x = tX*tMat.col1.x + tY*tMat.col1.y;
|
140
|
+
this.m_localAnchor2.y = tX*tMat.col2.x + tY*tMat.col2.y;
|
141
|
+
|
142
|
+
this.m_ratio = def.ratio;
|
143
|
+
|
144
|
+
//var d1 = def.groundPoint1 - def.anchorPoint1;
|
145
|
+
tX = def.groundPoint1.x - def.anchorPoint1.x;
|
146
|
+
tY = def.groundPoint1.y - def.anchorPoint1.y;
|
147
|
+
var d1Len = Math.sqrt(tX*tX + tY*tY);
|
148
|
+
//var d2 = def.groundPoint2 - def.anchorPoint2;
|
149
|
+
tX = def.groundPoint2.x - def.anchorPoint2.x;
|
150
|
+
tY = def.groundPoint2.y - def.anchorPoint2.y;
|
151
|
+
var d2Len = Math.sqrt(tX*tX + tY*tY);
|
152
|
+
|
153
|
+
var length1 = b2Math.b2Max(0.5 * b2PulleyJoint.b2_minPulleyLength, d1Len);
|
154
|
+
var length2 = b2Math.b2Max(0.5 * b2PulleyJoint.b2_minPulleyLength, d2Len);
|
155
|
+
|
156
|
+
this.m_constant = length1 + this.m_ratio * length2;
|
157
|
+
|
158
|
+
this.m_maxLength1 = b2Math.b2Clamp(def.maxLength1, length1, this.m_constant - this.m_ratio * b2PulleyJoint.b2_minPulleyLength);
|
159
|
+
this.m_maxLength2 = b2Math.b2Clamp(def.maxLength2, length2, (this.m_constant - b2PulleyJoint.b2_minPulleyLength) / this.m_ratio);
|
160
|
+
|
161
|
+
this.m_pulleyImpulse = 0.0;
|
162
|
+
this.m_limitImpulse1 = 0.0;
|
163
|
+
this.m_limitImpulse2 = 0.0;
|
164
|
+
|
165
|
+
},
|
166
|
+
|
167
|
+
PrepareVelocitySolver: function(){
|
168
|
+
var b1 = this.m_body1;
|
169
|
+
var b2 = this.m_body2;
|
170
|
+
|
171
|
+
var tMat;
|
172
|
+
|
173
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
174
|
+
tMat = b1.m_R;
|
175
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
176
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
177
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
178
|
+
tMat = b2.m_R;
|
179
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
180
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
181
|
+
|
182
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
183
|
+
var p1X = b1.m_position.x + r1X;
|
184
|
+
var p1Y = b1.m_position.y + r1Y;
|
185
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
186
|
+
var p2X = b2.m_position.x + r2X;
|
187
|
+
var p2Y = b2.m_position.y + r2Y;
|
188
|
+
|
189
|
+
//b2Vec2 s1 = this.m_ground->m_position + this.m_groundAnchor1;
|
190
|
+
var s1X = this.m_ground.m_position.x + this.m_groundAnchor1.x;
|
191
|
+
var s1Y = this.m_ground.m_position.y + this.m_groundAnchor1.y;
|
192
|
+
//b2Vec2 s2 = this.m_ground->m_position + this.m_groundAnchor2;
|
193
|
+
var s2X = this.m_ground.m_position.x + this.m_groundAnchor2.x;
|
194
|
+
var s2Y = this.m_ground.m_position.y + this.m_groundAnchor2.y;
|
195
|
+
|
196
|
+
// Get the pulley axes.
|
197
|
+
//this.m_u1 = p1 - s1;
|
198
|
+
this.m_u1.Set(p1X - s1X, p1Y - s1Y);
|
199
|
+
//this.m_u2 = p2 - s2;
|
200
|
+
this.m_u2.Set(p2X - s2X, p2Y - s2Y);
|
201
|
+
|
202
|
+
var length1 = this.m_u1.Length();
|
203
|
+
var length2 = this.m_u2.Length();
|
204
|
+
|
205
|
+
if (length1 > b2Settings.b2_linearSlop)
|
206
|
+
{
|
207
|
+
//this.m_u1 *= 1.0f / length1;
|
208
|
+
this.m_u1.Multiply(1.0 / length1);
|
209
|
+
}
|
210
|
+
else
|
211
|
+
{
|
212
|
+
this.m_u1.SetZero();
|
213
|
+
}
|
214
|
+
|
215
|
+
if (length2 > b2Settings.b2_linearSlop)
|
216
|
+
{
|
217
|
+
//this.m_u2 *= 1.0f / length2;
|
218
|
+
this.m_u2.Multiply(1.0 / length2);
|
219
|
+
}
|
220
|
+
else
|
221
|
+
{
|
222
|
+
this.m_u2.SetZero();
|
223
|
+
}
|
224
|
+
|
225
|
+
if (length1 < this.m_maxLength1)
|
226
|
+
{
|
227
|
+
this.m_limitState1 = b2Joint.e_inactiveLimit;
|
228
|
+
this.m_limitImpulse1 = 0.0;
|
229
|
+
}
|
230
|
+
else
|
231
|
+
{
|
232
|
+
this.m_limitState1 = b2Joint.e_atUpperLimit;
|
233
|
+
this.m_limitPositionImpulse1 = 0.0;
|
234
|
+
}
|
235
|
+
|
236
|
+
if (length2 < this.m_maxLength2)
|
237
|
+
{
|
238
|
+
this.m_limitState2 = b2Joint.e_inactiveLimit;
|
239
|
+
this.m_limitImpulse2 = 0.0;
|
240
|
+
}
|
241
|
+
else
|
242
|
+
{
|
243
|
+
this.m_limitState2 = b2Joint.e_atUpperLimit;
|
244
|
+
this.m_limitPositionImpulse2 = 0.0;
|
245
|
+
}
|
246
|
+
|
247
|
+
// Compute effective mass.
|
248
|
+
//var cr1u1 = b2Cross(r1, this.m_u1);
|
249
|
+
var cr1u1 = r1X * this.m_u1.y - r1Y * this.m_u1.x;
|
250
|
+
//var cr2u2 = b2Cross(r2, this.m_u2);
|
251
|
+
var cr2u2 = r2X * this.m_u2.y - r2Y * this.m_u2.x;
|
252
|
+
|
253
|
+
this.m_limitMass1 = b1.m_invMass + b1.m_invI * cr1u1 * cr1u1;
|
254
|
+
this.m_limitMass2 = b2.m_invMass + b2.m_invI * cr2u2 * cr2u2;
|
255
|
+
this.m_pulleyMass = this.m_limitMass1 + this.m_ratio * this.m_ratio * this.m_limitMass2;
|
256
|
+
//b2Settings.b2Assert(this.m_limitMass1 > Number.MIN_VALUE);
|
257
|
+
//b2Settings.b2Assert(this.m_limitMass2 > Number.MIN_VALUE);
|
258
|
+
//b2Settings.b2Assert(this.m_pulleyMass > Number.MIN_VALUE);
|
259
|
+
this.m_limitMass1 = 1.0 / this.m_limitMass1;
|
260
|
+
this.m_limitMass2 = 1.0 / this.m_limitMass2;
|
261
|
+
this.m_pulleyMass = 1.0 / this.m_pulleyMass;
|
262
|
+
|
263
|
+
// Warm starting.
|
264
|
+
//b2Vec2 P1 = (-this.m_pulleyImpulse - this.m_limitImpulse1) * this.m_u1;
|
265
|
+
var P1X = (-this.m_pulleyImpulse - this.m_limitImpulse1) * this.m_u1.x;
|
266
|
+
var P1Y = (-this.m_pulleyImpulse - this.m_limitImpulse1) * this.m_u1.y;
|
267
|
+
//b2Vec2 P2 = (-this.m_ratio * this.m_pulleyImpulse - this.m_limitImpulse2) * this.m_u2;
|
268
|
+
var P2X = (-this.m_ratio * this.m_pulleyImpulse - this.m_limitImpulse2) * this.m_u2.x;
|
269
|
+
var P2Y = (-this.m_ratio * this.m_pulleyImpulse - this.m_limitImpulse2) * this.m_u2.y;
|
270
|
+
//b1.m_linearVelocity += b1.m_invMass * P1;
|
271
|
+
b1.m_linearVelocity.x += b1.m_invMass * P1X;
|
272
|
+
b1.m_linearVelocity.y += b1.m_invMass * P1Y;
|
273
|
+
//b1.m_angularVelocity += b1.m_invI * b2Cross(r1, P1);
|
274
|
+
b1.m_angularVelocity += b1.m_invI * (r1X * P1Y - r1Y * P1X);
|
275
|
+
//b2.m_linearVelocity += b2.m_invMass * P2;
|
276
|
+
b2.m_linearVelocity.x += b2.m_invMass * P2X;
|
277
|
+
b2.m_linearVelocity.y += b2.m_invMass * P2Y;
|
278
|
+
//b2.m_angularVelocity += b2.m_invI * b2Cross(r2, P2);
|
279
|
+
b2.m_angularVelocity += b2.m_invI * (r2X * P2Y - r2Y * P2X);
|
280
|
+
},
|
281
|
+
|
282
|
+
SolveVelocityConstraints: function(step){
|
283
|
+
var b1 = this.m_body1;
|
284
|
+
var b2 = this.m_body2;
|
285
|
+
|
286
|
+
var tMat;
|
287
|
+
|
288
|
+
//var r1 = b2Mul(b1.m_R, this.m_localAnchor1);
|
289
|
+
tMat = b1.m_R;
|
290
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
291
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
292
|
+
//var r2 = b2Mul(b2.m_R, this.m_localAnchor2);
|
293
|
+
tMat = b2.m_R;
|
294
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
295
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
296
|
+
|
297
|
+
// temp vars
|
298
|
+
var v1X;
|
299
|
+
var v1Y;
|
300
|
+
var v2X;
|
301
|
+
var v2Y;
|
302
|
+
var P1X;
|
303
|
+
var P1Y;
|
304
|
+
var P2X;
|
305
|
+
var P2Y;
|
306
|
+
var Cdot;
|
307
|
+
var impulse;
|
308
|
+
var oldLimitImpulse;
|
309
|
+
|
310
|
+
//{
|
311
|
+
//b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1);
|
312
|
+
v1X = b1.m_linearVelocity.x + (-b1.m_angularVelocity * r1Y);
|
313
|
+
v1Y = b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X);
|
314
|
+
//b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2);
|
315
|
+
v2X = b2.m_linearVelocity.x + (-b2.m_angularVelocity * r2Y);
|
316
|
+
v2Y = b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X);
|
317
|
+
|
318
|
+
//Cdot = -b2Dot(this.m_u1, v1) - this.m_ratio * b2Dot(this.m_u2, v2);
|
319
|
+
Cdot = -(this.m_u1.x * v1X + this.m_u1.y * v1Y) - this.m_ratio * (this.m_u2.x * v2X + this.m_u2.y * v2Y);
|
320
|
+
impulse = -this.m_pulleyMass * Cdot;
|
321
|
+
this.m_pulleyImpulse += impulse;
|
322
|
+
|
323
|
+
//b2Vec2 P1 = -impulse * this.m_u1;
|
324
|
+
P1X = -impulse * this.m_u1.x;
|
325
|
+
P1Y = -impulse * this.m_u1.y;
|
326
|
+
//b2Vec2 P2 = -this.m_ratio * impulse * this.m_u2;
|
327
|
+
P2X = -this.m_ratio * impulse * this.m_u2.x;
|
328
|
+
P2Y = -this.m_ratio * impulse * this.m_u2.y;
|
329
|
+
//b1.m_linearVelocity += b1.m_invMass * P1;
|
330
|
+
b1.m_linearVelocity.x += b1.m_invMass * P1X;
|
331
|
+
b1.m_linearVelocity.y += b1.m_invMass * P1Y;
|
332
|
+
//b1.m_angularVelocity += b1.m_invI * b2Cross(r1, P1);
|
333
|
+
b1.m_angularVelocity += b1.m_invI * (r1X * P1Y - r1Y * P1X);
|
334
|
+
//b2.m_linearVelocity += b2.m_invMass * P2;
|
335
|
+
b2.m_linearVelocity.x += b2.m_invMass * P2X;
|
336
|
+
b2.m_linearVelocity.y += b2.m_invMass * P2Y;
|
337
|
+
//b2.m_angularVelocity += b2.m_invI * b2Cross(r2, P2);
|
338
|
+
b2.m_angularVelocity += b2.m_invI * (r2X * P2Y - r2Y * P2X);
|
339
|
+
//}
|
340
|
+
|
341
|
+
if (this.m_limitState1 == b2Joint.e_atUpperLimit)
|
342
|
+
{
|
343
|
+
//b2Vec2 v1 = b1->m_linearVelocity + b2Cross(b1->m_angularVelocity, r1);
|
344
|
+
v1X = b1.m_linearVelocity.x + (-b1.m_angularVelocity * r1Y);
|
345
|
+
v1Y = b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X);
|
346
|
+
|
347
|
+
//float32 Cdot = -b2Dot(this.m_u1, v1);
|
348
|
+
Cdot = -(this.m_u1.x * v1X + this.m_u1.y * v1Y);
|
349
|
+
impulse = -this.m_limitMass1 * Cdot;
|
350
|
+
oldLimitImpulse = this.m_limitImpulse1;
|
351
|
+
this.m_limitImpulse1 = b2Math.b2Max(0.0, this.m_limitImpulse1 + impulse);
|
352
|
+
impulse = this.m_limitImpulse1 - oldLimitImpulse;
|
353
|
+
//b2Vec2 P1 = -impulse * this.m_u1;
|
354
|
+
P1X = -impulse * this.m_u1.x;
|
355
|
+
P1Y = -impulse * this.m_u1.y;
|
356
|
+
//b1.m_linearVelocity += b1->m_invMass * P1;
|
357
|
+
b1.m_linearVelocity.x += b1.m_invMass * P1X;
|
358
|
+
b1.m_linearVelocity.y += b1.m_invMass * P1Y;
|
359
|
+
//b1.m_angularVelocity += b1->m_invI * b2Cross(r1, P1);
|
360
|
+
b1.m_angularVelocity += b1.m_invI * (r1X * P1Y - r1Y * P1X);
|
361
|
+
}
|
362
|
+
|
363
|
+
if (this.m_limitState2 == b2Joint.e_atUpperLimit)
|
364
|
+
{
|
365
|
+
//b2Vec2 v2 = b2->m_linearVelocity + b2Cross(b2->m_angularVelocity, r2);
|
366
|
+
v2X = b2.m_linearVelocity.x + (-b2.m_angularVelocity * r2Y);
|
367
|
+
v2Y = b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X);
|
368
|
+
|
369
|
+
//float32 Cdot = -b2Dot(this.m_u2, v2);
|
370
|
+
Cdot = -(this.m_u2.x * v2X + this.m_u2.y * v2Y);
|
371
|
+
impulse = -this.m_limitMass2 * Cdot;
|
372
|
+
oldLimitImpulse = this.m_limitImpulse2;
|
373
|
+
this.m_limitImpulse2 = b2Math.b2Max(0.0, this.m_limitImpulse2 + impulse);
|
374
|
+
impulse = this.m_limitImpulse2 - oldLimitImpulse;
|
375
|
+
//b2Vec2 P2 = -impulse * this.m_u2;
|
376
|
+
P2X = -impulse * this.m_u2.x;
|
377
|
+
P2Y = -impulse * this.m_u2.y;
|
378
|
+
//b2->m_linearVelocity += b2->m_invMass * P2;
|
379
|
+
b2.m_linearVelocity.x += b2.m_invMass * P2X;
|
380
|
+
b2.m_linearVelocity.y += b2.m_invMass * P2Y;
|
381
|
+
//b2->m_angularVelocity += b2->m_invI * b2Cross(r2, P2);
|
382
|
+
b2.m_angularVelocity += b2.m_invI * (r2X * P2Y - r2Y * P2X);
|
383
|
+
}
|
384
|
+
},
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
SolvePositionConstraints: function(){
|
389
|
+
var b1 = this.m_body1;
|
390
|
+
var b2 = this.m_body2;
|
391
|
+
|
392
|
+
var tMat;
|
393
|
+
|
394
|
+
//b2Vec2 s1 = this.m_ground->m_position + this.m_groundAnchor1;
|
395
|
+
var s1X = this.m_ground.m_position.x + this.m_groundAnchor1.x;
|
396
|
+
var s1Y = this.m_ground.m_position.y + this.m_groundAnchor1.y;
|
397
|
+
//b2Vec2 s2 = this.m_ground->m_position + this.m_groundAnchor2;
|
398
|
+
var s2X = this.m_ground.m_position.x + this.m_groundAnchor2.x;
|
399
|
+
var s2Y = this.m_ground.m_position.y + this.m_groundAnchor2.y;
|
400
|
+
|
401
|
+
// temp vars
|
402
|
+
var r1X;
|
403
|
+
var r1Y;
|
404
|
+
var r2X;
|
405
|
+
var r2Y;
|
406
|
+
var p1X;
|
407
|
+
var p1Y;
|
408
|
+
var p2X;
|
409
|
+
var p2Y;
|
410
|
+
var length1;
|
411
|
+
var length2;
|
412
|
+
var C;
|
413
|
+
var impulse;
|
414
|
+
var oldLimitPositionImpulse;
|
415
|
+
|
416
|
+
var linearError = 0.0;
|
417
|
+
|
418
|
+
{
|
419
|
+
//var r1 = b2Mul(b1.m_R, this.m_localAnchor1);
|
420
|
+
tMat = b1.m_R;
|
421
|
+
r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
422
|
+
r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
423
|
+
//var r2 = b2Mul(b2.m_R, this.m_localAnchor2);
|
424
|
+
tMat = b2.m_R;
|
425
|
+
r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
426
|
+
r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
427
|
+
|
428
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
429
|
+
p1X = b1.m_position.x + r1X;
|
430
|
+
p1Y = b1.m_position.y + r1Y;
|
431
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
432
|
+
p2X = b2.m_position.x + r2X;
|
433
|
+
p2Y = b2.m_position.y + r2Y;
|
434
|
+
|
435
|
+
// Get the pulley axes.
|
436
|
+
//this.m_u1 = p1 - s1;
|
437
|
+
this.m_u1.Set(p1X - s1X, p1Y - s1Y);
|
438
|
+
//this.m_u2 = p2 - s2;
|
439
|
+
this.m_u2.Set(p2X - s2X, p2Y - s2Y);
|
440
|
+
|
441
|
+
length1 = this.m_u1.Length();
|
442
|
+
length2 = this.m_u2.Length();
|
443
|
+
|
444
|
+
if (length1 > b2Settings.b2_linearSlop)
|
445
|
+
{
|
446
|
+
//this.m_u1 *= 1.0f / length1;
|
447
|
+
this.m_u1.Multiply( 1.0 / length1 );
|
448
|
+
}
|
449
|
+
else
|
450
|
+
{
|
451
|
+
this.m_u1.SetZero();
|
452
|
+
}
|
453
|
+
|
454
|
+
if (length2 > b2Settings.b2_linearSlop)
|
455
|
+
{
|
456
|
+
//this.m_u2 *= 1.0f / length2;
|
457
|
+
this.m_u2.Multiply( 1.0 / length2 );
|
458
|
+
}
|
459
|
+
else
|
460
|
+
{
|
461
|
+
this.m_u2.SetZero();
|
462
|
+
}
|
463
|
+
|
464
|
+
C = this.m_constant - length1 - this.m_ratio * length2;
|
465
|
+
linearError = b2Math.b2Max(linearError, Math.abs(C));
|
466
|
+
C = b2Math.b2Clamp(C, -b2Settings.b2_maxLinearCorrection, b2Settings.b2_maxLinearCorrection);
|
467
|
+
impulse = -this.m_pulleyMass * C;
|
468
|
+
|
469
|
+
p1X = -impulse * this.m_u1.x;
|
470
|
+
p1Y = -impulse * this.m_u1.y;
|
471
|
+
p2X = -this.m_ratio * impulse * this.m_u2.x;
|
472
|
+
p2Y = -this.m_ratio * impulse * this.m_u2.y;
|
473
|
+
|
474
|
+
b1.m_position.x += b1.m_invMass * p1X;
|
475
|
+
b1.m_position.y += b1.m_invMass * p1Y;
|
476
|
+
b1.m_rotation += b1.m_invI * (r1X * p1Y - r1Y * p1X);
|
477
|
+
b2.m_position.x += b2.m_invMass * p2X;
|
478
|
+
b2.m_position.y += b2.m_invMass * p2Y;
|
479
|
+
b2.m_rotation += b2.m_invI * (r2X * p2Y - r2Y * p2X);
|
480
|
+
|
481
|
+
b1.m_R.Set(b1.m_rotation);
|
482
|
+
b2.m_R.Set(b2.m_rotation);
|
483
|
+
}
|
484
|
+
|
485
|
+
if (this.m_limitState1 == b2Joint.e_atUpperLimit)
|
486
|
+
{
|
487
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
488
|
+
tMat = b1.m_R;
|
489
|
+
r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
490
|
+
r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
491
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
492
|
+
p1X = b1.m_position.x + r1X;
|
493
|
+
p1Y = b1.m_position.y + r1Y;
|
494
|
+
|
495
|
+
//this.m_u1 = p1 - s1;
|
496
|
+
this.m_u1.Set(p1X - s1X, p1Y - s1Y);
|
497
|
+
|
498
|
+
length1 = this.m_u1.Length();
|
499
|
+
|
500
|
+
if (length1 > b2Settings.b2_linearSlop)
|
501
|
+
{
|
502
|
+
//this.m_u1 *= 1.0 / length1;
|
503
|
+
this.m_u1.x *= 1.0 / length1;
|
504
|
+
this.m_u1.y *= 1.0 / length1;
|
505
|
+
}
|
506
|
+
else
|
507
|
+
{
|
508
|
+
this.m_u1.SetZero();
|
509
|
+
}
|
510
|
+
|
511
|
+
C = this.m_maxLength1 - length1;
|
512
|
+
linearError = b2Math.b2Max(linearError, -C);
|
513
|
+
C = b2Math.b2Clamp(C + b2Settings.b2_linearSlop, -b2Settings.b2_maxLinearCorrection, 0.0);
|
514
|
+
impulse = -this.m_limitMass1 * C;
|
515
|
+
oldLimitPositionImpulse = this.m_limitPositionImpulse1;
|
516
|
+
this.m_limitPositionImpulse1 = b2Math.b2Max(0.0, this.m_limitPositionImpulse1 + impulse);
|
517
|
+
impulse = this.m_limitPositionImpulse1 - oldLimitPositionImpulse;
|
518
|
+
|
519
|
+
//P1 = -impulse * this.m_u1;
|
520
|
+
p1X = -impulse * this.m_u1.x;
|
521
|
+
p1Y = -impulse * this.m_u1.y;
|
522
|
+
|
523
|
+
b1.m_position.x += b1.m_invMass * p1X;
|
524
|
+
b1.m_position.y += b1.m_invMass * p1Y;
|
525
|
+
//b1.m_rotation += b1.m_invI * b2Cross(r1, P1);
|
526
|
+
b1.m_rotation += b1.m_invI * (r1X * p1Y - r1Y * p1X);
|
527
|
+
b1.m_R.Set(b1.m_rotation);
|
528
|
+
}
|
529
|
+
|
530
|
+
if (this.m_limitState2 == b2Joint.e_atUpperLimit)
|
531
|
+
{
|
532
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
533
|
+
tMat = b2.m_R;
|
534
|
+
r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
535
|
+
r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
536
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
537
|
+
p2X = b2.m_position.x + r2X;
|
538
|
+
p2Y = b2.m_position.y + r2Y;
|
539
|
+
|
540
|
+
//this.m_u2 = p2 - s2;
|
541
|
+
this.m_u2.Set(p2X - s2X, p2Y - s2Y);
|
542
|
+
|
543
|
+
length2 = this.m_u2.Length();
|
544
|
+
|
545
|
+
if (length2 > b2Settings.b2_linearSlop)
|
546
|
+
{
|
547
|
+
//this.m_u2 *= 1.0 / length2;
|
548
|
+
this.m_u2.x *= 1.0 / length2;
|
549
|
+
this.m_u2.y *= 1.0 / length2;
|
550
|
+
}
|
551
|
+
else
|
552
|
+
{
|
553
|
+
this.m_u2.SetZero();
|
554
|
+
}
|
555
|
+
|
556
|
+
C = this.m_maxLength2 - length2;
|
557
|
+
linearError = b2Math.b2Max(linearError, -C);
|
558
|
+
C = b2Math.b2Clamp(C + b2Settings.b2_linearSlop, -b2Settings.b2_maxLinearCorrection, 0.0);
|
559
|
+
impulse = -this.m_limitMass2 * C;
|
560
|
+
oldLimitPositionImpulse = this.m_limitPositionImpulse2;
|
561
|
+
this.m_limitPositionImpulse2 = b2Math.b2Max(0.0, this.m_limitPositionImpulse2 + impulse);
|
562
|
+
impulse = this.m_limitPositionImpulse2 - oldLimitPositionImpulse;
|
563
|
+
|
564
|
+
//P2 = -impulse * this.m_u2;
|
565
|
+
p2X = -impulse * this.m_u2.x;
|
566
|
+
p2Y = -impulse * this.m_u2.y;
|
567
|
+
|
568
|
+
//b2.m_position += b2.m_invMass * P2;
|
569
|
+
b2.m_position.x += b2.m_invMass * p2X;
|
570
|
+
b2.m_position.y += b2.m_invMass * p2Y;
|
571
|
+
//b2.m_rotation += b2.m_invI * b2Cross(r2, P2);
|
572
|
+
b2.m_rotation += b2.m_invI * (r2X * p2Y - r2Y * p2X);
|
573
|
+
b2.m_R.Set(b2.m_rotation);
|
574
|
+
}
|
575
|
+
|
576
|
+
return linearError < b2Settings.b2_linearSlop;
|
577
|
+
},
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
m_ground: null,
|
582
|
+
m_groundAnchor1: new b2Vec2(),
|
583
|
+
m_groundAnchor2: new b2Vec2(),
|
584
|
+
m_localAnchor1: new b2Vec2(),
|
585
|
+
m_localAnchor2: new b2Vec2(),
|
586
|
+
|
587
|
+
m_u1: new b2Vec2(),
|
588
|
+
m_u2: new b2Vec2(),
|
589
|
+
|
590
|
+
m_constant: null,
|
591
|
+
m_ratio: null,
|
592
|
+
|
593
|
+
m_maxLength1: null,
|
594
|
+
m_maxLength2: null,
|
595
|
+
|
596
|
+
// Effective masses
|
597
|
+
m_pulleyMass: null,
|
598
|
+
m_limitMass1: null,
|
599
|
+
m_limitMass2: null,
|
600
|
+
|
601
|
+
// Impulses for accumulation/warm starting.
|
602
|
+
m_pulleyImpulse: null,
|
603
|
+
m_limitImpulse1: null,
|
604
|
+
m_limitImpulse2: null,
|
605
|
+
|
606
|
+
// Position impulses for accumulation.
|
607
|
+
m_limitPositionImpulse1: null,
|
608
|
+
m_limitPositionImpulse2: null,
|
609
|
+
|
610
|
+
m_limitState1: 0,
|
611
|
+
m_limitState2: 0
|
612
|
+
|
613
|
+
// static
|
614
|
+
});
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
b2PulleyJoint.b2_minPulleyLength = b2Settings.b2_lengthUnitsPerMeter;
|