This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.odin
1640 lines (1412 loc) · 44.3 KB
/
types.odin
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
package box2d
// Task interface
//
// This is prototype for a Box2D task. Your task system is expected to invoke the Box2D task with these arguments.
//
// The task spans a range of the parallel-for: ```[start_index, end_index)```
//
// The worker index must correctly identify each worker in the user thread pool, expected in ```[0, worker_count)```.
//
// A worker must only exist on only one thread at a time and is analogous to the thread index.
// The task context is the context pointer sent from Box2D when it is enqueued.
//
// The ```start_index``` and ```end_index``` are expected in the range ```[0, item_count)``` where ```item_count``` is the argument to ```Enqueue_Task_Callback```
// below. Box2D expects ```start_index < end_index``` and will execute a loop like this:
//
// for i := start_index; i < end_index; i += 1
// {
// do_work()
// }
Task_Callback :: #type proc "c" (start_index, end_index: i32, worker_index: u32, task_context: rawptr)
// These functions can be provided to Box2D to invoke a task system. These are designed to work well with **enkiTS**.
//
// Returns a pointer to the user's task object. May be ```nil```. A ```nil``` indicates to **Box2D** that the work was executed
// serially within the callback and there is no need to call ```Finish_Task_Callback```.
//
// The ```item_count``` is the number of **Box2D** work items that are to be partitioned among workers by the user's task system.
//
// This is essentially a parallel-for. The ```min_range``` parameter is a suggestion of the minimum number of items to assign
// per worker to reduce overhead. For example, suppose the task is small and that ```item_count``` is ```16```. A ```min_range``` of ```8``` suggests
// that your task system should split the work items among just two workers, even if you have more available.
//
// In general the range ```[start_index, end_index)``` send to ```Task_Callback``` should obey:
// ```end_index - start_index >= min_range```
//
// The exception of course is when ```item_count < min_range```.
Enqueue_Task_Callback :: #type proc "c" (task: ^Task_Callback, item_count, min_range: i32, task_context, user_context: rawptr) -> rawptr
// Finishes a user task object that wraps a **Box2D** task.
Finish_Task_Callback :: #type proc "c" (user_task, user_context: rawptr)
// Result from ```world_ray_cast_closest```
Ray_Result :: struct
{
shape_id: Shape_ID,
point,
normal: Vec2,
fraction: f32,
hit: bool,
}
// World definition used to create a simulation world.
//
// Must be initialized using ```default_world_def```.
World_Def :: struct
{
// Gravity vector. Box2D has no up-vector defined.
gravity: Vec2,
// Restitution velocity threshold, usually in m/s. Collisions above this
// speed have restitution applied (will bounce).
restitution_threshold,
// This parameter controls how fast overlap is resolved and has units of meters per second
contact_pushout_velocity,
// Threshold velocity for hit events. Usually meters per second.
hit_event_threshold,
// Contact stiffness. Cycles per second.
contact_hertz,
// Contact bounciness. Non-dimensional.
contact_damping_ratio,
// Joint stiffness. Cycles per second.
joint_hertz,
// Joint bounciness. Non-dimensional.
joint_damping_ratio: f32,
// Maximum linear velocity. Usually meters per second.
maximum_linear_velocity: f32,
// Can bodies go to sleep to improve performance
enable_sleep,
// Enable continuous collision
enable_continous: bool,
// Number of workers to use with the provided task system. Box2D performs best when using only
// performance cores and accessing a single L2 cache. Efficiency cores and hyper-threading provide
// little benefit and may even harm performance.
worker_count: u32,
// function to spawn tasks
enqueue_task: Enqueue_Task_Callback,
// function to finish a task
finish_task: Finish_Task_Callback,
// User context that is provided to ```enqueue_task``` and ```finish_task```
user_task_context: rawptr,
// Used internally to detect a valid definition. DO **NOT SET**.
internal_value: i32,
}
// The body simulation type.
//
// Each body is one of these three types. The type determines how the body behaves in the simulation.
Body_Type :: enum i32
{
Static = 0,
Kinematic = 1,
Dynamic = 2,
}
// 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.
//
// Body definitions are temporary objects used to bundle creation parameters.
//
// Must be initialized using ```default_body_def```.
Body_Def :: struct
{
// The body type: static, kinematic, or dynamic.
type: Body_Type,
// The initial world position of the body. Bodies should be created with the desired position.
// Creating bodies at the origin and then moving them nearly doubles the cost of body creation, especially
// if the body is moved after shapes have been added.
position: Vec2,
// The initial world rotation of the body. Use b2MakeRot() if you have an angle.
rotation: Rot,
// The initial linear velocity of the body's origin. Typically in meters per second.
linear_velocity: Vec2,
// The initial angular velocity of the body. Typically in meters per second.
angular_velocity: f32,
// Linear damping is use to reduce the linear velocity. The damping parameter
// can be larger than 1 but the damping effect becomes sensitive to the
// time step when the damping parameter is large.
//
// Generally linear damping is undesirable because it makes objects move slowly
// as if they are floating.
linear_damping: f32,
// 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
//
// Angular damping can be use slow down rotating bodies.
// time step when the damping parameter is large.
angular_damping: f32,
// Scale the gravity applied to this body. Non-dimensional.
gravity_scale: f32,
// Sleep velocity threshold, default is 0.05 meter per second
sleep_threshold: f32,
// Use this to store application specific body data.
user_data: rawptr,
// Set this flag to false if this body should never fall asleep.
enable_sleep: bool,
// Is this body initially awake or sleeping?
is_awake: bool,
// Should this body be prevented from rotating? Useful for characters.
fixed_rotation: bool,
// Treat this body as high speed object that performs continuous collision detection
// against dynamic and kinematic bodies, but not other bullet bodies.
//
// Bullets should be used sparingly. They are not a solution for general dynamic-versus-dynamic
// continuous collision. They may interfere with joint constraints.
is_bullet: bool,
// Used to disable a body. A disabled body does not move or collide.
is_enabled: bool,
// Automatically compute mass and related properties on this body from shapes.
//
// Triggers whenever a shape is add/removed/changed. Default is true.
automatic_mass: bool,
// This allows this body to bypass rotational speed limits. Should only be used
// for circular objects, like wheels.
allow_fast_rotation: bool,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// This is used to filter collision on shapes. It affects shape-vs-shape collision
// and shape-versus-query collision (such as ```World_Cast_Ray```).
Filter :: struct
{
// The collision category bits. Normally you would just set one bit. The category bits should
// represent your application object types. For example:
// @code{.cpp}
// My_Categories :: enum u32
// {
// Static = 0x00000001,
// Dynamic = 0x00000002,
// Debris = 0x00000004,
// Player = 0x00000008,
// etc..
// };
category_bits: u32,
// The collision mask bits. This states the categories that this
// shape would accept for collision.
// For example, you may want your player to only collide with static objects
// and other players.
// mask_bits := u32(My_Categories.Static | My_Categories.Player)
mask_bits: u32,
// Collision groups allow a certain group of objects to never collide (negative)
// or always collide (positive). A group index of zero has no effect. Non-zero group filtering
// always wins against the mask bits.
//
// For example, you may want ragdolls to collide with other ragdolls but you don't want
// ragdoll self-collision. In this case you would give each ragdoll a unique negative group index
// and apply that group index to all shapes on the ragdoll.
group_index: i32,
}
// The query filter is used to filter collisions between queries and shapes. For example,
// you may want a ray-cast representing a projectile to hit players and the static environment
// but not debris.
Query_Filter :: struct
{
// The collision category bits. Normally you would just set one bit.
category_bits,
// The collision mask bits. This states the categories that this
// shape would accept for collision.
mask_bits: u32,
}
// Shape type
Shape_Type :: enum i32
{
// A circle with an offset
Circle,
// A capsule is an extruded circle
Capsule,
// A line segment
Segment,
// A convex polygon
Polygon,
// A smooth segment owned by a chain shape
Smooth_Segment,
}
// Used to create a shape.
// This is a temporary object used to bundle shape creation parameters. You may use
// the same shape definition to create multiple shapes.
//
// Must be initialized using ```default_shape_def```.
Shape_Def :: struct
{
// Use this to store application specific shape data.
user_data: rawptr,
// The friction coefficient, usually in the range [0,1].
friction: f32,
// The restitution (elasticity) usually in the range [0,1].
restitution: f32,
// The density, usually in kg/m^2.
density: f32,
// Contact filtering data.
filter: Filter,
// Custom debug draw color.
custom_color: u32,
// A sensor shape collects contact information but never generates a collision
// response.
is_sensor: bool,
// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
enable_sensor_events: bool,
// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
enable_contact_events: bool,
// Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors.
enable_hit_events: bool,
// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive
// and must be carefully handled due to multi-threading. Ignored for sensors.
enable_pre_solve_events: bool,
// Normally shapes on static bodies don't invoke contact creation when they are added to the world. This overrides
// that behavior and causes contact creation. This significantly slows down static body creation which can be important
// when there are many static shapes.
force_contact_creation: bool,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// Used to create a chain of edges. This is designed to eliminate ghost collisions with some limitations.
// - chains are one-sided
// - chains have no mass and should be used on static bodies
// - chains have a counter-clockwise winding order
// - chains are either a loop or open
// - a chain must have at least 4 points
// - the distance between any two points must be greater than b2_linearSlop
// - a chain shape should not self intersect (this is not validated)
// - an open chain shape has NO COLLISION on the first and final edge
// - you may overlap two open chains on their first three and/or last three points to get smooth collision
// - a chain shape creates multiple smooth edges shapes on the body
// https://en.wikipedia.org/wiki/Polygonal_chain
// Must be initialized using ```default_chain_def```.
//
// Do not use chain shapes unless you understand the limitations. This is an advanced feature.
Chain_Def :: struct
{
// Use this to store application specific shape data.
user_data: rawptr,
// An array of at least 4 points. These are cloned and may be temporary.
points: [^]Vec2,
// The point count, must be 4 or more.
count: i32,
// The friction coefficient, usually in the range [0,1].
friction: f32,
// The restitution (elasticity) usually in the range [0,1].
restitution: f32,
// Contact filtering data.
filter: Filter,
// Indicates a closed chain formed by connecting the first and last points
is_loop: bool,
// Used internally to detect a valid definition. **DO NOT SET**.
internalValue: i32,
}
// Profiling data. Times are in milliseconds.
Profile :: struct
{
step,
pairs,
collide,
solve,
build_islands,
solve_constraints,
prepare_tasks,
solver_tasks,
prepare_constraints,
integrate_velocities,
warm_start,
solve_velocities,
integrate_positions,
relax_velocities,
apply_restitution,
store_impulses,
finalize_bodies,
split_islands,
sleep_islands,
hit_events,
broadphase,
continuous: f32,
}
// Counters that give details of the simulation size
Counters :: struct
{
island_count,
body_count,
contact_count,
joint_count,
proxy_count,
pair_count,
tree_height,
stack_capacity,
stack_used,
byte_count,
task_count: i32,
color_counts: [12]i32,
}
// Joint type enumeration
//
// This is useful because all joint types use b2JointId and sometimes you
// want to get the type of a joint.
Joint_Type :: enum i32
{
Distance,
Motor,
Mouse,
Prismatic,
Revolute,
Weld,
Wheel,
}
// Distance joint definition
//
// This requires defining an anchor point on both
// bodies and the non-zero distance of the distance joint. The definition uses
// local anchor points so that the initial configuration can violate the
// constraint slightly. This helps when saving and loading a game.
Distance_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
// The local anchor point relative to bodyA's origin.
local_anchor_a: Vec2,
// The local anchor point relative to bodyB's origin.
local_anchor_b: Vec2,
// The rest length of this joint. Clamped to a stable minimum value.
length: f32,
// Enable the distance constraint to behave like a spring. If false
// then the distance joint will be rigid, overriding the limit and motor.
enable_spring: bool,
// The linear stiffness hertz (cycles per second)
hertz: f32,
// The linear damping ratio (non-dimensional)
damping_ratio: f32,
// Enable/disable the joint limit
enable_limit: bool,
// Minimum length. Clamped to a stable minimum value.
min_length: f32,
// Maximum length. Must be greater than or equal to the minimum length.
max_length: f32,
// Enable/disable the joint motor
enable_motor: bool,
// The maximum motor force, usually in newtons
max_motor_force: f32,
// The desired motor speed, usually in meters per second
motor_speed: f32,
// Set this flag to true if the attached bodies should collide.
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// A motor joint is used to control the relative motion between two bodies
//
// A typical usage is to control the movement of a dynamic body with respect to the ground.
Motor_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
// Position of body_b minus the position of body_a, in body_a's frame.
linear_offset: Vec2,
// The body_b angle minus body_a angle in radians
angular_offset: f32,
// The maximum motor force in newtons
max_force: f32,
// The maximum motor torque in newton-meters
max_torque: f32,
// Position correction factor in the range [0,1]
correction_factor: f32,
// Set this flag to true if the attached bodies should collide
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// A mouse joint is used to make a point on a body track a specified world point.
//
// This a soft constraint and allows the constraint to stretch without
// applying huge forces. This also applies rotation constraint heuristic to improve control.
Mouse_Joint_Def :: struct
{
// The first attached body.
body_id_a,
// The second attached body.
body_id_b: Body_ID,
// The initial target point in world space
target: Vec2,
// Stiffness in hertz
hertz: f32,
// Damping ratio, non-dimensional
damping_ratio: f32,
// Maximum force, typically in newtons
max_force: f32,
// Set this flag to true if the attached bodies should collide.
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// 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.
Prismatic_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
/// The local anchor point relative to body_a's origin.
local_anchor_a: Vec2,
// The local anchor point relative to body_b's origin.
local_anchor_b: Vec2,
// The local translation unit axis in body_a.
local_axis_a: Vec2,
// The constrained angle between the bodies: body_b_angle - body_a_angle.
reference_angle: f32,
// Enable a linear spring along the prismatic joint axis
enable_spring: bool,
// The spring stiffness Hertz, cycles per second
hertz: f32,
// The spring damping ratio, non-dimensional
damping_ratio: f32,
// Enable/disable the joint limit.
enable_limit: bool,
// The lower translation limit, usually in meters.
lower_translation: f32,
// The upper translation limit, usually in meters.
upper_translation: f32,
// Enable/disable the joint motor.
enable_motor: bool,
// The maximum motor torque, usually in N-m.
max_motor_force: f32,
// The desired motor speed in radians per second.
motor_speed: f32,
// Set this flag to true if the attached bodies should collide.
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// 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
Revolute_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
// The local anchor point relative to bodyA's origin.
local_anchor_a: Vec2,
// The local anchor point relative to bodyB's origin.
local_anchor_b: Vec2,
// The bodyB angle minus bodyA angle in the reference state (radians).
// This defines the zero angle for the joint limit.
reference_angle: f32,
// Enable a rotational spring on the revolute hinge axis
enable_spring: bool,
// The spring stiffness Hertz, cycles per second
hertz: f32,
// The spring damping ratio, non-dimensional
damping_ratio: f32,
// A flag to enable joint limits.
enable_limit: bool,
// The lower angle for the joint limit (radians).
lower_angle: f32,
// The upper angle for the joint limit (radians).
upper_angle: f32,
// A flag to enable the joint motor.
enable_motor: bool,
// The maximum motor torque, typically in newton-meters
max_motor_torque: f32,
// The desired motor speed in radians per second
motor_speed: f32,
// Scale the debug draw
draw_size: f32,
// Set this flag to true if the attached bodies should collide
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// Weld joint definition
//
// A weld joint connect to bodies together rigidly. This constraint provides springs to mimic
// soft-body simulation.
//
// The approximate solver in Box2D cannot hold many bodies together rigidly
Weld_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
// The local anchor point relative to body_a's origin.
local_anchor_a: Vec2,
// The local anchor point relative to body_b's origin.
local_anchor_b: Vec2,
// The bodyB angle minus bodyA angle in the reference state (radians).
reference_angle: f32,
// Linear stiffness expressed as hertz (oscillations per second). Use zero for maximum stiffness.
linear_hertz: f32,
// Angular stiffness as hertz (oscillations per second). Use zero for maximum stiffness.
angular_hertz: f32,
// Linear damping ratio, non-dimensional. Use 1 for critical damping.
linear_damping_ratio: f32,
// Linear damping ratio, non-dimensional. Use 1 for critical damping.
angular_damping_ratio: f32,
// Set this flag to true if the attached bodies should collide.
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// Wheel 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.
Wheel_Joint_Def :: struct
{
// The first attached body.
body_id_a: Body_ID,
// The second attached body.
body_id_b: Body_ID,
// The local anchor point relative to bodyA's origin.
local_anchor_a: Vec2,
// The local anchor point relative to bodyB's origin.
local_anchor_b: Vec2,
// The local translation unit axis in bodyA.
local_axis_a: Vec2,
// Enable a linear spring along the local axis
enable_spring: bool,
// Spring stiffness in Hertz
hertz: f32,
// Spring damping ratio, non-dimensional
damping_ratio: f32,
// Enable/disable the joint limit.
enable_limit: bool,
// The lower translation limit
lower_translation,
// The upper translation limit
upper_translation: f32,
// Enable/disable the joint rotational motor
enable_motor: bool,
// The maximum motor torque, typically in newton-meters
max_motor_torque: f32,
// The desired motor speed in radians per second.
motor_speed: f32,
// Set this flag to true if the attached bodies should collide
collide_connected: bool,
// User data pointer
user_data: rawptr,
// Used internally to detect a valid definition. **DO NOT SET**.
internal_value: i32,
}
// A begin touch event is generated when a shape starts to overlap a sensor shape.
Sensor_Begin_Touch_Event :: struct
{
// The id of the sensor shape
sensor_shape_id: Shape_ID,
// The id of the dynamic shape that began touching the sensor shape
visitor_shape_id: Shape_ID,
}
// An end touch event is generated when a shape stops overlapping a sensor shape.
Sensor_End_Touch_Event :: struct
{
// The id of the sensor shape
sensor_shape_id: Shape_ID,
// The id of the dynamic shape that stopped touching the sensor shape
visitor_shape_id: Shape_ID,
}
// Sensor events are buffered in the Box2D world and are available
// as begin/end overlap event arrays after the time step is complete.
//
// **NOTE:** these may become invalid if bodies and/or shapes are destroyed
Sensor_Events :: struct
{
// Array of sensor begin touch events
begin_events: [^]Sensor_Begin_Touch_Event,
// Array of sensor end touch events
end_events: [^]Sensor_End_Touch_Event,
// The number of begin touch events
begin_count: i32,
// The number of end touch events
end_count: i32,
}
// A begin touch event is generated when two shapes begin touching.
Contact_Begin_Touch_Event :: struct
{
// Id of the first shape
shape_id_a: Shape_ID,
// Id of the second shape
shape_id_b: Shape_ID,
}
// An end touch event is generated when two shapes stop touching.
Contact_End_Touch_Event :: struct
{
// Id of the first shape
shape_id_a: Shape_ID,
// Id of the second shape
shape_id_b: Shape_ID,
}
// A hit touch event is generated when two shapes collide with a speed faster than the hit speed threshold.
Contact_Hit_Event :: struct
{
// Id of the first shape
shape_id_a: Shape_ID,
// Id of the second shape
shape_id_b: Shape_ID,
// Point where the shapes hit
point: Vec2,
// Normal vector pointing from shape A to shape B
normal: Vec2,
// The speed the shapes are approaching. Always positive. Typically in meters per second.
approach_speed: f32,
}
// Contact events are buffered in the Box2D world and are available
// as event arrays after the time step is complete.
//
// **NOTE:** these may become invalid if bodies and/or shapes are destroyed
Contact_Events :: struct
{
// Array of begin touch events
begin_events: [^]Contact_Begin_Touch_Event,
// Array of end touch events
end_events: [^]Contact_End_Touch_Event,
// Array of hit events
hit_events: [^]Contact_Hit_Event,
// Number of begin touch events
begin_count: i32,
/// Number of end touch events
end_count: i32,
// Number of hit events
hit_count: i32,
}
// Body move events triggered when a body moves.
//
// Triggered when a body moves due to simulation. Not reported for bodies moved by the user.
//
// This also has a flag to indicate that the body went to sleep so the application can also
// sleep that actor/entity/object associated with the body.
//
// On the other hand if the flag does not indicate the body went to sleep then the application
// can treat the actor/entity/object associated with the body as awake.
//
// This is an efficient way for an application to update game object transforms rather than
// calling functions such as b2Body_GetTransform() because this data is delivered as a contiguous array
// and it is only populated with bodies that have moved.
//
// **NOTE:** If sleeping is disabled all dynamic and kinematic bodies will trigger move events.
Body_Move_Event :: struct
{
transform: Transform,
body_id: Body_ID,
user_data: rawptr,
fell_asleep: bool,
}
// Body events are buffered in the Box2D world and are available
// as event arrays after the time step is complete.
//
// **NOTE:** this date becomes invalid if bodies are destroyed
Body_Events :: struct
{
// Array of move events
move_events: [^]Body_Move_Event,
// Number of move events
moveCount: i32,
}
// The contact data for two shapes. By convention the manifold normal points
// from shape **A** to shape **B**.
//
// **SEE:** ```shape_get_contact_data``` and ```body_get_contact_data```
Contact_Data :: struct
{
shape_id_a: Shape_ID,
shape_id_b: Shape_ID,
manifold: Manifold,
}
// Prototype for a contact filter callback.
//
// This is called when a contact pair is considered for collision. This allows you to
// perform custom logic to prevent collision between shapes. This is only called if
// one of the two shapes has custom filtering enabled. **SEE:** ```shape_def```.
//
// Notes:
// * this function must be thread-safe
// * this is only called if one of the two shapes has enabled custom filtering
// * this is called only for awake dynamic bodies
//
// Return ```false``` if you want to disable the collision
//
// **WARNING:** Do not attempt to modify the world inside this callback
Custom_Filter_Fcn :: #type proc "c" (shape_id_a, shape_id_b: Shape_ID, context_: rawptr) -> bool
// Prototype for a pre-solve callback.
//
// This is called after a contact is updated. This allows you to inspect a
// contact before it goes to the solver. If you are careful, you can modify the
// contact manifold (e.g. modify the normal).
//
// Notes:
// * this function must be thread-safe
// * this is only called if the shape has enabled presolve events
// * this is called only for awake dynamic bodies
// * this is not called for sensors
// * the supplied manifold has impulse values from the previous step
//
// Return ```false``` if you want to disable the contact this step
// **WARNING:** Do not attempt to modify the world inside this callback
Pre_Solve_Fcn :: #type proc "c" (shape_id_a, shape_id_b: Shape_ID, manifold: ^Manifold, context_: rawptr) -> bool
// Prototype callback for overlap queries.
//
// Called for each shape found in the query.
//
// **SEE:** ```world_query_aabb```
//
// **RETURN:** ```false``` to terminate the query.
Overlap_Result_Fcn :: #type proc "c" (shape_id: Shape_ID, context_: rawptr) -> bool
// Prototype callback for ray casts.
//
// Called for each shape found in the query. You control how the ray cast
// proceeds by returning a ```f32```:
// * *return* ```-1```: ignore this shape and continue
// * *return* ```0```: terminate the ray cast
// * *return* ```fraction```: clip the ray to this point
// * *return* ```1```: don't clip the ray and continue
// * ```shape_id``` the shape hit by the ray
// * ```point``` the point of initial intersection
// * ```normal``` the normal vector at the point of intersection
// * ```fraction``` the fraction along the ray at the point of intersection
// * ```context_``` the user context
//
// **RETURN:** ```-1``` to filter, ```0``` to terminate, fraction to clip the ray for closest hit, ```1``` to continue
// **SEE:** ```world_cast_ray```
Cast_Result_Fcn :: #type proc "c" (shape: Shape_ID, point, normal: Vec2, fraction: f32, context_: rawptr) -> f32