box2d-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +336 -0
  4. data/examples/contact_events.rb +22 -0
  5. data/examples/debug_draw.rb +15 -0
  6. data/examples/falling_ball.rb +19 -0
  7. data/examples/rugl_debug_draw.rb +68 -0
  8. data/examples/stagecraft_debug_draw.rb +64 -0
  9. data/examples/support/box2d_debug_lines.rb +125 -0
  10. data/ext/box2d/CMakeLists.txt +35 -0
  11. data/ext/box2d/extconf.rb +42 -0
  12. data/ext/box2d/native.c +9 -0
  13. data/ext/box2d/vendor/box2d/LICENSE +21 -0
  14. data/ext/box2d/vendor/box2d/VERSION +1 -0
  15. data/ext/box2d/vendor/box2d/include/box2d/base.h +131 -0
  16. data/ext/box2d/vendor/box2d/include/box2d/box2d.h +1222 -0
  17. data/ext/box2d/vendor/box2d/include/box2d/collision.h +830 -0
  18. data/ext/box2d/vendor/box2d/include/box2d/id.h +144 -0
  19. data/ext/box2d/vendor/box2d/include/box2d/math_functions.h +761 -0
  20. data/ext/box2d/vendor/box2d/include/box2d/types.h +1457 -0
  21. data/ext/box2d/vendor/box2d/src/CMakeLists.txt +223 -0
  22. data/ext/box2d/vendor/box2d/src/aabb.c +132 -0
  23. data/ext/box2d/vendor/box2d/src/aabb.h +56 -0
  24. data/ext/box2d/vendor/box2d/src/arena_allocator.c +112 -0
  25. data/ext/box2d/vendor/box2d/src/arena_allocator.h +48 -0
  26. data/ext/box2d/vendor/box2d/src/array.c +8 -0
  27. data/ext/box2d/vendor/box2d/src/array.h +179 -0
  28. data/ext/box2d/vendor/box2d/src/atomic.h +79 -0
  29. data/ext/box2d/vendor/box2d/src/bitset.c +67 -0
  30. data/ext/box2d/vendor/box2d/src/bitset.h +65 -0
  31. data/ext/box2d/vendor/box2d/src/body.c +1884 -0
  32. data/ext/box2d/vendor/box2d/src/body.h +194 -0
  33. data/ext/box2d/vendor/box2d/src/box2d.natvis +41 -0
  34. data/ext/box2d/vendor/box2d/src/broad_phase.c +524 -0
  35. data/ext/box2d/vendor/box2d/src/broad_phase.h +83 -0
  36. data/ext/box2d/vendor/box2d/src/constants.h +54 -0
  37. data/ext/box2d/vendor/box2d/src/constraint_graph.c +322 -0
  38. data/ext/box2d/vendor/box2d/src/constraint_graph.h +58 -0
  39. data/ext/box2d/vendor/box2d/src/contact.c +650 -0
  40. data/ext/box2d/vendor/box2d/src/contact.h +148 -0
  41. data/ext/box2d/vendor/box2d/src/contact_solver.c +2120 -0
  42. data/ext/box2d/vendor/box2d/src/contact_solver.h +54 -0
  43. data/ext/box2d/vendor/box2d/src/core.c +178 -0
  44. data/ext/box2d/vendor/box2d/src/core.h +149 -0
  45. data/ext/box2d/vendor/box2d/src/ctz.h +112 -0
  46. data/ext/box2d/vendor/box2d/src/distance.c +1415 -0
  47. data/ext/box2d/vendor/box2d/src/distance_joint.c +556 -0
  48. data/ext/box2d/vendor/box2d/src/dynamic_tree.c +1989 -0
  49. data/ext/box2d/vendor/box2d/src/geometry.c +1028 -0
  50. data/ext/box2d/vendor/box2d/src/hull.c +328 -0
  51. data/ext/box2d/vendor/box2d/src/id_pool.c +79 -0
  52. data/ext/box2d/vendor/box2d/src/id_pool.h +35 -0
  53. data/ext/box2d/vendor/box2d/src/island.c +977 -0
  54. data/ext/box2d/vendor/box2d/src/island.h +89 -0
  55. data/ext/box2d/vendor/box2d/src/joint.c +1272 -0
  56. data/ext/box2d/vendor/box2d/src/joint.h +335 -0
  57. data/ext/box2d/vendor/box2d/src/manifold.c +1726 -0
  58. data/ext/box2d/vendor/box2d/src/math_functions.c +159 -0
  59. data/ext/box2d/vendor/box2d/src/motor_joint.c +283 -0
  60. data/ext/box2d/vendor/box2d/src/mouse_joint.c +214 -0
  61. data/ext/box2d/vendor/box2d/src/mover.c +73 -0
  62. data/ext/box2d/vendor/box2d/src/prismatic_joint.c +656 -0
  63. data/ext/box2d/vendor/box2d/src/revolute_joint.c +534 -0
  64. data/ext/box2d/vendor/box2d/src/sensor.c +389 -0
  65. data/ext/box2d/vendor/box2d/src/sensor.h +36 -0
  66. data/ext/box2d/vendor/box2d/src/shape.c +1714 -0
  67. data/ext/box2d/vendor/box2d/src/shape.h +123 -0
  68. data/ext/box2d/vendor/box2d/src/solver.c +2038 -0
  69. data/ext/box2d/vendor/box2d/src/solver.h +155 -0
  70. data/ext/box2d/vendor/box2d/src/solver_set.c +613 -0
  71. data/ext/box2d/vendor/box2d/src/solver_set.h +57 -0
  72. data/ext/box2d/vendor/box2d/src/table.c +238 -0
  73. data/ext/box2d/vendor/box2d/src/table.h +37 -0
  74. data/ext/box2d/vendor/box2d/src/timer.c +185 -0
  75. data/ext/box2d/vendor/box2d/src/types.c +151 -0
  76. data/ext/box2d/vendor/box2d/src/weld_joint.c +310 -0
  77. data/ext/box2d/vendor/box2d/src/wheel_joint.c +551 -0
  78. data/ext/box2d/vendor/box2d/src/world.c +3301 -0
  79. data/ext/box2d/vendor/box2d/src/world.h +192 -0
  80. data/generator/generate.rb +316 -0
  81. data/generator/layout_probe.c +507 -0
  82. data/generator/verify_layouts.rb +32 -0
  83. data/lib/box2d/body.rb +172 -0
  84. data/lib/box2d/body_definition.rb +38 -0
  85. data/lib/box2d/body_shapes.rb +135 -0
  86. data/lib/box2d/chain.rb +61 -0
  87. data/lib/box2d/debug_draw.rb +118 -0
  88. data/lib/box2d/events.rb +103 -0
  89. data/lib/box2d/fixed_stepper.rb +39 -0
  90. data/lib/box2d/handle.rb +46 -0
  91. data/lib/box2d/hit.rb +5 -0
  92. data/lib/box2d/joint.rb +197 -0
  93. data/lib/box2d/native.rb +1462 -0
  94. data/lib/box2d/native_loader.rb +45 -0
  95. data/lib/box2d/pixel_scale.rb +29 -0
  96. data/lib/box2d/shape.rb +109 -0
  97. data/lib/box2d/shape_definition.rb +44 -0
  98. data/lib/box2d/value_conversion.rb +80 -0
  99. data/lib/box2d/version.rb +7 -0
  100. data/lib/box2d/world.rb +135 -0
  101. data/lib/box2d/world_joints.rb +156 -0
  102. data/lib/box2d/world_queries.rb +122 -0
  103. data/lib/box2d/world_registry.rb +95 -0
  104. data/lib/box2d.rb +31 -0
  105. data/script/build_platform_gem.rb +24 -0
  106. data/script/deterministic_scene.rb +56 -0
  107. data/script/update_deterministic_snapshot.rb +11 -0
  108. data/script/verify_platform_gem.rb +24 -0
  109. metadata +164 -0
