1 /******************************************************************************* 2 * Copyright (c) 2013, Daniel Murphy 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * * Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 20 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 22 * POSSIBILITY OF SUCH DAMAGE. 23 ******************************************************************************/ 24 package org.jbox2d.common; 25 26 /** 27 * Global tuning constants based on MKS units and various integer maximums (vertices per shape, 28 * pairs, etc.). 29 */ 30 public class Settings { 31 32 /** A "close to zero" float epsilon value for use */ 33 public static final float EPSILON = 1.1920928955078125E-7f; 34 35 /** Pi. */ 36 public static final float PI = (float) Math.PI; 37 38 // JBox2D specific settings 39 public static boolean FAST_ABS = true; 40 public static boolean FAST_FLOOR = true; 41 public static boolean FAST_CEIL = true; 42 public static boolean FAST_ROUND = true; 43 public static boolean FAST_ATAN2 = true; 44 public static boolean FAST_POW = true; 45 public static int CONTACT_STACK_INIT_SIZE = 10; 46 public static boolean SINCOS_LUT_ENABLED = true; 47 /** 48 * smaller the precision, the larger the table. If a small table is used (eg, precision is .006 or 49 * greater), make sure you set the table to lerp it's results. Accuracy chart is in the MathUtils 50 * source. Or, run the tests yourself in {@link SinCosTest}.</br> </br> Good lerp precision 51 * values: 52 * <ul> 53 * <li>.0092</li> 54 * <li>.008201</li> 55 * <li>.005904</li> 56 * <li>.005204</li> 57 * <li>.004305</li> 58 * <li>.002807</li> 59 * <li>.001508</li> 60 * <li>9.32500E-4</li> 61 * <li>7.48000E-4</li> 62 * <li>8.47000E-4</li> 63 * <li>.0005095</li> 64 * <li>.0001098</li> 65 * <li>9.50499E-5</li> 66 * <li>6.08500E-5</li> 67 * <li>3.07000E-5</li> 68 * <li>1.53999E-5</li> 69 * </ul> 70 */ 71 public static final float SINCOS_LUT_PRECISION = .00011f; 72 public static final int SINCOS_LUT_LENGTH = (int) Math.ceil(Math.PI * 2 / SINCOS_LUT_PRECISION); 73 /** 74 * Use if the table's precision is large (eg .006 or greater). Although it is more expensive, it 75 * greatly increases accuracy. Look in the MathUtils source for some test results on the accuracy 76 * and speed of lerp vs non lerp. Or, run the tests yourself in {@link SinCosTest}. 77 */ 78 public static boolean SINCOS_LUT_LERP = false; 79 80 81 // Collision 82 83 /** 84 * The maximum number of contact points between two convex shapes. 85 */ 86 public static int maxManifoldPoints = 2; 87 88 /** 89 * The maximum number of vertices on a convex polygon. 90 */ 91 public static int maxPolygonVertices = 8; 92 93 /** 94 * This is used to fatten AABBs in the dynamic tree. This allows proxies to move by a small amount 95 * without triggering a tree adjustment. This is in meters. 96 */ 97 public static float aabbExtension = 0.1f; 98 99 /** 100 * This is used to fatten AABBs in the dynamic tree. This is used to predict the future position 101 * based on the current displacement. This is a dimensionless multiplier. 102 */ 103 public static float aabbMultiplier = 2.0f; 104 105 /** 106 * A small length used as a collision and constraint tolerance. Usually it is chosen to be 107 * numerically significant, but visually insignificant. 108 */ 109 public static float linearSlop = 0.005f; 110 111 /** 112 * A small angle used as a collision and constraint tolerance. Usually it is chosen to be 113 * numerically significant, but visually insignificant. 114 */ 115 public static float angularSlop = (2.0f / 180.0f * PI); 116 117 /** 118 * The radius of the polygon/edge shape skin. This should not be modified. Making this smaller 119 * means polygons will have and insufficient for continuous collision. Making it larger may create 120 * artifacts for vertex collision. 121 */ 122 public static float polygonRadius = (2.0f * linearSlop); 123 124 /** Maximum number of sub-steps per contact in continuous physics simulation. */ 125 public static int maxSubSteps = 8; 126 127 // Dynamics 128 129 /** 130 * Maximum number of contacts to be handled to solve a TOI island. 131 */ 132 public static int maxTOIContacts = 32; 133 134 /** 135 * A velocity threshold for elastic collisions. Any collision with a relative linear velocity 136 * below this threshold will be treated as inelastic. 137 */ 138 public static float velocityThreshold = 1.0f; 139 140 /** 141 * The maximum linear position correction used when solving constraints. This helps to prevent 142 * overshoot. 143 */ 144 public static float maxLinearCorrection = 0.2f; 145 146 /** 147 * The maximum angular position correction used when solving constraints. This helps to prevent 148 * overshoot. 149 */ 150 public static float maxAngularCorrection = (8.0f / 180.0f * PI); 151 152 /** 153 * The maximum linear velocity of a body. This limit is very large and is used to prevent 154 * numerical problems. You shouldn't need to adjust this. 155 */ 156 public static float maxTranslation = 2.0f; 157 public static float maxTranslationSquared = (maxTranslation * maxTranslation); 158 159 /** 160 * The maximum angular velocity of a body. This limit is very large and is used to prevent 161 * numerical problems. You shouldn't need to adjust this. 162 */ 163 public static float maxRotation = (0.5f * PI); 164 public static float maxRotationSquared = (maxRotation * maxRotation); 165 166 /** 167 * This scale factor controls how fast overlap is resolved. Ideally this would be 1 so that 168 * overlap is removed in one time step. However using values close to 1 often lead to overshoot. 169 */ 170 public static float baumgarte = 0.2f; 171 public static float toiBaugarte = 0.75f; 172 173 174 // Sleep 175 176 /** 177 * The time that a body must be still before it will go to sleep. 178 */ 179 public static float timeToSleep = 0.5f; 180 181 /** 182 * A body cannot sleep if its linear velocity is above this tolerance. 183 */ 184 public static float linearSleepTolerance = 0.01f; 185 186 /** 187 * A body cannot sleep if its angular velocity is above this tolerance. 188 */ 189 public static float angularSleepTolerance = (2.0f / 180.0f * PI); 190 191 // Particle 192 193 /** 194 * A symbolic constant that stands for particle allocation error. 195 */ 196 public static final int invalidParticleIndex = (-1); 197 198 /** 199 * The standard distance between particles, divided by the particle radius. 200 */ 201 public static final float particleStride = 0.75f; 202 203 /** 204 * The minimum particle weight that produces pressure. 205 */ 206 public static final float minParticleWeight = 1.0f; 207 208 /** 209 * The upper limit for particle weight used in pressure calculation. 210 */ 211 public static final float maxParticleWeight = 5.0f; 212 213 /** 214 * The maximum distance between particles in a triad, divided by the particle radius. 215 */ 216 public static final int maxTriadDistance = 2; 217 public static final int maxTriadDistanceSquared = (maxTriadDistance * maxTriadDistance); 218 219 /** 220 * The initial size of particle data buffers. 221 */ 222 public static final int minParticleBufferCapacity = 256; 223 224 225 /** 226 * Friction mixing law. Feel free to customize this. TODO djm: add customization 227 * 228 * @param friction1 229 * @param friction2 230 * @return 231 */ 232 public static float mixFriction(float friction1, float friction2) { 233 return MathUtils.sqrt(friction1 * friction2); 234 } 235 236 /** 237 * Restitution mixing law. Feel free to customize this. TODO djm: add customization 238 * 239 * @param restitution1 240 * @param restitution2 241 * @return 242 */ 243 public static float mixRestitution(float restitution1, float restitution2) { 244 return restitution1 > restitution2 ? restitution1 : restitution2; 245 } 246 } 247