-
Notifications
You must be signed in to change notification settings - Fork 3
/
box2d.d.ts
3785 lines (3525 loc) · 154 KB
/
box2d.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
declare class box2d {
static DEBUG: boolean;
static ENABLE_ASSERTS: boolean;
static b2Assert(condition: boolean, opt_message?: string, ...var_args: any[]): void;
static b2_maxFloat: number;
static b2_epsilon: number;
static b2_epsilon_sq: number;
static b2_pi: number;
// The maximum number of contact points between two convex
// shapes. Do not change this value.
static b2_maxManifoldPoints: number;
// The maximum number of vertices on a convex polygon. You
// cannot increase this too much because b2BlockAllocator has a
// maximum object size.
static b2_maxPolygonVertices: number;
// This is used to fatten AABBs in the dynamic tree. This allows
// proxies to move by a small amount without triggering a tree
// adjustment.
// This is in meters.
static b2_aabbExtension: number;
// This is used to fatten AABBs in the dynamic tree. This is
// used to predict the future position based on the current
// displacement.
// This is a dimensionless multiplier.
static b2_aabbMultiplier: number;
// A small length used as a collision and constraint tolerance.
// Usually it is chosen to be numerically significant, but
// visually insignificant.
static b2_linearSlop: number;
// A small angle used as a collision and constraint tolerance.
// Usually it is chosen to be numerically significant, but
// visually insignificant.
static b2_angularSlop: number;
// The radius of the polygon/edge shape skin. This should not be
// modified. Making this smaller means polygons will have an
// insufficient buffer for continuous collision.
// Making it larger may create artifacts for vertex collision.
static b2_polygonRadius: number;
// Maximum number of sub-steps per contact in continuous physics
// simulation.
static b2_maxSubSteps: number;
// Maximum number of contacts to be handled to solve a TOI
// impact.
static b2_maxTOIContacts: number;
// A velocity threshold for elastic collisions. Any collision
// with a relative linear velocity below this threshold will be
// treated as inelastic.
static b2_velocityThreshold: number;
// The maximum linear position correction used when solving
// constraints. This helps to prevent overshoot.
static b2_maxLinearCorrection: number;
// The maximum angular position correction used when solving
// constraints. This helps to prevent overshoot.
static b2_maxAngularCorrection: number;
// The maximum linear velocity of a body. This limit is very
// large and is used to prevent numerical problems. You
// shouldn't need to adjust this.
static b2_maxTranslation: number;
static b2_maxTranslationSquared: number;
// The maximum angular velocity of a body. This limit is very
// large and is used to prevent numerical problems. You
// shouldn't need to adjust this.
static b2_maxRotation: number;
static b2_maxRotationSquared: number;
// This scale factor controls how fast overlap is resolved.
// Ideally this would be 1 so that overlap is removed in one
// time step. However using values close to 1 often lead to
// overshoot.
static b2_baumgarte: number;
static b2_toiBaumgarte: number;
// The time that a body must be still before it will go to
// sleep.
static b2_timeToSleep: number;
// A body cannot sleep if its linear velocity is above this
// tolerance.
static b2_linearSleepTolerance: number;
// A body cannot sleep if its angular velocity is above this
// tolerance.
static b2_angularSleepTolerance: number;
// Implement this function to use your own memory allocator.
static b2Alloc(size: number): any;
// If you implement b2Alloc, you should also implement this
// function.
static b2Free(mem: any): void;
// Logging function.
// You can modify this to use your logging facility.
static b2Log(...var_args: any[]): void;
// Current version.
static b2_version: box2d.b2Version;
static b2_changelist: number;
static b2ParseInt(v: string): number;
static b2ParseUInt(v: string): number;
static b2MakeArray(length?: number, init?: (length: number) => any): Array<any>;
static b2MakeNumberArray(length?: number): Array<number>;
static b2_pi_over_180: number;
static b2_180_over_pi: number;
static b2_two_pi: number;
static b2Abs(n: number): number;
static b2Min(a: number, b: number): number;
static b2Max(a: number, b: number): number;
static b2Clamp(a: number, lo: number, hi: number): number;
static b2Swap(a: Array<number>, b: Array<number>): void;
// This function is used to ensure that a floating point number
// is not a NaN or infinity.
static b2IsValid(n: number): boolean;
static b2Sq(n: number): number;
// This is a approximate yet fast inverse square-root.
static b2InvSqrt(n: number): number;
static b2Sqrt(n: number): number;
static b2Pow(x: number, y: number): number;
static b2DegToRad(degrees: number): number;
static b2RadToDeg(radians: number): number;
static b2Cos(radians: number): number;
static b2Sin(radians: number): number;
static b2Acos(n: number): number;
static b2Asin(n: number): number;
static b2Atan2(y: number, x: number): number;
// Next Largest Power of 2
// Given a binary integer value x, the next largest power of 2
// can be computed by a SWAR algorithm that recursively "folds"
// the upper bits into the lower bits. This process yields a bit
// vector with the same most significant 1 as x, but all 1's
// below it. Adding 1 to that value yields the next largest
// power of 2. For a 32-bit value:
static b2NextPowerOfTwo(x: number): number;
static b2IsPowerOfTwo(x: number): boolean;
static b2Random(): number;
static b2RandomRange(lo: number, hi: number): number;
static b2Vec2_zero: box2d.b2Vec2;
static b2AbsV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MinV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MaxV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2ClampV(v: box2d.b2Vec2, lo: box2d.b2Vec2, hi: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2RotateV(v: box2d.b2Vec2, c: number, s: number, out: box2d.b2Vec2): box2d.b2Vec2;
static b2RotateRadiansV(v: box2d.b2Vec2, radians: number, out: box2d.b2Vec2): box2d.b2Vec2;
static b2RotateDegreesV(v: box2d.b2Vec2, degrees: number, out: box2d.b2Vec2): box2d.b2Vec2;
// Perform the dot product on two vectors.
// a.x * b.x + a.y * b.y
static b2DotVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number;
// Perform the cross product on two vectors. In 2D this produces a scalar.
// a.x * b.y - a.y * b.x
static b2CrossVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number;
// Perform the cross product on a vector and a scalar. In 2D
// this produces a vector.
static b2CrossVS(v: box2d.b2Vec2, s: number, out: box2d.b2Vec2): box2d.b2Vec2;
// box2d.b2CrossVS(v, 1.0, out)
static b2CrossVOne(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Perform the cross product on a scalar and a vector. In 2D
// this produces a vector.
static b2CrossSV(s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// box2d.b2CrossSV(1.0, v, out)
static b2CrossOneV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Add two vectors component-wise.
static b2AddVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Subtract two vectors component-wise.
static b2SubVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MulSV(s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// out = a + (s * b)
static b2AddVMulSV(a: box2d.b2Vec2, s: number, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// out = a - (s * b)
static b2SubVMulSV(a: box2d.b2Vec2, s: number, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// out = a + b2CrossSV(s, v)
static b2AddVCrossSV(a: box2d.b2Vec2, s: number, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Get the center of two vectors.
static b2MidVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Get the extent of two vectors (half-widths).
static b2ExtVV(a: box2d.b2Vec2, b: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2IsEqualToV(a: box2d.b2Vec2, b: box2d.b2Vec2): boolean;
static b2DistanceVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number;
static b2DistanceSquaredVV(a: box2d.b2Vec2, b: box2d.b2Vec2): number;
static b2NegV(v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Perform the dot product on two vectors.
static b2DotV3V3(a: box2d.b2Vec3, b: box2d.b2Vec3): number;
// Perform the cross product on two vectors.
static b2CrossV3V3(a: box2d.b2Vec3, b: box2d.b2Vec3, out: box2d.b2Vec3): box2d.b2Vec3;
static b2AbsM(M: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22;
// Multiply a matrix times a vector. If a rotation matrix is
// provided, then this transforms the vector from one frame to
// another.
static b2MulMV(M: box2d.b2Mat22, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Multiply a matrix transpose times a vector. If a rotation
// matrix is provided, then this transforms the vector from one
// frame to another (inverse transform).
static b2MulTMV(M: box2d.b2Mat22, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2AddMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22;
static b2MulMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22;
static b2MulTMM(A: box2d.b2Mat22, B: box2d.b2Mat22, out: box2d.b2Mat22): box2d.b2Mat22;
// Multiply a matrix times a vector.
static b2MulM33V3(A: box2d.b2Mat33, v: box2d.b2Vec3, out: box2d.b2Vec3): box2d.b2Vec3;
static b2MulM33XYZ(A: box2d.b2Mat33, x: number, y: number, z: number, out: box2d.b2Vec3): box2d.b2Vec3;
static b2MulM33V2(A: box2d.b2Mat33, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MulM33XY(A: box2d.b2Mat33, x: number, y: number, out: box2d.b2Vec2): box2d.b2Vec2;
// Multiply two rotations: q * r
static b2MulRR(q: box2d.b2Rot, r: box2d.b2Rot, out: box2d.b2Rot): box2d.b2Rot;
// Transpose multiply two rotations: qT * r
static b2MulTRR(q: box2d.b2Rot, r: box2d.b2Rot, out: box2d.b2Rot): box2d.b2Rot;
// Rotate a vector
static b2MulRV(q: box2d.b2Rot, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// Inverse rotate a vector
static b2MulTRV(q: box2d.b2Rot, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MulXV(T: box2d.b2Transform, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
static b2MulTXV(T: box2d.b2Transform, v: box2d.b2Vec2, out: box2d.b2Vec2): box2d.b2Vec2;
// v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
// = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
static b2MulXX(A: box2d.b2Transform, B: box2d.b2Transform, out: box2d.b2Transform): box2d.b2Transform;
// v2 = A.q' * (B.q * v1 + B.p - A.p)
// = A.q' * B.q * v1 + A.q' * (B.p - A.p)
static b2MulTXX(A: box2d.b2Transform, B: box2d.b2Transform, out: box2d.b2Transform): box2d.b2Transform;
static b2_gjkCalls: number;
static b2_gjkIters: number;
static b2_gjkMaxIters: number;
// Compute the closest points between two shapes. Supports any combination of:
// box2d.b2CircleShape, box2d.b2PolygonShape, box2d.b2EdgeShape. The simplex cache is input/output.
// On the first call set box2d.b2SimplexCache.count to zero.
static b2Distance(output: box2d.b2DistanceOutput, cache: box2d.b2SimplexCache, input: box2d.b2DistanceInput): void;
// Compute the point states given two manifolds. The states
// pertain to the transition from manifold1 to manifold2. So
// state1 is either persist or remove while state2 is either add
// or persist.
static b2GetPointStates(state1: Array<box2d.b2PointState>, state2: Array<box2d.b2PointState>, manifold1: box2d.b2Manifold, manifold2: box2d.b2Manifold): void;
static b2TestOverlapAABB(a: box2d.b2AABB, b: box2d.b2AABB): boolean;
// Clipping for contact manifolds.
// Sutherland-Hodgman clipping.
static b2ClipSegmentToLine(vOut: Array<box2d.b2ClipVertex>, vIn: Array<box2d.b2ClipVertex>, normal: box2d.b2Vec2, offset: number, vertexIndexA: number): number;
static b2TestOverlapShape(shapeA: box2d.b2Shape, shapeB: box2d.b2Shape, xfA: box2d.b2Transform, xfB: box2d.b2Transform): boolean;
static b2_toiTime: number;
static b2_toiMaxTime: number;
static b2_toiCalls: number;
static b2_toiIters: number;
static b2_toiMaxIters: number;
static b2_toiRootIters: number;
static b2_toiMaxRootIters: number;
// Compute the upper bound on time before two shapes penetrate.
// Time is represented as a fraction between [0,tMax]. This uses
// a swept separating axis and may miss some intermediate,
// non-tunneling collision. If you change the time interval, you
// should call this function again.
// Note: use box2d.b2Distance to compute the contact point and
// normal at the time of impact.
static b2TimeOfImpact(output: box2d.b2TOIOutput, input: box2d.b2TOIInput): void;
// Friction mixing law. The idea is to allow either fixture to
// drive the restitution to zero. For example, anything slides
// on ice.
static b2MixFriction(friction1: number, friction2: number): number;
// Restitution mixing law. The idea is allow for anything to
// bounce off an inelastic surface. For example, a superball
// bounces on anything.
static b2MixRestitution(restitution1: number, restitution2: number): number;
// Compute the collision manifold between an edge and a circle.
// Compute contact points for edge versus circle.
// This accounts for edge connectivity.
static b2CollideEdgeAndCircle(manifold: box2d.b2Manifold, edgeA: box2d.b2EdgeShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void;
// Compute the collision manifold between an edge and a polygon.
static b2CollideEdgeAndPolygon(manifold: box2d.b2Manifold, edgeA: box2d.b2EdgeShape, xfA: box2d.b2Transform, polygonB: box2d.b2PolygonShape, xfB: box2d.b2Transform): void;
// Find the max separation between poly1 and poly2 using edge
// normals from poly1.
static b2FindMaxSeparation(edgeIndex: Array<number>, poly1: box2d.b2PolygonShape, xf1: box2d.b2Transform, poly2: box2d.b2PolygonShape, xf2: box2d.b2Transform): number;
static b2FindIncidentEdge(c: Array<box2d.b2ClipVertex>, poly1: box2d.b2PolygonShape, xf1: box2d.b2Transform, edge1: number, poly2: box2d.b2PolygonShape, xf2: box2d.b2Transform): void;
// Find edge normal of max separation on A - return if separating axis is found
// Find edge normal of max separation on B - return if separation axis is found
// Choose reference edge as min(minA, minB)
// Find incident edge
// Clip
// The normal points from 1 to 2
static b2CollidePolygons(manifold: box2d.b2Manifold, polyA: box2d.b2PolygonShape, xfA: box2d.b2Transform, polyB: box2d.b2PolygonShape, xfB: box2d.b2Transform): void;
// Compute the collision manifold between two circles.
static b2CollideCircles(manifold: box2d.b2Manifold, circleA: box2d.b2CircleShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void;
// Compute the collision manifold between a polygon and a
// circle.
static b2CollidePolygonAndCircle(manifold: box2d.b2Manifold, polygonA: box2d.b2PolygonShape, xfA: box2d.b2Transform, circleB: box2d.b2CircleShape, xfB: box2d.b2Transform): void;
// This is used to sort pairs.
static b2PairLessThan(pair1: box2d.b2Pair, pair2: box2d.b2Pair): number;
static b2_minPulleyLength: number;
}
declare module box2d {
enum b2JointType {
e_unknownJoint = 0,
e_revoluteJoint = 1,
e_prismaticJoint = 2,
e_distanceJoint = 3,
e_pulleyJoint = 4,
e_mouseJoint = 5,
e_gearJoint = 6,
e_wheelJoint = 7,
e_weldJoint = 8,
e_frictionJoint = 9,
e_ropeJoint = 10,
e_motorJoint = 11,
e_areaJoint = 12
}
enum b2LimitState {
e_inactiveLimit = 0,
e_atLowerLimit = 1,
e_atUpperLimit = 2,
e_equalLimits = 3
}
enum b2ContactFeatureType {
e_vertex = 0,
e_face = 1
}
enum b2ManifoldType {
e_unknown = -1,
e_circles = 0,
e_faceA = 1,
e_faceB = 2
}
// This is used for determining the state of contact points.
enum b2PointState {
b2_nullState = 0, ///< point does not exist
b2_addState = 1, ///< point was added in the update
b2_persistState = 2, ///< point persisted across the update
b2_removeState = 3 ///< point was removed in the update
}
enum b2TOIOutputState {
e_unknown = 0,
e_failed = 1,
e_overlapped = 2,
e_touching = 3,
e_separated = 4
}
enum b2SeparationFunctionType {
e_unknown = -1,
e_points = 0,
e_faceA = 1,
e_faceB = 2
}
// Flags stored in m_flags
enum b2ContactFlag {
e_none = 0,
e_islandFlag = 0x0001, /// Used when crawling contact graph when forming islands.
e_touchingFlag = 0x0002, /// Set when the shapes are touching.
e_enabledFlag = 0x0004, /// This contact can be disabled (by user)
e_filterFlag = 0x0008, /// This contact needs filtering because a fixture filter was changed.
e_bulletHitFlag = 0x0010, /// This bullet contact had a TOI event
e_toiFlag = 0x0020 /// This contact has a valid TOI in m_toi
}
enum b2ShapeType {
e_unknown = -1,
e_circleShape = 0,
e_edgeShape = 1,
e_polygonShape = 2,
e_chainShape = 3,
e_shapeTypeCount = 4
}
enum b2EPAxisType {
e_unknown = 0,
e_edgeA = 1,
e_edgeB = 2
}
enum b2EPColliderVertexType {
e_isolated = 0,
e_concave = 1,
e_convex = 2
}
enum b2DrawFlags {
e_none = 0,
e_shapeBit = 0x0001, ///< draw shapes
e_jointBit = 0x0002, ///< draw joint connections
e_aabbBit = 0x0004, ///< draw axis aligned bounding boxes
e_pairBit = 0x0008, ///< draw broad-phase pairs
e_centerOfMassBit = 0x0010, ///< draw center of mass frame
e_controllerBit = 0x0020, /// @see box2d.b2Controller list
e_all = 0x003f
}
// The body type.
// enum= zero mass, zero velocity, may be manually moved
// kinematic= zero mass, non-zero velocity set by user, moved by solver
// dynamic= positive mass, non-zero velocity determined by forces, moved by solver
enum b2BodyType {
b2_unknown = -1,
b2_staticBody = 0,
b2_kinematicBody = 1,
b2_dynamicBody = 2,
b2_bulletBody = 3 // TODO_ERIN
}
enum b2BodyFlag {
e_none = 0,
e_islandFlag = 0x0001,
e_awakeFlag = 0x0002,
e_autoSleepFlag = 0x0004,
e_bulletFlag = 0x0008,
e_fixedRotationFlag = 0x0010,
e_activeFlag = 0x0020,
e_toiFlag = 0x0040
}
enum b2WorldFlag {
e_none = 0,
e_newFixture = 0x1,
e_locked = 0x2,
e_clearForces = 0x4
}
class b2Version {
// Version numberinf scheme See
// http://en.wikipedia.org/wiki/Software_versioning
constructor(major?: number, minor?: number, revision?: number);
major: number;
minor: number;
revision: number;
toString(): string;
}
class b2Vec2 {
// A 2D column vector.
constructor(x?: number, y?: number);
x: number;
y: number;
static ZERO: b2Vec2;
static UNITX: b2Vec2;
static UNITY: b2Vec2;
static s_t0: b2Vec2;
static s_t1: b2Vec2;
static s_t2: b2Vec2;
static s_t3: b2Vec2;
static MakeArray(length?: number): Array<b2Vec2>;
Clone(): b2Vec2;
// Set this vector to all zeros.
SetZero(): b2Vec2;
// Set this vector to some specified coordinates.
SetXY(x: number, y: number): b2Vec2;
Copy(other: b2Vec2): b2Vec2;
// Add a vector to this vector.
SelfAdd(v: b2Vec2): b2Vec2;
SelfAddXY(x: number, y: number): b2Vec2;
// Subtract a vector from this vector.
SelfSub(v: b2Vec2): b2Vec2;
SelfSubXY(x: number, y: number): b2Vec2;
// Multiply this vector by a scalar.
SelfMul(s: number): b2Vec2;
// this += s * v
SelfMulAdd(s: number, v: b2Vec2): b2Vec2;
// this -= s * v
SelfMulSub(s: number, v: b2Vec2): b2Vec2;
Dot(v: b2Vec2): number;
Cross(v: b2Vec2): number;
// Get the length of this vector (the norm).
Length(): number;
GetLength(): number;
// Get the length squared. For performance, use this instead of
// b2Vec2::Length (if possible).
LengthSquared(): number;
GetLengthSquared(): number;
// Convert this vector into a unit vector. Returns the length.
Normalize(): number;
SelfNormalize(): b2Vec2;
SelfRotate(c: number, s: number): b2Vec2;
SelfRotateRadians(radians: number): b2Vec2;
SelfRotateDegrees(degrees: number): b2Vec2;
// Does this vector contain finite coordinates?
IsValid(): boolean;
SelfCrossVS(s: number): b2Vec2;
SelfCrossSV(s: number): b2Vec2;
SelfMinV(v: b2Vec2): b2Vec2;
SelfMaxV(v: b2Vec2): b2Vec2;
SelfAbs(): b2Vec2;
SelfNeg(): b2Vec2;
// Get the skew vector such that dot(skew_vec, other) ===
// cross(vec, other)
SelfSkew(): b2Vec2;
}
class b2Vec3 {
constructor(x?: number, y?: number, z?: number);
x: number;
y: number;
z: number;
static ZERO: b2Vec3;
static s_t0: b2Vec3;
Clone(): b2Vec3;
SetZero(): b2Vec3;
SetXYZ(x: number, y: number, z: number): b2Vec3;
Copy(other: b2Vec3): b2Vec3;
SelfNeg(): b2Vec3;
SelfAdd(v: b2Vec3): b2Vec3;
SelfAddXYZ(x: number, y: number, z: number): b2Vec3;
SelfSub(v: b2Vec3): b2Vec3;
SelfSubXYZ(x: number, y: number, z: number): b2Vec3;
SelfMul(s: number): b2Vec3;
}
class b2Mat22 {
// A 2-by-2 matrix. Stored in column-major order.
constructor();
ex: b2Vec2;
ey: b2Vec2;
static IDENTITY: b2Mat22;
Clone(): b2Mat22;
// Construct this matrix using columns.
static FromVV(c1: b2Vec2, c2: b2Vec2): b2Mat22;
// Construct this matrix using scalars.
static FromSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): b2Mat22;
// Construct this matrix using an angle. This matrix becomes an
// orthonormal rotation matrix.
static FromAngleRadians(radians: number): b2Mat22;
// Initialize this matrix using scalars.
SetSSSS(r1c1: number, r1c2: number, r2c1: number, r2c2: number): b2Mat22;
// Initialize this matrix using columns.
SetVV(c1: b2Vec2, c2: b2Vec2): b2Mat22;
// Initialize this matrix using an angle. This matrix becomes an
// orthonormal rotation matrix.
SetAngle(radians: number): b2Mat22;
Copy(other: b2Mat22): b2Mat22;
// Set this to the identity matrix.
SetIdentity(): b2Mat22;
// Set this matrix to all zeros.
SetZero(): b2Mat22;
// Extract the angle from this matrix (assumed to be a rotation
// matrix).
GetAngle(): number;
GetInverse(out: b2Mat22): b2Mat22;
// Solve A * x = b, where b is a column vector. This is more
// efficient than computing the inverse in one-shot cases.
Solve(b_x: number, b_y: number, out: b2Vec2): b2Vec2;
SelfAbs(): b2Mat22;
SelfInv(): b2Mat22;
SelfAddM(M: b2Mat22): b2Mat22;
SelfSubM(M: b2Mat22): b2Mat22;
}
class b2Mat33 {
// A 3-by-3 matrix. Stored in column-major order.
constructor();
ex: b2Vec3;
ey: b2Vec3;
ez: b2Vec3;
static IDENTITY: b2Mat33;
Clone(): b2Mat33;
SetVVV(c1: b2Vec3, c2: b2Vec3, c3: b2Vec3): b2Mat33;
Copy(other: b2Mat33): b2Mat33;
SetIdentity(): b2Mat33;
// Set this matrix to all zeros.
SetZero(): b2Mat33;
SelfAddM(M: b2Mat33): b2Mat33;
// Solve A * x = b, where b is a column vector. This is more
// efficient than computing the inverse in one-shot cases.
Solve33(b_x: number, b_y: number, b_z: number, out: b2Vec3): b2Vec3;
// Solve A * x = b, where b is a column vector. This is more
// efficient than computing the inverse in one-shot cases. Solve
// only the upper 2-by-2 matrix equation.
Solve22(b_x: number, b_y: number, out: b2Vec2): b2Vec2;
// Get the inverse of this matrix as a 2-by-2.
// Returns the zero matrix if singular.
GetInverse22(M: b2Mat33): void;
// Get the symmetric inverse of this matrix as a 3-by-3.
// Returns the zero matrix if singular.
GetSymInverse33(M: b2Mat33): void;
}
class b2Rot {
// Rotation
// Initialize from an angle in radians
constructor(angle?: number);
angle: number;
s: number;
c: number;
static IDENTITY: b2Rot;
Clone(): b2Rot;
Copy(other: b2Rot): b2Rot;
// Set using an angle in radians.
SetAngle(angle: number): b2Rot;
// Set to the identity rotation
SetIdentity(): b2Rot;
// Get the angle in radians
GetAngle(): number;
// Get the x-axis
GetXAxis(out: b2Vec2): b2Vec2;
// Get the y-axis
GetYAxis(out: b2Vec2): b2Vec2;
}
class b2Transform {
// A transform contains translation and rotation. It is used to
// represent the position and orientation of rigid frames.
constructor();
p: b2Vec2;
q: b2Rot;
static IDENTITY: b2Transform;
Clone(): b2Transform;
Copy(other: b2Transform): b2Transform;
// Set this to the identity transform.
SetIdentity(): b2Transform;
// Set this based on the position and angle.
SetPositionRotation(position: b2Vec2, q: b2Rot): b2Transform;
SetPositionAngleRadians(pos: b2Vec2, a: number): b2Transform;
SetPosition(position: b2Vec2): b2Transform;
SetPositionXY(x: number, y: number): b2Transform;
SetRotation(rotation: b2Rot): b2Transform;
SetRotationAngleRadians(radians: number): b2Transform;
GetPosition(): b2Vec2;
GetRotation(): b2Rot;
GetRotationAngle(): number;
GetAngle(): number;
}
class b2Sweep {
// This describes the motion of a body/shape for TOI computation.
// Shapes are defined with respect to the body origin, which may
// no coincide with the center of mass. However, to support dynamics
// we must interpolate the center of mass position.
constructor();
localCenter: b2Vec2;
c0: b2Vec2;
c: b2Vec2;
a0: number;
a: number;
// Fraction of the current time step in the range [0,1]
// c0 and a0 are the positions at alpha0.
alpha0: number;
Clone(): b2Sweep;
Copy(other: b2Sweep): b2Sweep;
// Get the interpolated transform at a specific time.
GetTransform(xf: b2Transform, beta: number): b2Transform;
// Advance the sweep forward, yielding a new initial state.
Advance(alpha: number): void;
// Normalize an angle in radians to be between -pi and pi
// (actually 0 and 2*pi)
Normalize(): void;
}
class b2ControllerEdge {
// A controller edge is used to connect bodies and controllers
// together in a bipartite graph.
constructor();
controller: b2Controller;
body: b2Body;
prevBody: b2ControllerEdge;
nextBody: b2ControllerEdge;
prevController: b2ControllerEdge;
nextController: b2ControllerEdge;
}
class b2Controller {
// Base class for controllers. Controllers are a convience for
// encapsulating common per-step functionality.
constructor();
m_world: b2World;
m_bodyList: b2ControllerEdge;
m_bodyCount: number;
m_prev: b2Controller;
m_next: b2Controller;
// Controllers override this to implement per-step
// functionality.
Step(step: b2TimeStep): void;
// Controllers override this to provide debug drawing.
Draw(debugDraw: b2Draw): void;
// Get the next controller in the world's body list.
GetNext(): b2Controller;
// Get the previous controller in the world's body list.
GetPrev(): b2Controller;
// Get the parent world of this body.
GetWorld(): b2World;
// Get the attached body list
GetBodyList(): b2ControllerEdge;
// Adds a body to the controller list.
AddBody(body: b2Body): void;
// Removes a body from the controller list.
RemoveBody(body: b2Body): void;
// Removes all bodies from the controller list.
Clear(): void;
}
class b2ConstantAccelController extends b2Controller {
// Applies a force every frame
constructor();
// The acceleration to apply
A: b2Vec2;
Step(step: b2TimeStep): void;
// The force to apply
F: b2Vec2;
}
class b2Jacobian {
constructor();
linear: b2Vec2;
angularA: number;
angularB: number;
SetZero(): b2Jacobian;
Set(x: b2Vec2, a1: number, a2: number): b2Jacobian;
}
class b2JointEdge {
// A joint edge is used to connect bodies and joints together in
// a joint graph where each body is a node and each joint is an
// edge. A joint edge belongs to a doubly linked list maintained
// in each attached body. Each joint has two joint nodes, one
// for each attached body.
constructor();
other: b2Body;
joint: b2Joint;
prev: b2JointEdge;
next: b2JointEdge;
}
class b2JointDef {
// Joint definitions are used to construct joints.
constructor(type: b2JointType);
// The joint type is set automatically for concrete joint types.
type: b2JointType;
// Use this to attach application specific data to your joints.
userData: any;
// The first attached body.
bodyA: b2Body;
// The second attached body.
bodyB: b2Body;
// Set this flag to true if the attached bodies should collide.
collideConnected: boolean;
}
class b2Joint {
// The base joint class. Joints are used to constraint two
// bodies together in various fashions. Some joints also feature
// limits and motors.
constructor();
m_type: b2JointType;
m_prev: b2Joint;
m_next: b2Joint;
m_edgeA: b2JointEdge;
m_edgeB: b2JointEdge;
m_bodyA: b2Body;
m_bodyB: b2Body;
m_index: number;
m_islandFlag: boolean;
m_collideConnected: boolean;
m_userData: any;
// Get the anchor point on bodyA in world coordinates.
GetAnchorA(out: b2Vec2): b2Vec2;
// Get the anchor point on bodyB in world coordinates.
GetAnchorB(out: b2Vec2): b2Vec2;
// Get the reaction force on bodyB at the joint anchor in
// Newtons.
GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2;
// Get the reaction torque on bodyB in N*m.
GetReactionTorque(inv_dt: number): number;
InitVelocityConstraints(data: b2SolverData): void;
SolveVelocityConstraints(data: b2SolverData): void;
// This returns true if the position errors are within
// tolerance.
SolvePositionConstraints(data: b2SolverData): boolean;
// Get the type of the concrete joint.
GetType(): b2JointType;
// Get the first body attached to this joint.
GetBodyA(): b2Body;
// Get the second body attached to this joint.
GetBodyB(): b2Body;
// Get the next joint the world joint list.
GetNext(): b2Joint;
// Get the user data pointer.
GetUserData(): any;
// Set the user data pointer.
SetUserData(data: any): void;
// Get collide connected.
// Note: modifying the collide connect flag won't work correctly
// because the flag is only checked when fixture AABBs begin to
// overlap.
GetCollideConnected(): boolean;
// Dump this joint to the log file.
Dump(): void;
// Short-cut function to determine if either body is inactive.
IsActive(): boolean;
// Shift the origin for any points stored in world coordinates.
ShiftOrigin(newOrigin: b2Vec2): void;
}
class b2RevoluteJointDef extends b2JointDef {
// Revolute joint definition. This requires defining an anchor
// point where the bodies are joined. The definition uses local
// anchor points so that the initial configuration can violate
// the constraint slightly. You also need to specify the initial
// relative angle for joint limits. This helps when saving and
// loading a game.
// The local anchor points are measured from the body's origin
// rather than the center of mass because:
// 1. you might not know where the center of mass will be.
// 2. if you add/remove shapes from a body and recompute the
// mass, the joints will be broken.
constructor();
// The local anchor point relative to bodyA's origin.
localAnchorA: b2Vec2;
// The local anchor point relative to bodyB's origin.
localAnchorB: b2Vec2;
// The bodyB angle minus bodyA angle in the reference state
// (radians).
referenceAngle: number;
// A flag to enable joint limits.
enableLimit: boolean;
// The lower angle for the joint limit (radians).
lowerAngle: number;
// The upper angle for the joint limit (radians).
upperAngle: number;
// A flag to enable the joint motor.
enableMotor: boolean;
// The desired motor speed. Usually in radians per second.
motorSpeed: number;
// The maximum motor torque used to achieve the desired motor
// speed.
// Usually in N-m.
maxMotorTorque: number;
Initialize(bA: b2Body, bB: b2Body, anchor: b2Vec2): void;
}
class b2RevoluteJoint extends b2Joint {
// A revolute joint constrains two bodies to share a common
// point while they are free to rotate about the point. The
// relative rotation about the shared point is the joint angle.
// You can limit the relative rotation with a joint limit that
// specifies a lower and upper angle. You can use a motor to
// drive the relative rotation about the shared point. A maximum
// motor torque is provided so that infinite forces are not
// generated.
constructor(def: b2RevoluteJointDef);
m_localAnchorA: b2Vec2;
m_localAnchorB: b2Vec2;
m_impulse: b2Vec3;
m_motorImpulse: number;
m_enableMotor: boolean;
m_maxMotorTorque: number;
m_motorSpeed: number;
m_enableLimit: boolean;
m_referenceAngle: number;
m_lowerAngle: number;
m_upperAngle: number;
m_indexA: number;
m_indexB: number;
m_rA: b2Vec2;
m_rB: b2Vec2;
m_localCenterA: b2Vec2;
m_localCenterB: b2Vec2;
m_invMassA: number;
m_invMassB: number;
m_invIA: number;
m_invIB: number;
m_mass: b2Mat33;
m_motorMass: number;
m_limitState: b2LimitState;
m_qA: b2Rot;
m_qB: b2Rot;
m_lalcA: b2Vec2;
m_lalcB: b2Vec2;
m_K: b2Mat22;
InitVelocityConstraints(data: b2SolverData): void;
SolveVelocityConstraints(data: b2SolverData): void;
SolvePositionConstraints(data: b2SolverData): boolean;
GetAnchorA(out: b2Vec2): b2Vec2;
GetAnchorB(out: b2Vec2): b2Vec2;
// Get the reaction force given the inverse time step.
// Unit is N.
GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2;
// Get the reaction torque due to the joint limit given the
// inverse time step.
// Unit is N*m.
GetReactionTorque(inv_dt: number): number;
// The local anchor point relative to bodyA's origin.
GetLocalAnchorA(out: b2Vec2): b2Vec2;
// The local anchor point relative to bodyB's origin.
GetLocalAnchorB(out?: b2Vec2): b2Vec2;
// Get the reference angle.
GetReferenceAngle(): number;
GetJointAngleRadians(): number;
GetJointSpeed(): number;
IsMotorEnabled(): boolean;
EnableMotor(flag: boolean): void;
// Get the current motor torque given the inverse time step.
// Unit is N*m.
GetMotorTorque(inv_dt: number): number;
GetMotorSpeed(): number;
SetMaxMotorTorque(torque: number): void;
GetMaxMotorTorque(): number;
IsLimitEnabled(): boolean;
EnableLimit(flag: boolean): void;
GetLowerLimit(): number;
GetUpperLimit(): number;
SetLimits(lower: number, upper: number): void;
SetMotorSpeed(speed: number): void;
// Dump to b2Log.
Dump(): void;
}
class b2PrismaticJointDef extends b2JointDef {
// Prismatic joint definition. This requires defining a line of
// motion using an axis and an anchor point. The definition uses
// local anchor points and a local axis so that the initial
// configuration can violate the constraint slightly. The joint
// translation is zero when the local anchor points coincide in
// world space. Using local anchors and a local axis helps when
// saving and loading a game.
constructor();
// The local anchor point relative to bodyA's origin.
localAnchorA: b2Vec2;
// The local anchor point relative to bodyB's origin.
localAnchorB: b2Vec2;
// The local translation unit axis in bodyA.
localAxisA: b2Vec2;
// The constrained angle between the bodies: bodyB_angle -
// bodyA_angle.
referenceAngle: number;
// Enable/disable the joint limit.
enableLimit: boolean;
// The lower translation limit, usually in meters.
lowerTranslation: number;
// The upper translation limit, usually in meters.
upperTranslation: number;
// Enable/disable the joint motor.
enableMotor: boolean;
// The maximum motor torque, usually in N-m.
maxMotorForce: number;
// The desired motor speed in radians per second.
motorSpeed: number;
// Initialize the bodies, anchors, axis, and reference angle
// using the world anchor and unit world axis.
Initialize(bA: b2Body, bB: b2Body, anchor: b2Vec2, axis: b2Vec2): void;
}
class b2PrismaticJoint extends b2Joint {
// A prismatic joint. This joint provides one degree of freedom:
// translation along an axis fixed in bodyA. Relative rotation
// is prevented. You can use a joint limit to restrict the range
// of motion and a joint motor to drive the motion or to model
// joint friction.
constructor(def: b2PrismaticJointDef);
m_localAnchorA: b2Vec2;
m_localAnchorB: b2Vec2;
m_localXAxisA: b2Vec2;
m_localYAxisA: b2Vec2;
m_referenceAngle: number;
m_impulse: b2Vec3;
m_motorImpulse: number;
m_lowerTranslation: number;
m_upperTranslation: number;
m_maxMotorForce: number;
m_motorSpeed: number;
m_enableLimit: boolean;
m_enableMotor: boolean;
m_limitState: b2LimitState;
m_indexA: number;
m_indexB: number;
m_localCenterA: b2Vec2;
m_localCenterB: b2Vec2;
m_invMassA: number;
m_invMassB: number;
m_invIA: number;
m_invIB: number;
m_axis: b2Vec2;
m_perp: b2Vec2;
m_s1: number;
m_s2: number;
m_a1: number;
m_a2: number;
m_K: b2Mat33;
m_K3: b2Mat33;
m_K2: b2Mat22;
m_motorMass: number;
m_qA: b2Rot;
m_qB: b2Rot;
m_lalcA: b2Vec2;
m_lalcB: b2Vec2;
m_rA: b2Vec2;
m_rB: b2Vec2;
InitVelocityConstraints(data: b2SolverData): void;
SolveVelocityConstraints(data: b2SolverData): void;
SolvePositionConstraints(data: b2SolverData): boolean;
GetAnchorA(out: b2Vec2): b2Vec2;
GetAnchorB(out: b2Vec2): b2Vec2;
GetReactionForce(inv_dt: number, out: b2Vec2): b2Vec2;
GetReactionTorque(inv_dt: number): number;
// The local anchor point relative to bodyA's origin.