@@ -0,0 +1,1457 @@
1
+ // SPDX-FileCopyrightText: 2023 Erin Catto
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ #pragma once
5
+
6
+ #include "base.h"
7
+ #include "collision.h"
8
+ #include "id.h"
9
+ #include "math_functions.h"
10
+
11
+ #include <stdbool.h>
12
+ #include <stdint.h>
13
+
14
+ #define B2_DEFAULT_CATEGORY_BITS 1
15
+ #define B2_DEFAULT_MASK_BITS UINT64_MAX
16
+
17
+ /// Task interface
18
+ /// This is prototype for a Box2D task. Your task system is expected to invoke the Box2D task with these arguments.
19
+ /// The task spans a range of the parallel-for: [startIndex, endIndex)
20
+ /// The worker index must correctly identify each worker in the user thread pool, expected in [0, workerCount).
21
+ /// A worker must only exist on only one thread at a time and is analogous to the thread index.
22
+ /// The task context is the context pointer sent from Box2D when it is enqueued.
23
+ /// The startIndex and endIndex are expected in the range [0, itemCount) where itemCount is the argument to b2EnqueueTaskCallback
24
+ /// below. Box2D expects startIndex < endIndex and will execute a loop like this:
25
+ ///
26
+ /// @code{.c}
27
+ /// for (int i = startIndex; i < endIndex; ++i)
28
+ /// {
29
+ /// DoWork();
30
+ /// }
31
+ /// @endcode
32
+ /// @ingroup world
33
+ typedef void b2TaskCallback( int startIndex, int endIndex, uint32_t workerIndex, void* taskContext );
34
+
35
+ /// These functions can be provided to Box2D to invoke a task system. These are designed to work well with enkiTS.
36
+ /// Returns a pointer to the user's task object. May be nullptr. A nullptr indicates to Box2D that the work was executed
37
+ /// serially within the callback and there is no need to call b2FinishTaskCallback.
38
+ /// The itemCount is the number of Box2D work items that are to be partitioned among workers by the user's task system.
39
+ /// This is essentially a parallel-for. The minRange parameter is a suggestion of the minimum number of items to assign
40
+ /// per worker to reduce overhead. For example, suppose the task is small and that itemCount is 16. A minRange of 8 suggests
41
+ /// that your task system should split the work items among just two workers, even if you have more available.
42
+ /// In general the range [startIndex, endIndex) send to b2TaskCallback should obey:
43
+ /// endIndex - startIndex >= minRange
44
+ /// The exception of course is when itemCount < minRange.
45
+ /// @ingroup world
46
+ typedef void* b2EnqueueTaskCallback( b2TaskCallback* task, int itemCount, int minRange, void* taskContext, void* userContext );
47
+
48
+ /// Finishes a user task object that wraps a Box2D task.
49
+ /// @ingroup world
50
+ typedef void b2FinishTaskCallback( void* userTask, void* userContext );
51
+
52
+ /// Optional friction mixing callback. This intentionally provides no context objects because this is called
53
+ /// from a worker thread.
54
+ /// @warning This function should not attempt to modify Box2D state or user application state.
55
+ /// @ingroup world
56
+ typedef float b2FrictionCallback( float frictionA, int userMaterialIdA, float frictionB, int userMaterialIdB );
57
+
58
+ /// Optional restitution mixing callback. This intentionally provides no context objects because this is called
59
+ /// from a worker thread.
60
+ /// @warning This function should not attempt to modify Box2D state or user application state.
61
+ /// @ingroup world
62
+ typedef float b2RestitutionCallback( float restitutionA, int userMaterialIdA, float restitutionB, int userMaterialIdB );
63
+
64
+ /// Result from b2World_RayCastClosest
65
+ /// @ingroup world
66
+ typedef struct b2RayResult
67
+ {
68
+ b2ShapeId shapeId;
69
+ b2Vec2 point;
70
+ b2Vec2 normal;
71
+ float fraction;
72
+ int nodeVisits;
73
+ int leafVisits;
74
+ bool hit;
75
+ } b2RayResult;
76
+
77
+ /// World definition used to create a simulation world.
78
+ /// Must be initialized using b2DefaultWorldDef().
79
+ /// @ingroup world
80
+ typedef struct b2WorldDef
81
+ {
82
+ /// Gravity vector. Box2D has no up-vector defined.
83
+ b2Vec2 gravity;
84
+
85
+ /// Restitution speed threshold, usually in m/s. Collisions above this
86
+ /// speed have restitution applied (will bounce).
87
+ float restitutionThreshold;
88
+
89
+ /// Threshold speed for hit events. Usually meters per second.
90
+ float hitEventThreshold;
91
+
92
+ /// Contact stiffness. Cycles per second. Increasing this increases the speed of overlap recovery, but can introduce jitter.
93
+ float contactHertz;
94
+
95
+ /// Contact bounciness. Non-dimensional. You can speed up overlap recovery by decreasing this with
96
+ /// the trade-off that overlap resolution becomes more energetic.
97
+ float contactDampingRatio;
98
+
99
+ /// This parameter controls how fast overlap is resolved and usually has units of meters per second. This only
100
+ /// puts a cap on the resolution speed. The resolution speed is increased by increasing the hertz and/or
101
+ /// decreasing the damping ratio.
102
+ float maxContactPushSpeed;
103
+
104
+ /// Joint stiffness. Cycles per second.
105
+ float jointHertz;
106
+
107
+ /// Joint bounciness. Non-dimensional.
108
+ float jointDampingRatio;
109
+
110
+ /// Maximum linear speed. Usually meters per second.
111
+ float maximumLinearSpeed;
112
+
113
+ /// Optional mixing callback for friction. The default uses sqrt(frictionA * frictionB).
114
+ b2FrictionCallback* frictionCallback;
115
+
116
+ /// Optional mixing callback for restitution. The default uses max(restitutionA, restitutionB).
117
+ b2RestitutionCallback* restitutionCallback;
118
+
119
+ /// Can bodies go to sleep to improve performance
120
+ bool enableSleep;
121
+
122
+ /// Enable continuous collision
123
+ bool enableContinuous;
124
+
125
+ /// Number of workers to use with the provided task system. Box2D performs best when using only
126
+ /// performance cores and accessing a single L2 cache. Efficiency cores and hyper-threading provide
127
+ /// little benefit and may even harm performance.
128
+ /// @note Box2D does not create threads. This is the number of threads your applications has created
129
+ /// that you are allocating to b2World_Step.
130
+ /// @warning Do not modify the default value unless you are also providing a task system and providing
131
+ /// task callbacks (enqueueTask and finishTask).
132
+ int workerCount;
133
+
134
+ /// Function to spawn tasks
135
+ b2EnqueueTaskCallback* enqueueTask;
136
+
137
+ /// Function to finish a task
138
+ b2FinishTaskCallback* finishTask;
139
+
140
+ /// User context that is provided to enqueueTask and finishTask
141
+ void* userTaskContext;
142
+
143
+ /// User data
144
+ void* userData;
145
+
146
+ /// Used internally to detect a valid definition. DO NOT SET.
147
+ int internalValue;
148
+ } b2WorldDef;
149
+
150
+ /// Use this to initialize your world definition
151
+ /// @ingroup world
152
+ B2_API b2WorldDef b2DefaultWorldDef( void );
153
+
154
+ /// The body simulation type.
155
+ /// Each body is one of these three types. The type determines how the body behaves in the simulation.
156
+ /// @ingroup body
157
+ typedef enum b2BodyType
158
+ {
159
+ /// zero mass, zero velocity, may be manually moved
160
+ b2_staticBody = 0,
161
+
162
+ /// zero mass, velocity set by user, moved by solver
163
+ b2_kinematicBody = 1,
164
+
165
+ /// positive mass, velocity determined by forces, moved by solver
166
+ b2_dynamicBody = 2,
167
+
168
+ /// number of body types
169
+ b2_bodyTypeCount,
170
+ } b2BodyType;
171
+
172
+ /// A body definition holds all the data needed to construct a rigid body.
173
+ /// You can safely re-use body definitions. Shapes are added to a body after construction.
174
+ /// Body definitions are temporary objects used to bundle creation parameters.
175
+ /// Must be initialized using b2DefaultBodyDef().
176
+ /// @ingroup body
177
+ typedef struct b2BodyDef
178
+ {
179
+ /// The body type: static, kinematic, or dynamic.
180
+ b2BodyType type;
181
+
182
+ /// The initial world position of the body. Bodies should be created with the desired position.
183
+ /// @note Creating bodies at the origin and then moving them nearly doubles the cost of body creation, especially
184
+ /// if the body is moved after shapes have been added.
185
+ b2Vec2 position;
186
+
187
+ /// The initial world rotation of the body. Use b2MakeRot() if you have an angle.
188
+ b2Rot rotation;
189
+
190
+ /// The initial linear velocity of the body's origin. Usually in meters per second.
191
+ b2Vec2 linearVelocity;
192
+
193
+ /// The initial angular velocity of the body. Radians per second.
194
+ float angularVelocity;
195
+
196
+ /// Linear damping is used to reduce the linear velocity. The damping parameter
197
+ /// can be larger than 1 but the damping effect becomes sensitive to the
198
+ /// time step when the damping parameter is large.
199
+ /// Generally linear damping is undesirable because it makes objects move slowly
200
+ /// as if they are floating.
201
+ float linearDamping;
202
+
203
+ /// Angular damping is used to reduce the angular velocity. The damping parameter
204
+ /// can be larger than 1.0f but the damping effect becomes sensitive to the
205
+ /// time step when the damping parameter is large.
206
+ /// Angular damping can be use slow down rotating bodies.
207
+ float angularDamping;
208
+
209
+ /// Scale the gravity applied to this body. Non-dimensional.
210
+ float gravityScale;
211
+
212
+ /// Sleep speed threshold, default is 0.05 meters per second
213
+ float sleepThreshold;
214
+
215
+ /// Optional body name for debugging. Up to 31 characters (excluding null termination)
216
+ const char* name;
217
+
218
+ /// Use this to store application specific body data.
219
+ void* userData;
220
+
221
+ /// Set this flag to false if this body should never fall asleep.
222
+ bool enableSleep;
223
+
224
+ /// Is this body initially awake or sleeping?
225
+ bool isAwake;
226
+
227
+ /// Should this body be prevented from rotating? Useful for characters.
228
+ bool fixedRotation;
229
+
230
+ /// Treat this body as high speed object that performs continuous collision detection
231
+ /// against dynamic and kinematic bodies, but not other bullet bodies.
232
+ /// @warning Bullets should be used sparingly. They are not a solution for general dynamic-versus-dynamic
233
+ /// continuous collision. They may interfere with joint constraints.
234
+ bool isBullet;
235
+
236
+ /// Used to disable a body. A disabled body does not move or collide.
237
+ bool isEnabled;
238
+
239
+ /// This allows this body to bypass rotational speed limits. Should only be used
240
+ /// for circular objects, like wheels.
241
+ bool allowFastRotation;
242
+
243
+ /// Used internally to detect a valid definition. DO NOT SET.
244
+ int internalValue;
245
+ } b2BodyDef;
246
+
247
+ /// Use this to initialize your body definition
248
+ /// @ingroup body
249
+ B2_API b2BodyDef b2DefaultBodyDef( void );
250
+
251
+ /// This is used to filter collision on shapes. It affects shape-vs-shape collision
252
+ /// and shape-versus-query collision (such as b2World_CastRay).
253
+ /// @ingroup shape
254
+ typedef struct b2Filter
255
+ {
256
+ /// The collision category bits. Normally you would just set one bit. The category bits should
257
+ /// represent your application object types. For example:
258
+ /// @code{.cpp}
259
+ /// enum MyCategories
260
+ /// {
261
+ /// Static = 0x00000001,
262
+ /// Dynamic = 0x00000002,
263
+ /// Debris = 0x00000004,
264
+ /// Player = 0x00000008,
265
+ /// // etc
266
+ /// };
267
+ /// @endcode
268
+ uint64_t categoryBits;
269
+
270
+ /// The collision mask bits. This states the categories that this
271
+ /// shape would accept for collision.
272
+ /// For example, you may want your player to only collide with static objects
273
+ /// and other players.
274
+ /// @code{.c}
275
+ /// maskBits = Static | Player;
276
+ /// @endcode
277
+ uint64_t maskBits;
278
+
279
+ /// Collision groups allow a certain group of objects to never collide (negative)
280
+ /// or always collide (positive). A group index of zero has no effect. Non-zero group filtering
281
+ /// always wins against the mask bits.
282
+ /// For example, you may want ragdolls to collide with other ragdolls but you don't want
283
+ /// ragdoll self-collision. In this case you would give each ragdoll a unique negative group index
284
+ /// and apply that group index to all shapes on the ragdoll.
285
+ int groupIndex;
286
+ } b2Filter;
287
+
288
+ /// Use this to initialize your filter
289
+ /// @ingroup shape
290
+ B2_API b2Filter b2DefaultFilter( void );
291
+
292
+ /// The query filter is used to filter collisions between queries and shapes. For example,
293
+ /// you may want a ray-cast representing a projectile to hit players and the static environment
294
+ /// but not debris.
295
+ /// @ingroup shape
296
+ typedef struct b2QueryFilter
297
+ {
298
+ /// The collision category bits of this query. Normally you would just set one bit.
299
+ uint64_t categoryBits;
300
+
301
+ /// The collision mask bits. This states the shape categories that this
302
+ /// query would accept for collision.
303
+ uint64_t maskBits;
304
+ } b2QueryFilter;
305
+
306
+ /// Use this to initialize your query filter
307
+ /// @ingroup shape
308
+ B2_API b2QueryFilter b2DefaultQueryFilter( void );
309
+
310
+ /// Shape type
311
+ /// @ingroup shape
312
+ typedef enum b2ShapeType
313
+ {
314
+ /// A circle with an offset
315
+ b2_circleShape,
316
+
317
+ /// A capsule is an extruded circle
318
+ b2_capsuleShape,
319
+
320
+ /// A line segment
321
+ b2_segmentShape,
322
+
323
+ /// A convex polygon
324
+ b2_polygonShape,
325
+
326
+ /// A line segment owned by a chain shape
327
+ b2_chainSegmentShape,
328
+
329
+ /// The number of shape types
330
+ b2_shapeTypeCount
331
+ } b2ShapeType;
332
+
333
+ /// Surface materials allow chain shapes to have per segment surface properties.
334
+ /// @ingroup shape
335
+ typedef struct b2SurfaceMaterial
336
+ {
337
+ /// The Coulomb (dry) friction coefficient, usually in the range [0,1].
338
+ float friction;
339
+
340
+ /// The coefficient of restitution (bounce) usually in the range [0,1].
341
+ /// https://en.wikipedia.org/wiki/Coefficient_of_restitution
342
+ float restitution;
343
+
344
+ /// The rolling resistance usually in the range [0,1].
345
+ float rollingResistance;
346
+
347
+ /// The tangent speed for conveyor belts
348
+ float tangentSpeed;
349
+
350
+ /// User material identifier. This is passed with query results and to friction and restitution
351
+ /// combining functions. It is not used internally.
352
+ int userMaterialId;
353
+
354
+ /// Custom debug draw color.
355
+ uint32_t customColor;
356
+ } b2SurfaceMaterial;
357
+
358
+ /// Use this to initialize your surface material
359
+ /// @ingroup shape
360
+ B2_API b2SurfaceMaterial b2DefaultSurfaceMaterial( void );
361
+
362
+ /// Used to create a shape.
363
+ /// This is a temporary object used to bundle shape creation parameters. You may use
364
+ /// the same shape definition to create multiple shapes.
365
+ /// Must be initialized using b2DefaultShapeDef().
366
+ /// @ingroup shape
367
+ typedef struct b2ShapeDef
368
+ {
369
+ /// Use this to store application specific shape data.
370
+ void* userData;
371
+
372
+ /// The surface material for this shape.
373
+ b2SurfaceMaterial material;
374
+
375
+ /// The density, usually in kg/m^2.
376
+ /// This is not part of the surface material because this is for the interior, which may have
377
+ /// other considerations, such as being hollow. For example a wood barrel may be hollow or full of water.
378
+ float density;
379
+
380
+ /// Collision filtering data.
381
+ b2Filter filter;
382
+
383
+ /// A sensor shape generates overlap events but never generates a collision response.
384
+ /// Sensors do not have continuous collision. Instead, use a ray or shape cast for those scenarios.
385
+ /// Sensors still contribute to the body mass if they have non-zero density.
386
+ /// @note Sensor events are disabled by default.
387
+ /// @see enableSensorEvents
388
+ bool isSensor;
389
+
390
+ /// Enable sensor events for this shape. This applies to sensors and non-sensors. False by default, even for sensors.
391
+ bool enableSensorEvents;
392
+
393
+ /// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default.
394
+ bool enableContactEvents;
395
+
396
+ /// Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default.
397
+ bool enableHitEvents;
398
+
399
+ /// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive
400
+ /// and must be carefully handled due to threading. Ignored for sensors.
401
+ bool enablePreSolveEvents;
402
+
403
+ /// When shapes are created they will scan the environment for collision the next time step. This can significantly slow down
404
+ /// static body creation when there are many static shapes.
405
+ /// This is flag is ignored for dynamic and kinematic shapes which always invoke contact creation.
406
+ bool invokeContactCreation;
407
+
408
+ /// Should the body update the mass properties when this shape is created. Default is true.
409
+ bool updateBodyMass;
410
+
411
+ /// Used internally to detect a valid definition. DO NOT SET.
412
+ int internalValue;
413
+ } b2ShapeDef;
414
+
415
+ /// Use this to initialize your shape definition
416
+ /// @ingroup shape
417
+ B2_API b2ShapeDef b2DefaultShapeDef( void );
418
+
419
+ /// Used to create a chain of line segments. This is designed to eliminate ghost collisions with some limitations.
420
+ /// - chains are one-sided
421
+ /// - chains have no mass and should be used on static bodies
422
+ /// - chains have a counter-clockwise winding order (normal points right of segment direction)
423
+ /// - chains are either a loop or open
424
+ /// - a chain must have at least 4 points
425
+ /// - the distance between any two points must be greater than B2_LINEAR_SLOP
426
+ /// - a chain shape should not self intersect (this is not validated)
427
+ /// - an open chain shape has NO COLLISION on the first and final edge
428
+ /// - you may overlap two open chains on their first three and/or last three points to get smooth collision
429
+ /// - a chain shape creates multiple line segment shapes on the body
430
+ /// https://en.wikipedia.org/wiki/Polygonal_chain
431
+ /// Must be initialized using b2DefaultChainDef().
432
+ /// @warning Do not use chain shapes unless you understand the limitations. This is an advanced feature.
433
+ /// @ingroup shape
434
+ typedef struct b2ChainDef
435
+ {
436
+ /// Use this to store application specific shape data.
437
+ void* userData;
438
+
439
+ /// An array of at least 4 points. These are cloned and may be temporary.
440
+ const b2Vec2* points;
441
+
442
+ /// The point count, must be 4 or more.
443
+ int count;
444
+
445
+ /// Surface materials for each segment. These are cloned.
446
+ const b2SurfaceMaterial* materials;
447
+
448
+ /// The material count. Must be 1 or count. This allows you to provide one
449
+ /// material for all segments or a unique material per segment.
450
+ int materialCount;
451
+
452
+ /// Contact filtering data.
453
+ b2Filter filter;
454
+
455
+ /// Indicates a closed chain formed by connecting the first and last points
456
+ bool isLoop;
457
+
458
+ /// Enable sensors to detect this chain. False by default.
459
+ bool enableSensorEvents;
460
+
461
+ /// Used internally to detect a valid definition. DO NOT SET.
462
+ int internalValue;
463
+ } b2ChainDef;
464
+
465
+ /// Use this to initialize your chain definition
466
+ /// @ingroup shape
467
+ B2_API b2ChainDef b2DefaultChainDef( void );
468
+
469
+ //! @cond
470
+ /// Profiling data. Times are in milliseconds.
471
+ typedef struct b2Profile
472
+ {
473
+ float step;
474
+ float pairs;
475
+ float collide;
476
+ float solve;
477
+ float mergeIslands;
478
+ float prepareStages;
479
+ float solveConstraints;
480
+ float prepareConstraints;
481
+ float integrateVelocities;
482
+ float warmStart;
483
+ float solveImpulses;
484
+ float integratePositions;
485
+ float relaxImpulses;
486
+ float applyRestitution;
487
+ float storeImpulses;
488
+ float splitIslands;
489
+ float transforms;
490
+ float hitEvents;
491
+ float refit;
492
+ float bullets;
493
+ float sleepIslands;
494
+ float sensors;
495
+ } b2Profile;
496
+
497
+ /// Counters that give details of the simulation size.
498
+ typedef struct b2Counters
499
+ {
500
+ int bodyCount;
501
+ int shapeCount;
502
+ int contactCount;
503
+ int jointCount;
504
+ int islandCount;
505
+ int stackUsed;
506
+ int staticTreeHeight;
507
+ int treeHeight;
508
+ int byteCount;
509
+ int taskCount;
510
+ int colorCounts[12];
511
+ } b2Counters;
512
+ //! @endcond
513
+
514
+ /// Joint type enumeration
515
+ ///
516
+ /// This is useful because all joint types use b2JointId and sometimes you
517
+ /// want to get the type of a joint.
518
+ /// @ingroup joint
519
+ typedef enum b2JointType
520
+ {
521
+ b2_distanceJoint,
522
+ b2_filterJoint,
523
+ b2_motorJoint,
524
+ b2_mouseJoint,
525
+ b2_prismaticJoint,
526
+ b2_revoluteJoint,
527
+ b2_weldJoint,
528
+ b2_wheelJoint,
529
+ } b2JointType;
530
+
531
+ /// Distance joint definition
532
+ ///
533
+ /// This requires defining an anchor point on both
534
+ /// bodies and the non-zero distance of the distance joint. The definition uses
535
+ /// local anchor points so that the initial configuration can violate the
536
+ /// constraint slightly. This helps when saving and loading a game.
537
+ /// @ingroup distance_joint
538
+ typedef struct b2DistanceJointDef
539
+ {
540
+ /// The first attached body
541
+ b2BodyId bodyIdA;
542
+
543
+ /// The second attached body
544
+ b2BodyId bodyIdB;
545
+
546
+ /// The local anchor point relative to bodyA's origin
547
+ b2Vec2 localAnchorA;
548
+
549
+ /// The local anchor point relative to bodyB's origin
550
+ b2Vec2 localAnchorB;
551
+
552
+ /// The rest length of this joint. Clamped to a stable minimum value.
553
+ float length;
554
+
555
+ /// Enable the distance constraint to behave like a spring. If false
556
+ /// then the distance joint will be rigid, overriding the limit and motor.
557
+ bool enableSpring;
558
+
559
+ /// The spring linear stiffness Hertz, cycles per second
560
+ float hertz;
561
+
562
+ /// The spring linear damping ratio, non-dimensional
563
+ float dampingRatio;
564
+
565
+ /// Enable/disable the joint limit
566
+ bool enableLimit;
567
+
568
+ /// Minimum length. Clamped to a stable minimum value.
569
+ float minLength;
570
+
571
+ /// Maximum length. Must be greater than or equal to the minimum length.
572
+ float maxLength;
573
+
574
+ /// Enable/disable the joint motor
575
+ bool enableMotor;
576
+
577
+ /// The maximum motor force, usually in newtons
578
+ float maxMotorForce;
579
+
580
+ /// The desired motor speed, usually in meters per second
581
+ float motorSpeed;
582
+
583
+ /// Set this flag to true if the attached bodies should collide
584
+ bool collideConnected;
585
+
586
+ /// User data pointer
587
+ void* userData;
588
+
589
+ /// Used internally to detect a valid definition. DO NOT SET.
590
+ int internalValue;
591
+ } b2DistanceJointDef;
592
+
593
+ /// Use this to initialize your joint definition
594
+ /// @ingroup distance_joint
595
+ B2_API b2DistanceJointDef b2DefaultDistanceJointDef( void );
596
+
597
+ /// A motor joint is used to control the relative motion between two bodies
598
+ ///
599
+ /// A typical usage is to control the movement of a dynamic body with respect to the ground.
600
+ /// @ingroup motor_joint
601
+ typedef struct b2MotorJointDef
602
+ {
603
+ /// The first attached body
604
+ b2BodyId bodyIdA;
605
+
606
+ /// The second attached body
607
+ b2BodyId bodyIdB;
608
+
609
+ /// Position of bodyB minus the position of bodyA, in bodyA's frame
610
+ b2Vec2 linearOffset;
611
+
612
+ /// The bodyB angle minus bodyA angle in radians
613
+ float angularOffset;
614
+
615
+ /// The maximum motor force in newtons
616
+ float maxForce;
617
+
618
+ /// The maximum motor torque in newton-meters
619
+ float maxTorque;
620
+
621
+ /// Position correction factor in the range [0,1]
622
+ float correctionFactor;
623
+
624
+ /// Set this flag to true if the attached bodies should collide
625
+ bool collideConnected;
626
+
627
+ /// User data pointer
628
+ void* userData;
629
+
630
+ /// Used internally to detect a valid definition. DO NOT SET.
631
+ int internalValue;
632
+ } b2MotorJointDef;
633
+
634
+ /// Use this to initialize your joint definition
635
+ /// @ingroup motor_joint
636
+ B2_API b2MotorJointDef b2DefaultMotorJointDef( void );
637
+
638
+ /// A mouse joint is used to make a point on a body track a specified world point.
639
+ ///
640
+ /// This a soft constraint and allows the constraint to stretch without
641
+ /// applying huge forces. This also applies rotation constraint heuristic to improve control.
642
+ /// @ingroup mouse_joint
643
+ typedef struct b2MouseJointDef
644
+ {
645
+ /// The first attached body. This is assumed to be static.
646
+ b2BodyId bodyIdA;
647
+
648
+ /// The second attached body.
649
+ b2BodyId bodyIdB;
650
+
651
+ /// The initial target point in world space
652
+ b2Vec2 target;
653
+
654
+ /// Stiffness in hertz
655
+ float hertz;
656
+
657
+ /// Damping ratio, non-dimensional
658
+ float dampingRatio;
659
+
660
+ /// Maximum force, typically in newtons
661
+ float maxForce;
662
+
663
+ /// Set this flag to true if the attached bodies should collide.
664
+ bool collideConnected;
665
+
666
+ /// User data pointer
667
+ void* userData;
668
+
669
+ /// Used internally to detect a valid definition. DO NOT SET.
670
+ int internalValue;
671
+ } b2MouseJointDef;
672
+
673
+ /// Use this to initialize your joint definition
674
+ /// @ingroup mouse_joint
675
+ B2_API b2MouseJointDef b2DefaultMouseJointDef( void );
676
+
677
+ /// A filter joint is used to disable collision between two specific bodies.
678
+ ///
679
+ /// @ingroup filter_joint
680
+ typedef struct b2FilterJointDef
681
+ {
682
+ /// The first attached body.
683
+ b2BodyId bodyIdA;
684
+
685
+ /// The second attached body.
686
+ b2BodyId bodyIdB;
687
+
688
+ /// User data pointer
689
+ void* userData;
690
+
691
+ /// Used internally to detect a valid definition. DO NOT SET.
692
+ int internalValue;
693
+ } b2FilterJointDef;
694
+
695
+ /// Use this to initialize your joint definition
696
+ /// @ingroup filter_joint
697
+ B2_API b2FilterJointDef b2DefaultFilterJointDef( void );
698
+
699
+ /// Prismatic joint definition
700
+ ///
701
+ /// This requires defining a line of motion using an axis and an anchor point.
702
+ /// The definition uses local anchor points and a local axis so that the initial
703
+ /// configuration can violate the constraint slightly. The joint translation is zero
704
+ /// when the local anchor points coincide in world space.
705
+ /// @ingroup prismatic_joint
706
+ typedef struct b2PrismaticJointDef
707
+ {
708
+ /// The first attached body
709
+ b2BodyId bodyIdA;
710
+
711
+ /// The second attached body
712
+ b2BodyId bodyIdB;
713
+
714
+ /// The local anchor point relative to bodyA's origin
715
+ b2Vec2 localAnchorA;
716
+
717
+ /// The local anchor point relative to bodyB's origin
718
+ b2Vec2 localAnchorB;
719
+
720
+ /// The local translation unit axis in bodyA
721
+ b2Vec2 localAxisA;
722
+
723
+ /// The constrained angle between the bodies: bodyB_angle - bodyA_angle
724
+ float referenceAngle;
725
+
726
+ /// Enable a linear spring along the prismatic joint axis
727
+ bool enableSpring;
728
+
729
+ /// The spring stiffness Hertz, cycles per second
730
+ float hertz;
731
+
732
+ /// The spring damping ratio, non-dimensional
733
+ float dampingRatio;
734
+
735
+ /// Enable/disable the joint limit
736
+ bool enableLimit;
737
+
738
+ /// The lower translation limit
739
+ float lowerTranslation;
740
+
741
+ /// The upper translation limit
742
+ float upperTranslation;
743
+
744
+ /// Enable/disable the joint motor
745
+ bool enableMotor;
746
+
747
+ /// The maximum motor force, typically in newtons
748
+ float maxMotorForce;
749
+
750
+ /// The desired motor speed, typically in meters per second
751
+ float motorSpeed;
752
+
753
+ /// Set this flag to true if the attached bodies should collide
754
+ bool collideConnected;
755
+
756
+ /// User data pointer
757
+ void* userData;
758
+
759
+ /// Used internally to detect a valid definition. DO NOT SET.
760
+ int internalValue;
761
+ } b2PrismaticJointDef;
762
+
763
+ /// Use this to initialize your joint definition
764
+ /// @ingroupd prismatic_joint
765
+ B2_API b2PrismaticJointDef b2DefaultPrismaticJointDef( void );
766
+
767
+ /// Revolute joint definition
768
+ ///
769
+ /// This requires defining an anchor point where the bodies are joined.
770
+ /// The definition uses local anchor points so that the
771
+ /// initial configuration can violate the constraint slightly. You also need to
772
+ /// specify the initial relative angle for joint limits. This helps when saving
773
+ /// and loading a game.
774
+ /// The local anchor points are measured from the body's origin
775
+ /// rather than the center of mass because:
776
+ /// 1. you might not know where the center of mass will be
777
+ /// 2. if you add/remove shapes from a body and recompute the mass, the joints will be broken
778
+ /// @ingroup revolute_joint
779
+ typedef struct b2RevoluteJointDef
780
+ {
781
+ /// The first attached body
782
+ b2BodyId bodyIdA;
783
+
784
+ /// The second attached body
785
+ b2BodyId bodyIdB;
786
+
787
+ /// The local anchor point relative to bodyA's origin
788
+ b2Vec2 localAnchorA;
789
+
790
+ /// The local anchor point relative to bodyB's origin
791
+ b2Vec2 localAnchorB;
792
+
793
+ /// The bodyB angle minus bodyA angle in the reference state (radians).
794
+ /// This defines the zero angle for the joint limit.
795
+ float referenceAngle;
796
+
797
+ /// Enable a rotational spring on the revolute hinge axis
798
+ bool enableSpring;
799
+
800
+ /// The spring stiffness Hertz, cycles per second
801
+ float hertz;
802
+
803
+ /// The spring damping ratio, non-dimensional
804
+ float dampingRatio;
805
+
806
+ /// A flag to enable joint limits
807
+ bool enableLimit;
808
+
809
+ /// The lower angle for the joint limit in radians. Minimum of -0.95*pi radians.
810
+ float lowerAngle;
811
+
812
+ /// The upper angle for the joint limit in radians. Maximum of 0.95*pi radians.
813
+ float upperAngle;
814
+
815
+ /// A flag to enable the joint motor
816
+ bool enableMotor;
817
+
818
+ /// The maximum motor torque, typically in newton-meters
819
+ float maxMotorTorque;
820
+
821
+ /// The desired motor speed in radians per second
822
+ float motorSpeed;
823
+
824
+ /// Scale the debug draw
825
+ float drawSize;
826
+
827
+ /// Set this flag to true if the attached bodies should collide
828
+ bool collideConnected;
829
+
830
+ /// User data pointer
831
+ void* userData;
832
+
833
+ /// Used internally to detect a valid definition. DO NOT SET.
834
+ int internalValue;
835
+ } b2RevoluteJointDef;
836
+
837
+ /// Use this to initialize your joint definition.
838
+ /// @ingroup revolute_joint
839
+ B2_API b2RevoluteJointDef b2DefaultRevoluteJointDef( void );
840
+
841
+ /// Weld joint definition
842
+ ///
843
+ /// A weld joint connect to bodies together rigidly. This constraint provides springs to mimic
844
+ /// soft-body simulation.
845
+ /// @note The approximate solver in Box2D cannot hold many bodies together rigidly
846
+ /// @ingroup weld_joint
847
+ typedef struct b2WeldJointDef
848
+ {
849
+ /// The first attached body
850
+ b2BodyId bodyIdA;
851
+
852
+ /// The second attached body
853
+ b2BodyId bodyIdB;
854
+
855
+ /// The local anchor point relative to bodyA's origin
856
+ b2Vec2 localAnchorA;
857
+
858
+ /// The local anchor point relative to bodyB's origin
859
+ b2Vec2 localAnchorB;
860
+
861
+ /// The bodyB angle minus bodyA angle in the reference state (radians)
862
+ /// todo maybe make this a b2Rot
863
+ float referenceAngle;
864
+
865
+ /// Linear stiffness expressed as Hertz (cycles per second). Use zero for maximum stiffness.
866
+ float linearHertz;
867
+
868
+ /// Angular stiffness as Hertz (cycles per second). Use zero for maximum stiffness.
869
+ float angularHertz;
870
+
871
+ /// Linear damping ratio, non-dimensional. Use 1 for critical damping.
872
+ float linearDampingRatio;
873
+
874
+ /// Linear damping ratio, non-dimensional. Use 1 for critical damping.
875
+ float angularDampingRatio;
876
+
877
+ /// Set this flag to true if the attached bodies should collide
878
+ bool collideConnected;
879
+
880
+ /// User data pointer
881
+ void* userData;
882
+
883
+ /// Used internally to detect a valid definition. DO NOT SET.
884
+ int internalValue;
885
+ } b2WeldJointDef;
886
+
887
+ /// Use this to initialize your joint definition
888
+ /// @ingroup weld_joint
889
+ B2_API b2WeldJointDef b2DefaultWeldJointDef( void );
890
+
891
+ /// Wheel joint definition
892
+ ///
893
+ /// This requires defining a line of motion using an axis and an anchor point.
894
+ /// The definition uses local anchor points and a local axis so that the initial
895
+ /// configuration can violate the constraint slightly. The joint translation is zero
896
+ /// when the local anchor points coincide in world space.
897
+ /// @ingroup wheel_joint
898
+ typedef struct b2WheelJointDef
899
+ {
900
+ /// The first attached body
901
+ b2BodyId bodyIdA;
902
+
903
+ /// The second attached body
904
+ b2BodyId bodyIdB;
905
+
906
+ /// The local anchor point relative to bodyA's origin
907
+ b2Vec2 localAnchorA;
908
+
909
+ /// The local anchor point relative to bodyB's origin
910
+ b2Vec2 localAnchorB;
911
+
912
+ /// The local translation unit axis in bodyA
913
+ b2Vec2 localAxisA;
914
+
915
+ /// Enable a linear spring along the local axis
916
+ bool enableSpring;
917
+
918
+ /// Spring stiffness in Hertz
919
+ float hertz;
920
+
921
+ /// Spring damping ratio, non-dimensional
922
+ float dampingRatio;
923
+
924
+ /// Enable/disable the joint linear limit
925
+ bool enableLimit;
926
+
927
+ /// The lower translation limit
928
+ float lowerTranslation;
929
+
930
+ /// The upper translation limit
931
+ float upperTranslation;
932
+
933
+ /// Enable/disable the joint rotational motor
934
+ bool enableMotor;
935
+
936
+ /// The maximum motor torque, typically in newton-meters
937
+ float maxMotorTorque;
938
+
939
+ /// The desired motor speed in radians per second
940
+ float motorSpeed;
941
+
942
+ /// Set this flag to true if the attached bodies should collide
943
+ bool collideConnected;
944
+
945
+ /// User data pointer
946
+ void* userData;
947
+
948
+ /// Used internally to detect a valid definition. DO NOT SET.
949
+ int internalValue;
950
+ } b2WheelJointDef;
951
+
952
+ /// Use this to initialize your joint definition
953
+ /// @ingroup wheel_joint
954
+ B2_API b2WheelJointDef b2DefaultWheelJointDef( void );
955
+
956
+ /// The explosion definition is used to configure options for explosions. Explosions
957
+ /// consider shape geometry when computing the impulse.
958
+ /// @ingroup world
959
+ typedef struct b2ExplosionDef
960
+ {
961
+ /// Mask bits to filter shapes
962
+ uint64_t maskBits;
963
+
964
+ /// The center of the explosion in world space
965
+ b2Vec2 position;
966
+
967
+ /// The radius of the explosion
968
+ float radius;
969
+
970
+ /// The falloff distance beyond the radius. Impulse is reduced to zero at this distance.
971
+ float falloff;
972
+
973
+ /// Impulse per unit length. This applies an impulse according to the shape perimeter that
974
+ /// is facing the explosion. Explosions only apply to circles, capsules, and polygons. This
975
+ /// may be negative for implosions.
976
+ float impulsePerLength;
977
+ } b2ExplosionDef;
978
+
979
+ /// Use this to initialize your explosion definition
980
+ /// @ingroup world
981
+ B2_API b2ExplosionDef b2DefaultExplosionDef( void );
982
+
983
+ /**
984
+ * @defgroup events Events
985
+ * World event types.
986
+ *
987
+ * Events are used to collect events that occur during the world time step. These events
988
+ * are then available to query after the time step is complete. This is preferable to callbacks
989
+ * because Box2D uses multithreaded simulation.
990
+ *
991
+ * Also when events occur in the simulation step it may be problematic to modify the world, which is
992
+ * often what applications want to do when events occur.
993
+ *
994
+ * With event arrays, you can scan the events in a loop and modify the world. However, you need to be careful
995
+ * that some event data may become invalid. There are several samples that show how to do this safely.
996
+ *
997
+ * @{
998
+ */
999
+
1000
+ /// A begin touch event is generated when a shape starts to overlap a sensor shape.
1001
+ typedef struct b2SensorBeginTouchEvent
1002
+ {
1003
+ /// The id of the sensor shape
1004
+ b2ShapeId sensorShapeId;
1005
+
1006
+ /// The id of the dynamic shape that began touching the sensor shape
1007
+ b2ShapeId visitorShapeId;
1008
+ } b2SensorBeginTouchEvent;
1009
+
1010
+ /// An end touch event is generated when a shape stops overlapping a sensor shape.
1011
+ /// These include things like setting the transform, destroying a body or shape, or changing
1012
+ /// a filter. You will also get an end event if the sensor or visitor are destroyed.
1013
+ /// Therefore you should always confirm the shape id is valid using b2Shape_IsValid.
1014
+ typedef struct b2SensorEndTouchEvent
1015
+ {
1016
+ /// The id of the sensor shape
1017
+ /// @warning this shape may have been destroyed
1018
+ /// @see b2Shape_IsValid
1019
+ b2ShapeId sensorShapeId;
1020
+
1021
+ /// The id of the dynamic shape that stopped touching the sensor shape
1022
+ /// @warning this shape may have been destroyed
1023
+ /// @see b2Shape_IsValid
1024
+ b2ShapeId visitorShapeId;
1025
+
1026
+ } b2SensorEndTouchEvent;
1027
+
1028
+ /// Sensor events are buffered in the Box2D world and are available
1029
+ /// as begin/end overlap event arrays after the time step is complete.
1030
+ /// Note: these may become invalid if bodies and/or shapes are destroyed
1031
+ typedef struct b2SensorEvents
1032
+ {
1033
+ /// Array of sensor begin touch events
1034
+ b2SensorBeginTouchEvent* beginEvents;
1035
+
1036
+ /// Array of sensor end touch events
1037
+ b2SensorEndTouchEvent* endEvents;
1038
+
1039
+ /// The number of begin touch events
1040
+ int beginCount;
1041
+
1042
+ /// The number of end touch events
1043
+ int endCount;
1044
+ } b2SensorEvents;
1045
+
1046
+ /// A begin touch event is generated when two shapes begin touching.
1047
+ typedef struct b2ContactBeginTouchEvent
1048
+ {
1049
+ /// Id of the first shape
1050
+ b2ShapeId shapeIdA;
1051
+
1052
+ /// Id of the second shape
1053
+ b2ShapeId shapeIdB;
1054
+
1055
+ /// The initial contact manifold. This is recorded before the solver is called,
1056
+ /// so all the impulses will be zero.
1057
+ b2Manifold manifold;
1058
+ } b2ContactBeginTouchEvent;
1059
+
1060
+ /// An end touch event is generated when two shapes stop touching.
1061
+ /// You will get an end event if you do anything that destroys contacts previous to the last
1062
+ /// world step. These include things like setting the transform, destroying a body
1063
+ /// or shape, or changing a filter or body type.
1064
+ typedef struct b2ContactEndTouchEvent
1065
+ {
1066
+ /// Id of the first shape
1067
+ /// @warning this shape may have been destroyed
1068
+ /// @see b2Shape_IsValid
1069
+ b2ShapeId shapeIdA;
1070
+
1071
+ /// Id of the second shape
1072
+ /// @warning this shape may have been destroyed
1073
+ /// @see b2Shape_IsValid
1074
+ b2ShapeId shapeIdB;
1075
+ } b2ContactEndTouchEvent;
1076
+
1077
+ /// A hit touch event is generated when two shapes collide with a speed faster than the hit speed threshold.
1078
+ typedef struct b2ContactHitEvent
1079
+ {
1080
+ /// Id of the first shape
1081
+ b2ShapeId shapeIdA;
1082
+
1083
+ /// Id of the second shape
1084
+ b2ShapeId shapeIdB;
1085
+
1086
+ /// Point where the shapes hit
1087
+ b2Vec2 point;
1088
+
1089
+ /// Normal vector pointing from shape A to shape B
1090
+ b2Vec2 normal;
1091
+
1092
+ /// The speed the shapes are approaching. Always positive. Typically in meters per second.
1093
+ float approachSpeed;
1094
+ } b2ContactHitEvent;
1095
+
1096
+ /// Contact events are buffered in the Box2D world and are available
1097
+ /// as event arrays after the time step is complete.
1098
+ /// Note: these may become invalid if bodies and/or shapes are destroyed
1099
+ typedef struct b2ContactEvents
1100
+ {
1101
+ /// Array of begin touch events
1102
+ b2ContactBeginTouchEvent* beginEvents;
1103
+
1104
+ /// Array of end touch events
1105
+ b2ContactEndTouchEvent* endEvents;
1106
+
1107
+ /// Array of hit events
1108
+ b2ContactHitEvent* hitEvents;
1109
+
1110
+ /// Number of begin touch events
1111
+ int beginCount;
1112
+
1113
+ /// Number of end touch events
1114
+ int endCount;
1115
+
1116
+ /// Number of hit events
1117
+ int hitCount;
1118
+ } b2ContactEvents;
1119
+
1120
+ /// Body move events triggered when a body moves.
1121
+ /// Triggered when a body moves due to simulation. Not reported for bodies moved by the user.
1122
+ /// This also has a flag to indicate that the body went to sleep so the application can also
1123
+ /// sleep that actor/entity/object associated with the body.
1124
+ /// On the other hand if the flag does not indicate the body went to sleep then the application
1125
+ /// can treat the actor/entity/object associated with the body as awake.
1126
+ /// This is an efficient way for an application to update game object transforms rather than
1127
+ /// calling functions such as b2Body_GetTransform() because this data is delivered as a contiguous array
1128
+ /// and it is only populated with bodies that have moved.
1129
+ /// @note If sleeping is disabled all dynamic and kinematic bodies will trigger move events.
1130
+ typedef struct b2BodyMoveEvent
1131
+ {
1132
+ b2Transform transform;
1133
+ b2BodyId bodyId;
1134
+ void* userData;
1135
+ bool fellAsleep;
1136
+ } b2BodyMoveEvent;
1137
+
1138
+ /// Body events are buffered in the Box2D world and are available
1139
+ /// as event arrays after the time step is complete.
1140
+ /// Note: this data becomes invalid if bodies are destroyed
1141
+ typedef struct b2BodyEvents
1142
+ {
1143
+ /// Array of move events
1144
+ b2BodyMoveEvent* moveEvents;
1145
+
1146
+ /// Number of move events
1147
+ int moveCount;
1148
+ } b2BodyEvents;
1149
+
1150
+ /// The contact data for two shapes. By convention the manifold normal points
1151
+ /// from shape A to shape B.
1152
+ /// @see b2Shape_GetContactData() and b2Body_GetContactData()
1153
+ typedef struct b2ContactData
1154
+ {
1155
+ b2ShapeId shapeIdA;
1156
+ b2ShapeId shapeIdB;
1157
+ b2Manifold manifold;
1158
+ } b2ContactData;
1159
+
1160
+ /**@}*/
1161
+
1162
+ /// Prototype for a contact filter callback.
1163
+ /// This is called when a contact pair is considered for collision. This allows you to
1164
+ /// perform custom logic to prevent collision between shapes. This is only called if
1165
+ /// one of the two shapes has custom filtering enabled.
1166
+ /// Notes:
1167
+ /// - this function must be thread-safe
1168
+ /// - this is only called if one of the two shapes has enabled custom filtering
1169
+ /// - this is called only for awake dynamic bodies
1170
+ /// Return false if you want to disable the collision
1171
+ /// @see b2ShapeDef
1172
+ /// @warning Do not attempt to modify the world inside this callback
1173
+ /// @ingroup world
1174
+ typedef bool b2CustomFilterFcn( b2ShapeId shapeIdA, b2ShapeId shapeIdB, void* context );
1175
+
1176
+ /// Prototype for a pre-solve callback.
1177
+ /// This is called after a contact is updated. This allows you to inspect a
1178
+ /// contact before it goes to the solver. If you are careful, you can modify the
1179
+ /// contact manifold (e.g. modify the normal).
1180
+ /// Notes:
1181
+ /// - this function must be thread-safe
1182
+ /// - this is only called if the shape has enabled pre-solve events
1183
+ /// - this is called only for awake dynamic bodies
1184
+ /// - this is not called for sensors
1185
+ /// - the supplied manifold has impulse values from the previous step
1186
+ /// Return false if you want to disable the contact this step
1187
+ /// @warning Do not attempt to modify the world inside this callback
1188
+ /// @ingroup world
1189
+ typedef bool b2PreSolveFcn( b2ShapeId shapeIdA, b2ShapeId shapeIdB, b2Manifold* manifold, void* context );
1190
+
1191
+ /// Prototype callback for overlap queries.
1192
+ /// Called for each shape found in the query.
1193
+ /// @see b2World_OverlapABB
1194
+ /// @return false to terminate the query.
1195
+ /// @ingroup world
1196
+ typedef bool b2OverlapResultFcn( b2ShapeId shapeId, void* context );
1197
+
1198
+ /// Prototype callback for ray casts.
1199
+ /// Called for each shape found in the query. You control how the ray cast
1200
+ /// proceeds by returning a float:
1201
+ /// return -1: ignore this shape and continue
1202
+ /// return 0: terminate the ray cast
1203
+ /// return fraction: clip the ray to this point
1204
+ /// return 1: don't clip the ray and continue
1205
+ /// @param shapeId the shape hit by the ray
1206
+ /// @param point the point of initial intersection
1207
+ /// @param normal the normal vector at the point of intersection
1208
+ /// @param fraction the fraction along the ray at the point of intersection
1209
+ /// @param context the user context
1210
+ /// @return -1 to filter, 0 to terminate, fraction to clip the ray for closest hit, 1 to continue
1211
+ /// @see b2World_CastRay
1212
+ /// @ingroup world
1213
+ typedef float b2CastResultFcn( b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, float fraction, void* context );
1214
+
1215
+ // Used to collect collision planes for character movers.
1216
+ // Return true to continue gathering planes.
1217
+ typedef bool b2PlaneResultFcn( b2ShapeId shapeId, const b2PlaneResult* plane, void* context );
1218
+
1219
+ /// These colors are used for debug draw and mostly match the named SVG colors.
1220
+ /// See https://www.rapidtables.com/web/color/index.html
1221
+ /// https://johndecember.com/html/spec/colorsvg.html
1222
+ /// https://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg
1223
+ typedef enum b2HexColor
1224
+ {
1225
+ b2_colorAliceBlue = 0xF0F8FF,
1226
+ b2_colorAntiqueWhite = 0xFAEBD7,
1227
+ b2_colorAqua = 0x00FFFF,
1228
+ b2_colorAquamarine = 0x7FFFD4,
1229
+ b2_colorAzure = 0xF0FFFF,
1230
+ b2_colorBeige = 0xF5F5DC,
1231
+ b2_colorBisque = 0xFFE4C4,
1232
+ b2_colorBlack = 0x000000,
1233
+ b2_colorBlanchedAlmond = 0xFFEBCD,
1234
+ b2_colorBlue = 0x0000FF,
1235
+ b2_colorBlueViolet = 0x8A2BE2,
1236
+ b2_colorBrown = 0xA52A2A,
1237
+ b2_colorBurlywood = 0xDEB887,
1238
+ b2_colorCadetBlue = 0x5F9EA0,
1239
+ b2_colorChartreuse = 0x7FFF00,
1240
+ b2_colorChocolate = 0xD2691E,
1241
+ b2_colorCoral = 0xFF7F50,
1242
+ b2_colorCornflowerBlue = 0x6495ED,
1243
+ b2_colorCornsilk = 0xFFF8DC,
1244
+ b2_colorCrimson = 0xDC143C,
1245
+ b2_colorCyan = 0x00FFFF,
1246
+ b2_colorDarkBlue = 0x00008B,
1247
+ b2_colorDarkCyan = 0x008B8B,
1248
+ b2_colorDarkGoldenRod = 0xB8860B,
1249
+ b2_colorDarkGray = 0xA9A9A9,
1250
+ b2_colorDarkGreen = 0x006400,
1251
+ b2_colorDarkKhaki = 0xBDB76B,
1252
+ b2_colorDarkMagenta = 0x8B008B,
1253
+ b2_colorDarkOliveGreen = 0x556B2F,
1254
+ b2_colorDarkOrange = 0xFF8C00,
1255
+ b2_colorDarkOrchid = 0x9932CC,
1256
+ b2_colorDarkRed = 0x8B0000,
1257
+ b2_colorDarkSalmon = 0xE9967A,
1258
+ b2_colorDarkSeaGreen = 0x8FBC8F,
1259
+ b2_colorDarkSlateBlue = 0x483D8B,
1260
+ b2_colorDarkSlateGray = 0x2F4F4F,
1261
+ b2_colorDarkTurquoise = 0x00CED1,
1262
+ b2_colorDarkViolet = 0x9400D3,
1263
+ b2_colorDeepPink = 0xFF1493,
1264
+ b2_colorDeepSkyBlue = 0x00BFFF,
1265
+ b2_colorDimGray = 0x696969,
1266
+ b2_colorDodgerBlue = 0x1E90FF,
1267
+ b2_colorFireBrick = 0xB22222,
1268
+ b2_colorFloralWhite = 0xFFFAF0,
1269
+ b2_colorForestGreen = 0x228B22,
1270
+ b2_colorFuchsia = 0xFF00FF,
1271
+ b2_colorGainsboro = 0xDCDCDC,
1272
+ b2_colorGhostWhite = 0xF8F8FF,
1273
+ b2_colorGold = 0xFFD700,
1274
+ b2_colorGoldenRod = 0xDAA520,
1275
+ b2_colorGray = 0x808080,
1276
+ b2_colorGreen = 0x008000,
1277
+ b2_colorGreenYellow = 0xADFF2F,
1278
+ b2_colorHoneyDew = 0xF0FFF0,
1279
+ b2_colorHotPink = 0xFF69B4,
1280
+ b2_colorIndianRed = 0xCD5C5C,
1281
+ b2_colorIndigo = 0x4B0082,
1282
+ b2_colorIvory = 0xFFFFF0,
1283
+ b2_colorKhaki = 0xF0E68C,
1284
+ b2_colorLavender = 0xE6E6FA,
1285
+ b2_colorLavenderBlush = 0xFFF0F5,
1286
+ b2_colorLawnGreen = 0x7CFC00,
1287
+ b2_colorLemonChiffon = 0xFFFACD,
1288
+ b2_colorLightBlue = 0xADD8E6,
1289
+ b2_colorLightCoral = 0xF08080,
1290
+ b2_colorLightCyan = 0xE0FFFF,
1291
+ b2_colorLightGoldenRodYellow = 0xFAFAD2,
1292
+ b2_colorLightGray = 0xD3D3D3,
1293
+ b2_colorLightGreen = 0x90EE90,
1294
+ b2_colorLightPink = 0xFFB6C1,
1295
+ b2_colorLightSalmon = 0xFFA07A,
1296
+ b2_colorLightSeaGreen = 0x20B2AA,
1297
+ b2_colorLightSkyBlue = 0x87CEFA,
1298
+ b2_colorLightSlateGray = 0x778899,
1299
+ b2_colorLightSteelBlue = 0xB0C4DE,
1300
+ b2_colorLightYellow = 0xFFFFE0,
1301
+ b2_colorLime = 0x00FF00,
1302
+ b2_colorLimeGreen = 0x32CD32,
1303
+ b2_colorLinen = 0xFAF0E6,
1304
+ b2_colorMagenta = 0xFF00FF,
1305
+ b2_colorMaroon = 0x800000,
1306
+ b2_colorMediumAquaMarine = 0x66CDAA,
1307
+ b2_colorMediumBlue = 0x0000CD,
1308
+ b2_colorMediumOrchid = 0xBA55D3,
1309
+ b2_colorMediumPurple = 0x9370DB,
1310
+ b2_colorMediumSeaGreen = 0x3CB371,
1311
+ b2_colorMediumSlateBlue = 0x7B68EE,
1312
+ b2_colorMediumSpringGreen = 0x00FA9A,
1313
+ b2_colorMediumTurquoise = 0x48D1CC,
1314
+ b2_colorMediumVioletRed = 0xC71585,
1315
+ b2_colorMidnightBlue = 0x191970,
1316
+ b2_colorMintCream = 0xF5FFFA,
1317
+ b2_colorMistyRose = 0xFFE4E1,
1318
+ b2_colorMoccasin = 0xFFE4B5,
1319
+ b2_colorNavajoWhite = 0xFFDEAD,
1320
+ b2_colorNavy = 0x000080,
1321
+ b2_colorOldLace = 0xFDF5E6,
1322
+ b2_colorOlive = 0x808000,
1323
+ b2_colorOliveDrab = 0x6B8E23,
1324
+ b2_colorOrange = 0xFFA500,
1325
+ b2_colorOrangeRed = 0xFF4500,
1326
+ b2_colorOrchid = 0xDA70D6,
1327
+ b2_colorPaleGoldenRod = 0xEEE8AA,
1328
+ b2_colorPaleGreen = 0x98FB98,
1329
+ b2_colorPaleTurquoise = 0xAFEEEE,
1330
+ b2_colorPaleVioletRed = 0xDB7093,
1331
+ b2_colorPapayaWhip = 0xFFEFD5,
1332
+ b2_colorPeachPuff = 0xFFDAB9,
1333
+ b2_colorPeru = 0xCD853F,
1334
+ b2_colorPink = 0xFFC0CB,
1335
+ b2_colorPlum = 0xDDA0DD,
1336
+ b2_colorPowderBlue = 0xB0E0E6,
1337
+ b2_colorPurple = 0x800080,
1338
+ b2_colorRebeccaPurple = 0x663399,
1339
+ b2_colorRed = 0xFF0000,
1340
+ b2_colorRosyBrown = 0xBC8F8F,
1341
+ b2_colorRoyalBlue = 0x4169E1,
1342
+ b2_colorSaddleBrown = 0x8B4513,
1343
+ b2_colorSalmon = 0xFA8072,
1344
+ b2_colorSandyBrown = 0xF4A460,
1345
+ b2_colorSeaGreen = 0x2E8B57,
1346
+ b2_colorSeaShell = 0xFFF5EE,
1347
+ b2_colorSienna = 0xA0522D,
1348
+ b2_colorSilver = 0xC0C0C0,
1349
+ b2_colorSkyBlue = 0x87CEEB,
1350
+ b2_colorSlateBlue = 0x6A5ACD,
1351
+ b2_colorSlateGray = 0x708090,
1352
+ b2_colorSnow = 0xFFFAFA,
1353
+ b2_colorSpringGreen = 0x00FF7F,
1354
+ b2_colorSteelBlue = 0x4682B4,
1355
+ b2_colorTan = 0xD2B48C,
1356
+ b2_colorTeal = 0x008080,
1357
+ b2_colorThistle = 0xD8BFD8,
1358
+ b2_colorTomato = 0xFF6347,
1359
+ b2_colorTurquoise = 0x40E0D0,
1360
+ b2_colorViolet = 0xEE82EE,
1361
+ b2_colorWheat = 0xF5DEB3,
1362
+ b2_colorWhite = 0xFFFFFF,
1363
+ b2_colorWhiteSmoke = 0xF5F5F5,
1364
+ b2_colorYellow = 0xFFFF00,
1365
+ b2_colorYellowGreen = 0x9ACD32,
1366
+
1367
+ b2_colorBox2DRed = 0xDC3132,
1368
+ b2_colorBox2DBlue = 0x30AEBF,
1369
+ b2_colorBox2DGreen = 0x8CC924,
1370
+ b2_colorBox2DYellow = 0xFFEE8C
1371
+ } b2HexColor;
1372
+
1373
+ /// This struct holds callbacks you can implement to draw a Box2D world.
1374
+ /// This structure should be zero initialized.
1375
+ /// @ingroup world
1376
+ typedef struct b2DebugDraw
1377
+ {
1378
+ /// Draw a closed polygon provided in CCW order.
1379
+ void ( *DrawPolygonFcn )( const b2Vec2* vertices, int vertexCount, b2HexColor color, void* context );
1380
+
1381
+ /// Draw a solid closed polygon provided in CCW order.
1382
+ void ( *DrawSolidPolygonFcn )( b2Transform transform, const b2Vec2* vertices, int vertexCount, float radius, b2HexColor color,
1383
+ void* context );
1384
+
1385
+ /// Draw a circle.
1386
+ void ( *DrawCircleFcn )( b2Vec2 center, float radius, b2HexColor color, void* context );
1387
+
1388
+ /// Draw a solid circle.
1389
+ void ( *DrawSolidCircleFcn )( b2Transform transform, float radius, b2HexColor color, void* context );
1390
+
1391
+ /// Draw a solid capsule.
1392
+ void ( *DrawSolidCapsuleFcn )( b2Vec2 p1, b2Vec2 p2, float radius, b2HexColor color, void* context );
1393
+
1394
+ /// Draw a line segment.
1395
+ void ( *DrawSegmentFcn )( b2Vec2 p1, b2Vec2 p2, b2HexColor color, void* context );
1396
+
1397
+ /// Draw a transform. Choose your own length scale.
1398
+ void ( *DrawTransformFcn )( b2Transform transform, void* context );
1399
+
1400
+ /// Draw a point.
1401
+ void ( *DrawPointFcn )( b2Vec2 p, float size, b2HexColor color, void* context );
1402
+
1403
+ /// Draw a string in world space
1404
+ void ( *DrawStringFcn )( b2Vec2 p, const char* s, b2HexColor color, void* context );
1405
+
1406
+ /// Bounds to use if restricting drawing to a rectangular region
1407
+ b2AABB drawingBounds;
1408
+
1409
+ /// Option to restrict drawing to a rectangular region. May suffer from unstable depth sorting.
1410
+ bool useDrawingBounds;
1411
+
1412
+ /// Option to draw shapes
1413
+ bool drawShapes;
1414
+
1415
+ /// Option to draw joints
1416
+ bool drawJoints;
1417
+
1418
+ /// Option to draw additional information for joints
1419
+ bool drawJointExtras;
1420
+
1421
+ /// Option to draw the bounding boxes for shapes
1422
+ bool drawBounds;
1423
+
1424
+ /// Option to draw the mass and center of mass of dynamic bodies
1425
+ bool drawMass;
1426
+
1427
+ /// Option to draw body names
1428
+ bool drawBodyNames;
1429
+
1430
+ /// Option to draw contact points
1431
+ bool drawContacts;
1432
+
1433
+ /// Option to visualize the graph coloring used for contacts and joints
1434
+ bool drawGraphColors;
1435
+
1436
+ /// Option to draw contact normals
1437
+ bool drawContactNormals;
1438
+
1439
+ /// Option to draw contact normal impulses
1440
+ bool drawContactImpulses;
1441
+
1442
+ /// Option to draw contact feature ids
1443
+ bool drawContactFeatures;
1444
+
1445
+ /// Option to draw contact friction impulses
1446
+ bool drawFrictionImpulses;
1447
+
1448
+ /// Option to draw islands as bounding boxes
1449
+ bool drawIslands;
1450
+
1451
+ /// User context that is passed as an argument to drawing callback functions
1452
+ void* context;
1453
+ } b2DebugDraw;
1454
+
1455
+ /// Use this to initialize your drawing interface. This allows you to implement a sub-set
1456
+ /// of the drawing functions.
1457
+ B2_API b2DebugDraw b2DefaultDebugDraw( void );