b2_common.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // MIT License
  2. // Copyright (c) 2019 Erin Catto
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. // The above copyright notice and this permission notice shall be included in all
  10. // copies or substantial portions of the Software.
  11. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. // SOFTWARE.
  18. #ifndef B2_COMMON_H
  19. #define B2_COMMON_H
  20. #include "b2_settings.h"
  21. #include <stddef.h>
  22. #include <assert.h>
  23. #include <float.h>
  24. #if !defined(NDEBUG)
  25. #define b2DEBUG
  26. #endif
  27. #define B2_NOT_USED(x) ((void)(x))
  28. #define b2Assert(A) assert(A)
  29. #define b2_maxFloat FLT_MAX
  30. #define b2_epsilon FLT_EPSILON
  31. #define b2_pi 3.14159265359f
  32. /// @file
  33. /// Global tuning constants based on meters-kilograms-seconds (MKS) units.
  34. ///
  35. // Collision
  36. /// The maximum number of contact points between two convex shapes. Do
  37. /// not change this value.
  38. #define b2_maxManifoldPoints 2
  39. /// This is used to fatten AABBs in the dynamic tree. This allows proxies
  40. /// to move by a small amount without triggering a tree adjustment.
  41. /// This is in meters.
  42. #define b2_aabbExtension (0.1f * b2_lengthUnitsPerMeter)
  43. /// This is used to fatten AABBs in the dynamic tree. This is used to predict
  44. /// the future position based on the current displacement.
  45. /// This is a dimensionless multiplier.
  46. #define b2_aabbMultiplier 4.0f
  47. /// A small length used as a collision and constraint tolerance. Usually it is
  48. /// chosen to be numerically significant, but visually insignificant. In meters.
  49. #define b2_linearSlop (0.005f * b2_lengthUnitsPerMeter)
  50. /// A small angle used as a collision and constraint tolerance. Usually it is
  51. /// chosen to be numerically significant, but visually insignificant.
  52. #define b2_angularSlop (2.0f / 180.0f * b2_pi)
  53. /// The radius of the polygon/edge shape skin. This should not be modified. Making
  54. /// this smaller means polygons will have an insufficient buffer for continuous collision.
  55. /// Making it larger may create artifacts for vertex collision.
  56. #define b2_polygonRadius (2.0f * b2_linearSlop)
  57. /// Maximum number of sub-steps per contact in continuous physics simulation.
  58. #define b2_maxSubSteps 8
  59. // Dynamics
  60. /// Maximum number of contacts to be handled to solve a TOI impact.
  61. #define b2_maxTOIContacts 32
  62. /// The maximum linear position correction used when solving constraints. This helps to
  63. /// prevent overshoot. Meters.
  64. #define b2_maxLinearCorrection (0.2f * b2_lengthUnitsPerMeter)
  65. /// The maximum angular position correction used when solving constraints. This helps to
  66. /// prevent overshoot.
  67. #define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
  68. /// The maximum linear translation of a body per step. This limit is very large and is used
  69. /// to prevent numerical problems. You shouldn't need to adjust this. Meters.
  70. #define b2_maxTranslation (2.0f * b2_lengthUnitsPerMeter)
  71. #define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
  72. /// The maximum angular velocity of a body. This limit is very large and is used
  73. /// to prevent numerical problems. You shouldn't need to adjust this.
  74. #define b2_maxRotation (0.5f * b2_pi)
  75. #define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
  76. /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
  77. /// that overlap is removed in one time step. However using values close to 1 often lead
  78. /// to overshoot.
  79. #define b2_baumgarte 0.2f
  80. #define b2_toiBaumgarte 0.75f
  81. // Sleep
  82. /// The time that a body must be still before it will go to sleep.
  83. #define b2_timeToSleep 0.5f
  84. /// A body cannot sleep if its linear velocity is above this tolerance.
  85. #define b2_linearSleepTolerance (0.01f * b2_lengthUnitsPerMeter)
  86. /// A body cannot sleep if its angular velocity is above this tolerance.
  87. #define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
  88. /// Dump to a file. Only one dump file allowed at a time.
  89. void b2OpenDump(const char* fileName);
  90. void b2Dump(const char* string, ...);
  91. void b2CloseDump();
  92. /// Version numbering scheme.
  93. /// See http://en.wikipedia.org/wiki/Software_versioning
  94. struct b2Version
  95. {
  96. int32 major; ///< significant changes
  97. int32 minor; ///< incremental changes
  98. int32 revision; ///< bug fixes
  99. };
  100. /// Current version.
  101. extern B2_API b2Version b2_version;
  102. #endif