-
Notifications
You must be signed in to change notification settings - Fork 3
/
box2d_header.lua
2307 lines (1818 loc) · 75.7 KB
/
box2d_header.lua
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
--region box2d
box2d = {}
box2d.b2Shape = {
e_circle = 0,
e_edge = 1,
e_polygon = 2,
e_chain = 3,
}
box2d.b2BodyType = {
b2_staticBody = 0,
b2_kinematicBody = 1,
b2_dynamicBody = 2,
}
box2d.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,
}
box2d.b2Draw = {
e_shapeBit = 1, e_jointBit = 2,
e_aabbBit = 4, e_pairBit = 8,
e_centerOfMassBit = 16
}
box2d.b2Manifold_Type = {
e_circles = 0, e_faceA = 1,
e_faceB = 2
}
---@param gravity vector3|nil the world gravity vector.
---@return Box2dWorld
function box2d.NewWorld(gravity) end
---@param data table
---@return Box2dDebugDraw
function box2d.NewDebugDraw(data) end
---@return Box2dPolygonShape
function box2d.NewPolygonShape() end
---@return Box2dCircleShape
function box2d.NewCircleShape() end
---@return Box2dChainShape
function box2d.NewChainShape() end
---@return Box2dEdgeShape
function box2d.NewEdgeShape() end
--- Utility to compute linear stiffness values from frequency and damping ratio
---@param frequencyHertz number
---@param dampingRatio number
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@return number stiffness
---@return number damping
function box2d.b2LinearStiffness(frequencyHertz, dampingRatio, bodyA, bodyB) end
--- Utility to compute rotational stiffness values frequency and damping ratio
---@param frequencyHertz number
---@param dampingRatio number
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@return number stiffness
---@return number damping
function box2d.b2AngularStiffness(frequencyHertz, dampingRatio, bodyA, bodyB) end
--- Use InitializeJoint methods to create b2JointDef and call b2JointDef::Initialize(...) if
--- joint have such method
--- Initialize the bodies, anchors, and reference angle using a world
--- anchor point.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchor vector3
---@return Box2dRevoluteJointDef
function box2d.InitializeRevoluteJointDef(bodyA, bodyB, anchor) end
--- Initialize the bodies, anchors, axis, and reference angle using the world
--- anchor and unit world axis.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchor vector3
---@param axis vector3
---@return Box2dPrismaticJointDef
function box2d.InitializePrismaticJointDef(bodyA, bodyB, anchor, axis) end
--- Initialize the bodies, anchors, and rest length using world space anchors.
--- The minimum and maximum lengths are set to the rest length.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchorA vector3
---@param anchorB vector3
---@return Box2dDistanceJointDef
function box2d.InitializeDistanceJointDef(bodyA, bodyB, anchorA, anchorB) end
--- Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param groundAnchorA vector3
---@param groundAnchorB vector3
---@param anchorA vector3
---@param anchorB vector3
---@param ratio number
---@return Box2dPulleyJointDef
function box2d.InitializePulleyJointDef(bodyA, bodyB, groundAnchorA, groundAnchorB, anchorA, anchorB, ratio) end
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@return Box2dMouseJointDef
function box2d.InitializeMouseJointDef(bodyA, bodyB) end
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param joint1 Box2dJoint
---@param joint2 Box2dBody
---@return Box2dGearJoint
function box2d.InitializeGearJointDef(bodyA, bodyB, joint1, joint2) end
--- Initialize the bodies, anchors, axis, and reference angle using the world
--- anchor and world axis.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchor vector3
---@param axis vector3
---@return Box2dWheelJointDef
function box2d.InitializeWheelJointDef(bodyA, bodyB, anchor, axis) end
--- Initialize the bodies, anchors, reference angle, stiffness, and damping.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchor vector3
---@return Box2dWeldJointDef
function box2d.InitializeWeldJointDef(bodyA, bodyB, anchor) end
--- Initialize the bodies, anchors, axis, and reference angle using the world
--- anchor and world axis.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@param anchor vector3
---@return Box2FrictionJointDef
function box2d.InitializeFrictionJointDef(bodyA, bodyB, anchor) end
--- Initialize the bodies and offsets using the current transforms.
---@param bodyA Box2dBody
---@param bodyB Box2dBody
---@return Box2dMotorJointDef
function box2d.InitializeMotorJointDef(bodyA, bodyB) end
--endregion
--region Box2dFixture
---@class Box2dFixture
local Box2dFixture = {}
---@return number box2d.b2Shape
function Box2dFixture:GetType() end
--- Get the copy of shape. You can modify it but fixture shape not changed.
---@return Box2dShape
function Box2dFixture:GetShape() end
--- Set if this fixture is a sensor.
---@param sensor boolean
function Box2dFixture:SetSensor(sensor) end
---Is this fixture a sensor (non-solid)?
---@return boolean the true if the shape is a sensor.
function Box2dFixture:IsSensor() end
--- Set the contact filtering data. This will not update contacts until the next time
--- step when either parent body is active and awake.
--- This automatically calls Refilter.
---@param filter Box2dFilter
function Box2dFixture:SetFilterData(filter) end
--- Get the contact filtering data.
---@return Box2dFilter
function Box2dFixture:GetFilterData() end
--- Call this if you want to establish collision that was previously disabled by b2ContactFilter::ShouldCollide.
function Box2dFixture:Refilter() end
--- Get the parent body of this fixture. This is nil if the fixture is not attached.
---@return Box2dBody the parent body
function Box2dFixture:GetBody() end
--- Get the next fixture in the parent body's fixture list.
---@return Box2dFixture|nil
function Box2dFixture:GetNext() end
--- Get the user data that was assigned in the fixture definition. Use this to
--- store your application specific data.
---@return table|nil
function Box2dFixture:GetUserData() end
--- Set the user data. Use this to
--- store your application specific data.
---@param userdata table|nil
function Box2dFixture:SetUserData(userdata) end
--- Test a point for containment in this fixture.
---@param point vector3 a point in world coordinates.
function Box2dFixture:TestPoint(point) end
--- Cast a ray against this shape.
--- @param input Box2dRayCastInput the ray-cast input parameters.
--- @param childIndex number|nil the child shape index (e.g. edge index)
---@return Box2dRayCastOutput|nil
function Box2dFixture:RayCast(input, childIndex) end
--- Get the mass data for this fixture. The mass data is based on the density and
--- the shape. The rotational inertia is about the shape's origin. This operation
--- may be expensive.
---@return Box2dMassData
function Box2dFixture:GetMassData() end
--- Get the density of this fixture.
---@return number
function Box2dFixture:GetDensity() end
--- Set the density of this fixture. This will _not_ automatically adjust the mass
--- of the body. You must call b2Body::ResetMassData to update the body's mass.
---@param density number
function Box2dFixture:SetDensity(density) end
--- Get the coefficient of friction.
---@return number
function Box2dFixture:GetFriction() end
--- Set the coefficient of friction. This will _not_ change the friction of
--- existing contacts.
---@param friction number
function Box2dFixture:SetFriction(friction) end
--- Get the coefficient of restitution.
---@return number
function Box2dFixture:GetRestitution() end
--- Set the coefficient of restitution. This will _not_ change the restitution of
--- existing contacts.
---@param restitution number
function Box2dFixture:SetRestitution(restitution) end
--- Get the restitution velocity threshold.
---@return number
function Box2dFixture:GetRestitutionThreshold() end
--- Set the restitution threshold. This will _not_ change the restitution threshold of
--- existing contacts.
---@param threshold number
function Box2dFixture:SetRestitutionThreshold(threshold) end
--- Get the fixture's AABB. This AABB may be enlarge and/or stale.
--- If you need a more accurate AABB, compute it using the shape and
--- the body transform.
---@param childIndex number|nil the child shape index
---@return Box2dAABB
function Box2dFixture:GetAABB(childIndex) end
--- Dump this fixture to the log file.
---@param bodyIndex number
function Box2dFixture:Dump(bodyIndex) end
--endregion
--region Box2dBody
--- A rigid body. These are created via world:CreateBody.
---@class Box2dBody
local Box2dBody = {}
--- Creates a fixture and attach it to this body. Use this function if you need
--- to set some fixture parameters, like friction. Otherwise you can create the
--- fixture directly from a shape.
--- If the density is non-zero, this function automatically updates the mass of the body.
--- Contacts are not created until the next time step.
--- warning This function is locked during callbacks.
---@param def Box2dFixtureDef
---@return Box2dFixture
function Box2dBody:CreateFixture(def) end
--- Creates a fixture from a shape and attach it to this body.
--- This is a convenience function. Use b2FixtureDef if you need to set parameters
--- like friction, restitution, user data, or filtering.
--- If the density is non-zero, this function automatically updates the mass of the body.
--- warning This function is locked during callbacks.
---@param shape Box2dShape|Box2dShapeTable
---@param density number the shape density (set to zero for static bodies)
---@return Box2dFixture
function Box2dBody:CreateFixture(shape, density) end
--- Destroy a fixture. This removes the fixture from the broad-phase and
--- destroys all contacts associated with this fixture. This will
--- automatically adjust the mass of the body if the body is dynamic and the
--- fixture has positive density.
--- All fixtures attached to a body are implicitly destroyed when the body is destroyed.
--- warning This function is locked during callbacks.
---@param fixture Box2dFixture
function Box2dBody:DestroyFixture(fixture) end
--- Set the position of the body's origin and rotation.
--- Manipulating a body's transform may cause non-physical behavior.
--- Note: contacts are updated on the next call to b2World::Step.
---@param position vector3 the world position of the body's local origin.
---@param angle number|nil the world rotation in radians. If nil use current angle
function Box2dBody:SetTransform(position, angle) end
--- Get the body transform for the body's origin.
---@return Box2dTransform
function Box2dBody:GetTransform() end
--- Get the world body origin position.
---@return vector3
function Box2dBody:GetPosition() end
--- Get the world body origin position.
---@return number x
---@return number y
function Box2dBody:GetPositionRaw() end
--- Get the angle in radians.
---@return number
function Box2dBody:GetAngle() end
--- Get the world position of the center of mass.
---@return vector3
function Box2dBody:GetWorldCenter() end
--- Get the local position of the center of mass.
---@return vector3
function Box2dBody:GetLocalCenter() end
--- Set the linear velocity of the center of mass.
---@param velocity vector3
function Box2dBody:SetLinearVelocity(velocity) end
--- Get the linear velocity of the center of mass.
---@return vector3
function Box2dBody:GetLinearVelocity() end
--- Set the angular velocity.
---@param omega number the new angular velocity in radians/second.
function Box2dBody:SetAngularVelocity(omega) end
--- Get the angular velocity.
---@return number the angular velocity in radians/second.
function Box2dBody:GetAngularVelocity() end
--- Apply a force at a world point. If the force is not
--- applied at the center of mass, it will generate a torque and
--- affect the angular velocity. This wakes up the body.
---@param force vector3 force the world force vector, usually in Newtons (N).
---@param point vector3 point the world position of the point of application.
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyForce(force, point, wake) end
--- Apply a force to the center of mass. This wakes up the body.
---@param force vector3 force the world force vector, usually in Newtons (N).
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyForceToCenter(force, wake) end
--- Apply a torque. This affects the angular velocity
--- without affecting the linear velocity of the center of mass.
---@param torque number torque about the z-axis (out of the screen), usually in N-m.
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyTorque(torque, wake) end
--- Apply an impulse at a point. This immediately modifies the velocity.
--- It also modifies the angular velocity if the point of application
--- is not at the center of mass. This wakes up the body.
---@param impulse vector3 impulse the world impulse vector, usually in N-seconds or kg-m/s.
---@param point vector3 point the world position of the point of application.
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyLinearImpulse(impulse, point, wake) end
--- Apply an impulse to the center of mass. This immediately modifies the velocity.
---@param impulse vector3 impulse the world impulse vector, usually in N-seconds or kg-m/s.
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyLinearImpulseToCenter(impulse, wake) end
--- Apply an angular impulse.
---@param impulse vector3 impulse the angular impulse in units of kg*m*m/s
---@param wake boolean wake also wake up the body
function Box2dBody:ApplyAngularImpulse(impulse, wake) end
--- Get the total mass of the body.
---@return number the mass, usually in kilograms (kg).
function Box2dBody:GetMass() end
--- Get the rotational inertia of the body about the local origin.
---@return number the rotational inertia, usually in kg-m^2.
function Box2dBody:GetInertia() end
--- This resets the mass properties to the sum of the mass properties of the fixtures.
--- This normally does not need to be called unless you called SetMassData to override
--- the mass and you later want to reset the mass.
function Box2dBody:ResetMassData() end
--- Get the mass data of the body.
---@return Box2dMassData a struct containing the mass, inertia and center of the body.
function Box2dBody:GetMassData() end
--- Set the mass properties to override the mass properties of the fixtures.
--- Note that this changes the center of mass position.
--- Note that creating or destroying fixtures can also alter the mass.
--- This function has no effect if the body isn't dynamic.
---@param data Box2dMassData the mass properties.
function Box2dBody:SetMassData(data) end
--- Get the world coordinates of a point given the local coordinates.
---@param localPoint vector3 a point on the body measured relative the the body's origin.
---@return vector3 the same point expressed in world coordinates.
function Box2dBody:GetWorldPoint(localPoint) end
--- Get the world coordinates of a vector given the local coordinates.
---@param localVector vector3 localVector a vector fixed in the body.
---@return vector3 the same vector expressed in world coordinates.
function Box2dBody:GetWorldVector(localVector) end
--- Gets a local point relative to the body's origin given a world point.
---@param worldPoint vector3 worldPoint a point in world coordinates.
---@return vector3 the corresponding local point relative to the body's origin.
function Box2dBody:GetLocalPoint(worldPoint) end
--- Gets a local vector given a world vector.
---@param worldVector vector3 worldVector a vector in world coordinates.
---@return vector3 the corresponding local vector.
function Box2dBody:GetLocalVector(worldVector) end
--- Get the world linear velocity of a world point attached to this body.
---@param worldPoint vector3 worldPoint a point in world coordinates.
---@return vector3 the world velocity of a point.
function Box2dBody:GetLinearVelocityFromWorldPoint(worldPoint) end
--- Get the world velocity of a local point.
---@param localPoint vector3 localPoint a point in local coordinates.
---@return vector3 the world velocity of a point.
function Box2dBody:GetLinearVelocityFromLocalPoint(localPoint) end
--- Set the linear damping of the body.
---@param linearDamping number
function Box2dBody:SetLinearDamping(linearDamping) end
--- Get the linear damping of the body.
---@return number
function Box2dBody:GetLinearDamping() end
--- Set the angular damping of the body.
---@param angularDamping number
function Box2dBody:SetAngularDamping(angularDamping) end
--- Get the angular damping of the body.
---@return number
function Box2dBody:GetAngularDamping() end
--- Set the gravity scale of the body.
---@param scale number
function Box2dBody:SetGravityScale(scale) end
--- Get the gravity scale of the body.
---@return number
function Box2dBody:GetGravityScale() end
--- Set the type of this body. This may alter the mass and velocity.
---@param type number box2d.b2BodyType
function Box2dBody:SetType(type) end
--- Get the type of this body.
---@return number box2d.b2BodyType
function Box2dBody:GetType() end
--- Should this body be treated like a bullet for continuous collision detection?
---@param flag boolean
function Box2dBody:SetBullet(flag) end
--- Is this body treated like a bullet for continuous collision detection?
---@return boolean
function Box2dBody:IsBullet() end
--- You can disable sleeping on this body. If you disable sleeping, the
--- body will be woken.
---@param flag boolean
function Box2dBody:SetSleepingAllowed(flag) end
--- Is this body allowed to sleep
---@return boolean
function Box2dBody:IsSleepingAllowed() end
--- Set the sleep state of the body. A sleeping body has very
--- low CPU cost.
---@param flag boolean flag set to true to wake the body, false to put it to sleep.
function Box2dBody:SetAwake(flag) end
--- Get the sleeping state of this body.
---@return boolean true if the body is awake.
function Box2dBody:IsAwake() end
--- Allow a body to be disabled. A disabled body is not simulated and cannot
--- be collided with or woken up.
--- If you pass a flag of true, all fixtures will be added to the broad-phase.
--- If you pass a flag of false, all fixtures will be removed from the
--- broad-phase and all contacts will be destroyed.
--- Fixtures and joints are otherwise unaffected. You may continue
--- to create/destroy fixtures and joints on disabled bodies.
--- Fixtures on a disabled body are implicitly disabled and will
--- not participate in collisions, ray-casts, or queries.
--- Joints connected to a disabled body are implicitly disabled.
--- An diabled body is still owned by a b2World object and remains
--- in the body list.
---@param flag boolean
function Box2dBody:SetEnabled(flag) end
--- Get the active state of the body.
---@return boolean
function Box2dBody:IsEnabled() end
--- Set this body to have fixed rotation. This causes the mass
--- to be reset.
---@param flag boolean
function Box2dBody:SetFixedRotation(flag) end
--- Does this body have fixed rotation?
---@return boolean
function Box2dBody:IsFixedRotation() end
--- Get the next body in the world's body list.
---@return Box2dBody
function Box2dBody:GetNext() end
--- Get the first fixture in list of all fixtures attached to this body or nil
---@return Box2dFixture|nil
function Box2dBody:GetFixtureList() end
--- Get the list of all joints attached to this body.
---@return Box2dJoint[]
function Box2dBody:GetJointList() end
--- Get the list of all contacts attached to this body.
--- @warning this list changes during the time step and you may
--- miss some collisions if you don't use b2ContactListener.
---@return Box2dContact[]|nil
function Box2dBody:GetContactList() end
--- Get the user data table. Use this to store your application specific data.
---@return table|nil
function Box2dBody:GetUserData() end
--- Set the user data. Use this to store your application specific data.
---@param data table|nil
function Box2dBody:SetUserData(data) end
--- Get the parent world of this body.
---@return Box2dWorld
function Box2dBody:GetWorld() end
--- Dump this body to a file
function Box2dBody:Dump() end
--endregion
--region Box2dShape
--Not b2Shape. Table that have field
---@class Box2dShapeTable
local Box2dShapeTable = {
--box2d.b2Shape e_circle, e_edge, e_polygon, e_chain
shape = 0,
--circle
circle_radius = 1,
circle_position = vmath.vector3(0), --or nil
--edge
edge_two_sided = false,
edge_v0 = vmath.vector3(0),
edge_v1 = vmath.vector3(0),
edge_v2 = vmath.vector3(0),
edge_v3 = vmath.vector3(0),
--polygon box
box = true,
box_hx = 1, box_hy = 1,
box_center = vmath.vector3(0), --or nil
box_angle = 0, -- or nil. need box_center when use angle
--polygon vertices
polygon_vertices = { vmath.vector3(0, 0, 0), vmath.vector3(1, 0, 0), vmath.vector3(0, 1, 0) },
--chain
chain_loop = false, --true use CreateLoop false use CreateChain
chain_vertices = { vmath.vector3(1.7, 0, 0), vmath.vector3(1, 0, 0), vmath.vector3(0, 0, 0), vmath.vector3(-1.7, 0.4, 0) },
chain_prev_vertex = vmath.vector3(0, 0, 0),
chain_next_vertex = vmath.vector3(0, 0, 0)
}
---@class Box2dShape
local Box2dShape = {}
--- Clone the concrete shape using the provided allocator
---@return Box2dShape
function Box2dShape:Clone() end
--- Get the type of this shape. You can use this to down cast to the concrete shape.
---@return number box2d.b2Shape
function Box2dShape:GetType() end
--- Get the number of child primitives.
---@return number
function Box2dShape:GetChildCount() end
--- Test a point for containment in this shape. This only works for convex shapes.
---@param xf Box2dTransform
---@param p vector3
---@return boolean
function Box2dShape:TestPoint(xf, p) end
--- Cast a ray against a child shape.
--- @param input Box2dRayCastInput the ray-cast input parameters.
--- @param transform Box2dTransform transform to be applied to the shape.
--- @param childIndex number|nil the child shape index
---@return Box2dRayCastOutput|nil
function Box2dShape:RayCast(input, transform, childIndex) end
--- Given a transform, compute the associated axis aligned bounding box for a child shape.
--- @param xf Box2dTransform the world transform of the shape.
--- @param childIndex number|nil the child shape index
---@return Box2dAABB
function Box2dShape:ComputeAABB(xf, childIndex) end
--- Compute the mass properties of this shape using its dimensions and density.
--- The inertia tensor is computed about the local origin.
--- @param density number the density in kilograms per meter squared.
---@return Box2dMassData the mass data for this shape.
function Box2dShape:ComputeMass(density) end
--- Radius of a shape. For polygonal shapes this must be b2_polygonRadius. There is no support for
--- making rounded polygons.
---@return number
function Box2dShape:GetRadius() end
---@param radius number
function Box2dShape:SetRadius(radius) end
---@class Box2dPolygonShape:Box2dShape
local Box2dPolygonShape = {}
--- Clone the concrete shape using the provided allocator
---@return Box2dPolygonShape
function Box2dPolygonShape:Clone() end
--- Create a convex hull from the given array of local points.
--- The count must be in the range [3, b2_maxPolygonVertices].
--- @warning the points may be re-ordered, even if they form a convex polygon
--- @warning collinear points are handled but not removed. Collinear points
--- may lead to poor stacking behavior.
---@param points vector3[]
function Box2dPolygonShape:Set(points) end
--- Build vertices to represent an axis-aligned box centered on the local origin.
---@param hx number the half-width.
---@param hy number the half-height.
function Box2dPolygonShape:SetAsBox(hx, hy) end
--- Build vertices to represent an oriented box.
---@param hx number the half-width.
---@param hy number the half-height.
---@param center vector3 the center of the box in local coordinates.
---@param angle float the rotation of the box in local coordinates.
function Box2dPolygonShape:SetAsBox(hx, hy, center, angle) end
--- Validate convexity. This is a very time consuming operation.
---@return boolean true if valid
function Box2dPolygonShape:Validate() end
---@return vector3
function Box2dPolygonShape:GetCentroid() end
---@return vector3[]
function Box2dPolygonShape:GetVertices() end
---@return vector3[]
function Box2dPolygonShape:GetNormals() end
---@return number
function Box2dPolygonShape:GetCount() end
---@class Box2dCircleShape:Box2dShape
local Box2dCircleShape = {}
--- Clone the concrete shape using the provided allocator
---@return Box2dCircleShape
function Box2dCircleShape:Clone() end
---@param position vector3
function Box2dCircleShape:SetPosition(position) end
---@return vector3
function Box2dCircleShape:GetPosition() end
---@class Box2dEdgeShape:Box2dShape
local Box2dEdgeShape = {}
--- Clone the concrete shape using the provided allocator
---@return Box2dEdgeShape
function Box2dEdgeShape:Clone() end
--- Set this as a part of a sequence. Vertex v0 precedes the edge and vertex v3
--- follows. These extra vertices are used to provide smooth movement
--- across junctions. This also makes the collision one-sided. The edge
--- normal points to the right looking from v1 to v2.
---@param v0 vector3
---@param v1 vector3
---@param v2 vector3
---@param v3 vector3
function Box2dEdgeShape:SetOneSided(v0, v1, v2, v3) end
--- Set this as an isolated edge. Collision is two-sided.
---@param v1 vector3
---@param v2 vector3
function Box2dEdgeShape:SetTwoSided(v1, v2) end
---@return vector3
function Box2dEdgeShape:GetVertex0() end
---@return vector3
function Box2dEdgeShape:GetVertex1() end
---@return vector3
function Box2dEdgeShape:GetVertex2() end
---@return vector3
function Box2dEdgeShape:GetVertex3() end
---@return boolean
function Box2dEdgeShape:IsOneSided() end
---@class Box2dChainShape:Box2dShape
local Box2dChainShape = {}
--- Clone the concrete shape using the provided allocator
---@return Box2dChainShape
function Box2dChainShape:Clone() end
--- Clear all data.
function Box2dChainShape:Clear() end
--- Create a loop. This automatically adjusts connectivity.
---@param vertices vector3[] an array of vertices, these are copied
function Box2dChainShape:CreateLoop(vertices) end
--- Create a chain with ghost vertices to connect multiple chains together.
---@param vertices vector3[] an array of vertices, these are copied
---@param prevVertex vector3 previous vertex from chain that connects to the start
---@param nextVertex vector3 next vertex from chain that connects to the end
function Box2dChainShape:CreateChain(vertices, prevVertex, nextVertex) end
---Get a child edge.
---@param index number
---@return Box2dEdgeShape edge
function Box2dChainShape:GetChildEdge(index) end
---@return vector3[]
function Box2dChainShape:GetVertices() end
---@return vector3
function Box2dChainShape:GetNextVertex() end
---@return vector3
function Box2dChainShape:GetPrevVertex() end
---@return vector3 vertices count
function Box2dChainShape:GetCount() end
--endregion
--region Box2dFixtureDef
--- A fixture definition is used to create a fixture. This class defines an
--- abstract fixture definition. You can reuse fixture definitions safely.
---@class Box2dFixtureDef
local Box2dFixtureDef = {
-- The shape, this must be set.
---@type Box2dShape|Box2dShapeTable
shape = { shape = box2d.b2Shape.e_circle, circle_radius = 1, circle_position = vmath.vector3(0) },
-- Use this to store application specific fixture data.
userData = nil,
-- The friction coefficient, usually in the range [0,1].
friction = 0.2,
-- The restitution (elasticity) usually in the range [0,1].
restitution = 0,
-- Restitution velocity threshold, usually in m/s. Collisions above this
-- speed have restitution applied (will bounce).
restitutionThreshold = 1,
--The density, usually in kg/m^2.
density = 0,
-- A sensor shape collects contact information but never generates a collision
-- response.
isSensor = false,
-- Contact filtering data. b2Filter
---@type Box2dFilter
filter = nil
}
--endregion
--region Box2dBodyDef
--- A body definition holds all the data needed to construct a rigid body.
--- You can safely re-use body definitions. Shapes are added to a body after construction.
---@class Box2dBodyDef
local Box2dBodyDef = {
-- The body type: static, kinematic, or dynamic.
-- box2d.b2BodyType
-- Note: if a dynamic body would have zero mass, the mass is set to one.
type = box2d.b2BodyType.b2_staticBody,
-- The world position of the body. Avoid creating bodies at the origin
-- since this can lead to many overlapping shapes.
position = vmath.vector3(0),
-- The world angle of the body in radians.
angle = 0,
-- The linear velocity of the body's origin in world co-ordinates.
linearVelocity = vmath.vector3(0),
-- The angular velocity of the body.
angularVelocity = 0,
-- Linear damping is use to reduce the linear velocity. The damping parameter
-- can be larger than 1.0f but the damping effect becomes sensitive to the
-- time step when the damping parameter is large.
-- Units are 1/time
linearDamping = 0,
-- Angular damping is use to reduce the angular velocity. The damping parameter
-- can be larger than 1.0f but the damping effect becomes sensitive to the
-- time step when the damping parameter is large.
-- Units are 1/time
angularDamping = 0,
-- Set this flag to false if this body should never fall asleep. Note that
-- this increases CPU usage.
allowSleep = true,
-- Is this body initially awake or sleeping?
awake = true,
-- Should this body be prevented from rotating? Useful for characters.
fixedRotation = false,
-- Is this a fast moving body that should be prevented from tunneling through
-- other moving bodies? Note that all bodies are prevented from tunneling through
-- kinematic and static bodies. This setting is only considered on dynamic bodies.
-- warning You should use this flag sparingly since it increases processing time.
bullet = false,
-- Does this body start out enabled?
enabled = true,
-- Use this to store application specific body data.
userData = nil,
-- Scale the gravity applied to this body.
gravityScale = 1
}
--endregion
--region Box2dWorld
--- The world class manages all physics entities, dynamic simulation,
--- and asynchronous queries. The world also contains efficient memory
--- management facilities.
--- warning Destroy world, world:Destroy() when you do not need it any more.
---@class Box2dWorld
local Box2dWorld = {}
--- Register a contact event listener.
--- listener = {
--- SayGoodbyeFixture = function (fixture) end,
--- SayGoodbyeJoint = function(joint) end,
--- }
---@param listener table|nil
function Box2dWorld:SetDestructionListener(listener) end
--- Register a contact event listener.
--- listener = {
--- BeginContact = function (contact) end,
--- EndContact = function(contact) end,
--- PreSolve = function(contact, old_manifold) end,
--- PostSolve = function(contact,impulse) end
--- }
---@param listener table|nil
function Box2dWorld:SetContactListener(listener) end
--- Register a routine for debug drawing. The debug draw functions are called
--- inside with b2World:DebugDraw method. The debug draw object is owned
--- by you and must remain in scope.
---@param draw Box2dDebugDraw|nil
function Box2dWorld:SetDebugDraw(draw) end
---Create a rigid body given a definition.
---warning This function is locked during callbacks.
---@param bodyDef Box2dBodyDef
---@return Box2dBody
function Box2dWorld:CreateBody(bodyDef) end
--- Destroy a rigid body given a definition.
--- warning This automatically deletes all associated shapes and joints.
--- warning This function is locked during callbacks.
---@param body Box2dBody
function Box2dWorld:DestroyBody(body) end
--- Create a joint to constrain bodies together.
--- This may cause the connected bodies to cease colliding.
--- warning This function is locked during callbacks.
---@param def Box2dJointDef
---@return Box2dJoint
function Box2dWorld:CreateJoint(def) end
--- Destroy a joint. This may cause the connected bodies to begin colliding.
--- warning This function is locked during callbacks.
---@param joint Box2dJoint
function Box2dWorld:DestroyJoint(joint) end
--- Take a time step. This performs collision detection, integration,
--- and constraint solution.
---@param timeStep number the amount of time to simulate, this should not vary.
---@param velocityIterations number for the velocity constraint solver.
---@param positionIterations number for the position constraint solver.
function Box2dWorld:Step(timeStep, velocityIterations, positionIterations) end
--- Manually clear the force buffer on all bodies. By default, forces are cleared automatically
--- after each call to Step. The default behavior is modified by calling SetAutoClearForces.
--- The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain
--- a fixed sized time step under a variable frame-rate.
--- When you perform sub-stepping you will disable auto clearing of forces and instead call
--- ClearForces after all sub-steps are complete in one pass of your game loop.
--- @see SetAutoClearForces
function Box2dWorld:ClearForces() end
--- Call this to draw shapes and other debug draw data. This is intentionally non-const.
function Box2dWorld:DebugDraw() end
---Get the world body list. With the returned body, use b2Body:GetNext() to get the next body in the world list.
---A nil body indicates the end of the list.
---@return Box2dBody|nil the head of the world body list.
function Box2dWorld:GetBodyList() end
--- Get the world contact list. With the returned contact, use b2Contact::GetNext to get
--- the next contact in the world list. A nullptr contact indicates the end of the list.
--- @warning contacts are created and destroyed in the middle of a time step.
--- Use b2ContactListener to avoid missing contacts.
---@return Box2dContact|nil the head of the world contact list.
function Box2dWorld:GetContactList() end
--- Ray-cast the world for all fixtures in the path of the ray. Your callback
--- controls whether you get the closest point, any point, or n-points.
--- The ray-cast ignores shapes that contain the starting point.
--- @param callback function(Box2dFixture fixture, vector3 point, vector3 normal, float fraction)
--- @param point1 vector3 ray starting point
--- @param point2 vector3 ray ending point
function Box2dWorld:RayCast(callback, point1, point2) end
--- Query the world for all fixtures that potentially overlap the
--- provided AABB.
---@param callback function(Box2dFixture fixture)
---@param aabb Box2dAABB the query box.
function Box2dWorld:QueryAABB(callback, aabb) end
---Get the world joint list. With the returned joint, use b2Joint:GetNext() to get the next joint in the world list.
---A nil joint indicates the end of the list.
---@return Box2dJoint|nil the head of the world joint list.
function Box2dWorld:GetJointList() end
--- Enable/disable sleep.
function Box2dWorld:SetAllowSleeping(flag) end
---@return boolean
function Box2dWorld:GetAllowSleeping() end
--- Enable/disable warm starting. For testing.
function Box2dWorld:SetWarmStarting(flag) end
---@return boolean
function Box2dWorld:GetWarmStarting() end
--- Enable/disable continuous physics. For testing.
function Box2dWorld:SetContinuousPhysics(flag) end
---@return boolean
function Box2dWorld:GetContinuousPhysics() end