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,49 @@
|
|
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 b2DistanceJointDef = Class.create();
|
24
|
+
Object.extend(b2DistanceJointDef.prototype, b2JointDef.prototype);
|
25
|
+
Object.extend(b2DistanceJointDef.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.anchorPoint1 = new b2Vec2();
|
39
|
+
this.anchorPoint2 = new b2Vec2();
|
40
|
+
//
|
41
|
+
|
42
|
+
this.type = b2Joint.e_distanceJoint;
|
43
|
+
//this.anchorPoint1.Set(0.0, 0.0);
|
44
|
+
//this.anchorPoint2.Set(0.0, 0.0);
|
45
|
+
},
|
46
|
+
|
47
|
+
anchorPoint1: new b2Vec2(),
|
48
|
+
anchorPoint2: new b2Vec2()});
|
49
|
+
|
@@ -0,0 +1,307 @@
|
|
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
|
+
var b2GearJoint = Class.create();
|
25
|
+
Object.extend(b2GearJoint.prototype, b2Joint.prototype);
|
26
|
+
Object.extend(b2GearJoint.prototype,
|
27
|
+
{
|
28
|
+
GetAnchor1: function(){
|
29
|
+
//return this.m_body1.m_position + b2MulMV(this.m_body1.m_R, this.m_localAnchor1);
|
30
|
+
var tMat = this.m_body1.m_R;
|
31
|
+
return new b2Vec2( this.m_body1.m_position.x + (tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y),
|
32
|
+
this.m_body1.m_position.y + (tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y));
|
33
|
+
},
|
34
|
+
GetAnchor2: function(){
|
35
|
+
//return this.m_body2->m_position + b2Mul(this.m_body2->m_R, this.m_localAnchor2);
|
36
|
+
var tMat = this.m_body2.m_R;
|
37
|
+
return new b2Vec2( this.m_body2.m_position.x + (tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y),
|
38
|
+
this.m_body2.m_position.y + (tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y));
|
39
|
+
},
|
40
|
+
|
41
|
+
GetReactionForce: function(invTimeStep){
|
42
|
+
//b2Vec2 F(0.0f, 0.0f);
|
43
|
+
return new b2Vec2();
|
44
|
+
},
|
45
|
+
GetReactionTorque: function(invTimeStep){
|
46
|
+
return 0.0;
|
47
|
+
},
|
48
|
+
|
49
|
+
GetRatio: function(){
|
50
|
+
return this.m_ratio;
|
51
|
+
},
|
52
|
+
|
53
|
+
//--------------- Internals Below -------------------
|
54
|
+
|
55
|
+
initialize: function(def){
|
56
|
+
// The constructor for b2Joint
|
57
|
+
// initialize instance variables for references
|
58
|
+
this.m_node1 = new b2JointNode();
|
59
|
+
this.m_node2 = new b2JointNode();
|
60
|
+
//
|
61
|
+
this.m_type = def.type;
|
62
|
+
this.m_prev = null;
|
63
|
+
this.m_next = null;
|
64
|
+
this.m_body1 = def.body1;
|
65
|
+
this.m_body2 = def.body2;
|
66
|
+
this.m_collideConnected = def.collideConnected;
|
67
|
+
this.m_islandFlag = false;
|
68
|
+
this.m_userData = def.userData;
|
69
|
+
//
|
70
|
+
|
71
|
+
// initialize instance variables for references
|
72
|
+
this.m_groundAnchor1 = new b2Vec2();
|
73
|
+
this.m_groundAnchor2 = new b2Vec2();
|
74
|
+
this.m_localAnchor1 = new b2Vec2();
|
75
|
+
this.m_localAnchor2 = new b2Vec2();
|
76
|
+
this.m_J = new b2Jacobian();
|
77
|
+
//
|
78
|
+
|
79
|
+
// parent constructor
|
80
|
+
//super(def);
|
81
|
+
|
82
|
+
//b2Settings.b2Assert(def.joint1.m_type == b2Joint.e_revoluteJoint || def.joint1.m_type == b2Joint.e_prismaticJoint);
|
83
|
+
//b2Settings.b2Assert(def.joint2.m_type == b2Joint.e_revoluteJoint || def.joint2.m_type == b2Joint.e_prismaticJoint);
|
84
|
+
//b2Settings.b2Assert(def.joint1.m_body1.IsStatic());
|
85
|
+
//b2Settings.b2Assert(def.joint2.m_body1.IsStatic());
|
86
|
+
|
87
|
+
this.m_revolute1 = null;
|
88
|
+
this.m_prismatic1 = null;
|
89
|
+
this.m_revolute2 = null;
|
90
|
+
this.m_prismatic2 = null;
|
91
|
+
|
92
|
+
var coordinate1;
|
93
|
+
var coordinate2;
|
94
|
+
|
95
|
+
this.m_ground1 = def.joint1.m_body1;
|
96
|
+
this.m_body1 = def.joint1.m_body2;
|
97
|
+
if (def.joint1.m_type == b2Joint.e_revoluteJoint)
|
98
|
+
{
|
99
|
+
this.m_revolute1 = def.joint1;
|
100
|
+
this.m_groundAnchor1.SetV( this.m_revolute1.m_localAnchor1 );
|
101
|
+
this.m_localAnchor1.SetV( this.m_revolute1.m_localAnchor2 );
|
102
|
+
coordinate1 = this.m_revolute1.GetJointAngle();
|
103
|
+
}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
this.m_prismatic1 = def.joint1;
|
107
|
+
this.m_groundAnchor1.SetV( this.m_prismatic1.m_localAnchor1 );
|
108
|
+
this.m_localAnchor1.SetV( this.m_prismatic1.m_localAnchor2 );
|
109
|
+
coordinate1 = this.m_prismatic1.GetJointTranslation();
|
110
|
+
}
|
111
|
+
|
112
|
+
this.m_ground2 = def.joint2.m_body1;
|
113
|
+
this.m_body2 = def.joint2.m_body2;
|
114
|
+
if (def.joint2.m_type == b2Joint.e_revoluteJoint)
|
115
|
+
{
|
116
|
+
this.m_revolute2 = def.joint2;
|
117
|
+
this.m_groundAnchor2.SetV( this.m_revolute2.m_localAnchor1 );
|
118
|
+
this.m_localAnchor2.SetV( this.m_revolute2.m_localAnchor2 );
|
119
|
+
coordinate2 = this.m_revolute2.GetJointAngle();
|
120
|
+
}
|
121
|
+
else
|
122
|
+
{
|
123
|
+
this.m_prismatic2 = def.joint2;
|
124
|
+
this.m_groundAnchor2.SetV( this.m_prismatic2.m_localAnchor1 );
|
125
|
+
this.m_localAnchor2.SetV( this.m_prismatic2.m_localAnchor2 );
|
126
|
+
coordinate2 = this.m_prismatic2.GetJointTranslation();
|
127
|
+
}
|
128
|
+
|
129
|
+
this.m_ratio = def.ratio;
|
130
|
+
|
131
|
+
this.m_constant = coordinate1 + this.m_ratio * coordinate2;
|
132
|
+
|
133
|
+
this.m_impulse = 0.0;
|
134
|
+
|
135
|
+
},
|
136
|
+
|
137
|
+
PrepareVelocitySolver: function(){
|
138
|
+
var g1 = this.m_ground1;
|
139
|
+
var g2 = this.m_ground2;
|
140
|
+
var b1 = this.m_body1;
|
141
|
+
var b2 = this.m_body2;
|
142
|
+
|
143
|
+
// temp vars
|
144
|
+
var ugX;
|
145
|
+
var ugY;
|
146
|
+
var rX;
|
147
|
+
var rY;
|
148
|
+
var tMat;
|
149
|
+
var tVec;
|
150
|
+
var crug;
|
151
|
+
|
152
|
+
var K = 0.0;
|
153
|
+
this.m_J.SetZero();
|
154
|
+
|
155
|
+
if (this.m_revolute1)
|
156
|
+
{
|
157
|
+
this.m_J.angular1 = -1.0;
|
158
|
+
K += b1.m_invI;
|
159
|
+
}
|
160
|
+
else
|
161
|
+
{
|
162
|
+
//b2Vec2 ug = b2MulMV(g1->m_R, this.m_prismatic1->m_localXAxis1);
|
163
|
+
tMat = g1.m_R;
|
164
|
+
tVec = this.m_prismatic1.m_localXAxis1;
|
165
|
+
ugX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
|
166
|
+
ugY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
|
167
|
+
//b2Vec2 r = b2MulMV(b1->m_R, this.m_localAnchor1);
|
168
|
+
tMat = b1.m_R;
|
169
|
+
rX = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
170
|
+
rY = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
171
|
+
|
172
|
+
//var crug = b2Cross(r, ug);
|
173
|
+
crug = rX * ugY - rY * ugX;
|
174
|
+
//this.m_J.linear1 = -ug;
|
175
|
+
this.m_J.linear1.Set(-ugX, -ugY);
|
176
|
+
this.m_J.angular1 = -crug;
|
177
|
+
K += b1.m_invMass + b1.m_invI * crug * crug;
|
178
|
+
}
|
179
|
+
|
180
|
+
if (this.m_revolute2)
|
181
|
+
{
|
182
|
+
this.m_J.angular2 = -this.m_ratio;
|
183
|
+
K += this.m_ratio * this.m_ratio * b2.m_invI;
|
184
|
+
}
|
185
|
+
else
|
186
|
+
{
|
187
|
+
//b2Vec2 ug = b2Mul(g2->m_R, this.m_prismatic2->m_localXAxis1);
|
188
|
+
tMat = g2.m_R;
|
189
|
+
tVec = this.m_prismatic2.m_localXAxis1;
|
190
|
+
ugX = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
|
191
|
+
ugY = tMat.col1.y * tVec.x + tMat.col2.y * tVec.y;
|
192
|
+
//b2Vec2 r = b2Mul(b2->m_R, this.m_localAnchor2);
|
193
|
+
tMat = b2.m_R;
|
194
|
+
rX = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
195
|
+
rY = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
196
|
+
//float32 crug = b2Cross(r, ug);
|
197
|
+
crug = rX * ugY - rY * ugX;
|
198
|
+
//this.m_J.linear2 = -this.m_ratio * ug;
|
199
|
+
this.m_J.linear2.Set(-this.m_ratio*ugX, -this.m_ratio*ugY);
|
200
|
+
this.m_J.angular2 = -this.m_ratio * crug;
|
201
|
+
K += this.m_ratio * this.m_ratio * (b2.m_invMass + b2.m_invI * crug * crug);
|
202
|
+
}
|
203
|
+
|
204
|
+
// Compute effective mass.
|
205
|
+
//b2Settings.b2Assert(K > 0.0);
|
206
|
+
this.m_mass = 1.0 / K;
|
207
|
+
|
208
|
+
// Warm starting.
|
209
|
+
//b1.m_linearVelocity += b1.m_invMass * this.m_impulse * this.m_J.linear1;
|
210
|
+
b1.m_linearVelocity.x += b1.m_invMass * this.m_impulse * this.m_J.linear1.x;
|
211
|
+
b1.m_linearVelocity.y += b1.m_invMass * this.m_impulse * this.m_J.linear1.y;
|
212
|
+
b1.m_angularVelocity += b1.m_invI * this.m_impulse * this.m_J.angular1;
|
213
|
+
//b2.m_linearVelocity += b2.m_invMass * this.m_impulse * this.m_J.linear2;
|
214
|
+
b2.m_linearVelocity.x += b2.m_invMass * this.m_impulse * this.m_J.linear2.x;
|
215
|
+
b2.m_linearVelocity.y += b2.m_invMass * this.m_impulse * this.m_J.linear2.y;
|
216
|
+
b2.m_angularVelocity += b2.m_invI * this.m_impulse * this.m_J.angular2;
|
217
|
+
},
|
218
|
+
|
219
|
+
|
220
|
+
SolveVelocityConstraints: function(step){
|
221
|
+
var b1 = this.m_body1;
|
222
|
+
var b2 = this.m_body2;
|
223
|
+
|
224
|
+
var Cdot = this.m_J.Compute( b1.m_linearVelocity, b1.m_angularVelocity,
|
225
|
+
b2.m_linearVelocity, b2.m_angularVelocity);
|
226
|
+
|
227
|
+
var impulse = -this.m_mass * Cdot;
|
228
|
+
this.m_impulse += impulse;
|
229
|
+
|
230
|
+
b1.m_linearVelocity.x += b1.m_invMass * impulse * this.m_J.linear1.x;
|
231
|
+
b1.m_linearVelocity.y += b1.m_invMass * impulse * this.m_J.linear1.y;
|
232
|
+
b1.m_angularVelocity += b1.m_invI * impulse * this.m_J.angular1;
|
233
|
+
b2.m_linearVelocity.x += b2.m_invMass * impulse * this.m_J.linear2.x;
|
234
|
+
b2.m_linearVelocity.y += b2.m_invMass * impulse * this.m_J.linear2.y;
|
235
|
+
b2.m_angularVelocity += b2.m_invI * impulse * this.m_J.angular2;
|
236
|
+
},
|
237
|
+
|
238
|
+
SolvePositionConstraints: function(){
|
239
|
+
var linearError = 0.0;
|
240
|
+
|
241
|
+
var b1 = this.m_body1;
|
242
|
+
var b2 = this.m_body2;
|
243
|
+
|
244
|
+
var coordinate1;
|
245
|
+
var coordinate2;
|
246
|
+
if (this.m_revolute1)
|
247
|
+
{
|
248
|
+
coordinate1 = this.m_revolute1.GetJointAngle();
|
249
|
+
}
|
250
|
+
else
|
251
|
+
{
|
252
|
+
coordinate1 = this.m_prismatic1.GetJointTranslation();
|
253
|
+
}
|
254
|
+
|
255
|
+
if (this.m_revolute2)
|
256
|
+
{
|
257
|
+
coordinate2 = this.m_revolute2.GetJointAngle();
|
258
|
+
}
|
259
|
+
else
|
260
|
+
{
|
261
|
+
coordinate2 = this.m_prismatic2.GetJointTranslation();
|
262
|
+
}
|
263
|
+
|
264
|
+
var C = this.m_constant - (coordinate1 + this.m_ratio * coordinate2);
|
265
|
+
|
266
|
+
var impulse = -this.m_mass * C;
|
267
|
+
|
268
|
+
b1.m_position.x += b1.m_invMass * impulse * this.m_J.linear1.x;
|
269
|
+
b1.m_position.y += b1.m_invMass * impulse * this.m_J.linear1.y;
|
270
|
+
b1.m_rotation += b1.m_invI * impulse * this.m_J.angular1;
|
271
|
+
b2.m_position.x += b2.m_invMass * impulse * this.m_J.linear2.x;
|
272
|
+
b2.m_position.y += b2.m_invMass * impulse * this.m_J.linear2.y;
|
273
|
+
b2.m_rotation += b2.m_invI * impulse * this.m_J.angular2;
|
274
|
+
b1.m_R.Set(b1.m_rotation);
|
275
|
+
b2.m_R.Set(b2.m_rotation);
|
276
|
+
|
277
|
+
return linearError < b2Settings.b2_linearSlop;
|
278
|
+
},
|
279
|
+
|
280
|
+
m_ground1: null,
|
281
|
+
m_ground2: null,
|
282
|
+
|
283
|
+
// One of these is NULL.
|
284
|
+
m_revolute1: null,
|
285
|
+
m_prismatic1: null,
|
286
|
+
|
287
|
+
// One of these is NULL.
|
288
|
+
m_revolute2: null,
|
289
|
+
m_prismatic2: null,
|
290
|
+
|
291
|
+
m_groundAnchor1: new b2Vec2(),
|
292
|
+
m_groundAnchor2: new b2Vec2(),
|
293
|
+
|
294
|
+
m_localAnchor1: new b2Vec2(),
|
295
|
+
m_localAnchor2: new b2Vec2(),
|
296
|
+
|
297
|
+
m_J: new b2Jacobian(),
|
298
|
+
|
299
|
+
m_constant: null,
|
300
|
+
m_ratio: null,
|
301
|
+
|
302
|
+
// Effective mass
|
303
|
+
m_mass: null,
|
304
|
+
|
305
|
+
// Impulse for accumulation/warm starting.
|
306
|
+
m_impulse: null});
|
307
|
+
|
@@ -0,0 +1,50 @@
|
|
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
|
+
// A gear joint is used to connect two joints together. Either joint
|
25
|
+
// can be a revolute or prismatic joint. You specify a gear ratio
|
26
|
+
// to bind the motions together:
|
27
|
+
// coordinate1 + ratio * coordinate2 = constant
|
28
|
+
// The ratio can be negative or positive. If one joint is a revolute joint
|
29
|
+
// and the other joint is a prismatic joint, then the ratio will have units
|
30
|
+
// of length or units of 1/length.
|
31
|
+
//
|
32
|
+
// RESTRICITON: The revolute and prismatic joints must be attached to
|
33
|
+
// a fixed body (which must be body1 on those joints).
|
34
|
+
|
35
|
+
var b2GearJointDef = Class.create();
|
36
|
+
Object.extend(b2GearJointDef.prototype, b2JointDef.prototype);
|
37
|
+
Object.extend(b2GearJointDef.prototype,
|
38
|
+
{
|
39
|
+
initialize: function()
|
40
|
+
{
|
41
|
+
this.type = b2Joint.e_gearJoint;
|
42
|
+
this.joint1 = null;
|
43
|
+
this.joint2 = null;
|
44
|
+
this.ratio = 1.0;
|
45
|
+
},
|
46
|
+
|
47
|
+
joint1: null,
|
48
|
+
joint2: null,
|
49
|
+
ratio: null});
|
50
|
+
|
@@ -0,0 +1,49 @@
|
|
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 b2Jacobian = Class.create();
|
24
|
+
b2Jacobian.prototype =
|
25
|
+
{
|
26
|
+
linear1: new b2Vec2(),
|
27
|
+
angular1: null,
|
28
|
+
linear2: new b2Vec2(),
|
29
|
+
angular2: null,
|
30
|
+
|
31
|
+
SetZero: function(){
|
32
|
+
this.linear1.SetZero(); this.angular1 = 0.0;
|
33
|
+
this.linear2.SetZero(); this.angular2 = 0.0;
|
34
|
+
},
|
35
|
+
Set: function(x1, a1, x2, a2){
|
36
|
+
this.linear1.SetV(x1); this.angular1 = a1;
|
37
|
+
this.linear2.SetV(x2); this.angular2 = a2;
|
38
|
+
},
|
39
|
+
Compute: function(x1, a1, x2, a2){
|
40
|
+
|
41
|
+
//return b2Math.b2Dot(this.linear1, x1) + this.angular1 * a1 + b2Math.b2Dot(this.linear2, x2) + this.angular2 * a2;
|
42
|
+
return (this.linear1.x*x1.x + this.linear1.y*x1.y) + this.angular1 * a1 + (this.linear2.x*x2.x + this.linear2.y*x2.y) + this.angular2 * a2;
|
43
|
+
},
|
44
|
+
initialize: function() {
|
45
|
+
// initialize instance variables for references
|
46
|
+
this.linear1 = new b2Vec2();
|
47
|
+
this.linear2 = new b2Vec2();
|
48
|
+
//
|
49
|
+
}};
|