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