2 * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
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.
25 #define B2_NOT_USED(x) x
26 #define b2Assert(A) assert(A)
29 // need to include NDS jtypes.h instead of
30 // usual typedefs because NDS jtypes defines
31 // them slightly differently, oh well.
38 typedef signed char int8;
39 typedef signed short int16;
40 typedef signed int int32;
41 typedef unsigned char uint8;
42 typedef unsigned short uint16;
43 typedef unsigned int uint32;
47 #ifdef TARGET_FLOAT32_IS_FIXED
51 typedef Fixed float32;
52 #define B2_FLT_MAX FIXED_MAX
53 #define B2_FLT_EPSILON FIXED_EPSILON
54 #define B2FORCE_SCALE(x) ((x)<<7)
55 #define B2FORCE_INV_SCALE(x) ((x)>>7)
59 typedef float float32;
60 #define B2_FLT_MAX FLT_MAX
61 #define B2_FLT_EPSILON FLT_EPSILON
62 #define B2FORCE_SCALE(x) (x)
63 #define B2FORCE_INV_SCALE(x) (x)
67 const float32 b2_pi = 3.14159265359f;
70 /// Global tuning constants based on meters-kilograms-seconds (MKS) units.
74 const int32 b2_maxManifoldPoints = 2;
75 const int32 b2_maxPolygonVertices = 8;
76 const int32 b2_maxProxies = 512; // this must be a power of two
77 const int32 b2_maxPairs = 8 * b2_maxProxies; // this must be a power of two
81 /// A small length used as a collision and constraint tolerance. Usually it is
82 /// chosen to be numerically significant, but visually insignificant.
83 const float32 b2_linearSlop = 0.005f; // 0.5 cm
85 /// A small angle used as a collision and constraint tolerance. Usually it is
86 /// chosen to be numerically significant, but visually insignificant.
87 const float32 b2_angularSlop = 2.0f / 180.0f * b2_pi; // 2 degrees
89 /// Continuous collision detection (CCD) works with core, shrunken shapes. This is the
90 /// amount by which shapes are automatically shrunk to work with CCD. This must be
91 /// larger than b2_linearSlop.
92 const float32 b2_toiSlop = 8.0f * b2_linearSlop;
94 /// Maximum number of contacts to be handled to solve a TOI island.
95 const int32 b2_maxTOIContactsPerIsland = 32;
97 /// A velocity threshold for elastic collisions. Any collision with a relative linear
98 /// velocity below this threshold will be treated as inelastic.
99 const float32 b2_velocityThreshold = 1.0f; // 1 m/s
101 /// The maximum linear position correction used when solving constraints. This helps to
102 /// prevent overshoot.
103 const float32 b2_maxLinearCorrection = 0.2f; // 20 cm
105 /// The maximum angular position correction used when solving constraints. This helps to
106 /// prevent overshoot.
107 const float32 b2_maxAngularCorrection = 8.0f / 180.0f * b2_pi; // 8 degrees
109 /// The maximum linear velocity of a body. This limit is very large and is used
110 /// to prevent numerical problems. You shouldn't need to adjust this.
111 #ifdef TARGET_FLOAT32_IS_FIXED
112 const float32 b2_maxLinearVelocity = 100.0f;
114 const float32 b2_maxLinearVelocity = 200.0f;
115 const float32 b2_maxLinearVelocitySquared = b2_maxLinearVelocity * b2_maxLinearVelocity;
118 /// The maximum angular velocity of a body. This limit is very large and is used
119 /// to prevent numerical problems. You shouldn't need to adjust this.
120 const float32 b2_maxAngularVelocity = 250.0f;
121 #ifndef TARGET_FLOAT32_IS_FIXED
122 const float32 b2_maxAngularVelocitySquared = b2_maxAngularVelocity * b2_maxAngularVelocity;
125 /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
126 /// that overlap is removed in one time step. However using values close to 1 often lead
128 const float32 b2_contactBaumgarte = 0.2f;
132 /// The time that a body must be still before it will go to sleep.
133 const float32 b2_timeToSleep = 0.5f; // half a second
135 /// A body cannot sleep if its linear velocity is above this tolerance.
136 const float32 b2_linearSleepTolerance = 0.01f; // 1 cm/s
138 /// A body cannot sleep if its angular velocity is above this tolerance.
139 const float32 b2_angularSleepTolerance = 2.0f / 180.0f; // 2 degrees/s
143 /// The current number of bytes allocated through b2Alloc.
144 extern int32 b2_byteCount;
146 /// Implement this function to use your own memory allocator.
147 void* b2Alloc(int32 size);
149 /// If you implement b2Alloc, you should also implement this function.
150 void b2Free(void* mem);
152 /// Version numbering scheme.
153 /// See http://en.wikipedia.org/wiki/Software_versioning
156 int32 major; ///< significant changes
157 int32 minor; ///< incremental changes
158 int32 revision; ///< bug fixes
162 extern b2Version b2_version;
164 /// Friction mixing law. Feel free to customize this.
165 inline float32 b2MixFriction(float32 friction1, float32 friction2)
167 return sqrtf(friction1 * friction2);
170 /// Restitution mixing law. Feel free to customize this.
171 inline float32 b2MixRestitution(float32 restitution1, float32 restitution2)
173 return restitution1 > restitution2 ? restitution1 : restitution2;