Settings.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Farseer Physics Engine based on Box2D.XNA port:
  3. * Copyright (c) 2010 Ian Qvist
  4. *
  5. * Box2D.XNA port of Box2D:
  6. * Copyright (c) 2009 Brandon Furtwangler, Nathan Furtwangler
  7. *
  8. * Original source Box2D:
  9. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  10. *
  11. * This software is provided 'as-is', without any express or implied
  12. * warranty. In no event will the authors be held liable for any damages
  13. * arising from the use of this software.
  14. * Permission is granted to anyone to use this software for any purpose,
  15. * including commercial applications, and to alter it and redistribute it
  16. * freely, subject to the following restrictions:
  17. * 1. The origin of this software must not be misrepresented; you must not
  18. * claim that you wrote the original software. If you use this software
  19. * in a product, an acknowledgment in the product documentation would be
  20. * appreciated but is not required.
  21. * 2. Altered source versions must be plainly marked as such, and must not be
  22. * misrepresented as being the original software.
  23. * 3. This notice may not be removed or altered from any source distribution.
  24. */
  25. using System;
  26. namespace FarseerPhysics
  27. {
  28. public static class Settings
  29. {
  30. public const float MaxFloat = 3.402823466e+38f;
  31. public const float Epsilon = 1.192092896e-07f;
  32. public const float Pi = 3.14159265359f;
  33. // Common
  34. /// <summary>
  35. /// Enabling diagnistics causes the engine to gather timing information.
  36. /// You can see how much time it took to solve the contacts, solve CCD
  37. /// and update the controllers.
  38. /// NOTE: If you are using a debug view that shows performance counters,
  39. /// you might want to enable this.
  40. /// </summary>
  41. public static bool EnableDiagnostics = true;
  42. /// <summary>
  43. /// The number of velocity iterations used in the solver.
  44. /// </summary>
  45. public static int VelocityIterations = 8;
  46. /// <summary>
  47. /// The number of position iterations used in the solver.
  48. /// </summary>
  49. public static int PositionIterations = 3;
  50. /// <summary>
  51. /// Enable/Disable Continuous Collision Detection (CCD)
  52. /// </summary>
  53. public static bool ContinuousPhysics = true;
  54. /// <summary>
  55. /// The number of velocity iterations in the TOI solver
  56. /// </summary>
  57. public static int TOIVelocityIterations = 8;
  58. /// <summary>
  59. /// The number of position iterations in the TOI solver
  60. /// </summary>
  61. public static int TOIPositionIterations = 20;
  62. /// <summary>
  63. /// Maximum number of sub-steps per contact in continuous physics simulation.
  64. /// </summary>
  65. public const int MaxSubSteps = 8;
  66. /// <summary>
  67. /// Enable/Disable warmstarting
  68. /// </summary>
  69. public static bool EnableWarmstarting = true;
  70. /// <summary>
  71. /// Enable/Disable sleeping
  72. /// </summary>
  73. public static bool AllowSleep = true;
  74. /// <summary>
  75. /// The maximum number of vertices on a convex polygon.
  76. /// </summary>
  77. public static int MaxPolygonVertices = 8;
  78. /// <summary>
  79. /// Farseer Physics Engine has a different way of filtering fixtures than Box2d.
  80. /// We have both FPE and Box2D filtering in the engine. If you are upgrading
  81. /// from earlier versions of FPE, set this to true.
  82. /// </summary>
  83. public static bool UseFPECollisionCategories;
  84. /// <summary>
  85. /// Conserve memory makes sure that objects are used by reference instead of cloned.
  86. /// When you give a vertices collection to a PolygonShape, it will by default copy the vertices
  87. /// instead of using the original reference. This is to ensure that objects modified outside the engine
  88. /// does not affect the engine itself, however, this uses extra memory. This behavior
  89. /// can be turned off by setting ConserveMemory to true.
  90. /// </summary>
  91. public const bool ConserveMemory = false;
  92. /// <summary>
  93. /// The maximum number of contact points between two convex shapes.
  94. /// </summary>
  95. public const int MaxManifoldPoints = 2;
  96. /// <summary>
  97. /// This is used to fatten AABBs in the dynamic tree. This allows proxies
  98. /// to move by a small amount without triggering a tree adjustment.
  99. /// This is in meters.
  100. /// </summary>
  101. public const float AABBExtension = 0.1f;
  102. /// <summary>
  103. /// This is used to fatten AABBs in the dynamic tree. This is used to predict
  104. /// the future position based on the current displacement.
  105. /// This is a dimensionless multiplier.
  106. /// </summary>
  107. public const float AABBMultiplier = 2.0f;
  108. /// <summary>
  109. /// A small length used as a collision and constraint tolerance. Usually it is
  110. /// chosen to be numerically significant, but visually insignificant.
  111. /// </summary>
  112. public const float LinearSlop = 0.005f;
  113. /// <summary>
  114. /// A small angle used as a collision and constraint tolerance. Usually it is
  115. /// chosen to be numerically significant, but visually insignificant.
  116. /// </summary>
  117. public const float AngularSlop = (2.0f / 180.0f * Pi);
  118. /// <summary>
  119. /// The radius of the polygon/edge shape skin. This should not be modified. Making
  120. /// this smaller means polygons will have an insufficient buffer for continuous collision.
  121. /// Making it larger may create artifacts for vertex collision.
  122. /// </summary>
  123. public const float PolygonRadius = (2.0f * LinearSlop);
  124. // Dynamics
  125. /// <summary>
  126. /// Maximum number of contacts to be handled to solve a TOI impact.
  127. /// </summary>
  128. public const int MaxTOIContacts = 32;
  129. /// <summary>
  130. /// A velocity threshold for elastic collisions. Any collision with a relative linear
  131. /// velocity below this threshold will be treated as inelastic.
  132. /// </summary>
  133. public const float VelocityThreshold = 1.0f;
  134. /// <summary>
  135. /// The maximum linear position correction used when solving constraints. This helps to
  136. /// prevent overshoot.
  137. /// </summary>
  138. public const float MaxLinearCorrection = 0.2f;
  139. /// <summary>
  140. /// The maximum angular position correction used when solving constraints. This helps to
  141. /// prevent overshoot.
  142. /// </summary>
  143. public const float MaxAngularCorrection = (8.0f / 180.0f * Pi);
  144. /// <summary>
  145. /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
  146. /// that overlap is removed in one time step. However using values close to 1 often lead
  147. /// to overshoot.
  148. /// </summary>
  149. public const float ContactBaumgarte = 0.2f;
  150. // Sleep
  151. /// <summary>
  152. /// The time that a body must be still before it will go to sleep.
  153. /// </summary>
  154. public const float TimeToSleep = 0.5f;
  155. /// <summary>
  156. /// A body cannot sleep if its linear velocity is above this tolerance.
  157. /// </summary>
  158. public const float LinearSleepTolerance = 0.01f;
  159. /// <summary>
  160. /// A body cannot sleep if its angular velocity is above this tolerance.
  161. /// </summary>
  162. public const float AngularSleepTolerance = (2.0f / 180.0f * Pi);
  163. /// <summary>
  164. /// The maximum linear velocity of a body. This limit is very large and is used
  165. /// to prevent numerical problems. You shouldn't need to adjust this.
  166. /// </summary>
  167. public const float MaxTranslation = 2.0f;
  168. public const float MaxTranslationSquared = (MaxTranslation * MaxTranslation);
  169. /// <summary>
  170. /// The maximum angular velocity of a body. This limit is very large and is used
  171. /// to prevent numerical problems. You shouldn't need to adjust this.
  172. /// </summary>
  173. public const float MaxRotation = (0.5f * Pi);
  174. public const float MaxRotationSquared = (MaxRotation * MaxRotation);
  175. /// <summary>
  176. /// Friction mixing law. Feel free to customize this.
  177. /// </summary>
  178. /// <param name="friction1">The friction1.</param>
  179. /// <param name="friction2">The friction2.</param>
  180. /// <returns></returns>
  181. public static float MixFriction(float friction1, float friction2)
  182. {
  183. return (float) Math.Sqrt(friction1 * friction2);
  184. }
  185. /// <summary>
  186. /// Restitution mixing law. Feel free to customize this.
  187. /// </summary>
  188. /// <param name="restitution1">The restitution1.</param>
  189. /// <param name="restitution2">The restitution2.</param>
  190. /// <returns></returns>
  191. public static float MixRestitution(float restitution1, float restitution2)
  192. {
  193. return restitution1 > restitution2 ? restitution1 : restitution2;
  194. }
  195. }
  196. }