Settings.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Box2D.XNA port of Box2D:
  3. * Copyright (c) 2009 Brandon Furtwangler, Nathan Furtwangler
  4. *
  5. * Original source Box2D:
  6. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  7. *
  8. * This software is provided 'as-is', without any express or implied
  9. * warranty. In no event will the authors be held liable for any damages
  10. * arising from the use of this software.
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. * 1. The origin of this software must not be misrepresented; you must not
  15. * claim that you wrote the original software. If you use this software
  16. * in a product, an acknowledgment in the product documentation would be
  17. * appreciated but is not required.
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. * 3. This notice may not be removed or altered from any source distribution.
  21. */
  22. using System;
  23. namespace Box2D.XNA
  24. {
  25. public static class Settings
  26. {
  27. public const float b2_maxFloat = 3.402823466e+38f;
  28. public const float b2_epsilon = 1.192092896e-07f;
  29. public const float b2_pi = 3.14159265359f;
  30. /// The maximum number of contact points between two convex shapes.
  31. public const int b2_maxManifoldPoints = 2;
  32. /// The maximum number of vertices on a convex polygon.
  33. public const int b2_maxPolygonVertices = 8;
  34. /// This is used to fatten AABBs in the dynamic tree. This allows proxies
  35. /// to move by a small amount without triggering a tree adjustment.
  36. /// This is in meters.
  37. public const float b2_aabbExtension = 0.1f;
  38. /// This is used to fatten AABBs in the dynamic tree. This is used to predict
  39. /// the future position based on the current displacement.
  40. /// This is a dimensionless multiplier.
  41. public const float b2_aabbMultiplier = 2.0f;
  42. /// A small length used as a collision and constraint tolerance. Usually it is
  43. /// chosen to be numerically significant, but visually insignificant.
  44. public const float b2_linearSlop = 0.005f;
  45. /// A small angle used as a collision and constraint tolerance. Usually it is
  46. /// chosen to be numerically significant, but visually insignificant.
  47. public const float b2_angularSlop = (2.0f / 180.0f * b2_pi);
  48. /// The radius of the polygon/edge shape skin. This should not be modified. Making
  49. /// this smaller means polygons will have an insufficient buffer for continuous collision.
  50. /// Making it larger may create artifacts for vertex collision.
  51. public const float b2_polygonRadius = (2.0f * b2_linearSlop);
  52. // Dynamics
  53. /// Maximum number of contacts to be handled to solve a TOI impact.
  54. public const int b2_maxTOIContacts = 32;
  55. /// A velocity threshold for elastic collisions. Any collision with a relative linear
  56. /// velocity below this threshold will be treated as inelastic.
  57. public const float b2_velocityThreshold = 1.0f;
  58. /// The maximum linear position correction used when solving constraints. This helps to
  59. /// prevent overshoot.
  60. public const float b2_maxLinearCorrection = 0.2f;
  61. /// The maximum angular position correction used when solving constraints. This helps to
  62. /// prevent overshoot.
  63. public const float b2_maxAngularCorrection = (8.0f / 180.0f * b2_pi);
  64. /// The maximum linear velocity of a body. This limit is very large and is used
  65. /// to prevent numerical problems. You shouldn't need to adjust this.
  66. public static float b2_maxTranslation = 2.0f;
  67. public static float b2_maxTranslationSquared = (b2_maxTranslation * b2_maxTranslation);
  68. /// The maximum angular velocity of a body. This limit is very large and is used
  69. /// to prevent numerical problems. You shouldn't need to adjust this.
  70. public static float b2_maxRotation = (0.5f * b2_pi);
  71. public static float b2_maxRotationSquared = (b2_maxRotation * b2_maxRotation);
  72. /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
  73. /// that overlap is removed in one time step. However using values close to 1 often lead
  74. /// to overshoot.
  75. public const float b2_contactBaumgarte = 0.2f;
  76. // Sleep
  77. /// The time that a body must be still before it will go to sleep.
  78. public const float b2_timeToSleep = 0.5f;
  79. /// A body cannot sleep if its linear velocity is above this tolerance.
  80. public const float b2_linearSleepTolerance = 0.01f;
  81. /// A body cannot sleep if its angular velocity is above this tolerance.
  82. public const float b2_angularSleepTolerance = (2.0f / 180.0f * b2_pi);
  83. /// Friction mixing law. Feel free to customize this.
  84. public static float b2MixFriction(float friction1, float friction2)
  85. {
  86. return (float)Math.Sqrt((double)(friction1 * friction2));
  87. }
  88. /// Restitution mixing law. Feel free to customize this.
  89. public static float b2MixRestitution(float restitution1, float restitution2)
  90. {
  91. return restitution1 > restitution2 ? restitution1 : restitution2;
  92. }
  93. }
  94. }