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,40 @@
|
|
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
|
+
var b2Proxy = Class.create();
|
22
|
+
b2Proxy.prototype = {
|
23
|
+
GetNext: function(){ return this.lowerBounds[0]; },
|
24
|
+
SetNext: function(next) { this.lowerBounds[0] = next /*& 0x0000ffff*/; },
|
25
|
+
|
26
|
+
IsValid: function(){ return this.overlapCount != b2BroadPhase.b2_invalid; },
|
27
|
+
|
28
|
+
lowerBounds: [/*uint*/(0), /*uint*/(0)],
|
29
|
+
upperBounds: [/*uint*/(0), /*uint*/(0)],
|
30
|
+
overlapCount: 0,
|
31
|
+
timeStamp: 0,
|
32
|
+
|
33
|
+
userData: null,
|
34
|
+
|
35
|
+
initialize: function() {
|
36
|
+
// initialize instance variables for references
|
37
|
+
this.lowerBounds = [/*uint*/(0), /*uint*/(0)];
|
38
|
+
this.upperBounds = [/*uint*/(0), /*uint*/(0)];
|
39
|
+
//
|
40
|
+
}}
|
@@ -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
|
+
|
24
|
+
|
25
|
+
var b2BoxDef = Class.create();
|
26
|
+
Object.extend(b2BoxDef.prototype, b2ShapeDef.prototype);
|
27
|
+
Object.extend(b2BoxDef.prototype,
|
28
|
+
{
|
29
|
+
initialize: function()
|
30
|
+
{
|
31
|
+
// The constructor for b2ShapeDef
|
32
|
+
this.type = b2Shape.e_unknownShape;
|
33
|
+
this.userData = null;
|
34
|
+
this.localPosition = new b2Vec2(0.0, 0.0);
|
35
|
+
this.localRotation = 0.0;
|
36
|
+
this.friction = 0.2;
|
37
|
+
this.restitution = 0.0;
|
38
|
+
this.density = 0.0;
|
39
|
+
this.categoryBits = 0x0001;
|
40
|
+
this.maskBits = 0xFFFF;
|
41
|
+
this.groupIndex = 0;
|
42
|
+
//
|
43
|
+
|
44
|
+
this.type = b2Shape.e_boxShape;
|
45
|
+
this.extents = new b2Vec2(1.0, 1.0);
|
46
|
+
},
|
47
|
+
|
48
|
+
extents: null});
|
49
|
+
|
@@ -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
|
+
|
24
|
+
|
25
|
+
var b2CircleDef = Class.create();
|
26
|
+
Object.extend(b2CircleDef.prototype, b2ShapeDef.prototype);
|
27
|
+
Object.extend(b2CircleDef.prototype,
|
28
|
+
{
|
29
|
+
initialize: function()
|
30
|
+
{
|
31
|
+
// The constructor for b2ShapeDef
|
32
|
+
this.type = b2Shape.e_unknownShape;
|
33
|
+
this.userData = null;
|
34
|
+
this.localPosition = new b2Vec2(0.0, 0.0);
|
35
|
+
this.localRotation = 0.0;
|
36
|
+
this.friction = 0.2;
|
37
|
+
this.restitution = 0.0;
|
38
|
+
this.density = 0.0;
|
39
|
+
this.categoryBits = 0x0001;
|
40
|
+
this.maskBits = 0xFFFF;
|
41
|
+
this.groupIndex = 0;
|
42
|
+
//
|
43
|
+
|
44
|
+
this.type = b2Shape.e_circleShape;
|
45
|
+
this.radius = 1.0;
|
46
|
+
},
|
47
|
+
|
48
|
+
radius: null});
|
49
|
+
|
@@ -0,0 +1,198 @@
|
|
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 b2CircleShape = Class.create();
|
26
|
+
Object.extend(b2CircleShape.prototype, b2Shape.prototype);
|
27
|
+
Object.extend(b2CircleShape.prototype,
|
28
|
+
{
|
29
|
+
TestPoint: function(p){
|
30
|
+
//var d = b2Math.SubtractVV(p, this.m_position);
|
31
|
+
var d = new b2Vec2();
|
32
|
+
d.SetV(p);
|
33
|
+
d.Subtract(this.m_position);
|
34
|
+
return b2Math.b2Dot(d, d) <= this.m_radius * this.m_radius;
|
35
|
+
},
|
36
|
+
|
37
|
+
//--------------- Internals Below -------------------
|
38
|
+
|
39
|
+
initialize: function(def, body, localCenter){
|
40
|
+
// initialize instance variables for references
|
41
|
+
this.m_R = new b2Mat22();
|
42
|
+
this.m_position = new b2Vec2();
|
43
|
+
//
|
44
|
+
|
45
|
+
// The constructor for b2Shape
|
46
|
+
this.m_userData = def.userData;
|
47
|
+
|
48
|
+
this.m_friction = def.friction;
|
49
|
+
this.m_restitution = def.restitution;
|
50
|
+
this.m_body = body;
|
51
|
+
|
52
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
53
|
+
|
54
|
+
this.m_maxRadius = 0.0;
|
55
|
+
|
56
|
+
this.m_categoryBits = def.categoryBits;
|
57
|
+
this.m_maskBits = def.maskBits;
|
58
|
+
this.m_groupIndex = def.groupIndex;
|
59
|
+
//
|
60
|
+
|
61
|
+
// initialize instance variables for references
|
62
|
+
this.m_localPosition = new b2Vec2();
|
63
|
+
//
|
64
|
+
|
65
|
+
//super(def, body);
|
66
|
+
|
67
|
+
//b2Settings.b2Assert(def.type == b2Shape.e_circleShape);
|
68
|
+
var circle = def;
|
69
|
+
|
70
|
+
//this.m_localPosition = def.localPosition - localCenter;
|
71
|
+
this.m_localPosition.Set(def.localPosition.x - localCenter.x, def.localPosition.y - localCenter.y);
|
72
|
+
this.m_type = b2Shape.e_circleShape;
|
73
|
+
this.m_radius = circle.radius;
|
74
|
+
|
75
|
+
this.m_R.SetM(this.m_body.m_R);
|
76
|
+
//b2Vec2 r = b2Mul(this.m_body->this.m_R, this.m_localPosition);
|
77
|
+
var rX = this.m_R.col1.x * this.m_localPosition.x + this.m_R.col2.x * this.m_localPosition.y;
|
78
|
+
var rY = this.m_R.col1.y * this.m_localPosition.x + this.m_R.col2.y * this.m_localPosition.y;
|
79
|
+
//this.m_position = this.m_body->this.m_position + r;
|
80
|
+
this.m_position.x = this.m_body.m_position.x + rX;
|
81
|
+
this.m_position.y = this.m_body.m_position.y + rY;
|
82
|
+
//this.m_maxRadius = r.Length() + this.m_radius;
|
83
|
+
this.m_maxRadius = Math.sqrt(rX*rX+rY*rY) + this.m_radius;
|
84
|
+
|
85
|
+
var aabb = new b2AABB();
|
86
|
+
aabb.minVertex.Set(this.m_position.x - this.m_radius, this.m_position.y - this.m_radius);
|
87
|
+
aabb.maxVertex.Set(this.m_position.x + this.m_radius, this.m_position.y + this.m_radius);
|
88
|
+
|
89
|
+
var broadPhase = this.m_body.m_world.m_broadPhase;
|
90
|
+
if (broadPhase.InRange(aabb))
|
91
|
+
{
|
92
|
+
this.m_proxyId = broadPhase.CreateProxy(aabb, this);
|
93
|
+
}
|
94
|
+
else
|
95
|
+
{
|
96
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
100
|
+
{
|
101
|
+
this.m_body.Freeze();
|
102
|
+
}
|
103
|
+
},
|
104
|
+
|
105
|
+
Synchronize: function(position1, R1, position2, R2){
|
106
|
+
this.m_R.SetM(R2);
|
107
|
+
//this.m_position = position2 + b2Mul(R2, this.m_localPosition);
|
108
|
+
this.m_position.x = (R2.col1.x * this.m_localPosition.x + R2.col2.x * this.m_localPosition.y) + position2.x;
|
109
|
+
this.m_position.y = (R2.col1.y * this.m_localPosition.x + R2.col2.y * this.m_localPosition.y) + position2.y;
|
110
|
+
|
111
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
112
|
+
{
|
113
|
+
return;
|
114
|
+
}
|
115
|
+
|
116
|
+
// Compute an AABB that covers the swept shape (may miss some rotation effect).
|
117
|
+
//b2Vec2 p1 = position1 + b2Mul(R1, this.m_localPosition);
|
118
|
+
var p1X = position1.x + (R1.col1.x * this.m_localPosition.x + R1.col2.x * this.m_localPosition.y);
|
119
|
+
var p1Y = position1.y + (R1.col1.y * this.m_localPosition.x + R1.col2.y * this.m_localPosition.y);
|
120
|
+
//b2Vec2 lower = b2Min(p1, this.m_position);
|
121
|
+
var lowerX = Math.min(p1X, this.m_position.x);
|
122
|
+
var lowerY = Math.min(p1Y, this.m_position.y);
|
123
|
+
//b2Vec2 upper = b2Max(p1, this.m_position);
|
124
|
+
var upperX = Math.max(p1X, this.m_position.x);
|
125
|
+
var upperY = Math.max(p1Y, this.m_position.y);
|
126
|
+
|
127
|
+
var aabb = new b2AABB();
|
128
|
+
aabb.minVertex.Set(lowerX - this.m_radius, lowerY - this.m_radius);
|
129
|
+
aabb.maxVertex.Set(upperX + this.m_radius, upperY + this.m_radius);
|
130
|
+
|
131
|
+
var broadPhase = this.m_body.m_world.m_broadPhase;
|
132
|
+
if (broadPhase.InRange(aabb))
|
133
|
+
{
|
134
|
+
broadPhase.MoveProxy(this.m_proxyId, aabb);
|
135
|
+
}
|
136
|
+
else
|
137
|
+
{
|
138
|
+
this.m_body.Freeze();
|
139
|
+
}
|
140
|
+
},
|
141
|
+
|
142
|
+
QuickSync: function(position, R){
|
143
|
+
this.m_R.SetM(R);
|
144
|
+
//this.m_position = position + b2Mul(R, this.m_localPosition);
|
145
|
+
this.m_position.x = (R.col1.x * this.m_localPosition.x + R.col2.x * this.m_localPosition.y) + position.x;
|
146
|
+
this.m_position.y = (R.col1.y * this.m_localPosition.x + R.col2.y * this.m_localPosition.y) + position.y;
|
147
|
+
},
|
148
|
+
|
149
|
+
|
150
|
+
ResetProxy: function(broadPhase)
|
151
|
+
{
|
152
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
153
|
+
{
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
|
157
|
+
var proxy = broadPhase.GetProxy(this.m_proxyId);
|
158
|
+
|
159
|
+
broadPhase.DestroyProxy(this.m_proxyId);
|
160
|
+
proxy = null;
|
161
|
+
|
162
|
+
var aabb = new b2AABB();
|
163
|
+
aabb.minVertex.Set(this.m_position.x - this.m_radius, this.m_position.y - this.m_radius);
|
164
|
+
aabb.maxVertex.Set(this.m_position.x + this.m_radius, this.m_position.y + this.m_radius);
|
165
|
+
|
166
|
+
if (broadPhase.InRange(aabb))
|
167
|
+
{
|
168
|
+
this.m_proxyId = broadPhase.CreateProxy(aabb, this);
|
169
|
+
}
|
170
|
+
else
|
171
|
+
{
|
172
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
176
|
+
{
|
177
|
+
this.m_body.Freeze();
|
178
|
+
}
|
179
|
+
},
|
180
|
+
|
181
|
+
|
182
|
+
Support: function(dX, dY, out)
|
183
|
+
{
|
184
|
+
//b2Vec2 u = d;
|
185
|
+
//u.Normalize();
|
186
|
+
var len = Math.sqrt(dX*dX + dY*dY);
|
187
|
+
dX /= len;
|
188
|
+
dY /= len;
|
189
|
+
//return this.m_position + this.m_radius * u;
|
190
|
+
out.Set( this.m_position.x + this.m_radius*dX,
|
191
|
+
this.m_position.y + this.m_radius*dY);
|
192
|
+
},
|
193
|
+
|
194
|
+
|
195
|
+
// Local position in parent body
|
196
|
+
m_localPosition: new b2Vec2(),
|
197
|
+
m_radius: null});
|
198
|
+
|
@@ -0,0 +1,36 @@
|
|
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 b2MassData = Class.create();
|
26
|
+
b2MassData.prototype =
|
27
|
+
{
|
28
|
+
mass: 0.0,
|
29
|
+
center: new b2Vec2(0,0),
|
30
|
+
I: 0.0,
|
31
|
+
|
32
|
+
initialize: function() {
|
33
|
+
// initialize instance variables for references
|
34
|
+
this.center = new b2Vec2(0,0);
|
35
|
+
//
|
36
|
+
}}
|
@@ -0,0 +1,58 @@
|
|
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 b2PolyDef = Class.create();
|
26
|
+
Object.extend(b2PolyDef.prototype, b2ShapeDef.prototype);
|
27
|
+
Object.extend(b2PolyDef.prototype,
|
28
|
+
{
|
29
|
+
initialize: function()
|
30
|
+
{
|
31
|
+
// The constructor for b2ShapeDef
|
32
|
+
this.type = b2Shape.e_unknownShape;
|
33
|
+
this.userData = null;
|
34
|
+
this.localPosition = new b2Vec2(0.0, 0.0);
|
35
|
+
this.localRotation = 0.0;
|
36
|
+
this.friction = 0.2;
|
37
|
+
this.restitution = 0.0;
|
38
|
+
this.density = 0.0;
|
39
|
+
this.categoryBits = 0x0001;
|
40
|
+
this.maskBits = 0xFFFF;
|
41
|
+
this.groupIndex = 0;
|
42
|
+
//
|
43
|
+
|
44
|
+
// initialize instance variables for references
|
45
|
+
this.vertices = new Array(b2Settings.b2_maxPolyVertices);
|
46
|
+
//
|
47
|
+
|
48
|
+
this.type = b2Shape.e_polyShape;
|
49
|
+
this.vertexCount = 0;
|
50
|
+
|
51
|
+
for (var i = 0; i < b2Settings.b2_maxPolyVertices; i++){
|
52
|
+
this.vertices[i] = new b2Vec2();
|
53
|
+
}
|
54
|
+
},
|
55
|
+
|
56
|
+
vertices: new Array(b2Settings.b2_maxPolyVertices),
|
57
|
+
vertexCount: 0});
|
58
|
+
|
@@ -0,0 +1,492 @@
|
|
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
|
+
// A convex polygon. The position of the polygon (m_position) is the
|
24
|
+
// position of the centroid. The vertices of the incoming polygon are pre-rotated
|
25
|
+
// according to the local rotation. The vertices are also shifted to be centered
|
26
|
+
// on the centroid. Since the local rotation is absorbed into the vertex
|
27
|
+
// coordinates, the polygon rotation is equal to the body rotation. However,
|
28
|
+
// the polygon position is centered on the polygon centroid. This simplifies
|
29
|
+
// some collision algorithms.
|
30
|
+
|
31
|
+
var b2PolyShape = Class.create();
|
32
|
+
Object.extend(b2PolyShape.prototype, b2Shape.prototype);
|
33
|
+
Object.extend(b2PolyShape.prototype,
|
34
|
+
{
|
35
|
+
TestPoint: function(p){
|
36
|
+
|
37
|
+
//var pLocal = b2Math.b2MulTMV(this.m_R, b2Math.SubtractVV(p, this.m_position));
|
38
|
+
var pLocal = new b2Vec2();
|
39
|
+
pLocal.SetV(p);
|
40
|
+
pLocal.Subtract(this.m_position);
|
41
|
+
pLocal.MulTM(this.m_R);
|
42
|
+
|
43
|
+
for (var i = 0; i < this.m_vertexCount; ++i)
|
44
|
+
{
|
45
|
+
//var dot = b2Math.b2Dot(this.m_normals[i], b2Math.SubtractVV(pLocal, this.m_vertices[i]));
|
46
|
+
var tVec = new b2Vec2();
|
47
|
+
tVec.SetV(pLocal);
|
48
|
+
tVec.Subtract(this.m_vertices[i]);
|
49
|
+
|
50
|
+
var dot = b2Math.b2Dot(this.m_normals[i], tVec);
|
51
|
+
if (dot > 0.0)
|
52
|
+
{
|
53
|
+
return false;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
return true;
|
58
|
+
},
|
59
|
+
|
60
|
+
//--------------- Internals Below -------------------
|
61
|
+
// Temp vec for b2Shape.PolyCentroid
|
62
|
+
|
63
|
+
initialize: function(def, body, newOrigin){
|
64
|
+
// initialize instance variables for references
|
65
|
+
this.m_R = new b2Mat22();
|
66
|
+
this.m_position = new b2Vec2();
|
67
|
+
//
|
68
|
+
|
69
|
+
// The constructor for b2Shape
|
70
|
+
this.m_userData = def.userData;
|
71
|
+
|
72
|
+
this.m_friction = def.friction;
|
73
|
+
this.m_restitution = def.restitution;
|
74
|
+
this.m_body = body;
|
75
|
+
|
76
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
77
|
+
|
78
|
+
this.m_maxRadius = 0.0;
|
79
|
+
|
80
|
+
this.m_categoryBits = def.categoryBits;
|
81
|
+
this.m_maskBits = def.maskBits;
|
82
|
+
this.m_groupIndex = def.groupIndex;
|
83
|
+
//
|
84
|
+
|
85
|
+
// initialize instance variables for references
|
86
|
+
this.syncAABB = new b2AABB();
|
87
|
+
this.syncMat = new b2Mat22();
|
88
|
+
this.m_localCentroid = new b2Vec2();
|
89
|
+
this.m_localOBB = new b2OBB();
|
90
|
+
//
|
91
|
+
|
92
|
+
|
93
|
+
//super(def, body);
|
94
|
+
|
95
|
+
var i = 0;
|
96
|
+
|
97
|
+
|
98
|
+
var hX;
|
99
|
+
var hY;
|
100
|
+
|
101
|
+
var tVec;
|
102
|
+
|
103
|
+
var aabb = new b2AABB();
|
104
|
+
|
105
|
+
// Vertices
|
106
|
+
this.m_vertices = new Array(b2Settings.b2_maxPolyVertices);
|
107
|
+
this.m_coreVertices = new Array(b2Settings.b2_maxPolyVertices);
|
108
|
+
//for (i = 0; i < b2Settings.b2_maxPolyVertices; i++)
|
109
|
+
// this.m_vertices[i] = new b2Vec2();
|
110
|
+
|
111
|
+
// Normals
|
112
|
+
this.m_normals = new Array(b2Settings.b2_maxPolyVertices);
|
113
|
+
//for (i = 0; i < b2Settings.b2_maxPolyVertices; i++)
|
114
|
+
// this.m_normals[i] = new b2Vec2();
|
115
|
+
|
116
|
+
//b2Settings.b2Assert(def.type == b2Shape.e_boxShape || def.type == b2Shape.e_polyShape);
|
117
|
+
this.m_type = b2Shape.e_polyShape;
|
118
|
+
|
119
|
+
var localR = new b2Mat22(def.localRotation);
|
120
|
+
|
121
|
+
// Get the vertices transformed into the body frame.
|
122
|
+
if (def.type == b2Shape.e_boxShape)
|
123
|
+
{
|
124
|
+
//this.m_localCentroid = def.localPosition - newOrigin;
|
125
|
+
this.m_localCentroid.x = def.localPosition.x - newOrigin.x;
|
126
|
+
this.m_localCentroid.y = def.localPosition.y - newOrigin.y;
|
127
|
+
|
128
|
+
var box = def;
|
129
|
+
this.m_vertexCount = 4;
|
130
|
+
hX = box.extents.x;
|
131
|
+
hY = box.extents.y;
|
132
|
+
|
133
|
+
//hc.x = b2Max(0.0f, h.x - 2.0f * b2_linearSlop);
|
134
|
+
var hcX = Math.max(0.0, hX - 2.0 * b2Settings.b2_linearSlop);
|
135
|
+
//hc.y = b2Max(0.0f, h.y - 2.0f * b2_linearSlop);
|
136
|
+
var hcY = Math.max(0.0, hY - 2.0 * b2Settings.b2_linearSlop);
|
137
|
+
|
138
|
+
//this.m_vertices[0] = b2Mul(localR, b2Vec2(h.x, h.y));
|
139
|
+
tVec = this.m_vertices[0] = new b2Vec2();
|
140
|
+
tVec.x = localR.col1.x * hX + localR.col2.x * hY;
|
141
|
+
tVec.y = localR.col1.y * hX + localR.col2.y * hY;
|
142
|
+
//this.m_vertices[1] = b2Mul(localR, b2Vec2(-h.x, h.y));
|
143
|
+
tVec = this.m_vertices[1] = new b2Vec2();
|
144
|
+
tVec.x = localR.col1.x * -hX + localR.col2.x * hY;
|
145
|
+
tVec.y = localR.col1.y * -hX + localR.col2.y * hY;
|
146
|
+
//this.m_vertices[2] = b2Mul(localR, b2Vec2(-h.x, -h.y));
|
147
|
+
tVec = this.m_vertices[2] = new b2Vec2();
|
148
|
+
tVec.x = localR.col1.x * -hX + localR.col2.x * -hY;
|
149
|
+
tVec.y = localR.col1.y * -hX + localR.col2.y * -hY;
|
150
|
+
//this.m_vertices[3] = b2Mul(localR, b2Vec2(h.x, -h.y));
|
151
|
+
tVec = this.m_vertices[3] = new b2Vec2();
|
152
|
+
tVec.x = localR.col1.x * hX + localR.col2.x * -hY;
|
153
|
+
tVec.y = localR.col1.y * hX + localR.col2.y * -hY;
|
154
|
+
|
155
|
+
//this.m_coreVertices[0] = b2Mul(localR, b2Vec2(hc.x, hc.y));
|
156
|
+
tVec = this.m_coreVertices[0] = new b2Vec2();
|
157
|
+
tVec.x = localR.col1.x * hcX + localR.col2.x * hcY;
|
158
|
+
tVec.y = localR.col1.y * hcX + localR.col2.y * hcY;
|
159
|
+
//this.m_coreVertices[1] = b2Mul(localR, b2Vec2(-hc.x, hc.y));
|
160
|
+
tVec = this.m_coreVertices[1] = new b2Vec2();
|
161
|
+
tVec.x = localR.col1.x * -hcX + localR.col2.x * hcY;
|
162
|
+
tVec.y = localR.col1.y * -hcX + localR.col2.y * hcY;
|
163
|
+
//this.m_coreVertices[2] = b2Mul(localR, b2Vec2(-hc.x, -hc.y));
|
164
|
+
tVec = this.m_coreVertices[2] = new b2Vec2();
|
165
|
+
tVec.x = localR.col1.x * -hcX + localR.col2.x * -hcY;
|
166
|
+
tVec.y = localR.col1.y * -hcX + localR.col2.y * -hcY;
|
167
|
+
//this.m_coreVertices[3] = b2Mul(localR, b2Vec2(hc.x, -hc.y));
|
168
|
+
tVec = this.m_coreVertices[3] = new b2Vec2();
|
169
|
+
tVec.x = localR.col1.x * hcX + localR.col2.x * -hcY;
|
170
|
+
tVec.y = localR.col1.y * hcX + localR.col2.y * -hcY;
|
171
|
+
}
|
172
|
+
else
|
173
|
+
{
|
174
|
+
var poly = def;
|
175
|
+
|
176
|
+
this.m_vertexCount = poly.vertexCount;
|
177
|
+
//b2Settings.b2Assert(3 <= this.m_vertexCount && this.m_vertexCount <= b2Settings.b2_maxPolyVertices);
|
178
|
+
//b2Vec2 centroid = b2Shape.PolyCentroid(poly->vertices, poly->vertexCount);
|
179
|
+
b2Shape.PolyCentroid(poly.vertices, poly.vertexCount, b2PolyShape.tempVec);
|
180
|
+
var centroidX = b2PolyShape.tempVec.x;
|
181
|
+
var centroidY = b2PolyShape.tempVec.y;
|
182
|
+
//this.m_localCentroid = def->localPosition + b2Mul(localR, centroid) - newOrigin;
|
183
|
+
this.m_localCentroid.x = def.localPosition.x + (localR.col1.x * centroidX + localR.col2.x * centroidY) - newOrigin.x;
|
184
|
+
this.m_localCentroid.y = def.localPosition.y + (localR.col1.y * centroidX + localR.col2.y * centroidY) - newOrigin.y;
|
185
|
+
|
186
|
+
for (i = 0; i < this.m_vertexCount; ++i)
|
187
|
+
{
|
188
|
+
this.m_vertices[i] = new b2Vec2();
|
189
|
+
this.m_coreVertices[i] = new b2Vec2();
|
190
|
+
|
191
|
+
//this.m_vertices[i] = b2Mul(localR, poly->vertices[i] - centroid);
|
192
|
+
hX = poly.vertices[i].x - centroidX;
|
193
|
+
hY = poly.vertices[i].y - centroidY;
|
194
|
+
this.m_vertices[i].x = localR.col1.x * hX + localR.col2.x * hY;
|
195
|
+
this.m_vertices[i].y = localR.col1.y * hX + localR.col2.y * hY;
|
196
|
+
|
197
|
+
//b2Vec2 u = this.m_vertices[i];
|
198
|
+
var uX = this.m_vertices[i].x;
|
199
|
+
var uY = this.m_vertices[i].y;
|
200
|
+
//float32 length = u.Length();
|
201
|
+
var length = Math.sqrt(uX*uX + uY*uY);
|
202
|
+
if (length > Number.MIN_VALUE)
|
203
|
+
{
|
204
|
+
uX *= 1.0 / length;
|
205
|
+
uY *= 1.0 / length;
|
206
|
+
}
|
207
|
+
|
208
|
+
//this.m_coreVertices[i] = this.m_vertices[i] - 2.0f * b2_linearSlop * u;
|
209
|
+
this.m_coreVertices[i].x = this.m_vertices[i].x - 2.0 * b2Settings.b2_linearSlop * uX;
|
210
|
+
this.m_coreVertices[i].y = this.m_vertices[i].y - 2.0 * b2Settings.b2_linearSlop * uY;
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
// Compute bounding box. TODO_ERIN optimize OBB
|
216
|
+
//var minVertex = new b2Vec2(Number.MAX_VALUE, Number.MAX_VALUE);
|
217
|
+
var minVertexX = Number.MAX_VALUE;
|
218
|
+
var minVertexY = Number.MAX_VALUE;
|
219
|
+
var maxVertexX = -Number.MAX_VALUE;
|
220
|
+
var maxVertexY = -Number.MAX_VALUE;
|
221
|
+
this.m_maxRadius = 0.0;
|
222
|
+
for (i = 0; i < this.m_vertexCount; ++i)
|
223
|
+
{
|
224
|
+
var v = this.m_vertices[i];
|
225
|
+
//minVertex = b2Math.b2MinV(minVertex, this.m_vertices[i]);
|
226
|
+
minVertexX = Math.min(minVertexX, v.x);
|
227
|
+
minVertexY = Math.min(minVertexY, v.y);
|
228
|
+
//maxVertex = b2Math.b2MaxV(maxVertex, this.m_vertices[i]);
|
229
|
+
maxVertexX = Math.max(maxVertexX, v.x);
|
230
|
+
maxVertexY = Math.max(maxVertexY, v.y);
|
231
|
+
//this.m_maxRadius = b2Max(this.m_maxRadius, v.Length());
|
232
|
+
this.m_maxRadius = Math.max(this.m_maxRadius, v.Length());
|
233
|
+
}
|
234
|
+
|
235
|
+
this.m_localOBB.R.SetIdentity();
|
236
|
+
//this.m_localOBB.center = 0.5 * (minVertex + maxVertex);
|
237
|
+
this.m_localOBB.center.Set((minVertexX + maxVertexX) * 0.5, (minVertexY + maxVertexY) * 0.5);
|
238
|
+
//this.m_localOBB.extents = 0.5 * (maxVertex - minVertex);
|
239
|
+
this.m_localOBB.extents.Set((maxVertexX - minVertexX) * 0.5, (maxVertexY - minVertexY) * 0.5);
|
240
|
+
|
241
|
+
// Compute the edge normals and next index map.
|
242
|
+
var i1 = 0;
|
243
|
+
var i2 = 0;
|
244
|
+
for (i = 0; i < this.m_vertexCount; ++i)
|
245
|
+
{
|
246
|
+
this.m_normals[i] = new b2Vec2();
|
247
|
+
i1 = i;
|
248
|
+
i2 = i + 1 < this.m_vertexCount ? i + 1 : 0;
|
249
|
+
//b2Vec2 edge = this.m_vertices[i2] - this.m_vertices[i1];
|
250
|
+
//var edgeX = this.m_vertices[i2].x - this.m_vertices[i1].x;
|
251
|
+
//var edgeY = this.m_vertices[i2].y - this.m_vertices[i1].y;
|
252
|
+
//this.m_normals[i] = b2Cross(edge, 1.0f);
|
253
|
+
this.m_normals[i].x = this.m_vertices[i2].y - this.m_vertices[i1].y;
|
254
|
+
this.m_normals[i].y = -(this.m_vertices[i2].x - this.m_vertices[i1].x);
|
255
|
+
this.m_normals[i].Normalize();
|
256
|
+
}
|
257
|
+
|
258
|
+
// Ensure the polygon in convex. TODO_ERIN compute convex hull.
|
259
|
+
for (i = 0; i < this.m_vertexCount; ++i)
|
260
|
+
{
|
261
|
+
i1 = i;
|
262
|
+
i2 = i + 1 < this.m_vertexCount ? i + 1 : 0;
|
263
|
+
|
264
|
+
//b2Settings.b2Assert(b2Math.b2CrossVV(this.m_normals[i1], this.m_normals[i2]) > Number.MIN_VALUE);
|
265
|
+
}
|
266
|
+
|
267
|
+
this.m_R.SetM(this.m_body.m_R);
|
268
|
+
//this.m_position.SetV( this.m_body.m_position + b2Mul(this.m_body->this.m_R, this.m_localCentroid) );
|
269
|
+
this.m_position.x = this.m_body.m_position.x + (this.m_R.col1.x * this.m_localCentroid.x + this.m_R.col2.x * this.m_localCentroid.y);
|
270
|
+
this.m_position.y = this.m_body.m_position.y + (this.m_R.col1.y * this.m_localCentroid.x + this.m_R.col2.y * this.m_localCentroid.y);
|
271
|
+
|
272
|
+
//var R = b2Math.b2MulMM(this.m_R, this.m_localOBB.R);
|
273
|
+
//R.col1 = b2MulMV(this.m_R, this.m_localOBB.R.col1);
|
274
|
+
b2PolyShape.tAbsR.col1.x = this.m_R.col1.x * this.m_localOBB.R.col1.x + this.m_R.col2.x * this.m_localOBB.R.col1.y;
|
275
|
+
b2PolyShape.tAbsR.col1.y = this.m_R.col1.y * this.m_localOBB.R.col1.x + this.m_R.col2.y * this.m_localOBB.R.col1.y;
|
276
|
+
//R.col2 = b2MulMV(this.m_R, this.m_localOBB.R.col2)
|
277
|
+
b2PolyShape.tAbsR.col2.x = this.m_R.col1.x * this.m_localOBB.R.col2.x + this.m_R.col2.x * this.m_localOBB.R.col2.y;
|
278
|
+
b2PolyShape.tAbsR.col2.y = this.m_R.col1.y * this.m_localOBB.R.col2.x + this.m_R.col2.y * this.m_localOBB.R.col2.y;
|
279
|
+
//var absR = b2Math.b2AbsM(R);
|
280
|
+
b2PolyShape.tAbsR.Abs()
|
281
|
+
|
282
|
+
//h = b2Math.b2MulMV(b2PolyShape.tAbsR, this.m_localOBB.extents);
|
283
|
+
hX = b2PolyShape.tAbsR.col1.x * this.m_localOBB.extents.x + b2PolyShape.tAbsR.col2.x * this.m_localOBB.extents.y;
|
284
|
+
hY = b2PolyShape.tAbsR.col1.y * this.m_localOBB.extents.x + b2PolyShape.tAbsR.col2.y * this.m_localOBB.extents.y;
|
285
|
+
|
286
|
+
//var position = this.m_position + b2Mul(this.m_R, this.m_localOBB.center);
|
287
|
+
var positionX = this.m_position.x + (this.m_R.col1.x * this.m_localOBB.center.x + this.m_R.col2.x * this.m_localOBB.center.y);
|
288
|
+
var positionY = this.m_position.y + (this.m_R.col1.y * this.m_localOBB.center.x + this.m_R.col2.y * this.m_localOBB.center.y);
|
289
|
+
|
290
|
+
//aabb.minVertex = b2Math.SubtractVV(this.m_position, h);
|
291
|
+
aabb.minVertex.x = positionX - hX;
|
292
|
+
aabb.minVertex.y = positionY - hY;
|
293
|
+
//aabb.maxVertex = b2Math.AddVV(this.m_position, h);
|
294
|
+
aabb.maxVertex.x = positionX + hX;
|
295
|
+
aabb.maxVertex.y = positionY + hY;
|
296
|
+
|
297
|
+
var broadPhase = this.m_body.m_world.m_broadPhase;
|
298
|
+
if (broadPhase.InRange(aabb))
|
299
|
+
{
|
300
|
+
this.m_proxyId = broadPhase.CreateProxy(aabb, this);
|
301
|
+
}
|
302
|
+
else
|
303
|
+
{
|
304
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
305
|
+
}
|
306
|
+
|
307
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
308
|
+
{
|
309
|
+
this.m_body.Freeze();
|
310
|
+
}
|
311
|
+
},
|
312
|
+
|
313
|
+
// Temp AABB for Synch function
|
314
|
+
syncAABB: new b2AABB(),
|
315
|
+
syncMat: new b2Mat22(),
|
316
|
+
Synchronize: function(position1, R1, position2, R2){
|
317
|
+
// The body transform is copied for convenience.
|
318
|
+
this.m_R.SetM(R2);
|
319
|
+
//this.m_position = this.m_body->this.m_position + b2Mul(this.m_body->this.m_R, this.m_localCentroid)
|
320
|
+
this.m_position.x = this.m_body.m_position.x + (R2.col1.x * this.m_localCentroid.x + R2.col2.x * this.m_localCentroid.y);
|
321
|
+
this.m_position.y = this.m_body.m_position.y + (R2.col1.y * this.m_localCentroid.x + R2.col2.y * this.m_localCentroid.y);
|
322
|
+
|
323
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
324
|
+
{
|
325
|
+
return;
|
326
|
+
}
|
327
|
+
|
328
|
+
//b2AABB aabb1, aabb2;
|
329
|
+
var hX;
|
330
|
+
var hY;
|
331
|
+
|
332
|
+
//b2Mat22 obbR = b2Mul(R1, this.m_localOBB.R);
|
333
|
+
var v1 = R1.col1;
|
334
|
+
var v2 = R1.col2;
|
335
|
+
var v3 = this.m_localOBB.R.col1;
|
336
|
+
var v4 = this.m_localOBB.R.col2;
|
337
|
+
//this.syncMat.col1 = b2MulMV(R1, this.m_localOBB.R.col1);
|
338
|
+
this.syncMat.col1.x = v1.x * v3.x + v2.x * v3.y;
|
339
|
+
this.syncMat.col1.y = v1.y * v3.x + v2.y * v3.y;
|
340
|
+
//this.syncMat.col2 = b2MulMV(R1, this.m_localOBB.R.col2);
|
341
|
+
this.syncMat.col2.x = v1.x * v4.x + v2.x * v4.y;
|
342
|
+
this.syncMat.col2.y = v1.y * v4.x + v2.y * v4.y;
|
343
|
+
//b2Mat22 absR = b2Abs(obbR);
|
344
|
+
this.syncMat.Abs();
|
345
|
+
//b2Vec2 center = position1 + b2Mul(R1, this.m_localCentroid + this.m_localOBB.center);
|
346
|
+
hX = this.m_localCentroid.x + this.m_localOBB.center.x;
|
347
|
+
hY = this.m_localCentroid.y + this.m_localOBB.center.y;
|
348
|
+
var centerX = position1.x + (R1.col1.x * hX + R1.col2.x * hY);
|
349
|
+
var centerY = position1.y + (R1.col1.y * hX + R1.col2.y * hY);
|
350
|
+
//b2Vec2 h = b2Mul(this.syncMat, this.m_localOBB.extents);
|
351
|
+
hX = this.syncMat.col1.x * this.m_localOBB.extents.x + this.syncMat.col2.x * this.m_localOBB.extents.y;
|
352
|
+
hY = this.syncMat.col1.y * this.m_localOBB.extents.x + this.syncMat.col2.y * this.m_localOBB.extents.y;
|
353
|
+
//aabb1.minVertex = center - h;
|
354
|
+
this.syncAABB.minVertex.x = centerX - hX;
|
355
|
+
this.syncAABB.minVertex.y = centerY - hY;
|
356
|
+
//aabb1.maxVertex = center + h;
|
357
|
+
this.syncAABB.maxVertex.x = centerX + hX;
|
358
|
+
this.syncAABB.maxVertex.y = centerY + hY;
|
359
|
+
|
360
|
+
//b2Mat22 obbR = b2Mul(R2, this.m_localOBB.R);
|
361
|
+
v1 = R2.col1;
|
362
|
+
v2 = R2.col2;
|
363
|
+
v3 = this.m_localOBB.R.col1;
|
364
|
+
v4 = this.m_localOBB.R.col2;
|
365
|
+
//this.syncMat.col1 = b2MulMV(R1, this.m_localOBB.R.col1);
|
366
|
+
this.syncMat.col1.x = v1.x * v3.x + v2.x * v3.y;
|
367
|
+
this.syncMat.col1.y = v1.y * v3.x + v2.y * v3.y;
|
368
|
+
//this.syncMat.col2 = b2MulMV(R1, this.m_localOBB.R.col2);
|
369
|
+
this.syncMat.col2.x = v1.x * v4.x + v2.x * v4.y;
|
370
|
+
this.syncMat.col2.y = v1.y * v4.x + v2.y * v4.y;
|
371
|
+
//b2Mat22 absR = b2Abs(obbR);
|
372
|
+
this.syncMat.Abs();
|
373
|
+
//b2Vec2 center = position2 + b2Mul(R2, this.m_localCentroid + this.m_localOBB.center);
|
374
|
+
hX = this.m_localCentroid.x + this.m_localOBB.center.x;
|
375
|
+
hY = this.m_localCentroid.y + this.m_localOBB.center.y;
|
376
|
+
centerX = position2.x + (R2.col1.x * hX + R2.col2.x * hY);
|
377
|
+
centerY = position2.y + (R2.col1.y * hX + R2.col2.y * hY);
|
378
|
+
//b2Vec2 h = b2Mul(absR, this.m_localOBB.extents);
|
379
|
+
hX = this.syncMat.col1.x * this.m_localOBB.extents.x + this.syncMat.col2.x * this.m_localOBB.extents.y;
|
380
|
+
hY = this.syncMat.col1.y * this.m_localOBB.extents.x + this.syncMat.col2.y * this.m_localOBB.extents.y;
|
381
|
+
//aabb2.minVertex = center - h;
|
382
|
+
//aabb2.maxVertex = center + h;
|
383
|
+
|
384
|
+
//aabb.minVertex = b2Min(aabb1.minVertex, aabb2.minVertex);
|
385
|
+
this.syncAABB.minVertex.x = Math.min(this.syncAABB.minVertex.x, centerX - hX);
|
386
|
+
this.syncAABB.minVertex.y = Math.min(this.syncAABB.minVertex.y, centerY - hY);
|
387
|
+
//aabb.maxVertex = b2Max(aabb1.maxVertex, aabb2.maxVertex);
|
388
|
+
this.syncAABB.maxVertex.x = Math.max(this.syncAABB.maxVertex.x, centerX + hX);
|
389
|
+
this.syncAABB.maxVertex.y = Math.max(this.syncAABB.maxVertex.y, centerY + hY);
|
390
|
+
|
391
|
+
var broadPhase = this.m_body.m_world.m_broadPhase;
|
392
|
+
if (broadPhase.InRange(this.syncAABB))
|
393
|
+
{
|
394
|
+
broadPhase.MoveProxy(this.m_proxyId, this.syncAABB);
|
395
|
+
}
|
396
|
+
else
|
397
|
+
{
|
398
|
+
this.m_body.Freeze();
|
399
|
+
}
|
400
|
+
},
|
401
|
+
|
402
|
+
QuickSync: function(position, R){
|
403
|
+
//this.m_R = R;
|
404
|
+
this.m_R.SetM(R);
|
405
|
+
//this.m_position = position + b2Mul(R, this.m_localCentroid);
|
406
|
+
this.m_position.x = position.x + (R.col1.x * this.m_localCentroid.x + R.col2.x * this.m_localCentroid.y);
|
407
|
+
this.m_position.y = position.y + (R.col1.y * this.m_localCentroid.x + R.col2.y * this.m_localCentroid.y);
|
408
|
+
},
|
409
|
+
|
410
|
+
ResetProxy: function(broadPhase){
|
411
|
+
|
412
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
413
|
+
{
|
414
|
+
return;
|
415
|
+
}
|
416
|
+
|
417
|
+
var proxy = broadPhase.GetProxy(this.m_proxyId);
|
418
|
+
|
419
|
+
broadPhase.DestroyProxy(this.m_proxyId);
|
420
|
+
proxy = null;
|
421
|
+
|
422
|
+
var R = b2Math.b2MulMM(this.m_R, this.m_localOBB.R);
|
423
|
+
var absR = b2Math.b2AbsM(R);
|
424
|
+
var h = b2Math.b2MulMV(absR, this.m_localOBB.extents);
|
425
|
+
//var position = this.m_position + b2Mul(this.m_R, this.m_localOBB.center);
|
426
|
+
var position = b2Math.b2MulMV(this.m_R, this.m_localOBB.center);
|
427
|
+
position.Add(this.m_position);
|
428
|
+
|
429
|
+
var aabb = new b2AABB();
|
430
|
+
//aabb.minVertex = position - h;
|
431
|
+
aabb.minVertex.SetV(position);
|
432
|
+
aabb.minVertex.Subtract(h);
|
433
|
+
//aabb.maxVertex = position + h;
|
434
|
+
aabb.maxVertex.SetV(position);
|
435
|
+
aabb.maxVertex.Add(h);
|
436
|
+
|
437
|
+
if (broadPhase.InRange(aabb))
|
438
|
+
{
|
439
|
+
this.m_proxyId = broadPhase.CreateProxy(aabb, this);
|
440
|
+
}
|
441
|
+
else
|
442
|
+
{
|
443
|
+
this.m_proxyId = b2Pair.b2_nullProxy;
|
444
|
+
}
|
445
|
+
|
446
|
+
if (this.m_proxyId == b2Pair.b2_nullProxy)
|
447
|
+
{
|
448
|
+
this.m_body.Freeze();
|
449
|
+
}
|
450
|
+
},
|
451
|
+
|
452
|
+
|
453
|
+
Support: function(dX, dY, out)
|
454
|
+
{
|
455
|
+
//b2Vec2 dLocal = b2MulT(this.m_R, d);
|
456
|
+
var dLocalX = (dX*this.m_R.col1.x + dY*this.m_R.col1.y);
|
457
|
+
var dLocalY = (dX*this.m_R.col2.x + dY*this.m_R.col2.y);
|
458
|
+
|
459
|
+
var bestIndex = 0;
|
460
|
+
//float32 bestValue = b2Dot(this.m_vertices[0], dLocal);
|
461
|
+
var bestValue = (this.m_coreVertices[0].x * dLocalX + this.m_coreVertices[0].y * dLocalY);
|
462
|
+
for (var i = 1; i < this.m_vertexCount; ++i)
|
463
|
+
{
|
464
|
+
//float32 value = b2Dot(this.m_vertices[i], dLocal);
|
465
|
+
var value = (this.m_coreVertices[i].x * dLocalX + this.m_coreVertices[i].y * dLocalY);
|
466
|
+
if (value > bestValue)
|
467
|
+
{
|
468
|
+
bestIndex = i;
|
469
|
+
bestValue = value;
|
470
|
+
}
|
471
|
+
}
|
472
|
+
|
473
|
+
//return this.m_position + b2Mul(this.m_R, this.m_vertices[bestIndex]);
|
474
|
+
out.Set( this.m_position.x + (this.m_R.col1.x * this.m_coreVertices[bestIndex].x + this.m_R.col2.x * this.m_coreVertices[bestIndex].y),
|
475
|
+
this.m_position.y + (this.m_R.col1.y * this.m_coreVertices[bestIndex].x + this.m_R.col2.y * this.m_coreVertices[bestIndex].y));
|
476
|
+
|
477
|
+
},
|
478
|
+
|
479
|
+
|
480
|
+
// Local position of the shape centroid in parent body frame.
|
481
|
+
m_localCentroid: new b2Vec2(),
|
482
|
+
|
483
|
+
// Local position oriented bounding box. The OBB center is relative to
|
484
|
+
// shape centroid.
|
485
|
+
m_localOBB: new b2OBB(),
|
486
|
+
m_vertices: null,
|
487
|
+
m_coreVertices: null,
|
488
|
+
m_vertexCount: 0,
|
489
|
+
m_normals: null});
|
490
|
+
|
491
|
+
b2PolyShape.tempVec = new b2Vec2();
|
492
|
+
b2PolyShape.tAbsR = new b2Mat22();
|