forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matter-js.d.ts
1532 lines (1310 loc) · 56 KB
/
matter-js.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
// Type definitions for Matter.js 0.8.0
// Project: https://github.com/liabru/matter-js
// Definitions by: Ivane Gegia <https://twitter.com/ivanegegia>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module Matter
{
export interface IEngineOptions
{
}
export interface IEngineTimingOptions
{
/**
*A Number that specifies the time correction factor to apply to the current timestep. It is automatically handled when using Engine.run, but is also only optional even if you use your own game loop. The value is defined as delta / lastDelta, i.e. the percentage change of delta between steps. This value is always 1 (no correction) when frame rate is constant or engine.timing.isFixed is true. If the framerate and hence delta are changing, then correction should be applied to the current update to account for the change. See the paper on Time Corrected Verlet for more information.
*/
correction:number;
/**
* A Number that specifies the time step between updates in milliseconds. If engine.timing.isFixed is set to true, then delta is fixed. If it is false, then delta can dynamically change to maintain the correct apparant simulation speed.
*/
delta:number;
/**
* A Number that specifies the global scaling factor of time for all bodies. A value of 0 freezes the simulation. A value of 0.1 gives a slow-motion effect. A value of 1.2 gives a speed-up effect.
*/
timeScale:number;
/**
* A Number that specifies the current simulation-time in milliseconds starting from 0. It is incremented on every Engine.update by the timing.delta.
*/
timestamp:number;
/**
* An integer Number that specifies the number of velocity iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance.
*/
velocityIterations:number;
}
export class Engine
{
/**
* Clears the engine including the world, pairs and broadphase.
* @param engine
*/
static clear(engine:Engine):void;
/**
* Creates a new engine. The options parameter is an object that specifies any properties you wish to override the defaults. All properties have default values, and many are pre-calculated automatically based on other properties. See the properites section below for detailed information on what you can pass via the options object.
* @param element
* @param options
*/
static create(element?: HTMLElement|IEngineOptions, options?:IEngineOptions):Engine;
/**
* Merges two engines by keeping the configuration of engineA but replacing the world with the one from engineB.
* @param engineA
* @param engineB
*/
static merge(engineA:Engine, engineB:Engine):void;
/**
* Renders the world by calling its defined renderer engine.render.controller. Triggers beforeRender and afterRender events.
* @param engineA
* @param engineB
*/
static render(engineA:Engine, engineB:Engine):void;
/**
* An optional utility function that provides a game loop, that handles updating the engine for you. Calls Engine.update and Engine.render on the requestAnimationFrame event automatically. Handles time correction and non-fixed dynamic timing (if enabled). Triggers beforeTick, tick and afterTick events.
* @param engine
*/
static run(engine:Engine):void;
/**
* Moves the simulation forward in time by delta ms. Triggers beforeUpdate and afterUpdate events.
*
* @param engine
* @param delta
* @param correction
*/
static update(engine:Engine, delta:number, correction?:number):void;
/**
* An integer Number that specifies the number of constraint iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance. The default value of 2 is usually very adequate.
*/
constraintIterations:number;
/**
* A flag that specifies whether the engine is running or not.
*/
enabled:boolean;
/**
* A flag that specifies whether the engine should allow sleeping via the Matter.Sleeping module. Sleeping can improve stability and performance, but often at the expense of accuracy.
*/
enableSleeping:boolean;
/**
* An integer Number that specifies the number of position iterations to perform each update. The higher the value, the higher quality the simulation will be at the expense of performance.
*/
positionIterations:number;
/**
* An instance of a Render controller. The default value is a Matter.Render instance created by Engine.create. One may also develop a custom renderer module based on Matter.Render and pass an instance of it to Engine.create via options.render.
A minimal custom renderer object must define at least three functions: create, clear and world (see Matter.Render). It is also possible to instead pass the module reference via options.render.controller and Engine.create will instantiate one for you.
*/
render:Render;
/**
* An Object containing properties regarding the timing systems of the engine.
*/
timing:IEngineTimingOptions;
/**
* A World composite object that will contain all simulated bodies and constraints.
*/
world:World;
}
interface IWorldOptions
{
}
/**
* The Matter.World module contains methods for creating and manipulating the world composite. A Matter.World is a Matter.Composite body, which is a collection of Matter.Body, Matter.Constraint and other Matter.Composite. A Matter.World has a few additional properties including gravity and bounds. It is important to use the functions in the Matter.Composite module to modify the world composite, rather than directly modifying its properties. There are also a few methods here that alias those in Matter.Composite for easier readability.
*/
export class World
{
/**
* Add objects or arrays of objects of types: Body, Constraint, Composite
* @param world
* @param body
* @returns world
*/
static add(world:World, body:Body|Array<Body>|Composite|Array<Composite>|Constraint|Array<Constraint>):World;
/**
* An alias for Composite.addBody since World is also a Composite
* @param world
* @param body
* @returns world
*/
static addBody(world:World, body:Body):World;
/**
* An alias for Composite.add since World is also a Composite
* @param world
* @param composite
*/
static addComposite(world:World, composite:Composite):World;
/**
* An alias for Composite.addConstraint since World is also a Composite.
* @param world
* @param constraint
*/
static addConstraint(world:World, constraint:Constraint):World;
/**
* An alias for Composite.clear since World is also a Composite.
* @param world
* @param keepStatic
*/
static clear(world:World, keepStatic:boolean):void;
/**
* Creates a new world composite. The options parameter is an object that specifies any properties you wish to override the defaults. See the properites section below for detailed information on what you can pass via the options object.
* @param options
*/
static create(options:IWorldOptions):World;
}
export interface IBodyDefinition
{
angle?:number;
angularSpeed?:number;
angularVelocity?:number;
area?:number;
axes?:Array<Vector>;
bounds?:Bounds;
density?:number;
force?:Vector;
friction?:number;
frictionAir?:number;
groupId?:number;
id?:number;
inertia?:number;
inverseInertia?:number;
inverseMass?:number;
isSleeping?:boolean;
isStatic?:boolean;
label?:string;
mass?:number;
motion?:number;
position?:Vector;
render?:IBodyRenderOptions;
restitution?:number;
sleepThreshold?:number;
slop?:number;
speed?:number;
timeScale?:number;
torque?:number;
type?:string;
velocity?:Vector;
vertices?:Array<Vector>;
}
/**
* The Matter.Body module contains methods for creating and manipulating body models. A Matter.Body is a rigid body that can be simulated by a Matter.Engine. Factories for commonly used body configurations (such as rectangles, circles and other polygons) can be found in the module Matter.Bodies.
*/
export class Body
{
/**
* Applies a force to a body from a given world-space position, including resulting torque.
* @param body
* @param position
* @param force
*/
static applyForce(body:Body, position:Vector, force:Vector):void;
/**
* Applys a mass dependant force to all given bodies.
* @param bodies
* @param gravity
*/
static applyGravityAll(bodies:Array<Body>, gravity:Vector):void;
/**
* Creates a new rigid body model. The options parameter is an object that specifies any properties you wish to override the defaults. All properties have default values, and many are pre-calculated automatically based on other properties. See the properites section below for detailed information on what you can pass via the options object.
* @param options
*/
static create(options:IBodyDefinition):Body;
/**
* Returns the next unique groupID number.
*/
static nextGroupId():number;
/**
* Zeroes the body.force and body.torque force buffers.
* @param bodies
*/
static resetForcesAll(bodies:Array<Body>):void;
/**
* Rotates a body by a given angle relative to its current angle, without imparting any angular velocity.
* @param body
* @param angle
*/
static rotate(body:Body, angle:number):void;
/**
* Sets the body as static, including isStatic flag and setting mass and inertia to Infinity.
* @param isStatic
*/
setStatic(isStatic:boolean):void;
/**
* Scales the body, including updating physical properties (mass, area, axes, inertia), from a world-space point (default is body centre).
* @param body
* @param scaleX
* @param scaleY
* @param poinst
*/
static scale(body:Body, scaleX:number, scaleY:number, poinst?:Vector):void;
/**
* Moves a body by a given vector relative to its current position, without imparting any velocity.
*
* @param body
* @param translation
*/
static translate(body:Body, translation:Vector):void;
/**
*Performs a simulation step for the given body, including updating position and angle using Verlet integration.
*
* @param body
* @param deltaTime
* @param timeScale
* @param correction
*/
static update(body:Body, deltaTime:number, timeScale:number, correction:number):void;
/**
* Applys Body.update to all given bodies.
*
* @param bodies
* @param deltaTime
* @param timeScale
* @param correction
* @param worldBounds
*/
static updateAll ( bodies:Array<Body>, deltaTime:number, timeScale:number, correction:number, worldBounds:Bounds ):void;
/**
* A Number specifying the angle of the body, in radians.
*/
angle:number;
/**
* A Number that measures the current angular speed of the body after the last Body.update. It is read-only and always positive (it's the magnitude of body.angularVelocity).
*/
angularSpeed:number;
/**
* A Number that measures the current angular velocity of the body after the last Body.update. It is read-only. If you need to modify a body's angular velocity directly, you should apply a torque or simply change the body's angle (as the engine uses position-Verlet integration).
*/
angularVelocity:number;
/**
* A Number that measures the area of the body's convex hull, calculated at creation by Body.create.
*/
area:number;
/**
* An array of unique axis vectors (edge normals) used for collision detection. These are automatically calculated from the given convex hull (vertices array) in Body.create. They are constantly updated by Body.update during the simulation.
*/
axes:Array<Vector>;
/**
* A Bounds object that defines the AABB region for the body. It is automatically calculated from the given convex hull (vertices array) in Body.create and constantly updated by Body.update during simulation.
*/
bounds:Bounds;
/**
* A Number that defines the density of the body, that is its mass per unit area. If you pass the density via Body.create the mass property is automatically calculated for you based on the size (area) of the object. This is generally preferable to simply setting mass and allows for more intuitive definition of materials (e.g. rock has a higher density than wood).
*/
density:number;
/**
* A Vector that specifies the force to apply in the current step. It is zeroed after every Body.update. See also Body.applyForce.
*/
force:Vector;
/**
* A Number that defines the friction of the body. The value is always positive and is in the range (0, 1). A value of 0 means that the body may slide indefinitely. A value of 1 means the body may come to a stop almost instantly after a force is applied.
The effects of the value may be non-linear. High values may be unstable depending on the body. The engine uses a Coulomb friction model including static and kinetic friction. Note that collision response is based on pairs of bodies, and that friction values are combined with the following formula:
Math.min(bodyA.friction, bodyB.friction)
*/
friction:number;
/**
* A Number that defines the air friction of the body (air resistance). A value of 0 means the body will never slow as it moves through space. The higher the value, the faster a body slows when moving through space. The effects of the value are non-linear.
Default: 0.01
*/
frictionAir:number;
/**
* An integer Number that specifies the collision group the body belongs to. Bodies with the same groupId are considered as-one body and therefore do not interact. This allows for creation of segmented bodies that can self-intersect, such as a rope. The default value 0 means the body does not belong to a group, and can interact with all other bodies.
Default: 0
*/
groupId:number;
/**
* An integer Number uniquely identifying number generated in Body.create by Common.nextId.
*/
id:number;
/**
* A Number that defines the moment of inertia (i.e. second moment of area) of the body. It is automatically calculated from the given convex hull (vertices array) and density in Body.create. If you modify this value, you must also modify the body.inverseInertia property (1 / inertia).
*/
inertia:number;
/**
* A Number that defines the inverse moment of inertia of the body (1 / inertia). If you modify this value, you must also modify the body.inertia property.
*/
inverseInertia:number;
/**
* A Number that defines the inverse mass of the body (1 / mass). If you modify this value, you must also modify the body.mass property.
*/
inverseMass:number;
/**
* A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken. If you need to set a body as sleeping, you should use Sleeping.set as this requires more than just setting this flag.
Default: false
*/
isSleeping:boolean;
/**
* A flag that indicates whether a body is considered static. A static body can never change position or angle and is completely fixed. If you need to set a body as static after its creation, you should use Body.setStatic as this requires more than just setting this flag.
Default: false
*/
isStatic:boolean;
/**
* An arbitrary String name to help the user identify and manage bodies.
Default: "Body"
*/
label:string;
/**
* A Number that defines the mass of the body, although it may be more appropriate to specify the density property instead. If you modify this value, you must also modify the body.inverseMass property (1 / mass).
*/
mass:number;
/**
* A Number that measures the amount of movement a body currently has (a combination of speed and angularSpeed). It is read-only and always positive. It is used and updated by the Matter.Sleeping module during simulation to decide if a body has come to rest.
Default: 0
*/
motion:number;
/**
* A Vector that specifies the current world-space position of the body.
Default: { x: 0, y: 0 }
*/
position:Vector;
/**
* An Object that defines the rendering properties to be consumed by the module Matter.Render.
*/
render:IBodyRenderOptions;
/**
* A Number that defines the restitution (elasticity) of the body. The value is always positive and is in the range (0, 1). A value of 0 means collisions may be perfectly inelastic and no bouncing may occur. A value of 0.8 means the body may bounce back with approximately 80% of its kinetic energy. Note that collision response is based on pairs of bodies, and that restitution values are combined with the following formula:
Math.max(bodyA.restitution, bodyB.restitution)
Default: 0
*/
restitution:number;
/**
* A Number that defines the number of updates in which this body must have near-zero velocity before it is set as sleeping by the Matter.Sleeping module (if sleeping is enabled by the engine).
Default: 60
*/
sleepThreshold:number;
/**
* A Number that specifies a tollerance on how far a body is allowed to 'sink' or rotate into other bodies. Avoid changing this value unless you understand the purpose of slop in physics engines. The default should generally suffice, although very large bodies may require larger values for stable stacking.
Default: 0.05
*/
slop:number;
/**
* A Number that measures the current speed of the body after the last Body.update. It is read-only and always positive (it's the magnitude of body.velocity).
Default: 0
*/
speed:number;
/**
* A Number that allows per-body time scaling, e.g. a force-field where bodies inside are in slow-motion, while others are at full speed.
Default: 1
*/
timeScale:number;
/**
* A Number that specifies the torque (turning force) to apply in the current step. It is zeroed after every Body.update.
Default: 0
*/
torque:number;
/**
*A String denoting the type of object.
Default: "body"
*/
type:string;
/**
* A Vector that measures the current velocity of the body after the last Body.update. It is read-only. If you need to modify a body's velocity directly, you should either apply a force or simply change the body's position (as the engine uses position-Verlet integration).
Default: { x: 0, y: 0 }
*/
velocity:Vector;
/**
* An array of Vector objects that specify the convex hull of the rigid body. These should be provided about the origin (0, 0). E.g.
[{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }]
When passed via Body.create, the verticies are translated relative to body.position (i.e. world-space, and constantly updated by Body.update during simulation). The Vector objects are also augmented with additional properties required for efficient collision detection.
Other properties such as inertia and bounds are automatically calculated from the passed vertices (unless provided via options). Concave hulls are not currently supported. The module Matter.Vertices contains useful methods for working with vertices.
*/
vertices:Array<Vector>;
}
export class Bodies {
/**
* Creates a new rigid body model with a circle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properites section of the Matter.Body module for detailed information on what you can pass via the options object.
*
* @param x
* @param y
* @param radius
* @param options
* @param maxSides
*/
static circle(x:number, y:number, radius:number, options?:IBodyDefinition, maxSides?:number):Body;
/**
* Creates a new rigid body model with a regular polygon hull with the given number of sides. The options parameter is an object that specifies any properties you wish to override the defaults. See the properites section of the Matter.Body module for detailed information on what you can pass via the options object.
*
* @param x
* @param y
* @param sides
* @param radius
* @param options
*/
static polygon(x:number, y:number, sides:number, radius:number, options?:IBodyDefinition):Body;
/**
* Creates a new rigid body model with a rectangle hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properites section of the Matter.Body module for detailed information on what you can pass via the options object.
*
* @param x
* @param y
* @param width
* @param height
* @param options
*/
static rectangle(x:number, y:number, width:number, height:number, options?:IBodyDefinition):Body;
/**
* Creates a new rigid body model with a trapezoid hull. The options parameter is an object that specifies any properties you wish to override the defaults. See the properites section of the Matter.Body module for detailed information on what you can pass via the options object.
*
* @param x
* @param y
* @param width
* @param height
* @param slope
* @param options
*/
static trapezoid(x:number, y:number, width:number, height:number, slope:number, options?:IBodyDefinition):Body;
}
export interface IBodyRenderOptions
{
/**
* A String that defines the fill style to use when rendering the body (if a sprite is not defined). It is the same as when using a canvas, so it accepts CSS style property values.
Default: a random colour
*/
fillStyle:string;
/**
* A Number that defines the line width to use when rendering the body outline (if a sprite is not defined). A value of 0 means no outline will be rendered.
Default: 1.5
*/
lineWidth:number;
/**
* An Object that defines the sprite properties to use when rendering, if any.
*/
sprite:IBodyRenderOptionsSprite;
/**
* A String that defines the stroke style to use when rendering the body outline (if a sprite is not defined). It is the same as when using a canvas, so it accepts CSS style property values.
Default: a random colour
*/
strokeStyle:string;
/**
* A flag that indicates if the body should be rendered.
Default: true
*/
visible:boolean;
}
export interface IBodyRenderOptionsSprite
{
/**
* An String that defines the path to the image to use as the sprite texture, if any.
*/
texture:string;
/**
* A Number that defines the scaling in the x-axis for the sprite, if any.
Default: 1
*/
xScale:number;
/**
* A Number that defines the scaling in the y-axis for the sprite, if any.
Default: 1
*/
yScale:number;
}
export class Bounds
{
}
export class Vector
{
x:number;
y:number;
/**
* Adds the two vectors.
*
* @param vectorA
* @param vectorB
* @returns A new vector of vectorA and vectorB added.
*/
static add ( vectorA:Vector, vectorB:Vector ):Vector;
/**
* Returns the angle in radians between the two vectors relative to the x-axis.
*
* @param vectorA
* @param vectorB
* @returns The angle in radians.
*/
static angle ( vectorA:Vector, vectorB:Vector ):number;
/**
* Returns the cross-product of two vectors.
*
* @param vectorA
* @param vectorB
* @returns The cross product of the two vectors.
*/
static cross ( vectorA:Vector, vectorB:Vector ):number;
/**
* Divides a vector and a scalar.
*
* @param vector
* @param scalar
* @returns A new vector divided by scalar.
*/
static div ( vector:Vector, scalar:number ):Vector;
/**
* Returns the dot-product of two vectors.
*
* @param vectorA
* @param vectorB
* @returns The dot product of the two vectors
*/
static dot ( vectorA:Vector, vectorB:Vector ):Number;
/**
* Returns the magnitude (length) of a vector.
*
* @param vector
* @returns The magnitude of the vector
*/
static magnitude ( vector:Vector ):number;
/**
* Returns the magnitude (length) of a vector (therefore saving a sqrt operation).
*
* @param vector
* @returns The squared magnitude of the vector.
*/
static magnitudeSquared ( vector:Vector ):number;
/**
* Multiplies a vector and a scalar.
*
* @param vector
* @param scalar
* @returns A new vector multiplied by scalar
*/
static mult ( vector:Vector, scalar:number ):Vector;
/**
* Negates both components of a vector such that it points in the opposite direction.
* @param vector
* @returns The negated vector.
*/
static neg ( vector:Vector ):Vector;
/**
* Normalises a vector (such that its magnitude is 1).
*
* @param vector
* @returns A new vector normalised
*/
static normalise ( vector:Vector ):Vector;
/**
* Returns the perpendicular vector. Set negate to true for the perpendicular in the opposite direction.
*
* @param vector
* @param negate
* @returns The perpendicular vector
*/
static perp ( vector:Vector, negate?:boolean ):Vector;
/**
* Rotates the vector about (0, 0) by specified angle.
*
* @param vector
* @param angle
* @returns A new vector rotated about (0, 0)
*/
static rotate ( vector:Vector, angle:number ):Vector;
/**
* Rotates the vector about a specified point by specified angle.
*
* @param vector
* @param angle
* @param point
* @returns A new vector rotated about the point
*/
static rotateAbout ( vector:Vector, angle:number, point:Vector ):Vector;
/**
* Subtracts the two vectors.
*
* @param vectorA
* @param vectorB
* @returns A new vector of vectorA and vectorB subtracted
*/
static sub ( vectorA:Vector, vectorB:Vector ):Vector;
}
export class Constraint
{
/**
* Creates a new constraint. All properties have default values, and many are pre-calculated automatically based on other properties. See the properites section below for detailed information on what you can pass via the options object.
*
* @param options
* @returns constraint
*/
static create(options:IConstraintDefinition):Constraint;
/**
* The first possible Body that this constraint is attached to.
*/
bodyA:Body;
/**
* The second possible Body that this constraint is attached to.
*/
bodyB:Body;
/**
* An integer Number uniquely identifying number generated in Composite.create by Common.nextId.
*/
id:number;
/**
* An arbitrary String name to help the user identify and manage bodies.
* Default: "Constraint"
*/
label:string;
/**
* A Number that specifies the target resting length of the constraint. It is calculated automatically in Constraint.create from intial positions of the constraint.bodyA and constraint.bodyB.
*/
length:number;
/**
* A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.
Default: { x: 0, y: 0 }
*/
pointA:Vector;
/**
* A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.
Default: { x: 0, y: 0 }
*/
pointB:Vector;
/**
* An Object that defines the rendering properties to be consumed by the module Matter.Render.
*/
render:IConstraintRenderRefinition;
/**
* A Number that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting constraint.length. A value of 1 means the constraint should be very stiff. A value of 0.2 means the constraint acts like a soft spring.
Default: 1
*/
stiffness:number;
/**
* A String denoting the type of object.
Default: "constraint"
*/
type:string;
}
export class MouseConstraint
{
create(engine:Engine, options:IMouseConstraintDefinition):MouseConstraint;
/**
* The Constraint object that is used to move the body during interaction.
*/
constraint:Constraint;
/**
* The Body that is currently being moved by the user, or null if no body.
Default: null
*/
dragBody:Body;
/**
* The Vector offset at which the drag started relative to the dragBody, if any.
Default: null
*/
dragPoint:Vector;
/**
* The Mouse instance in use.
Default: engine.input.mouse
*/
mouse:Mouse;
/**
* A String denoting the type of object.
Default: "constraint"
*/
type:string;
}
export interface IMouseConstraintDefinition
{
/**
* The Constraint object that is used to move the body during interaction.
*/
constraint?:Constraint;
/**
* The Body that is currently being moved by the user, or null if no body.
Default: null
*/
dragBody?:Body;
/**
* The Vector offset at which the drag started relative to the dragBody, if any.
Default: null
*/
dragPoint?:Vector;
/**
* The Mouse instance in use.
Default: engine.input.mouse
*/
mouse?:Mouse;
/**
* A String denoting the type of object.
Default: "constraint"
*/
type?:string;
}
export class Query
{
/**
* Casts a ray segment against a set of bodies and returns all collisions, ray width is optional. Intersection points are not provided.
*
* @param bodies
* @param startPoint
* @param endPoint
* @param [rayWidth]
*
* @returns Object[] Collisions
*/
static ray( bodies:Array<Body>, startPoint:Vector, endPoint:Vector, rayWidth?:number ):Array<any>;
/**
* Returns all bodies whose bounds are inside (or outside if set) the given set of bounds, from the given set of bodies.
*
* @param bodies
* @param bounds
* @returns Body[] The bodies matching the query
*/
static region( bodies:Array<Body>, bounds:Bounds, outside?:boolean ):Array<Body>;
}
export class Mouse
{
}
export interface IConstraintRenderRefinition
{
/**
* A Number that defines the line width to use when rendering the constraint outline. A value of 0 means no outline will be rendered.
Default: 2
*/
lineWidth:number;
/**
* A String that defines the stroke style to use when rendering the constraint outline. It is the same as when using a canvas, so it accepts CSS style property values.
Default: a random colour
*/
strokeStyle:string;
/**
* A flag that indicates if the constraint should be rendered.
Default: true
*/
visible:boolean;
}
export interface IConstraintDefinition
{
/**
* The first possible Body that this constraint is attached to.
*/
bodyA?:Body;
/**
* The second possible Body that this constraint is attached to.
*/
bodyB?:Body;
/**
* An integer Number uniquely identifying number generated in Composite.create by Common.nextId.
*/
id?:number;
/**
* An arbitrary String name to help the user identify and manage bodies.
* Default: "Constraint"
*/
label?:string;
/**
* A Number that specifies the target resting length of the constraint. It is calculated automatically in Constraint.create from intial positions of the constraint.bodyA and constraint.bodyB.
*/
length?:number;
/**
* A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.
Default: { x: 0, y: 0 }
*/
pointA?:Vector;
/**
* A Vector that specifies the offset of the constraint from center of the constraint.bodyA if defined, otherwise a world-space position.
Default: { x: 0, y: 0 }
*/
pointB?:Vector;
/**
* An Object that defines the rendering properties to be consumed by the module Matter.Render.
*/
render?:IConstraintRenderRefinition;
/**
* A Number that specifies the stiffness of the constraint, i.e. the rate at which it returns to its resting constraint.length. A value of 1 means the constraint should be very stiff. A value of 0.2 means the constraint acts like a soft spring.
Default: 1
*/
stiffness?:number;
/**
* A String denoting the type of object.
Default: "constraint"
*/
type?:string;
}
export class Composite
{
/**
* Generic add function. Adds one or many body(s), constraint(s) or a composite(s) to the given composite.
*
* @param composite
* @param object
*
* @returns The original composite with the objects added
*/
static add(composite:Composite, object:Body|Composite|Constraint ):Composite;
/**
* Adds a body to the given composite
*
* @param composite
* @param body
*
* @returns Composite The original composite with the body added
*/
static addBody(composite:Composite, body:Body):Composite;
/**
* Adds a composite to the given composite
*
* @param compositeA
* @param compositeB
*
* @returns The original compositeA with the objects from compositeB added
*/
static addComposite(compositeA:Composite, compositeB:Composite):Composite;
/**
*
* @param composite
* @param constraint
* @returns The original composite with the constraint added
*/
static addConstraint(composite:Composite, constraint:Constraint):Composite;
/**
* Returns all bodies in the given composite, including all bodies in its children, recursively.
*
* @param composite
* @returns Body[] All the bodies