planck-v2 2.0.0
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.
Potentially problematic release.
This version of planck-v2 might be problematic. Click here for more details.
- package/LICENSE.txt +20 -0
- package/README.md +21 -0
- package/dist/planck-with-testbed.d.ts +4433 -0
- package/dist/planck-with-testbed.js +20730 -0
- package/dist/planck-with-testbed.js.map +1 -0
- package/dist/planck-with-testbed.umd.cjs +20730 -0
- package/dist/planck-with-testbed.umd.cjs.map +1 -0
- package/dist/planck.d.ts +4343 -0
- package/dist/planck.js +13516 -0
- package/dist/planck.js.map +1 -0
- package/dist/planck.umd.cjs +13516 -0
- package/dist/planck.umd.cjs.map +1 -0
- package/package.json +105 -0
- package/src/Settings.ts +238 -0
- package/src/__test__/Basic.test.ts +43 -0
- package/src/__test__/CCD.test.ts +70 -0
- package/src/__test__/Collision.test.ts +133 -0
- package/src/__test__/Math.test.ts +105 -0
- package/src/__test__/Pool.test.ts +48 -0
- package/src/__test__/World.test.ts +73 -0
- package/src/collision/AABB.ts +287 -0
- package/src/collision/BroadPhase.ts +210 -0
- package/src/collision/Distance.ts +962 -0
- package/src/collision/DynamicTree.ts +907 -0
- package/src/collision/Manifold.ts +420 -0
- package/src/collision/Raycast.ts +30 -0
- package/src/collision/Shape.ts +114 -0
- package/src/collision/TimeOfImpact.ts +502 -0
- package/src/collision/shape/BoxShape.ts +34 -0
- package/src/collision/shape/ChainShape.ts +360 -0
- package/src/collision/shape/CircleShape.ts +202 -0
- package/src/collision/shape/CollideCircle.ts +66 -0
- package/src/collision/shape/CollideCirclePolygon.ts +142 -0
- package/src/collision/shape/CollideEdgeCircle.ts +185 -0
- package/src/collision/shape/CollideEdgePolygon.ts +528 -0
- package/src/collision/shape/CollidePolygon.ts +280 -0
- package/src/collision/shape/EdgeShape.ts +316 -0
- package/src/collision/shape/PolygonShape.ts +581 -0
- package/src/common/Geo.ts +589 -0
- package/src/common/Jacobian.ts +17 -0
- package/src/common/Mat22.ts +221 -0
- package/src/common/Mat33.ts +224 -0
- package/src/common/Math.ts +96 -0
- package/src/common/Rot.ts +218 -0
- package/src/common/Sweep.ts +119 -0
- package/src/common/Transform.ts +203 -0
- package/src/common/Vec2.ts +624 -0
- package/src/common/Vec3.ts +188 -0
- package/src/dynamics/Body.ts +1198 -0
- package/src/dynamics/Contact.ts +1366 -0
- package/src/dynamics/Fixture.ts +506 -0
- package/src/dynamics/Joint.ts +226 -0
- package/src/dynamics/Position.ts +44 -0
- package/src/dynamics/Solver.ts +890 -0
- package/src/dynamics/Velocity.ts +18 -0
- package/src/dynamics/World.ts +1169 -0
- package/src/dynamics/joint/DistanceJoint.ts +463 -0
- package/src/dynamics/joint/FrictionJoint.ts +396 -0
- package/src/dynamics/joint/GearJoint.ts +591 -0
- package/src/dynamics/joint/MotorJoint.ts +430 -0
- package/src/dynamics/joint/MouseJoint.ts +390 -0
- package/src/dynamics/joint/PrismaticJoint.ts +903 -0
- package/src/dynamics/joint/PulleyJoint.ts +529 -0
- package/src/dynamics/joint/RevoluteJoint.ts +745 -0
- package/src/dynamics/joint/RopeJoint.ts +383 -0
- package/src/dynamics/joint/WeldJoint.ts +544 -0
- package/src/dynamics/joint/WheelJoint.ts +683 -0
- package/src/dynamics/joint/__test__/DistanceJoint.test.ts +66 -0
- package/src/index.ts +60 -0
- package/src/internal.ts +20 -0
- package/src/main.ts +3 -0
- package/src/serializer/__test__/Serialize.test.ts +52 -0
- package/src/serializer/__test__/Validator.test.ts +55 -0
- package/src/serializer/index.ts +257 -0
- package/src/serializer/schema.json +168 -0
- package/src/util/Pool.ts +120 -0
- package/src/util/Testbed.ts +157 -0
- package/src/util/Timer.ts +15 -0
- package/src/util/options.ts +28 -0
- package/src/util/stats.ts +26 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Planck.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Erin Catto, Ali Shakiba
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @internal */ const _ASSERT = typeof ASSERT === "undefined" ? false : ASSERT;
|
|
11
|
+
|
|
12
|
+
/** 3D vector */
|
|
13
|
+
export interface Vec3Value {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
z: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 3D vector
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Use Vec3Value and geo functions instead.
|
|
23
|
+
*/
|
|
24
|
+
export class Vec3 {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
z: number;
|
|
28
|
+
|
|
29
|
+
constructor(x: number, y: number, z: number);
|
|
30
|
+
constructor(obj: Vec3Value);
|
|
31
|
+
constructor();
|
|
32
|
+
constructor(x?, y?, z?) {
|
|
33
|
+
if (typeof x === "undefined") {
|
|
34
|
+
this.x = 0;
|
|
35
|
+
this.y = 0;
|
|
36
|
+
this.z = 0;
|
|
37
|
+
} else if (typeof x === "object") {
|
|
38
|
+
this.x = x.x;
|
|
39
|
+
this.y = x.y;
|
|
40
|
+
this.z = x.z;
|
|
41
|
+
} else {
|
|
42
|
+
this.x = x;
|
|
43
|
+
this.y = y;
|
|
44
|
+
this.z = z;
|
|
45
|
+
}
|
|
46
|
+
if (_ASSERT) Vec3.assert(this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @hidden */
|
|
50
|
+
_serialize(): object {
|
|
51
|
+
return {
|
|
52
|
+
x: this.x,
|
|
53
|
+
y: this.y,
|
|
54
|
+
z: this.z,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @hidden */
|
|
59
|
+
static _deserialize(data: any): Vec3 {
|
|
60
|
+
const obj = Object.create(Vec3.prototype);
|
|
61
|
+
obj.x = data.x;
|
|
62
|
+
obj.y = data.y;
|
|
63
|
+
obj.z = data.z;
|
|
64
|
+
return obj;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @hidden */
|
|
68
|
+
static neo(x: number, y: number, z: number): Vec3 {
|
|
69
|
+
const obj = Object.create(Vec3.prototype);
|
|
70
|
+
obj.x = x;
|
|
71
|
+
obj.y = y;
|
|
72
|
+
obj.z = z;
|
|
73
|
+
return obj;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static zero(): Vec3 {
|
|
77
|
+
const obj = Object.create(Vec3.prototype);
|
|
78
|
+
obj.x = 0;
|
|
79
|
+
obj.y = 0;
|
|
80
|
+
obj.z = 0;
|
|
81
|
+
return obj;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static clone(v: Vec3Value): Vec3 {
|
|
85
|
+
if (_ASSERT) Vec3.assert(v);
|
|
86
|
+
return Vec3.neo(v.x, v.y, v.z);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** @hidden */
|
|
90
|
+
toString(): string {
|
|
91
|
+
return JSON.stringify(this);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Does this vector contain finite coordinates? */
|
|
95
|
+
static isValid(obj: any): boolean {
|
|
96
|
+
if (obj === null || typeof obj === "undefined") {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return Number.isFinite(obj.x) && Number.isFinite(obj.y) && Number.isFinite(obj.z);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static assert(o: any): void {
|
|
103
|
+
if (_ASSERT) console.assert(!Vec3.isValid(o), "Invalid Vec3!", o);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setZero(): Vec3 {
|
|
107
|
+
this.x = 0.0;
|
|
108
|
+
this.y = 0.0;
|
|
109
|
+
this.z = 0.0;
|
|
110
|
+
return this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
set(x: number, y: number, z: number): Vec3 {
|
|
114
|
+
this.x = x;
|
|
115
|
+
this.y = y;
|
|
116
|
+
this.z = z;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
add(w: Vec3Value): Vec3 {
|
|
121
|
+
this.x += w.x;
|
|
122
|
+
this.y += w.y;
|
|
123
|
+
this.z += w.z;
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
sub(w: Vec3Value): Vec3 {
|
|
128
|
+
this.x -= w.x;
|
|
129
|
+
this.y -= w.y;
|
|
130
|
+
this.z -= w.z;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
mul(m: number): Vec3 {
|
|
135
|
+
this.x *= m;
|
|
136
|
+
this.y *= m;
|
|
137
|
+
this.z *= m;
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static areEqual(v: Vec3Value, w: Vec3Value): boolean {
|
|
142
|
+
if (_ASSERT) Vec3.assert(v);
|
|
143
|
+
if (_ASSERT) Vec3.assert(w);
|
|
144
|
+
return (
|
|
145
|
+
v === w ||
|
|
146
|
+
(typeof v === "object" &&
|
|
147
|
+
v !== null &&
|
|
148
|
+
typeof w === "object" &&
|
|
149
|
+
w !== null &&
|
|
150
|
+
v.x === w.x &&
|
|
151
|
+
v.y === w.y &&
|
|
152
|
+
v.z === w.z)
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Dot product on two vectors */
|
|
157
|
+
static dot(v: Vec3Value, w: Vec3Value): number {
|
|
158
|
+
return v.x * w.x + v.y * w.y + v.z * w.z;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Cross product on two vectors */
|
|
162
|
+
static cross(v: Vec3Value, w: Vec3Value): Vec3 {
|
|
163
|
+
return new Vec3(v.y * w.z - v.z * w.y, v.z * w.x - v.x * w.z, v.x * w.y - v.y * w.x);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
static add(v: Vec3Value, w: Vec3Value): Vec3 {
|
|
167
|
+
return new Vec3(v.x + w.x, v.y + w.y, v.z + w.z);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static sub(v: Vec3Value, w: Vec3Value): Vec3 {
|
|
171
|
+
return new Vec3(v.x - w.x, v.y - w.y, v.z - w.z);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
static mul(v: Vec3Value, m: number): Vec3 {
|
|
175
|
+
return new Vec3(m * v.x, m * v.y, m * v.z);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
neg(): Vec3 {
|
|
179
|
+
this.x = -this.x;
|
|
180
|
+
this.y = -this.y;
|
|
181
|
+
this.z = -this.z;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
static neg(v: Vec3Value): Vec3 {
|
|
186
|
+
return new Vec3(-v.x, -v.y, -v.z);
|
|
187
|
+
}
|
|
188
|
+
}
|