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,70 @@
|
|
|
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
|
+
// The pulley joint is connected to two bodies and two fixed ground points.
|
|
25
|
+
// The pulley supports a ratio such that:
|
|
26
|
+
// length1 + ratio * length2 = constant
|
|
27
|
+
// Yes, the force transmitted is scaled by the ratio.
|
|
28
|
+
// The pulley also enforces a maximum length limit on both sides. This is
|
|
29
|
+
// useful to prevent one side of the pulley hitting the top.
|
|
30
|
+
|
|
31
|
+
var b2PulleyJointDef = Class.create();
|
|
32
|
+
Object.extend(b2PulleyJointDef.prototype, b2JointDef.prototype);
|
|
33
|
+
Object.extend(b2PulleyJointDef.prototype,
|
|
34
|
+
{
|
|
35
|
+
initialize: function()
|
|
36
|
+
{
|
|
37
|
+
// The constructor for b2JointDef
|
|
38
|
+
this.type = b2Joint.e_unknownJoint;
|
|
39
|
+
this.userData = null;
|
|
40
|
+
this.body1 = null;
|
|
41
|
+
this.body2 = null;
|
|
42
|
+
this.collideConnected = false;
|
|
43
|
+
//
|
|
44
|
+
|
|
45
|
+
// initialize instance variables for references
|
|
46
|
+
this.groundPoint1 = new b2Vec2();
|
|
47
|
+
this.groundPoint2 = new b2Vec2();
|
|
48
|
+
this.anchorPoint1 = new b2Vec2();
|
|
49
|
+
this.anchorPoint2 = new b2Vec2();
|
|
50
|
+
//
|
|
51
|
+
|
|
52
|
+
this.type = b2Joint.e_pulleyJoint;
|
|
53
|
+
this.groundPoint1.Set(-1.0, 1.0);
|
|
54
|
+
this.groundPoint2.Set(1.0, 1.0);
|
|
55
|
+
this.anchorPoint1.Set(-1.0, 0.0);
|
|
56
|
+
this.anchorPoint2.Set(1.0, 0.0);
|
|
57
|
+
this.maxLength1 = 0.5 * b2PulleyJoint.b2_minPulleyLength;
|
|
58
|
+
this.maxLength2 = 0.5 * b2PulleyJoint.b2_minPulleyLength;
|
|
59
|
+
this.ratio = 1.0;
|
|
60
|
+
this.collideConnected = true;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
groundPoint1: new b2Vec2(),
|
|
64
|
+
groundPoint2: new b2Vec2(),
|
|
65
|
+
anchorPoint1: new b2Vec2(),
|
|
66
|
+
anchorPoint2: new b2Vec2(),
|
|
67
|
+
maxLength1: null,
|
|
68
|
+
maxLength2: null,
|
|
69
|
+
ratio: null});
|
|
70
|
+
|
|
@@ -0,0 +1,491 @@
|
|
|
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
|
+
// Point-to-point constraint
|
|
24
|
+
// C = p2 - p1
|
|
25
|
+
// Cdot = v2 - v1
|
|
26
|
+
// = v2 + cross(w2, r2) - v1 - cross(w1, r1)
|
|
27
|
+
// J = [-I -r1_skew I r2_skew ]
|
|
28
|
+
// Identity used:
|
|
29
|
+
// w k % (rx i + ry j) = w * (-ry i + rx j)
|
|
30
|
+
|
|
31
|
+
// Motor constraint
|
|
32
|
+
// Cdot = w2 - w1
|
|
33
|
+
// J = [0 0 -1 0 0 1]
|
|
34
|
+
// K = invI1 + invI2
|
|
35
|
+
|
|
36
|
+
var b2RevoluteJoint = Class.create();
|
|
37
|
+
Object.extend(b2RevoluteJoint.prototype, b2Joint.prototype);
|
|
38
|
+
Object.extend(b2RevoluteJoint.prototype,
|
|
39
|
+
{
|
|
40
|
+
GetAnchor1: function(){
|
|
41
|
+
var tMat = this.m_body1.m_R;
|
|
42
|
+
return new b2Vec2( this.m_body1.m_position.x + (tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y),
|
|
43
|
+
this.m_body1.m_position.y + (tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y));
|
|
44
|
+
},
|
|
45
|
+
GetAnchor2: function(){
|
|
46
|
+
var tMat = this.m_body2.m_R;
|
|
47
|
+
return new b2Vec2( this.m_body2.m_position.x + (tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y),
|
|
48
|
+
this.m_body2.m_position.y + (tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y));
|
|
49
|
+
},
|
|
50
|
+
GetJointAngle: function(){
|
|
51
|
+
return this.m_body2.m_rotation - this.m_body1.m_rotation;
|
|
52
|
+
},
|
|
53
|
+
GetJointSpeed: function(){
|
|
54
|
+
return this.m_body2.m_angularVelocity - this.m_body1.m_angularVelocity;
|
|
55
|
+
},
|
|
56
|
+
GetMotorTorque: function(invTimeStep){
|
|
57
|
+
return invTimeStep * this.m_motorImpulse;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
SetMotorSpeed: function(speed)
|
|
61
|
+
{
|
|
62
|
+
this.m_motorSpeed = speed;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
SetMotorTorque: function(torque)
|
|
66
|
+
{
|
|
67
|
+
this.m_maxMotorTorque = torque;
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
GetReactionForce: function(invTimeStep)
|
|
71
|
+
{
|
|
72
|
+
var tVec = this.m_ptpImpulse.Copy();
|
|
73
|
+
tVec.Multiply(invTimeStep);
|
|
74
|
+
//return invTimeStep * this.m_ptpImpulse;
|
|
75
|
+
return tVec;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
GetReactionTorque: function(invTimeStep)
|
|
79
|
+
{
|
|
80
|
+
return invTimeStep * this.m_limitImpulse;
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
//--------------- Internals Below -------------------
|
|
84
|
+
|
|
85
|
+
initialize: function(def){
|
|
86
|
+
// The constructor for b2Joint
|
|
87
|
+
// initialize instance variables for references
|
|
88
|
+
this.m_node1 = new b2JointNode();
|
|
89
|
+
this.m_node2 = new b2JointNode();
|
|
90
|
+
//
|
|
91
|
+
this.m_type = def.type;
|
|
92
|
+
this.m_prev = null;
|
|
93
|
+
this.m_next = null;
|
|
94
|
+
this.m_body1 = def.body1;
|
|
95
|
+
this.m_body2 = def.body2;
|
|
96
|
+
this.m_collideConnected = def.collideConnected;
|
|
97
|
+
this.m_islandFlag = false;
|
|
98
|
+
this.m_userData = def.userData;
|
|
99
|
+
//
|
|
100
|
+
|
|
101
|
+
// initialize instance variables for references
|
|
102
|
+
this.K = new b2Mat22();
|
|
103
|
+
this.K1 = new b2Mat22();
|
|
104
|
+
this.K2 = new b2Mat22();
|
|
105
|
+
this.K3 = new b2Mat22();
|
|
106
|
+
this.m_localAnchor1 = new b2Vec2();
|
|
107
|
+
this.m_localAnchor2 = new b2Vec2();
|
|
108
|
+
this.m_ptpImpulse = new b2Vec2();
|
|
109
|
+
this.m_ptpMass = new b2Mat22();
|
|
110
|
+
//
|
|
111
|
+
|
|
112
|
+
//super(def);
|
|
113
|
+
|
|
114
|
+
var tMat;
|
|
115
|
+
var tX;
|
|
116
|
+
var tY;
|
|
117
|
+
|
|
118
|
+
//this.m_localAnchor1 = b2Math.b2MulTMV(this.m_body1.m_R, b2Math.SubtractVV( def.anchorPoint, this.m_body1.m_position));
|
|
119
|
+
tMat = this.m_body1.m_R;
|
|
120
|
+
tX = def.anchorPoint.x - this.m_body1.m_position.x;
|
|
121
|
+
tY = def.anchorPoint.y - this.m_body1.m_position.y;
|
|
122
|
+
this.m_localAnchor1.x = tX * tMat.col1.x + tY * tMat.col1.y;
|
|
123
|
+
this.m_localAnchor1.y = tX * tMat.col2.x + tY * tMat.col2.y;
|
|
124
|
+
//this.m_localAnchor2 = b2Math.b2MulTMV(this.m_body2.m_R, b2Math.SubtractVV( def.anchorPoint, this.m_body2.m_position));
|
|
125
|
+
tMat = this.m_body2.m_R;
|
|
126
|
+
tX = def.anchorPoint.x - this.m_body2.m_position.x;
|
|
127
|
+
tY = def.anchorPoint.y - this.m_body2.m_position.y;
|
|
128
|
+
this.m_localAnchor2.x = tX * tMat.col1.x + tY * tMat.col1.y;
|
|
129
|
+
this.m_localAnchor2.y = tX * tMat.col2.x + tY * tMat.col2.y;
|
|
130
|
+
|
|
131
|
+
this.m_intialAngle = this.m_body2.m_rotation - this.m_body1.m_rotation;
|
|
132
|
+
|
|
133
|
+
this.m_ptpImpulse.Set(0.0, 0.0);
|
|
134
|
+
this.m_motorImpulse = 0.0;
|
|
135
|
+
this.m_limitImpulse = 0.0;
|
|
136
|
+
this.m_limitPositionImpulse = 0.0;
|
|
137
|
+
|
|
138
|
+
this.m_lowerAngle = def.lowerAngle;
|
|
139
|
+
this.m_upperAngle = def.upperAngle;
|
|
140
|
+
this.m_maxMotorTorque = def.motorTorque;
|
|
141
|
+
this.m_motorSpeed = def.motorSpeed;
|
|
142
|
+
this.m_enableLimit = def.enableLimit;
|
|
143
|
+
this.m_enableMotor = def.enableMotor;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// internal vars
|
|
147
|
+
K: new b2Mat22(),
|
|
148
|
+
K1: new b2Mat22(),
|
|
149
|
+
K2: new b2Mat22(),
|
|
150
|
+
K3: new b2Mat22(),
|
|
151
|
+
PrepareVelocitySolver: function(){
|
|
152
|
+
var b1 = this.m_body1;
|
|
153
|
+
var b2 = this.m_body2;
|
|
154
|
+
|
|
155
|
+
var tMat;
|
|
156
|
+
|
|
157
|
+
// Compute the effective mass matrix.
|
|
158
|
+
//b2Vec2 r1 = b2Mul(b1->m_R, this.m_localAnchor1);
|
|
159
|
+
tMat = b1.m_R;
|
|
160
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
161
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
162
|
+
//b2Vec2 r2 = b2Mul(b2->m_R, this.m_localAnchor2);
|
|
163
|
+
tMat = b2.m_R;
|
|
164
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
165
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
166
|
+
|
|
167
|
+
// this.K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)]
|
|
168
|
+
// = [1/m1+1/m2 0 ] + invI1 * [r1.y*r1.y -r1.x*r1.y] + invI2 * [r1.y*r1.y -r1.x*r1.y]
|
|
169
|
+
// [ 0 1/m1+1/m2] [-r1.x*r1.y r1.x*r1.x] [-r1.x*r1.y r1.x*r1.x]
|
|
170
|
+
var invMass1 = b1.m_invMass;
|
|
171
|
+
var invMass2 = b2.m_invMass;
|
|
172
|
+
var invI1 = b1.m_invI;
|
|
173
|
+
var invI2 = b2.m_invI;
|
|
174
|
+
|
|
175
|
+
//var this.K1 = new b2Mat22();
|
|
176
|
+
this.K1.col1.x = invMass1 + invMass2; this.K1.col2.x = 0.0;
|
|
177
|
+
this.K1.col1.y = 0.0; this.K1.col2.y = invMass1 + invMass2;
|
|
178
|
+
|
|
179
|
+
//var this.K2 = new b2Mat22();
|
|
180
|
+
this.K2.col1.x = invI1 * r1Y * r1Y; this.K2.col2.x = -invI1 * r1X * r1Y;
|
|
181
|
+
this.K2.col1.y = -invI1 * r1X * r1Y; this.K2.col2.y = invI1 * r1X * r1X;
|
|
182
|
+
|
|
183
|
+
//var this.K3 = new b2Mat22();
|
|
184
|
+
this.K3.col1.x = invI2 * r2Y * r2Y; this.K3.col2.x = -invI2 * r2X * r2Y;
|
|
185
|
+
this.K3.col1.y = -invI2 * r2X * r2Y; this.K3.col2.y = invI2 * r2X * r2X;
|
|
186
|
+
|
|
187
|
+
//var this.K = b2Math.AddMM(b2Math.AddMM(this.K1, this.K2), this.K3);
|
|
188
|
+
this.K.SetM(this.K1);
|
|
189
|
+
this.K.AddM(this.K2);
|
|
190
|
+
this.K.AddM(this.K3);
|
|
191
|
+
|
|
192
|
+
//this.m_ptpMass = this.K.Invert();
|
|
193
|
+
this.K.Invert(this.m_ptpMass);
|
|
194
|
+
|
|
195
|
+
this.m_motorMass = 1.0 / (invI1 + invI2);
|
|
196
|
+
|
|
197
|
+
if (this.m_enableMotor == false)
|
|
198
|
+
{
|
|
199
|
+
this.m_motorImpulse = 0.0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (this.m_enableLimit)
|
|
203
|
+
{
|
|
204
|
+
var jointAngle = b2.m_rotation - b1.m_rotation - this.m_intialAngle;
|
|
205
|
+
if (b2Math.b2Abs(this.m_upperAngle - this.m_lowerAngle) < 2.0 * b2Settings.b2_angularSlop)
|
|
206
|
+
{
|
|
207
|
+
this.m_limitState = b2Joint.e_equalLimits;
|
|
208
|
+
}
|
|
209
|
+
else if (jointAngle <= this.m_lowerAngle)
|
|
210
|
+
{
|
|
211
|
+
if (this.m_limitState != b2Joint.e_atLowerLimit)
|
|
212
|
+
{
|
|
213
|
+
this.m_limitImpulse = 0.0;
|
|
214
|
+
}
|
|
215
|
+
this.m_limitState = b2Joint.e_atLowerLimit;
|
|
216
|
+
}
|
|
217
|
+
else if (jointAngle >= this.m_upperAngle)
|
|
218
|
+
{
|
|
219
|
+
if (this.m_limitState != b2Joint.e_atUpperLimit)
|
|
220
|
+
{
|
|
221
|
+
this.m_limitImpulse = 0.0;
|
|
222
|
+
}
|
|
223
|
+
this.m_limitState = b2Joint.e_atUpperLimit;
|
|
224
|
+
}
|
|
225
|
+
else
|
|
226
|
+
{
|
|
227
|
+
this.m_limitState = b2Joint.e_inactiveLimit;
|
|
228
|
+
this.m_limitImpulse = 0.0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else
|
|
232
|
+
{
|
|
233
|
+
this.m_limitImpulse = 0.0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Warm starting.
|
|
237
|
+
if (b2World.s_enableWarmStarting)
|
|
238
|
+
{
|
|
239
|
+
//b1.m_linearVelocity.Subtract( b2Math.MulFV( invMass1, this.m_ptpImpulse) );
|
|
240
|
+
b1.m_linearVelocity.x -= invMass1 * this.m_ptpImpulse.x;
|
|
241
|
+
b1.m_linearVelocity.y -= invMass1 * this.m_ptpImpulse.y;
|
|
242
|
+
//b1.m_angularVelocity -= invI1 * (b2Math.b2CrossVV(r1, this.m_ptpImpulse) + this.m_motorImpulse + this.m_limitImpulse);
|
|
243
|
+
b1.m_angularVelocity -= invI1 * ((r1X * this.m_ptpImpulse.y - r1Y * this.m_ptpImpulse.x) + this.m_motorImpulse + this.m_limitImpulse);
|
|
244
|
+
|
|
245
|
+
//b2.m_linearVelocity.Add( b2Math.MulFV( invMass2 , this.m_ptpImpulse ));
|
|
246
|
+
b2.m_linearVelocity.x += invMass2 * this.m_ptpImpulse.x;
|
|
247
|
+
b2.m_linearVelocity.y += invMass2 * this.m_ptpImpulse.y;
|
|
248
|
+
//b2.m_angularVelocity += invI2 * (b2Math.b2CrossVV(r2, this.m_ptpImpulse) + this.m_motorImpulse + this.m_limitImpulse);
|
|
249
|
+
b2.m_angularVelocity += invI2 * ((r2X * this.m_ptpImpulse.y - r2Y * this.m_ptpImpulse.x) + this.m_motorImpulse + this.m_limitImpulse);
|
|
250
|
+
}
|
|
251
|
+
else{
|
|
252
|
+
this.m_ptpImpulse.SetZero();
|
|
253
|
+
this.m_motorImpulse = 0.0;
|
|
254
|
+
this.m_limitImpulse = 0.0;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.m_limitPositionImpulse = 0.0;
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
SolveVelocityConstraints: function(step){
|
|
262
|
+
var b1 = this.m_body1;
|
|
263
|
+
var b2 = this.m_body2;
|
|
264
|
+
|
|
265
|
+
var tMat;
|
|
266
|
+
|
|
267
|
+
//var r1 = b2Math.b2MulMV(b1.m_R, this.m_localAnchor1);
|
|
268
|
+
tMat = b1.m_R;
|
|
269
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
270
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
271
|
+
//var r2 = b2Math.b2MulMV(b2.m_R, this.m_localAnchor2);
|
|
272
|
+
tMat = b2.m_R;
|
|
273
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
274
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
275
|
+
|
|
276
|
+
var oldLimitImpulse;
|
|
277
|
+
|
|
278
|
+
// Solve point-to-point constraint
|
|
279
|
+
//b2Vec2 ptpCdot = b2.m_linearVelocity + b2Cross(b2.m_angularVelocity, r2) - b1.m_linearVelocity - b2Cross(b1.m_angularVelocity, r1);
|
|
280
|
+
var ptpCdotX = b2.m_linearVelocity.x + (-b2.m_angularVelocity * r2Y) - b1.m_linearVelocity.x - (-b1.m_angularVelocity * r1Y);
|
|
281
|
+
var ptpCdotY = b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X) - b1.m_linearVelocity.y - (b1.m_angularVelocity * r1X);
|
|
282
|
+
|
|
283
|
+
//b2Vec2 ptpImpulse = -b2Mul(this.m_ptpMass, ptpCdot);
|
|
284
|
+
var ptpImpulseX = -(this.m_ptpMass.col1.x * ptpCdotX + this.m_ptpMass.col2.x * ptpCdotY);
|
|
285
|
+
var ptpImpulseY = -(this.m_ptpMass.col1.y * ptpCdotX + this.m_ptpMass.col2.y * ptpCdotY);
|
|
286
|
+
this.m_ptpImpulse.x += ptpImpulseX;
|
|
287
|
+
this.m_ptpImpulse.y += ptpImpulseY;
|
|
288
|
+
|
|
289
|
+
//b1->m_linearVelocity -= b1->m_invMass * ptpImpulse;
|
|
290
|
+
b1.m_linearVelocity.x -= b1.m_invMass * ptpImpulseX;
|
|
291
|
+
b1.m_linearVelocity.y -= b1.m_invMass * ptpImpulseY;
|
|
292
|
+
//b1->m_angularVelocity -= b1->m_invI * b2Cross(r1, ptpImpulse);
|
|
293
|
+
b1.m_angularVelocity -= b1.m_invI * (r1X * ptpImpulseY - r1Y * ptpImpulseX);
|
|
294
|
+
|
|
295
|
+
//b2->m_linearVelocity += b2->m_invMass * ptpImpulse;
|
|
296
|
+
b2.m_linearVelocity.x += b2.m_invMass * ptpImpulseX;
|
|
297
|
+
b2.m_linearVelocity.y += b2.m_invMass * ptpImpulseY;
|
|
298
|
+
//b2->m_angularVelocity += b2->m_invI * b2Cross(r2, ptpImpulse);
|
|
299
|
+
b2.m_angularVelocity += b2.m_invI * (r2X * ptpImpulseY - r2Y * ptpImpulseX);
|
|
300
|
+
|
|
301
|
+
if (this.m_enableMotor && this.m_limitState != b2Joint.e_equalLimits)
|
|
302
|
+
{
|
|
303
|
+
var motorCdot = b2.m_angularVelocity - b1.m_angularVelocity - this.m_motorSpeed;
|
|
304
|
+
var motorImpulse = -this.m_motorMass * motorCdot;
|
|
305
|
+
var oldMotorImpulse = this.m_motorImpulse;
|
|
306
|
+
this.m_motorImpulse = b2Math.b2Clamp(this.m_motorImpulse + motorImpulse, -step.dt * this.m_maxMotorTorque, step.dt * this.m_maxMotorTorque);
|
|
307
|
+
motorImpulse = this.m_motorImpulse - oldMotorImpulse;
|
|
308
|
+
b1.m_angularVelocity -= b1.m_invI * motorImpulse;
|
|
309
|
+
b2.m_angularVelocity += b2.m_invI * motorImpulse;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit)
|
|
313
|
+
{
|
|
314
|
+
var limitCdot = b2.m_angularVelocity - b1.m_angularVelocity;
|
|
315
|
+
var limitImpulse = -this.m_motorMass * limitCdot;
|
|
316
|
+
|
|
317
|
+
if (this.m_limitState == b2Joint.e_equalLimits)
|
|
318
|
+
{
|
|
319
|
+
this.m_limitImpulse += limitImpulse;
|
|
320
|
+
}
|
|
321
|
+
else if (this.m_limitState == b2Joint.e_atLowerLimit)
|
|
322
|
+
{
|
|
323
|
+
oldLimitImpulse = this.m_limitImpulse;
|
|
324
|
+
this.m_limitImpulse = b2Math.b2Max(this.m_limitImpulse + limitImpulse, 0.0);
|
|
325
|
+
limitImpulse = this.m_limitImpulse - oldLimitImpulse;
|
|
326
|
+
}
|
|
327
|
+
else if (this.m_limitState == b2Joint.e_atUpperLimit)
|
|
328
|
+
{
|
|
329
|
+
oldLimitImpulse = this.m_limitImpulse;
|
|
330
|
+
this.m_limitImpulse = b2Math.b2Min(this.m_limitImpulse + limitImpulse, 0.0);
|
|
331
|
+
limitImpulse = this.m_limitImpulse - oldLimitImpulse;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
b1.m_angularVelocity -= b1.m_invI * limitImpulse;
|
|
335
|
+
b2.m_angularVelocity += b2.m_invI * limitImpulse;
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
SolvePositionConstraints: function(){
|
|
341
|
+
|
|
342
|
+
var oldLimitImpulse;
|
|
343
|
+
var limitC;
|
|
344
|
+
|
|
345
|
+
var b1 = this.m_body1;
|
|
346
|
+
var b2 = this.m_body2;
|
|
347
|
+
|
|
348
|
+
var positionError = 0.0;
|
|
349
|
+
|
|
350
|
+
var tMat;
|
|
351
|
+
|
|
352
|
+
// Solve point-to-point position error.
|
|
353
|
+
//var r1 = b2Math.b2MulMV(b1.m_R, this.m_localAnchor1);
|
|
354
|
+
tMat = b1.m_R;
|
|
355
|
+
var r1X = tMat.col1.x * this.m_localAnchor1.x + tMat.col2.x * this.m_localAnchor1.y;
|
|
356
|
+
var r1Y = tMat.col1.y * this.m_localAnchor1.x + tMat.col2.y * this.m_localAnchor1.y;
|
|
357
|
+
//var r2 = b2Math.b2MulMV(b2.m_R, this.m_localAnchor2);
|
|
358
|
+
tMat = b2.m_R;
|
|
359
|
+
var r2X = tMat.col1.x * this.m_localAnchor2.x + tMat.col2.x * this.m_localAnchor2.y;
|
|
360
|
+
var r2Y = tMat.col1.y * this.m_localAnchor2.x + tMat.col2.y * this.m_localAnchor2.y;
|
|
361
|
+
|
|
362
|
+
//b2Vec2 p1 = b1->m_position + r1;
|
|
363
|
+
var p1X = b1.m_position.x + r1X;
|
|
364
|
+
var p1Y = b1.m_position.y + r1Y;
|
|
365
|
+
//b2Vec2 p2 = b2->m_position + r2;
|
|
366
|
+
var p2X = b2.m_position.x + r2X;
|
|
367
|
+
var p2Y = b2.m_position.y + r2Y;
|
|
368
|
+
|
|
369
|
+
//b2Vec2 ptpC = p2 - p1;
|
|
370
|
+
var ptpCX = p2X - p1X;
|
|
371
|
+
var ptpCY = p2Y - p1Y;
|
|
372
|
+
|
|
373
|
+
//float32 positionError = ptpC.Length();
|
|
374
|
+
positionError = Math.sqrt(ptpCX*ptpCX + ptpCY*ptpCY);
|
|
375
|
+
|
|
376
|
+
// Prevent overly large corrections.
|
|
377
|
+
//b2Vec2 dpMax(b2_maxLinearCorrection, b2_maxLinearCorrection);
|
|
378
|
+
//ptpC = b2Clamp(ptpC, -dpMax, dpMax);
|
|
379
|
+
|
|
380
|
+
//float32 invMass1 = b1->m_invMass, invMass2 = b2->m_invMass;
|
|
381
|
+
var invMass1 = b1.m_invMass;
|
|
382
|
+
var invMass2 = b2.m_invMass;
|
|
383
|
+
//float32 invI1 = b1->m_invI, invI2 = b2->m_invI;
|
|
384
|
+
var invI1 = b1.m_invI;
|
|
385
|
+
var invI2 = b2.m_invI;
|
|
386
|
+
|
|
387
|
+
//b2Mat22 this.K1;
|
|
388
|
+
this.K1.col1.x = invMass1 + invMass2; this.K1.col2.x = 0.0;
|
|
389
|
+
this.K1.col1.y = 0.0; this.K1.col2.y = invMass1 + invMass2;
|
|
390
|
+
|
|
391
|
+
//b2Mat22 this.K2;
|
|
392
|
+
this.K2.col1.x = invI1 * r1Y * r1Y; this.K2.col2.x = -invI1 * r1X * r1Y;
|
|
393
|
+
this.K2.col1.y = -invI1 * r1X * r1Y; this.K2.col2.y = invI1 * r1X * r1X;
|
|
394
|
+
|
|
395
|
+
//b2Mat22 this.K3;
|
|
396
|
+
this.K3.col1.x = invI2 * r2Y * r2Y; this.K3.col2.x = -invI2 * r2X * r2Y;
|
|
397
|
+
this.K3.col1.y = -invI2 * r2X * r2Y; this.K3.col2.y = invI2 * r2X * r2X;
|
|
398
|
+
|
|
399
|
+
//b2Mat22 this.K = this.K1 + this.K2 + this.K3;
|
|
400
|
+
this.K.SetM(this.K1);
|
|
401
|
+
this.K.AddM(this.K2);
|
|
402
|
+
this.K.AddM(this.K3);
|
|
403
|
+
//b2Vec2 impulse = this.K.Solve(-ptpC);
|
|
404
|
+
this.K.Solve(b2RevoluteJoint.tImpulse, -ptpCX, -ptpCY);
|
|
405
|
+
var impulseX = b2RevoluteJoint.tImpulse.x;
|
|
406
|
+
var impulseY = b2RevoluteJoint.tImpulse.y;
|
|
407
|
+
|
|
408
|
+
//b1.m_position -= b1.m_invMass * impulse;
|
|
409
|
+
b1.m_position.x -= b1.m_invMass * impulseX;
|
|
410
|
+
b1.m_position.y -= b1.m_invMass * impulseY;
|
|
411
|
+
//b1.m_rotation -= b1.m_invI * b2Cross(r1, impulse);
|
|
412
|
+
b1.m_rotation -= b1.m_invI * (r1X * impulseY - r1Y * impulseX);
|
|
413
|
+
b1.m_R.Set(b1.m_rotation);
|
|
414
|
+
|
|
415
|
+
//b2.m_position += b2.m_invMass * impulse;
|
|
416
|
+
b2.m_position.x += b2.m_invMass * impulseX;
|
|
417
|
+
b2.m_position.y += b2.m_invMass * impulseY;
|
|
418
|
+
//b2.m_rotation += b2.m_invI * b2Cross(r2, impulse);
|
|
419
|
+
b2.m_rotation += b2.m_invI * (r2X * impulseY - r2Y * impulseX);
|
|
420
|
+
b2.m_R.Set(b2.m_rotation);
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
// Handle limits.
|
|
424
|
+
var angularError = 0.0;
|
|
425
|
+
|
|
426
|
+
if (this.m_enableLimit && this.m_limitState != b2Joint.e_inactiveLimit)
|
|
427
|
+
{
|
|
428
|
+
var angle = b2.m_rotation - b1.m_rotation - this.m_intialAngle;
|
|
429
|
+
var limitImpulse = 0.0;
|
|
430
|
+
|
|
431
|
+
if (this.m_limitState == b2Joint.e_equalLimits)
|
|
432
|
+
{
|
|
433
|
+
// Prevent large angular corrections
|
|
434
|
+
limitC = b2Math.b2Clamp(angle, -b2Settings.b2_maxAngularCorrection, b2Settings.b2_maxAngularCorrection);
|
|
435
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
436
|
+
angularError = b2Math.b2Abs(limitC);
|
|
437
|
+
}
|
|
438
|
+
else if (this.m_limitState == b2Joint.e_atLowerLimit)
|
|
439
|
+
{
|
|
440
|
+
limitC = angle - this.m_lowerAngle;
|
|
441
|
+
angularError = b2Math.b2Max(0.0, -limitC);
|
|
442
|
+
|
|
443
|
+
// Prevent large angular corrections and allow some slop.
|
|
444
|
+
limitC = b2Math.b2Clamp(limitC + b2Settings.b2_angularSlop, -b2Settings.b2_maxAngularCorrection, 0.0);
|
|
445
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
446
|
+
oldLimitImpulse = this.m_limitPositionImpulse;
|
|
447
|
+
this.m_limitPositionImpulse = b2Math.b2Max(this.m_limitPositionImpulse + limitImpulse, 0.0);
|
|
448
|
+
limitImpulse = this.m_limitPositionImpulse - oldLimitImpulse;
|
|
449
|
+
}
|
|
450
|
+
else if (this.m_limitState == b2Joint.e_atUpperLimit)
|
|
451
|
+
{
|
|
452
|
+
limitC = angle - this.m_upperAngle;
|
|
453
|
+
angularError = b2Math.b2Max(0.0, limitC);
|
|
454
|
+
|
|
455
|
+
// Prevent large angular corrections and allow some slop.
|
|
456
|
+
limitC = b2Math.b2Clamp(limitC - b2Settings.b2_angularSlop, 0.0, b2Settings.b2_maxAngularCorrection);
|
|
457
|
+
limitImpulse = -this.m_motorMass * limitC;
|
|
458
|
+
oldLimitImpulse = this.m_limitPositionImpulse;
|
|
459
|
+
this.m_limitPositionImpulse = b2Math.b2Min(this.m_limitPositionImpulse + limitImpulse, 0.0);
|
|
460
|
+
limitImpulse = this.m_limitPositionImpulse - oldLimitImpulse;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
b1.m_rotation -= b1.m_invI * limitImpulse;
|
|
464
|
+
b1.m_R.Set(b1.m_rotation);
|
|
465
|
+
b2.m_rotation += b2.m_invI * limitImpulse;
|
|
466
|
+
b2.m_R.Set(b2.m_rotation);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return positionError <= b2Settings.b2_linearSlop && angularError <= b2Settings.b2_angularSlop;
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
m_localAnchor1: new b2Vec2(),
|
|
473
|
+
m_localAnchor2: new b2Vec2(),
|
|
474
|
+
m_ptpImpulse: new b2Vec2(),
|
|
475
|
+
m_motorImpulse: null,
|
|
476
|
+
m_limitImpulse: null,
|
|
477
|
+
m_limitPositionImpulse: null,
|
|
478
|
+
|
|
479
|
+
m_ptpMass: new b2Mat22(),
|
|
480
|
+
m_motorMass: null,
|
|
481
|
+
m_intialAngle: null,
|
|
482
|
+
m_lowerAngle: null,
|
|
483
|
+
m_upperAngle: null,
|
|
484
|
+
m_maxMotorTorque: null,
|
|
485
|
+
m_motorSpeed: null,
|
|
486
|
+
|
|
487
|
+
m_enableLimit: null,
|
|
488
|
+
m_enableMotor: null,
|
|
489
|
+
m_limitState: 0});
|
|
490
|
+
|
|
491
|
+
b2RevoluteJoint.tImpulse = new b2Vec2();
|