b2Settings.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef B2_SETTINGS_H
  19. #define B2_SETTINGS_H
  20. #include <stddef.h>
  21. #include <assert.h>
  22. #include <float.h>
  23. #define B2_NOT_USED(x) ((void)(x))
  24. #define b2Assert(A) assert(A)
  25. typedef signed char int8;
  26. typedef signed short int16;
  27. typedef signed int int32;
  28. typedef unsigned char uint8;
  29. typedef unsigned short uint16;
  30. typedef unsigned int uint32;
  31. typedef float float32;
  32. typedef double float64;
  33. #define b2_maxFloat FLT_MAX
  34. #define b2_epsilon FLT_EPSILON
  35. #define b2_pi 3.14159265359f
  36. /// @file
  37. /// Global tuning constants based on meters-kilograms-seconds (MKS) units.
  38. ///
  39. // Collision
  40. /// The maximum number of contact points between two convex shapes. Do
  41. /// not change this value.
  42. #define b2_maxManifoldPoints 2
  43. /// The maximum number of vertices on a convex polygon. You cannot increase
  44. /// this too much because b2BlockAllocator has a maximum object size.
  45. #define b2_maxPolygonVertices 8
  46. /// This is used to fatten AABBs in the dynamic tree. This allows proxies
  47. /// to move by a small amount without triggering a tree adjustment.
  48. /// This is in meters.
  49. #define b2_aabbExtension 0.1f
  50. /// This is used to fatten AABBs in the dynamic tree. This is used to predict
  51. /// the future position based on the current displacement.
  52. /// This is a dimensionless multiplier.
  53. #define b2_aabbMultiplier 2.0f
  54. /// A small length used as a collision and constraint tolerance. Usually it is
  55. /// chosen to be numerically significant, but visually insignificant.
  56. #define b2_linearSlop 0.005f
  57. /// A small angle used as a collision and constraint tolerance. Usually it is
  58. /// chosen to be numerically significant, but visually insignificant.
  59. #define b2_angularSlop (2.0f / 180.0f * b2_pi)
  60. /// The radius of the polygon/edge shape skin. This should not be modified. Making
  61. /// this smaller means polygons will have an insufficient buffer for continuous collision.
  62. /// Making it larger may create artifacts for vertex collision.
  63. #define b2_polygonRadius (2.0f * b2_linearSlop)
  64. /// Maximum number of sub-steps per contact in continuous physics simulation.
  65. #define b2_maxSubSteps 8
  66. // Dynamics
  67. /// Maximum number of contacts to be handled to solve a TOI impact.
  68. #define b2_maxTOIContacts 32
  69. /// A velocity threshold for elastic collisions. Any collision with a relative linear
  70. /// velocity below this threshold will be treated as inelastic.
  71. #define b2_velocityThreshold 1.0f
  72. /// The maximum linear position correction used when solving constraints. This helps to
  73. /// prevent overshoot.
  74. #define b2_maxLinearCorrection 0.2f
  75. /// The maximum angular position correction used when solving constraints. This helps to
  76. /// prevent overshoot.
  77. #define b2_maxAngularCorrection (8.0f / 180.0f * b2_pi)
  78. /// The maximum linear velocity of a body. This limit is very large and is used
  79. /// to prevent numerical problems. You shouldn't need to adjust this.
  80. #define b2_maxTranslation 2.0f
  81. #define b2_maxTranslationSquared (b2_maxTranslation * b2_maxTranslation)
  82. /// The maximum angular velocity of a body. This limit is very large and is used
  83. /// to prevent numerical problems. You shouldn't need to adjust this.
  84. #define b2_maxRotation (0.5f * b2_pi)
  85. #define b2_maxRotationSquared (b2_maxRotation * b2_maxRotation)
  86. /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
  87. /// that overlap is removed in one time step. However using values close to 1 often lead
  88. /// to overshoot.
  89. #define b2_baumgarte 0.2f
  90. #define b2_toiBaugarte 0.75f
  91. // Sleep
  92. /// The time that a body must be still before it will go to sleep.
  93. #define b2_timeToSleep 0.5f
  94. /// A body cannot sleep if its linear velocity is above this tolerance.
  95. #define b2_linearSleepTolerance 0.01f
  96. /// A body cannot sleep if its angular velocity is above this tolerance.
  97. #define b2_angularSleepTolerance (2.0f / 180.0f * b2_pi)
  98. // Memory Allocation
  99. /// Implement this function to use your own memory allocator.
  100. void* b2Alloc(int32 size);
  101. /// If you implement b2Alloc, you should also implement this function.
  102. void b2Free(void* mem);
  103. /// Logging function.
  104. void b2Log(const char* string, ...);
  105. /// Version numbering scheme.
  106. /// See http://en.wikipedia.org/wiki/Software_versioning
  107. struct b2Version
  108. {
  109. int32 major; ///< significant changes
  110. int32 minor; ///< incremental changes
  111. int32 revision; ///< bug fixes
  112. };
  113. /// Current version.
  114. extern b2Version b2_version;
  115. #endif