diff --git a/CMakeLists.txt b/CMakeLists.txt index c7f31e52f..77793a95f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ project(box2d ) # stuff to help debug cmake +# message(STATUS "cmake tool chain: ${CMAKE_TOOLCHAIN_FILE}") # message(STATUS "cmake source dir: ${CMAKE_SOURCE_DIR}") # message(STATUS "library postfix: ${CMAKE_DEBUG_POSTFIX}") message(STATUS "CMake C compiler: ${CMAKE_C_COMPILER_ID}") @@ -66,7 +67,7 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_COMPILE_WARNING_AS_ERROR ON) -# set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/include/box2d/box2d.h b/include/box2d/box2d.h index 2b0ba1760..b9c811f78 100644 --- a/include/box2d/box2d.h +++ b/include/box2d/box2d.h @@ -542,8 +542,9 @@ B2_API b2Filter b2Shape_GetFilter( b2ShapeId shapeId ); /// @see b2ShapeDef::filter B2_API void b2Shape_SetFilter( b2ShapeId shapeId, b2Filter filter ); -/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. +/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. /// @see b2ShapeDef::isSensor +/// @warning changing this at run-time may lead to lost begin/end events B2_API void b2Shape_EnableSensorEvents( b2ShapeId shapeId, bool flag ); /// Returns true if sensor events are enabled @@ -551,6 +552,7 @@ B2_API bool b2Shape_AreSensorEventsEnabled( b2ShapeId shapeId ); /// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. /// @see b2ShapeDef::enableContactEvents +/// @warning changing this at run-time may lead to lost begin/end events B2_API void b2Shape_EnableContactEvents( b2ShapeId shapeId, bool flag ); /// Returns true if contact events are enabled diff --git a/include/box2d/collision.h b/include/box2d/collision.h index 2047a2446..59b49671a 100644 --- a/include/box2d/collision.h +++ b/include/box2d/collision.h @@ -8,13 +8,7 @@ #include -typedef struct b2Circle b2Circle; -typedef struct b2Capsule b2Capsule; typedef struct b2DistanceCache b2DistanceCache; -typedef struct b2Polygon b2Polygon; -typedef struct b2Segment b2Segment; -typedef struct b2ChainSegment b2ChainSegment; - typedef struct b2Hull b2Hull; /** diff --git a/include/box2d/math_functions.h b/include/box2d/math_functions.h index 89e019814..977736f64 100644 --- a/include/box2d/math_functions.h +++ b/include/box2d/math_functions.h @@ -24,7 +24,7 @@ typedef struct b2Vec2 } b2Vec2; /// Cosine and sine pair -/// This uses a custom implementation designed for cross platform determinism +/// This uses a custom implementation designed for cross-platform determinism typedef struct b2CosSin { /// cosine and sine @@ -69,67 +69,71 @@ typedef struct b2AABB */ /// https://en.wikipedia.org/wiki/Pi -#define b2_pi 3.14159265359f +#define B2_PI 3.14159265359f static const b2Vec2 b2Vec2_zero = { 0.0f, 0.0f }; static const b2Rot b2Rot_identity = { 1.0f, 0.0f }; static const b2Transform b2Transform_identity = { { 0.0f, 0.0f }, { 1.0f, 0.0f } }; static const b2Mat22 b2Mat22_zero = { { 0.0f, 0.0f }, { 0.0f, 0.0f } }; -/// Compute an approximate arctangent in the range [-pi, pi] -/// This is hand coded for cross platform determinism. The atan2f -/// function in the standard library is not cross platform deterministic. -/// Accurate to around 0.0023 degrees -B2_API float b2Atan2( float y, float x ); - -/// @return the minimum of two floats -B2_INLINE float b2MinFloat( float a, float b ) +/// @return the minimum of two integers +B2_INLINE int b2MinInt( int a, int b ) { return a < b ? a : b; } -/// @return the maximum of two floats -B2_INLINE float b2MaxFloat( float a, float b ) +/// @return the maximum of two integers +B2_INLINE int b2MaxInt( int a, int b ) { return a > b ? a : b; } -/// @return the absolute value of a float -B2_INLINE float b2AbsFloat( float a ) +/// @return the absolute value of an integer +B2_INLINE int b2AbsInt( int a ) { return a < 0 ? -a : a; } -/// @return a float clamped between a lower and upper bound -B2_INLINE float b2ClampFloat( float a, float lower, float upper ) +/// @return an integer clamped between a lower and upper bound +B2_INLINE int b2ClampInt( int a, int lower, int upper ) { return a < lower ? lower : ( a > upper ? upper : a ); } -/// @return the minimum of two integers -B2_INLINE int b2MinInt( int a, int b ) +/// @return the minimum of two floats +B2_INLINE float b2MinFloat( float a, float b ) { return a < b ? a : b; } -/// @return the maximum of two integers -B2_INLINE int b2MaxInt( int a, int b ) +/// @return the maximum of two floats +B2_INLINE float b2MaxFloat( float a, float b ) { return a > b ? a : b; } -/// @return the absolute value of an integer -B2_INLINE int b2AbsInt( int a ) +/// @return the absolute value of a float +B2_INLINE float b2AbsFloat( float a ) { return a < 0 ? -a : a; } -/// @return an integer clamped between a lower and upper bound -B2_INLINE int b2ClampInt( int a, int lower, int upper ) +/// @return a float clamped between a lower and upper bound +B2_INLINE float b2ClampFloat( float a, float lower, float upper ) { return a < lower ? lower : ( a > upper ? upper : a ); } +/// Compute an approximate arctangent in the range [-pi, pi] +/// This is hand coded for cross-platform determinism. The atan2f +/// function in the standard library is not cross-platform deterministic. +/// Accurate to around 0.0023 degrees +B2_API float b2Atan2( float y, float x ); + +/// Compute the cosine and sine of an angle in radians. Implemented +/// for cross-platform determinism. +B2_API b2CosSin b2ComputeCosSin( float radians ); + /// Vector dot product B2_INLINE float b2Dot( b2Vec2 a, b2Vec2 b ) { @@ -191,11 +195,11 @@ B2_INLINE b2Vec2 b2Lerp( b2Vec2 a, b2Vec2 b, float t ) return B2_LITERAL( b2Vec2 ){ ( 1.0f - t ) * a.x + t * b.x, ( 1.0f - t ) * a.y + t * b.y }; } -///// Component-wise multiplication -//B2_INLINE b2Vec2 b2Mul( b2Vec2 a, b2Vec2 b ) -//{ -// return B2_LITERAL( b2Vec2 ){ a.x * b.x, a.y * b.y }; -//} +/// Component-wise multiplication +B2_INLINE b2Vec2 b2Mul( b2Vec2 a, b2Vec2 b ) +{ + return B2_LITERAL( b2Vec2 ){ a.x * b.x, a.y * b.y }; +} /// Multiply a scalar and vector B2_INLINE b2Vec2 b2MulSV( float s, b2Vec2 v ) @@ -333,12 +337,9 @@ B2_INLINE float b2DistanceSquared( b2Vec2 a, b2Vec2 b ) } /// Make a rotation using an angle in radians -B2_API b2CosSin b2ComputeCosSin( float angle ); - -/// Make a rotation using an angle in radians -B2_INLINE b2Rot b2MakeRot( float angle ) +B2_INLINE b2Rot b2MakeRot( float radians ) { - b2CosSin cs = b2ComputeCosSin( angle ); + b2CosSin cs = b2ComputeCosSin( radians ); return B2_LITERAL( b2Rot ){ cs.cosine, cs.sine }; } @@ -444,34 +445,34 @@ B2_INLINE float b2RelativeAngle( b2Rot b, b2Rot a ) } /// Convert an angle in the range [-2*pi, 2*pi] into the range [-pi, pi] -B2_INLINE float b2UnwindAngle( float angle ) +B2_INLINE float b2UnwindAngle( float radians ) { - if ( angle < -b2_pi ) + if ( radians < -B2_PI ) { - return angle + 2.0f * b2_pi; + return radians + 2.0f * B2_PI; } - else if ( angle > b2_pi ) + else if ( radians > B2_PI ) { - return angle - 2.0f * b2_pi; + return radians - 2.0f * B2_PI; } - return angle; + return radians; } /// Convert any into the range [-pi, pi] (slow) -B2_INLINE float b2UnwindLargeAngle( float angle ) +B2_INLINE float b2UnwindLargeAngle( float radians ) { - while ( angle > b2_pi ) + while ( radians > B2_PI ) { - angle -= 2.0f * b2_pi; + radians -= 2.0f * B2_PI; } - while ( angle < -b2_pi ) + while ( radians < -B2_PI ) { - angle += 2.0f * b2_pi; + radians += 2.0f * B2_PI; } - return angle; + return radians; } /// Rotate a vector diff --git a/include/box2d/types.h b/include/box2d/types.h index fa0c14300..0ce563ddd 100644 --- a/include/box2d/types.h +++ b/include/box2d/types.h @@ -86,7 +86,7 @@ typedef struct b2WorldDef float restitutionThreshold; /// This parameter controls how fast overlap is resolved and has units of meters per second - float contactPushoutVelocity; + float contactPushVelocity; /// Threshold velocity for hit events. Usually meters per second. float hitEventThreshold; @@ -346,11 +346,12 @@ typedef struct b2ShapeDef /// A sensor shape generates overlap events but never generates a collision response. /// Sensors do not collide with other sensors and do not have continuous collision. - /// Instead use a ray or shape cast for those scenarios. + /// Instead, use a ray or shape cast for those scenarios. bool isSensor; - /// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. - bool enableSensorEvents; +/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. +/// This applies for sensors and non-sensors. +bool enableSensorEvents; /// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. bool enableContactEvents; @@ -1173,162 +1174,155 @@ typedef float b2CastResultFcn( b2ShapeId shapeId, b2Vec2 point, b2Vec2 normal, f /// These colors are used for debug draw. /// See https://www.rapidtables.com/web/color/index.html +/// https://johndecember.com/html/spec/colorsvg.html +/// https://upload.wikimedia.org/wikipedia/commons/2/2b/SVG_Recognized_color_keyword_names.svg typedef enum b2HexColor { - b2_colorAliceBlue = 0xf0f8ff, - b2_colorAntiqueWhite = 0xfaebd7, - b2_colorAquamarine = 0x7fffd4, - b2_colorAzure = 0xf0ffff, - b2_colorBeige = 0xf5f5dc, - b2_colorBisque = 0xffe4c4, + b2_colorAliceBlue = 0xF0F8FF, + b2_colorAntiqueWhite = 0xFAEBD7, + b2_colorAqua = 0x00FFFF, + b2_colorAquamarine = 0x7FFFD4, + b2_colorAzure = 0xF0FFFF, + b2_colorBeige = 0xF5F5DC, + b2_colorBisque = 0xFFE4C4, b2_colorBlack = 0x000000, - b2_colorBlanchedAlmond = 0xffebcd, - b2_colorBlue = 0x0000ff, - b2_colorBlueViolet = 0x8a2be2, - b2_colorBrown = 0xa52a2a, - b2_colorBurlywood = 0xdeb887, - b2_colorCadetBlue = 0x5f9ea0, - b2_colorChartreuse = 0x7fff00, - b2_colorChocolate = 0xd2691e, - b2_colorCoral = 0xff7f50, - b2_colorCornflowerBlue = 0x6495ed, - b2_colorCornsilk = 0xfff8dc, - b2_colorCrimson = 0xdc143c, - b2_colorCyan = 0x00ffff, - b2_colorDarkBlue = 0x00008b, - b2_colorDarkCyan = 0x008b8b, - b2_colorDarkGoldenrod = 0xb8860b, - b2_colorDarkGray = 0xa9a9a9, + b2_colorBlanchedAlmond = 0xFFEBCD, + b2_colorBlue = 0x0000FF, + b2_colorBlueViolet = 0x8A2BE2, + b2_colorBrown = 0xA52A2A, + b2_colorBurlywood = 0xDEB887, + b2_colorCadetBlue = 0x5F9EA0, + b2_colorChartreuse = 0x7FFF00, + b2_colorChocolate = 0xD2691E, + b2_colorCoral = 0xFF7F50, + b2_colorCornflowerBlue = 0x6495ED, + b2_colorCornsilk = 0xFFF8DC, + b2_colorCrimson = 0xDC143C, + b2_colorCyan = 0x00FFFF, + b2_colorDarkBlue = 0x00008B, + b2_colorDarkCyan = 0x008B8B, + b2_colorDarkGoldenRod = 0xB8860B, + b2_colorDarkGray = 0xA9A9A9, b2_colorDarkGreen = 0x006400, - b2_colorDarkKhaki = 0xbdb76b, - b2_colorDarkMagenta = 0x8b008b, - b2_colorDarkOliveGreen = 0x556b2f, - b2_colorDarkOrange = 0xff8c00, - b2_colorDarkOrchid = 0x9932cc, - b2_colorDarkRed = 0x8b0000, - b2_colorDarkSalmon = 0xe9967a, - b2_colorDarkSeaGreen = 0x8fbc8f, - b2_colorDarkSlateBlue = 0x483d8b, - b2_colorDarkSlateGray = 0x2f4f4f, - b2_colorDarkTurquoise = 0x00ced1, - b2_colorDarkViolet = 0x9400d3, - b2_colorDeepPink = 0xff1493, - b2_colorDeepSkyBlue = 0x00bfff, + b2_colorDarkKhaki = 0xBDB76B, + b2_colorDarkMagenta = 0x8B008B, + b2_colorDarkOliveGreen = 0x556B2F, + b2_colorDarkOrange = 0xFF8C00, + b2_colorDarkOrchid = 0x9932CC, + b2_colorDarkRed = 0x8B0000, + b2_colorDarkSalmon = 0xE9967A, + b2_colorDarkSeaGreen = 0x8FBC8F, + b2_colorDarkSlateBlue = 0x483D8B, + b2_colorDarkSlateGray = 0x2F4F4F, + b2_colorDarkTurquoise = 0x00CED1, + b2_colorDarkViolet = 0x9400D3, + b2_colorDeepPink = 0xFF1493, + b2_colorDeepSkyBlue = 0x00BFFF, b2_colorDimGray = 0x696969, - b2_colorDodgerBlue = 0x1e90ff, - b2_colorFirebrick = 0xb22222, - b2_colorFloralWhite = 0xfffaf0, - b2_colorForestGreen = 0x228b22, - b2_colorGainsboro = 0xdcdcdc, - b2_colorGhostWhite = 0xf8f8ff, - b2_colorGold = 0xffd700, - b2_colorGoldenrod = 0xdaa520, - b2_colorGray = 0xbebebe, - b2_colorGray1 = 0x1a1a1a, - b2_colorGray2 = 0x333333, - b2_colorGray3 = 0x4d4d4d, - b2_colorGray4 = 0x666666, - b2_colorGray5 = 0x7f7f7f, - b2_colorGray6 = 0x999999, - b2_colorGray7 = 0xb3b3b3, - b2_colorGray8 = 0xcccccc, - b2_colorGray9 = 0xe5e5e5, - b2_colorGreen = 0x00ff00, - b2_colorGreenYellow = 0xadff2f, - b2_colorHoneydew = 0xf0fff0, - b2_colorHotPink = 0xff69b4, - b2_colorIndianRed = 0xcd5c5c, - b2_colorIndigo = 0x4b0082, - b2_colorIvory = 0xfffff0, - b2_colorKhaki = 0xf0e68c, - b2_colorLavender = 0xe6e6fa, - b2_colorLavenderBlush = 0xfff0f5, - b2_colorLawnGreen = 0x7cfc00, - b2_colorLemonChiffon = 0xfffacd, - b2_colorLightBlue = 0xadd8e6, - b2_colorLightCoral = 0xf08080, - b2_colorLightCyan = 0xe0ffff, - b2_colorLightGoldenrod = 0xeedd82, - b2_colorLightGoldenrodYellow = 0xfafad2, - b2_colorLightGray = 0xd3d3d3, - b2_colorLightGreen = 0x90ee90, - b2_colorLightPink = 0xffb6c1, - b2_colorLightSalmon = 0xffa07a, - b2_colorLightSeaGreen = 0x20b2aa, - b2_colorLightSkyBlue = 0x87cefa, - b2_colorLightSlateBlue = 0x8470ff, + b2_colorDodgerBlue = 0x1E90FF, + b2_colorFireBrick = 0xB22222, + b2_colorFloralWhite = 0xFFFAF0, + b2_colorForestGreen = 0x228B22, + b2_colorFuchsia = 0xFF00FF, + b2_colorGainsboro = 0xDCDCDC, + b2_colorGhostWhite = 0xF8F8FF, + b2_colorGold = 0xFFD700, + b2_colorGoldenRod = 0xDAA520, + b2_colorGray = 0x808080, + b2_colorGreen = 0x008000, + b2_colorGreenYellow = 0xADFF2F, + b2_colorHoneyDew = 0xF0FFF0, + b2_colorHotPink = 0xFF69B4, + b2_colorIndianRed = 0xCD5C5C, + b2_colorIndigo = 0x4B0082, + b2_colorIvory = 0xFFFFF0, + b2_colorKhaki = 0xF0E68C, + b2_colorLavender = 0xE6E6FA, + b2_colorLavenderBlush = 0xFFF0F5, + b2_colorLawnGreen = 0x7CFC00, + b2_colorLemonChiffon = 0xFFFACD, + b2_colorLightBlue = 0xADD8E6, + b2_colorLightCoral = 0xF08080, + b2_colorLightCyan = 0xE0FFFF, + b2_colorLightGoldenRodYellow = 0xFAFAD2, + b2_colorLightGray = 0xD3D3D3, + b2_colorLightGreen = 0x90EE90, + b2_colorLightPink = 0xFFB6C1, + b2_colorLightSalmon = 0xFFA07A, + b2_colorLightSeaGreen = 0x20B2AA, + b2_colorLightSkyBlue = 0x87CEFA, b2_colorLightSlateGray = 0x778899, - b2_colorLightSteelBlue = 0xb0c4de, - b2_colorLightYellow = 0xffffe0, - b2_colorLimeGreen = 0x32cd32, - b2_colorLinen = 0xfaf0e6, - b2_colorMagenta = 0xff00ff, - b2_colorMaroon = 0xb03060, - b2_colorMediumAquamarine = 0x66cdaa, - b2_colorMediumBlue = 0x0000cd, - b2_colorMediumOrchid = 0xba55d3, - b2_colorMediumPurple = 0x9370db, - b2_colorMediumSeaGreen = 0x3cb371, - b2_colorMediumSlateBlue = 0x7b68ee, - b2_colorMediumSpringGreen = 0x00fa9a, - b2_colorMediumTurquoise = 0x48d1cc, - b2_colorMediumVioletRed = 0xc71585, + b2_colorLightSteelBlue = 0xB0C4DE, + b2_colorLightYellow = 0xFFFFE0, + b2_colorLime = 0x00FF00, + b2_colorLimeGreen = 0x32CD32, + b2_colorLinen = 0xFAF0E6, + b2_colorMagenta = 0xFF00FF, + b2_colorMaroon = 0x800000, + b2_colorMediumAquaMarine = 0x66CDAA, + b2_colorMediumBlue = 0x0000CD, + b2_colorMediumOrchid = 0xBA55D3, + b2_colorMediumPurple = 0x9370DB, + b2_colorMediumSeaGreen = 0x3CB371, + b2_colorMediumSlateBlue = 0x7B68EE, + b2_colorMediumSpringGreen = 0x00FA9A, + b2_colorMediumTurquoise = 0x48D1CC, + b2_colorMediumVioletRed = 0xC71585, b2_colorMidnightBlue = 0x191970, - b2_colorMintCream = 0xf5fffa, - b2_colorMistyRose = 0xffe4e1, - b2_colorMoccasin = 0xffe4b5, - b2_colorNavajoWhite = 0xffdead, - b2_colorNavyBlue = 0x000080, - b2_colorOldLace = 0xfdf5e6, + b2_colorMintCream = 0xF5FFFA, + b2_colorMistyRose = 0xFFE4E1, + b2_colorMoccasin = 0xFFE4B5, + b2_colorNavajoWhite = 0xFFDEAD, + b2_colorNavy = 0x000080, + b2_colorOldLace = 0xFDF5E6, b2_colorOlive = 0x808000, - b2_colorOliveDrab = 0x6b8e23, - b2_colorOrange = 0xffa500, - b2_colorOrangeRed = 0xff4500, - b2_colorOrchid = 0xda70d6, - b2_colorPaleGoldenrod = 0xeee8aa, - b2_colorPaleGreen = 0x98fb98, - b2_colorPaleTurquoise = 0xafeeee, - b2_colorPaleVioletRed = 0xdb7093, - b2_colorPapayaWhip = 0xffefd5, - b2_colorPeachPuff = 0xffdab9, - b2_colorPeru = 0xcd853f, - b2_colorPink = 0xffc0cb, - b2_colorPlum = 0xdda0dd, - b2_colorPowderBlue = 0xb0e0e6, - b2_colorPurple = 0xa020f0, + b2_colorOliveDrab = 0x6B8E23, + b2_colorOrange = 0xFFA500, + b2_colorOrangeRed = 0xFF4500, + b2_colorOrchid = 0xDA70D6, + b2_colorPaleGoldenRod = 0xEEE8AA, + b2_colorPaleGreen = 0x98FB98, + b2_colorPaleTurquoise = 0xAFEEEE, + b2_colorPaleVioletRed = 0xDB7093, + b2_colorPapayaWhip = 0xFFEFD5, + b2_colorPeachPuff = 0xFFDAB9, + b2_colorPeru = 0xCD853F, + b2_colorPink = 0xFFC0CB, + b2_colorPlum = 0xDDA0DD, + b2_colorPowderBlue = 0xB0E0E6, + b2_colorPurple = 0x800080, b2_colorRebeccaPurple = 0x663399, - b2_colorRed = 0xff0000, - b2_colorRosyBrown = 0xbc8f8f, - b2_colorRoyalBlue = 0x4169e1, - b2_colorSaddleBrown = 0x8b4513, - b2_colorSalmon = 0xfa8072, - b2_colorSandyBrown = 0xf4a460, - b2_colorSeaGreen = 0x2e8b57, - b2_colorSeashell = 0xfff5ee, - b2_colorSienna = 0xa0522d, - b2_colorSilver = 0xc0c0c0, - b2_colorSkyBlue = 0x87ceeb, - b2_colorSlateBlue = 0x6a5acd, + b2_colorRed = 0xFF0000, + b2_colorRosyBrown = 0xBC8F8F, + b2_colorRoyalBlue = 0x4169E1, + b2_colorSaddleBrown = 0x8B4513, + b2_colorSalmon = 0xFA8072, + b2_colorSandyBrown = 0xF4A460, + b2_colorSeaGreen = 0x2E8B57, + b2_colorSeaShell = 0xFFF5EE, + b2_colorSienna = 0xA0522D, + b2_colorSilver = 0xC0C0C0, + b2_colorSkyBlue = 0x87CEEB, + b2_colorSlateBlue = 0x6A5ACD, b2_colorSlateGray = 0x708090, - b2_colorSnow = 0xfffafa, - b2_colorSpringGreen = 0x00ff7f, - b2_colorSteelBlue = 0x4682b4, - b2_colorTan = 0xd2b48c, + b2_colorSnow = 0xFFFAFA, + b2_colorSpringGreen = 0x00FF7F, + b2_colorSteelBlue = 0x4682B4, + b2_colorTan = 0xD2B48C, b2_colorTeal = 0x008080, - b2_colorThistle = 0xd8bfd8, - b2_colorTomato = 0xff6347, - b2_colorTurquoise = 0x40e0d0, - b2_colorViolet = 0xee82ee, - b2_colorVioletRed = 0xd02090, - b2_colorWheat = 0xf5deb3, - b2_colorWhite = 0xffffff, - b2_colorWhiteSmoke = 0xf5f5f5, - b2_colorYellow = 0xffff00, - b2_colorYellowGreen = 0x9acd32, - b2_colorBox2DRed = 0xdc3132, - b2_colorBox2DBlue = 0x30aebf, - b2_colorBox2DGreen = 0x8cc924, - b2_colorBox2DYellow = 0xffee8c + b2_colorThistle = 0xD8BFD8, + b2_colorTomato = 0xFF6347, + b2_colorTurquoise = 0x40E0D0, + b2_colorViolet = 0xEE82EE, + b2_colorWheat = 0xF5DEB3, + b2_colorWhite = 0xFFFFFF, + b2_colorWhiteSmoke = 0xF5F5F5, + b2_colorYellow = 0xFFFF00, + b2_colorYellowGreen = 0x9ACD32, + b2_colorBox2DRed = 0xDC3132, + b2_colorBox2DBlue = 0x30AEBF, + b2_colorBox2DGreen = 0x8CC924, + b2_colorBox2DYellow = 0xFFEE8C } b2HexColor; /// This struct holds callbacks you can implement to draw a Box2D world. diff --git a/samples/donut.cpp b/samples/donut.cpp index 48c3f65af..7acad387d 100644 --- a/samples/donut.cpp +++ b/samples/donut.cpp @@ -30,8 +30,8 @@ void Donut::Spawn( b2WorldId worldId, b2Vec2 position, float scale, int groupInd } float radius = 1.0f * scale; - float deltaAngle = 2.0f * b2_pi / e_sides; - float length = 2.0f * b2_pi * radius / e_sides; + float deltaAngle = 2.0f * B2_PI / e_sides; + float length = 2.0f * B2_PI * radius / e_sides; b2Capsule capsule = { { 0.0f, -0.5f * length }, { 0.0f, 0.5f * length }, 0.25f * scale }; diff --git a/samples/draw.cpp b/samples/draw.cpp index 53776cbf6..bc65eb75b 100644 --- a/samples/draw.cpp +++ b/samples/draw.cpp @@ -1328,6 +1328,8 @@ Draw::Draw() m_smallFont = nullptr; m_mediumFont = nullptr; m_largeFont = nullptr; + m_regularFont = nullptr; + m_background = nullptr; } Draw::~Draw() @@ -1339,6 +1341,7 @@ Draw::~Draw() assert( m_solidCircles == nullptr ); assert( m_solidCapsules == nullptr ); assert( m_solidPolygons == nullptr ); + assert( m_background == nullptr ); } void Draw::Create() diff --git a/samples/main.cpp b/samples/main.cpp index a00777041..2de8007a6 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -541,6 +541,7 @@ int main( int, char** ) s_settings.Load(); s_settings.workerCount = b2MinInt( 8, (int)enki::GetNumHardwareThreads() / 2 ); + SortSamples(); glfwSetErrorCallback( glfwErrorCallback ); diff --git a/samples/sample_benchmark.cpp b/samples/sample_benchmark.cpp index 7d4a53151..1601edcf9 100644 --- a/samples/sample_benchmark.cpp +++ b/samples/sample_benchmark.cpp @@ -22,7 +22,7 @@ class BenchmarkBarrel : public Sample enum ShapeType { e_circleShape = 0, - e_caspuleShape, + e_capsuleShape, e_mixShape, e_compoundShape, e_humanShape, @@ -218,7 +218,7 @@ class BenchmarkBarrel : public Sample circle.radius = RandomFloatRange( 0.25f, 0.75f ); b2CreateCircleShape( m_bodies[index], &shapeDef, &circle ); } - else if ( m_shapeType == e_caspuleShape ) + else if ( m_shapeType == e_capsuleShape ) { m_bodies[index] = b2CreateBody( m_worldId, &bodyDef ); capsule.radius = RandomFloatRange( 0.25f, 0.5f ); @@ -394,7 +394,7 @@ class BenchmarkManyTumblers : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.type = b2_kinematicBody; bodyDef.position = { position.x, position.y }; - bodyDef.angularVelocity = ( b2_pi / 180.0f ) * m_angularSpeed; + bodyDef.angularVelocity = ( B2_PI / 180.0f ) * m_angularSpeed; b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef ); m_tumblerIds[index] = bodyId; @@ -482,7 +482,7 @@ class BenchmarkManyTumblers : public Sample { for ( int i = 0; i < m_tumblerCount; ++i ) { - b2Body_SetAngularVelocity( m_tumblerIds[i], ( b2_pi / 180.0f ) * m_angularSpeed ); + b2Body_SetAngularVelocity( m_tumblerIds[i], ( B2_PI / 180.0f ) * m_angularSpeed ); b2Body_SetAwake( m_tumblerIds[i], true ); } } @@ -1476,6 +1476,16 @@ class BenchmarkSpinner : public Sample CreateSpinner( m_worldId ); } + void Step( Settings& settings ) override + { + Sample::Step( settings ); + + if ( m_stepCount == 2000 ) + { + m_stepCount += 0; + } + } + static Sample* Create( Settings& settings ) { return new BenchmarkSpinner( settings ); @@ -1510,6 +1520,11 @@ class BenchmarkRain : public Sample } Sample::Step( settings ); + + if (m_stepCount == 1000) + { + m_stepCount += 0; + } } static Sample* Create( Settings& settings ) diff --git a/samples/sample_bodies.cpp b/samples/sample_bodies.cpp index b99dc1431..0ebf1ceea 100644 --- a/samples/sample_bodies.cpp +++ b/samples/sample_bodies.cpp @@ -69,7 +69,7 @@ class BodyType : public Sample bodyDef.position = { -4.0f, 5.0f }; m_platformId = b2CreateBody( m_worldId, &bodyDef ); - b2Polygon box = b2MakeOffsetBox( 0.5f, 4.0f, { 4.0f, 0.0f }, b2MakeRot( 0.5f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 0.5f, 4.0f, { 4.0f, 0.0f }, b2MakeRot( 0.5f * B2_PI ) ); b2ShapeDef shapeDef = b2DefaultShapeDef(); shapeDef.friction = 0.6f; @@ -333,7 +333,7 @@ class Character : public Sample // Chain shape { b2BodyDef bodyDef = b2DefaultBodyDef(); - bodyDef.rotation = b2MakeRot( 0.25f * b2_pi ); + bodyDef.rotation = b2MakeRot( 0.25f * B2_PI ); b2BodyId groundId = b2CreateBody( m_worldId, &bodyDef ); b2Vec2 points[4] = { { 8.0f, 7.0f }, { 7.0f, 8.0f }, { 6.0f, 8.0f }, { 5.0f, 7.0f } }; @@ -495,7 +495,7 @@ class Weeble : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.type = b2_dynamicBody; bodyDef.position = { 0.0f, 3.0f }; - bodyDef.rotation = b2MakeRot( 0.25f * b2_pi ); + bodyDef.rotation = b2MakeRot( 0.25f * B2_PI ); m_weebleId = b2CreateBody( m_worldId, &bodyDef ); b2Capsule capsule = { { 0.0f, -1.0f }, { 0.0f, 1.0f }, 1.0f }; @@ -528,7 +528,7 @@ class Weeble : public Sample ImGui::Begin( "Weeble", nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize ); if ( ImGui::Button( "Teleport" ) ) { - b2Body_SetTransform( m_weebleId, { 0.0f, 5.0f }, b2MakeRot( 0.95 * b2_pi ) ); + b2Body_SetTransform( m_weebleId, { 0.0f, 5.0f }, b2MakeRot( 0.95 * B2_PI ) ); } if ( ImGui::Button( "Explode" ) ) @@ -633,7 +633,7 @@ class Sleep : public Sample bodyDef.enableSleep = false; b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef ); - b2Polygon box = b2MakeOffsetBox( 1.0f, 1.0f, { 0.0f, 1.0f }, b2MakeRot( 0.25f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 1.0f, 1.0f, { 0.0f, 1.0f }, b2MakeRot( 0.25f * B2_PI ) ); b2ShapeDef shapeDef = b2DefaultShapeDef(); b2CreatePolygonShape( bodyId, &shapeDef, &box ); } @@ -791,7 +791,7 @@ class BadBody : public Sample bodyDef.type = b2_dynamicBody; bodyDef.position = { 0.0f, 3.0f }; bodyDef.angularVelocity = 0.5f; - bodyDef.rotation = b2MakeRot( 0.25f * b2_pi ); + bodyDef.rotation = b2MakeRot( 0.25f * B2_PI ); m_badBodyId = b2CreateBody( m_worldId, &bodyDef ); @@ -808,7 +808,7 @@ class BadBody : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.type = b2_dynamicBody; bodyDef.position = { 2.0f, 3.0f }; - bodyDef.rotation = b2MakeRot( 0.25f * b2_pi ); + bodyDef.rotation = b2MakeRot( 0.25f * B2_PI ); b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef ); diff --git a/samples/sample_collision.cpp b/samples/sample_collision.cpp index 3ea0b83d8..21cf7581e 100644 --- a/samples/sample_collision.cpp +++ b/samples/sample_collision.cpp @@ -12,7 +12,6 @@ #include #include - #include constexpr int SIMPLEX_CAPACITY = 20; @@ -197,7 +196,7 @@ class ShapeDistance : public Sample ImGui::SliderFloat( "x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f" ); ImGui::SliderFloat( "y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f" ); - if ( ImGui::SliderFloat( "angle", &m_angle, -b2_pi, b2_pi, "%.2f" ) ) + if ( ImGui::SliderFloat( "angle", &m_angle, -B2_PI, B2_PI, "%.2f" ) ) { m_transform.q = b2MakeRot( m_angle ); } @@ -261,7 +260,7 @@ class ShapeDistance : public Sample else if ( m_rotating ) { float dx = p.x - m_startPoint.x; - m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -b2_pi, b2_pi ); + m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -B2_PI, B2_PI ); m_transform.q = b2MakeRot( m_angle ); } } @@ -927,7 +926,7 @@ class RayCast : public Sample ImGui::SliderFloat( "x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f" ); ImGui::SliderFloat( "y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f" ); - if ( ImGui::SliderFloat( "angle", &m_angle, -b2_pi, b2_pi, "%.2f" ) ) + if ( ImGui::SliderFloat( "angle", &m_angle, -B2_PI, B2_PI, "%.2f" ) ) { m_transform.q = b2MakeRot( m_angle ); } @@ -1003,7 +1002,7 @@ class RayCast : public Sample else if ( m_rotating ) { float dx = p.x - m_startPosition.x; - m_angle = b2ClampFloat( m_baseAngle + 0.5f * dx, -b2_pi, b2_pi ); + m_angle = b2ClampFloat( m_baseAngle + 0.5f * dx, -B2_PI, B2_PI ); m_transform.q = b2MakeRot( m_angle ); } } @@ -1473,7 +1472,7 @@ class RayCastWorld : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.position = { x, y }; - bodyDef.rotation = b2MakeRot( RandomFloatRange( -b2_pi, b2_pi ) ); + bodyDef.rotation = b2MakeRot( RandomFloatRange( -B2_PI, B2_PI ) ); m_bodyIds[m_bodyIndex] = b2CreateBody( m_worldId, &bodyDef ); @@ -1661,7 +1660,7 @@ class RayCastWorld : public Sample m_textLine += m_textIncrement; b2HexColor color1 = b2_colorGreen; - b2HexColor color2 = b2_colorGray8; + b2HexColor color2 = b2_colorLightGray; b2HexColor color3 = b2_colorMagenta; b2Vec2 rayTranslation = b2Sub( m_rayEnd, m_rayStart ); @@ -1959,7 +1958,7 @@ class OverlapWorld : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.position = { x, y }; - bodyDef.rotation = b2MakeRot( RandomFloatRange( -b2_pi, b2_pi ) ); + bodyDef.rotation = b2MakeRot( RandomFloatRange( -B2_PI, B2_PI ) ); m_bodyIds[m_bodyIndex] = b2CreateBody( m_worldId, &bodyDef ); @@ -2270,7 +2269,7 @@ class Manifold : public Sample ImGui::SliderFloat( "x offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f" ); ImGui::SliderFloat( "y offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f" ); - if ( ImGui::SliderFloat( "angle", &m_angle, -b2_pi, b2_pi, "%.2f" ) ) + if ( ImGui::SliderFloat( "angle", &m_angle, -B2_PI, B2_PI, "%.2f" ) ) { m_transform.q = b2MakeRot( m_angle ); } @@ -2333,7 +2332,7 @@ class Manifold : public Sample else if ( m_rotating ) { float dx = p.x - m_startPoint.x; - m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -b2_pi, b2_pi ); + m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -B2_PI, B2_PI ); m_transform.q = b2MakeRot( m_angle ); } } @@ -2380,7 +2379,7 @@ class Manifold : public Sample b2Vec2 increment = { 4.0f, 0.0f }; b2HexColor color1 = b2_colorAquamarine; - b2HexColor color2 = b2_colorPaleGoldenrod; + b2HexColor color2 = b2_colorPaleGoldenRod; if ( m_enableCaching == false ) { @@ -2495,7 +2494,7 @@ class Manifold : public Sample // box-capsule { b2Capsule capsule = { { -0.4f, 0.0f }, { -0.1f, 0.0f }, 0.1f }; - b2Polygon box = b2MakeOffsetBox( 0.25f, 1.0f, { 1.0f, -1.0f }, b2MakeRot( 0.25f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 0.25f, 1.0f, { 1.0f, -1.0f }, b2MakeRot( 0.25f * B2_PI ) ); b2Transform transform1 = { offset, b2Rot_identity }; b2Transform transform2 = { b2Add( m_transform.p, offset ), m_transform.q }; @@ -2955,7 +2954,7 @@ class SmoothManifold : public Sample ImGui::SliderFloat( "x Offset", &m_transform.p.x, -2.0f, 2.0f, "%.2f" ); ImGui::SliderFloat( "y Offset", &m_transform.p.y, -2.0f, 2.0f, "%.2f" ); - if ( ImGui::SliderFloat( "Angle", &m_angle, -b2_pi, b2_pi, "%.2f" ) ) + if ( ImGui::SliderFloat( "Angle", &m_angle, -B2_PI, B2_PI, "%.2f" ) ) { m_transform.q = b2MakeRot( m_angle ); } @@ -3018,7 +3017,7 @@ class SmoothManifold : public Sample else if ( m_rotating ) { float dx = p.x - m_startPoint.x; - m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -b2_pi, b2_pi ); + m_angle = b2ClampFloat( m_baseAngle + 1.0f * dx, -B2_PI, B2_PI ); m_transform.q = b2MakeRot( m_angle ); } } @@ -3183,7 +3182,7 @@ class ShapeCast : public Sample m_radiusB = 0.25f; m_transformA.p = { 0.0f, 0.0 }; - m_transformA.q = b2MakeRot( 0.25f * b2_pi ); + m_transformA.q = b2MakeRot( 0.25f * B2_PI ); m_transformB.p = { -8.0f, 0.0f }; m_transformB.q = b2Rot_identity; m_translationB = { 8.0f, 0.0f }; @@ -3313,16 +3312,16 @@ class ShapeCast : public Sample { if ( m_radiusA > 0.0f ) { - g_draw.DrawSolidCircle( b2Transform_identity, vertices[0], m_radiusA, b2_colorGray9 ); + g_draw.DrawSolidCircle( b2Transform_identity, vertices[0], m_radiusA, b2_colorLightGray ); } else { - g_draw.DrawPoint( vertices[0], 5.0f, b2_colorGray9 ); + g_draw.DrawPoint( vertices[0], 5.0f, b2_colorLightGray ); } } else { - g_draw.DrawSolidPolygon( b2Transform_identity, vertices, m_countA, m_radiusA, b2_colorGray9 ); + g_draw.DrawSolidPolygon( b2Transform_identity, vertices, m_countA, m_radiusA, b2_colorLightGray ); } for ( int i = 0; i < m_countB; ++i ) @@ -3403,7 +3402,8 @@ class TimeOfImpact : public Sample if ( settings.restart == false ) { g_camera.m_center = { 0.6f, 2.0f }; - g_camera.m_zoom = 25.0f * 0.18f; + g_camera.m_center = { -123.750000f, 134.750000f }; + g_camera.m_zoom = 5.0f; } } @@ -3412,16 +3412,63 @@ class TimeOfImpact : public Sample return new TimeOfImpact( settings ); } +#if 0 +- input 0x00000044f14fd550 {proxyA={points=0x00000044f14fd550 {{...}, {...}, {...}, {...}, {...}, {...}, {...}, ...} ...} ...} const b2TOIInput * +- proxyA {points=0x00000044f14fd550 {{x=-123.750000 y=134.750000 }, {x=-123.250000 y=134.750000 }, {x=-123.250000 ...}, ...} ...} b2DistanceProxy +- points 0x00000044f14fd550 {{x=-123.750000 y=134.750000 }, {x=-123.250000 y=134.750000 }, {x=-123.250000 y=135.250000 }, ...} b2Vec2[8] ++ [0] {x=-123.750000 y=134.750000 } b2Vec2 ++ [1] {x=-123.250000 y=134.750000 } b2Vec2 ++ [2] {x=-123.250000 y=135.250000 } b2Vec2 ++ [3] {x=-123.750000 y=135.250000 } b2Vec2 ++ [4] {x=-123.905960 y=135.246246 } b2Vec2 ++ [5] {x=-123.583496 y=135.491089 } b2Vec2 ++ [6] {x=-1.02951760e+30 y=9.529e-44#DEN } b2Vec2 ++ [7] {x=8.40272566e-18 y=7.539e-43#DEN } b2Vec2 + count 4 int + radius 0.00000000 float +- proxyB {points=0x00000044f14fd598 {{x=0.00000000 y=-0.125000000 }, {x=0.00000000 y=0.125000000 }, {x=-123.250000 ...}, ...} ...} b2DistanceProxy +- points 0x00000044f14fd598 {{x=0.00000000 y=-0.125000000 }, {x=0.00000000 y=0.125000000 }, {x=-123.250000 y=...}, ...} b2Vec2[8] ++ [0] {x=0.00000000 y=-0.125000000 } b2Vec2 ++ [1] {x=0.00000000 y=0.125000000 } b2Vec2 ++ [2] {x=-123.250000 y=135.250000 } b2Vec2 ++ [3] {x=-123.750000 y=135.250000 } b2Vec2 ++ [4] {x=-123.905960 y=135.246246 } b2Vec2 ++ [5] {x=-123.583496 y=135.491089 } b2Vec2 ++ [6] {x=-1.02951760e+30 y=9.529e-44#DEN } b2Vec2 ++ [7] {x=8.40272566e-18 y=7.539e-43#DEN } b2Vec2 + count 2 int + radius 0.0350000001 float +- sweepA {localCenter={x=0.00000000 y=0.00000000 } c1={x=0.00000000 y=0.00000000 } c2={x=0.00000000 y=0.00000000 } ...} b2Sweep ++ localCenter {x=0.00000000 y=0.00000000 } b2Vec2 ++ c1 {x=0.00000000 y=0.00000000 } b2Vec2 ++ c2 {x=0.00000000 y=0.00000000 } b2Vec2 ++ q1 {c=1.00000000 s=0.00000000 } b2Rot ++ q2 {c=1.00000000 s=0.00000000 } b2Rot +- sweepB {localCenter={x=0.00000000 y=0.00000000 } c1={x=-123.721443 y=135.385178 } c2={x=-123.757744 y=135.334244 } ...} b2Sweep ++ localCenter {x=0.00000000 y=0.00000000 } b2Vec2 ++ c1 {x=-123.721443 y=135.385178 } b2Vec2 ++ c2 {x=-123.757744 y=135.334244 } b2Vec2 ++ q1 {c=0.567239463 s=0.823552966 } b2Rot ++ q2 {c=0.423919678 s=0.905699849 } b2Rot + tMax 1.00000000 float + +#endif void Step( Settings& settings ) override { Sample::Step( settings ); - b2Sweep sweepA = { b2Vec2_zero, { 0.0f, 0.0f }, { 0.0f, 0.0f }, b2Rot_identity, b2Rot_identity }; - b2Sweep sweepB = { b2Vec2_zero, { 2.0f, 4.0f }, { 2.0f, 4.0f }, b2Rot_identity, b2MakeRot( -0.25f * b2_pi ) }; + b2Sweep sweepA = { + b2Vec2_zero, { 0.0f, 0.0f }, { 0.0f, 0.0f }, b2Rot_identity, b2Rot_identity, + }; + b2Sweep sweepB = { b2Vec2_zero, + { -123.721443f, 135.385178f }, + { -123.757744f, 135.334244f }, + { 0.567239463f, 0.823552966f }, + { 0.423919678f, 0.905699849f } }; b2TOIInput input; - input.proxyA = b2MakeProxy( m_verticesA, m_countA, 0.0f ); - input.proxyB = b2MakeProxy( m_verticesB, m_countB, 0.0f ); + input.proxyA = b2MakeProxy( m_verticesA, m_countA, m_radiusA ); + input.proxyB = b2MakeProxy( m_verticesB, m_countB, m_radiusB ); input.sweepA = sweepA; input.sweepB = sweepB; input.tMax = 1.0f; @@ -3451,7 +3498,8 @@ class TimeOfImpact : public Sample { vertices[i] = b2TransformPoint( transformB, m_verticesB[i] ); } - g_draw.DrawPolygon( vertices, m_countB, b2_colorGreen ); + g_draw.DrawSolidCapsule( vertices[0], vertices[1], m_radiusB, b2_colorGreen ); + // g_draw.DrawPolygon( vertices, m_countB, b2_colorGreen ); // Draw B at t = hit_time transformB = b2GetSweepTransform( &sweepB, output.t ); @@ -3467,7 +3515,8 @@ class TimeOfImpact : public Sample { vertices[i] = b2TransformPoint( transformB, m_verticesB[i] ); } - g_draw.DrawPolygon( vertices, m_countB, b2_colorRed ); + g_draw.DrawSolidCapsule( vertices[0], vertices[1], m_radiusB, b2_colorRed ); + // g_draw.DrawPolygon( vertices, m_countB, b2_colorRed ); if ( output.state == b2_toiStateHit ) { @@ -3496,10 +3545,15 @@ class TimeOfImpact : public Sample #endif } - b2Vec2 m_verticesA[4] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 5.0f }, { -1.0f, 5.0f } }; - b2Vec2 m_verticesB[4] = { { -0.5f, -4.0f }, { 0.0f, -4.0f }, { 0.0f, 0.0f }, { -0.5f, 0.0f } }; + b2Vec2 m_verticesA[4] = { + { -123.750000, 134.750000 }, { -123.250000, 134.750000 }, { -123.250000, 135.250000 }, { -123.750000, 135.250000 } }; + b2Vec2 m_verticesB[2] = { { 0.0f, -0.125000000f }, { 0.0f, 0.125000000f } }; + int m_countA = ARRAY_COUNT( m_verticesA ); int m_countB = ARRAY_COUNT( m_verticesB ); + + float m_radiusA = 0.0f; + float m_radiusB = 0.0350000001f; }; static int sampleTimeOfImpact = RegisterSample( "Collision", "Time of Impact", TimeOfImpact::Create ); diff --git a/samples/sample_continuous.cpp b/samples/sample_continuous.cpp index 36d748ed9..05364c664 100644 --- a/samples/sample_continuous.cpp +++ b/samples/sample_continuous.cpp @@ -64,7 +64,7 @@ class BounceHouse : public Sample b2CreateSegmentShape( groundId, &shapeDef, &segment ); } - m_shapeType = e_circleShape; + m_shapeType = e_boxShape; m_bodyId = b2_nullBodyId; m_enableHitEvents = true; @@ -171,6 +171,11 @@ class BounceHouse : public Sample g_draw.DrawString( e->point, "%.1f", e->speed ); } } + + if ( m_stepCount == 1000 ) + { + m_stepCount += 0; + } } static Sample* Create( Settings& settings ) @@ -499,7 +504,7 @@ class GhostBumps : public Sample // Left slope x = -3.0f * hx - m * hx - m * hy; y = hy + m * hx - m * hy; - transform.q = b2MakeRot( -0.25f * b2_pi ); + transform.q = b2MakeRot( -0.25f * B2_PI ); { transform.p = { x, y }; @@ -548,7 +553,7 @@ class GhostBumps : public Sample x = 3.0f * hx + m * hx + m * hy; y = hy + m * hx - m * hy; - transform.q = b2MakeRot( 0.25f * b2_pi ); + transform.q = b2MakeRot( 0.25f * B2_PI ); { transform.p = { x, y }; @@ -718,7 +723,7 @@ class SpeculativeFallback : public Sample b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef ); b2ShapeDef shapeDef = b2DefaultShapeDef(); - b2Polygon box = b2MakeOffsetBox( 2.0f, 0.05f, { -offset, 0.0f }, b2MakeRot( b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 2.0f, 0.05f, { -offset, 0.0f }, b2MakeRot( B2_PI ) ); b2CreatePolygonShape( bodyId, &shapeDef, &box ); } } @@ -948,7 +953,7 @@ class Drop : public Sample float h = 0.05f; for ( int j = 0; j <= count; ++j ) { - b2Polygon box = b2MakeOffsetBox( w, h, { x, 0.0f }, b2Rot_identity ); + b2Polygon box = b2MakeOffsetBox( 0.5f * w, h, { x, 0.0f }, b2Rot_identity ); b2CreatePolygonShape( groundId, &shapeDef, &box ); x += w; } @@ -1009,7 +1014,7 @@ class Drop : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.type = b2_dynamicBody; bodyDef.position = { 0.0f, 4.0f }; - bodyDef.rotation = b2MakeRot( 0.5f * b2_pi ); + bodyDef.rotation = b2MakeRot( 0.5f * B2_PI ); bodyDef.linearVelocity = { 0.0f, 0.0f }; bodyDef.angularVelocity = -0.5f; @@ -1248,15 +1253,15 @@ class Pinball : public Sample jointDef.motorSpeed = 0.0f; jointDef.localAnchorA = p1; jointDef.bodyIdB = leftFlipperId; - jointDef.lowerAngle = -30.0f * b2_pi / 180.0f; - jointDef.upperAngle = 5.0f * b2_pi / 180.0f; + jointDef.lowerAngle = -30.0f * B2_PI / 180.0f; + jointDef.upperAngle = 5.0f * B2_PI / 180.0f; m_leftJointId = b2CreateRevoluteJoint( m_worldId, &jointDef ); jointDef.motorSpeed = 0.0f; jointDef.localAnchorA = p2; jointDef.bodyIdB = rightFlipperId; - jointDef.lowerAngle = -5.0f * b2_pi / 180.0f; - jointDef.upperAngle = 30.0f * b2_pi / 180.0f; + jointDef.lowerAngle = -5.0f * B2_PI / 180.0f; + jointDef.upperAngle = 30.0f * B2_PI / 180.0f; m_rightJointId = b2CreateRevoluteJoint( m_worldId, &jointDef ); } diff --git a/samples/sample_determinism.cpp b/samples/sample_determinism.cpp index 3c9c8d2e2..03b34ccd9 100644 --- a/samples/sample_determinism.cpp +++ b/samples/sample_determinism.cpp @@ -66,8 +66,8 @@ class FallingHinges : public Sample b2RevoluteJointDef jointDef = b2DefaultRevoluteJointDef(); jointDef.enableLimit = true; - jointDef.lowerAngle = -0.1f * b2_pi; - jointDef.upperAngle = 0.2f * b2_pi; + jointDef.lowerAngle = -0.1f * B2_PI; + jointDef.upperAngle = 0.2f * B2_PI; jointDef.enableSpring = true; jointDef.hertz = 0.5f; jointDef.dampingRatio = 0.5f; diff --git a/samples/sample_events.cpp b/samples/sample_events.cpp index 01d4c1260..3f85b6290 100644 --- a/samples/sample_events.cpp +++ b/samples/sample_events.cpp @@ -681,7 +681,7 @@ class ContactEvent : public Sample b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.type = b2_dynamicBody; bodyDef.position = { RandomFloatRange( -38.0f, 38.0f ), RandomFloatRange( -38.0f, 38.0f ) }; - bodyDef.rotation = b2MakeRot( RandomFloatRange( -b2_pi, b2_pi ) ); + bodyDef.rotation = b2MakeRot( RandomFloatRange( -B2_PI, B2_PI ) ); bodyDef.linearVelocity = { RandomFloatRange( -5.0f, 5.0f ), RandomFloatRange( -5.0f, 5.0f ) }; bodyDef.angularVelocity = RandomFloatRange( -1.0f, 1.0f ); bodyDef.gravityScale = 0.0f; @@ -1259,10 +1259,10 @@ class BodyMove : public Sample b2ShapeDef shapeDef = b2DefaultShapeDef(); shapeDef.friction = 0.1f; - b2Polygon box = b2MakeOffsetBox( 12.0f, 0.1f, { -10.0f, -0.1f }, b2MakeRot( -0.15f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 12.0f, 0.1f, { -10.0f, -0.1f }, b2MakeRot( -0.15f * B2_PI ) ); b2CreatePolygonShape( groundId, &shapeDef, &box ); - box = b2MakeOffsetBox( 12.0f, 0.1f, { 10.0f, -0.1f }, b2MakeRot( 0.15f * b2_pi ) ); + box = b2MakeOffsetBox( 12.0f, 0.1f, { 10.0f, -0.1f }, b2MakeRot( 0.15f * B2_PI ) ); b2CreatePolygonShape( groundId, &shapeDef, &box ); shapeDef.restitution = 0.8f; diff --git a/samples/sample_geometry.cpp b/samples/sample_geometry.cpp index be9e83b5b..3f73553cf 100644 --- a/samples/sample_geometry.cpp +++ b/samples/sample_geometry.cpp @@ -66,7 +66,7 @@ class ConvexHull : public Sample m_count = e_count; #else - float angle = b2_pi * RandomFloat(); + float angle = B2_PI * RandomFloat(); b2Rot r = b2MakeRot( angle ); b2Vec2 lowerBound = { -4.0f, -4.0f }; diff --git a/samples/sample_joints.cpp b/samples/sample_joints.cpp index 98dc17971..59e0f6300 100644 --- a/samples/sample_joints.cpp +++ b/samples/sample_joints.cpp @@ -317,7 +317,7 @@ class MotorJoint : public Sample linearOffset.x = 6.0f * sinf( 2.0f * m_time ); linearOffset.y = 8.0f + 4.0f * sinf( 1.0f * m_time ); - float angularOffset = b2_pi * sinf( -0.5f * m_time ); + float angularOffset = B2_PI * sinf( -0.5f * m_time ); b2MotorJoint_SetLinearOffset( m_jointId, linearOffset ); b2MotorJoint_SetAngularOffset( m_jointId, angularOffset ); @@ -458,9 +458,9 @@ class RevoluteJoint : public Sample jointDef.motorSpeed = m_motorSpeed; jointDef.maxMotorTorque = m_motorTorque; jointDef.enableMotor = m_enableMotor; - jointDef.referenceAngle = 0.5f * b2_pi; - jointDef.lowerAngle = -0.5f * b2_pi; - jointDef.upperAngle = 0.75f * b2_pi; + jointDef.referenceAngle = 0.5f * B2_PI; + jointDef.lowerAngle = -0.5f * B2_PI; + jointDef.upperAngle = 0.75f * B2_PI; jointDef.enableLimit = m_enableLimit; m_jointId1 = b2CreateRevoluteJoint( m_worldId, &jointDef ); @@ -498,8 +498,8 @@ class RevoluteJoint : public Sample jointDef.bodyIdB = body; jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); - jointDef.lowerAngle = -0.25f * b2_pi; - jointDef.upperAngle = 0.0f * b2_pi; + jointDef.lowerAngle = -0.25f * B2_PI; + jointDef.upperAngle = 0.0f * B2_PI; jointDef.enableLimit = true; jointDef.enableMotor = true; jointDef.motorSpeed = 0.0f; @@ -1830,7 +1830,7 @@ class UserConstraint : public Sample static float hertz = 3.0f; static float zeta = 0.7f; static float maxForce = 1000.0f; - float omega = 2.0f * b2_pi * hertz; + float omega = 2.0f * B2_PI * hertz; float sigma = 2.0f * zeta + timeStep * omega; float s = timeStep * omega * sigma; float impulseCoefficient = 1.0f / ( 1.0f + s ); @@ -1992,8 +1992,8 @@ class Driving : public Sample jointDef.bodyIdB = bodyId; jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); - jointDef.lowerAngle = -8.0f * b2_pi / 180.0f; - jointDef.upperAngle = 8.0f * b2_pi / 180.0f; + jointDef.lowerAngle = -8.0f * B2_PI / 180.0f; + jointDef.upperAngle = 8.0f * B2_PI / 180.0f; jointDef.enableLimit = true; b2CreateRevoluteJoint( m_worldId, &jointDef ); } diff --git a/samples/sample_shapes.cpp b/samples/sample_shapes.cpp index 88127cbad..a38e41fd2 100644 --- a/samples/sample_shapes.cpp +++ b/samples/sample_shapes.cpp @@ -1266,7 +1266,7 @@ class OffsetShapes : public Sample b2BodyId groundId = b2CreateBody( m_worldId, &bodyDef ); b2ShapeDef shapeDef = b2DefaultShapeDef(); - b2Polygon box = b2MakeOffsetBox( 1.0f, 1.0f, { 10.0f, -2.0f }, b2MakeRot( 0.5f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 1.0f, 1.0f, { 10.0f, -2.0f }, b2MakeRot( 0.5f * B2_PI ) ); b2CreatePolygonShape( groundId, &shapeDef, &box ); } @@ -1281,7 +1281,7 @@ class OffsetShapes : public Sample } { - b2Polygon box = b2MakeOffsetBox( 0.75f, 0.5f, { 9.0f, 2.0f }, b2MakeRot( 0.5f * b2_pi ) ); + b2Polygon box = b2MakeOffsetBox( 0.75f, 0.5f, { 9.0f, 2.0f }, b2MakeRot( 0.5f * B2_PI ) ); b2BodyDef bodyDef = b2DefaultBodyDef(); bodyDef.position = { 0.0f, 0.0f }; bodyDef.type = b2_dynamicBody; @@ -1340,7 +1340,7 @@ class Explosion : public Sample float r = 8.0f; for ( float angle = 0.0f; angle < 360.0f; angle += 30.0f ) { - b2CosSin cosSin = b2ComputeCosSin( angle * b2_pi / 180.0f ); + b2CosSin cosSin = b2ComputeCosSin( angle * B2_PI / 180.0f ); bodyDef.position = { r * cosSin.cosine, r * cosSin.sine }; b2BodyId bodyId = b2CreateBody( m_worldId, &bodyDef ); @@ -1387,7 +1387,7 @@ class Explosion : public Sample { if ( settings.pause == false || settings.singleStep == true ) { - m_referenceAngle += settings.hertz > 0.0f ? 60.0f * b2_pi / 180.0f / settings.hertz : 0.0f; + m_referenceAngle += settings.hertz > 0.0f ? 60.0f * B2_PI / 180.0f / settings.hertz : 0.0f; m_referenceAngle = b2UnwindAngle( m_referenceAngle ); int count = m_jointIds.size(); diff --git a/samples/sample_stacking.cpp b/samples/sample_stacking.cpp index ecffcac9a..301180837 100644 --- a/samples/sample_stacking.cpp +++ b/samples/sample_stacking.cpp @@ -883,9 +883,9 @@ class CardHouse : public Sample float cardHeight = 0.2f; float cardThickness = 0.001f; - float angle0 = 25.0f * b2_pi / 180.0f; - float angle1 = -25.0f * b2_pi / 180.0f; - float angle2 = 0.5f * b2_pi; + float angle0 = 25.0f * B2_PI / 180.0f; + float angle1 = -25.0f * B2_PI / 180.0f; + float angle2 = 0.5f * B2_PI; b2Polygon cardBox = b2MakeBox( cardThickness, cardHeight ); bodyDef.type = b2_dynamicBody; diff --git a/samples/sample_world.cpp b/samples/sample_world.cpp index b559a5cf0..91511ce67 100644 --- a/samples/sample_world.cpp +++ b/samples/sample_world.cpp @@ -21,7 +21,7 @@ class LargeWorld : public Sample : Sample( settings ) { m_period = 40.0f; - float omega = 2.0 * b2_pi / m_period; + float omega = 2.0 * B2_PI / m_period; m_cycleCount = g_sampleDebug ? 10 : 600; m_gridSize = 1.0f; m_gridCount = (int)( m_cycleCount * m_period / m_gridSize ); diff --git a/shared/benchmarks.c b/shared/benchmarks.c index f5c43a650..b6645d841 100644 --- a/shared/benchmarks.c +++ b/shared/benchmarks.c @@ -336,7 +336,7 @@ void CreateSpinner( b2WorldId worldId ) b2Vec2 points[SPINNER_POINT_COUNT]; - b2Rot q = b2MakeRot( -2.0f * b2_pi / SPINNER_POINT_COUNT ); + b2Rot q = b2MakeRot( -2.0f * B2_PI / SPINNER_POINT_COUNT ); b2Vec2 p = { 40.0f, 0.0f }; for ( int i = 0; i < SPINNER_POINT_COUNT; ++i ) { @@ -499,7 +499,7 @@ void CreateTumbler( b2WorldId worldId ) jd.localAnchorA = ( b2Vec2 ){ 0.0f, 10.0f }; jd.localAnchorB = ( b2Vec2 ){ 0.0f, 0.0f }; jd.referenceAngle = 0.0f; - jd.motorSpeed = ( b2_pi / 180.0f ) * motorSpeed; + jd.motorSpeed = ( B2_PI / 180.0f ) * motorSpeed; jd.maxMotorTorque = 1e8f; jd.enableMotor = true; diff --git a/shared/human.c b/shared/human.c index bd10fba1e..6465e7584 100644 --- a/shared/human.c +++ b/shared/human.c @@ -105,7 +105,7 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.25f * b2_pi; + jointDef.lowerAngle = -0.25f * B2_PI; jointDef.upperAngle = 0.0f; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; @@ -147,8 +147,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.3f * b2_pi; - jointDef.upperAngle = 0.1f * b2_pi; + jointDef.lowerAngle = -0.3f * B2_PI; + jointDef.upperAngle = 0.1f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -184,8 +184,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.05f * b2_pi; - jointDef.upperAngle = 0.4f * b2_pi; + jointDef.lowerAngle = -0.05f * B2_PI; + jointDef.upperAngle = 0.4f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -239,8 +239,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.5f * b2_pi; - jointDef.upperAngle = -0.02f * b2_pi; + jointDef.lowerAngle = -0.5f * B2_PI; + jointDef.upperAngle = -0.02f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -276,8 +276,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.05f * b2_pi; - jointDef.upperAngle = 0.4f * b2_pi; + jointDef.lowerAngle = -0.05f * B2_PI; + jointDef.upperAngle = 0.4f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -321,8 +321,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.5f * b2_pi; - jointDef.upperAngle = -0.02f * b2_pi; + jointDef.lowerAngle = -0.5f * B2_PI; + jointDef.upperAngle = -0.02f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -358,8 +358,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.1f * b2_pi; - jointDef.upperAngle = 0.8f * b2_pi; + jointDef.lowerAngle = -0.1f * B2_PI; + jointDef.upperAngle = 0.8f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -394,10 +394,10 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.bodyIdB = bone->bodyId; jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); - jointDef.referenceAngle = 0.25f * b2_pi; + jointDef.referenceAngle = 0.25f * B2_PI; jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.2f * b2_pi; - jointDef.upperAngle = 0.3f * b2_pi; + jointDef.lowerAngle = -0.2f * B2_PI; + jointDef.upperAngle = 0.3f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -433,8 +433,8 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.1f * b2_pi; - jointDef.upperAngle = 0.8f * b2_pi; + jointDef.lowerAngle = -0.1f * B2_PI; + jointDef.upperAngle = 0.8f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; @@ -469,10 +469,10 @@ void CreateHuman( Human* human, b2WorldId worldId, b2Vec2 position, float scale, jointDef.bodyIdB = bone->bodyId; jointDef.localAnchorA = b2Body_GetLocalPoint( jointDef.bodyIdA, pivot ); jointDef.localAnchorB = b2Body_GetLocalPoint( jointDef.bodyIdB, pivot ); - jointDef.referenceAngle = 0.25f * b2_pi; + jointDef.referenceAngle = 0.25f * B2_PI; jointDef.enableLimit = enableLimit; - jointDef.lowerAngle = -0.2f * b2_pi; - jointDef.upperAngle = 0.3f * b2_pi; + jointDef.lowerAngle = -0.2f * B2_PI; + jointDef.upperAngle = 0.3f * B2_PI; jointDef.enableMotor = enableMotor; jointDef.maxMotorTorque = bone->frictionScale * maxTorque; jointDef.enableSpring = hertz > 0.0f; diff --git a/src/body.c b/src/body.c index 94e8cca56..db125d2a1 100644 --- a/src/body.c +++ b/src/body.c @@ -238,7 +238,7 @@ b2BodyId b2CreateBody( b2WorldId worldId, const b2BodyDef* def ) bodySim->invMass = 0.0f; bodySim->inertia = 0.0f; bodySim->invInertia = 0.0f; - bodySim->minExtent = b2_huge; + bodySim->minExtent = B2_HUGE; bodySim->maxExtent = 0.0f; bodySim->linearDamping = def->linearDamping; bodySim->angularDamping = def->angularDamping; @@ -517,7 +517,7 @@ void b2UpdateBodyMassData( b2World* world, b2Body* body ) bodySim->inertia = 0.0f; bodySim->invInertia = 0.0f; bodySim->localCenter = b2Vec2_zero; - bodySim->minExtent = b2_huge; + bodySim->minExtent = B2_HUGE; bodySim->maxExtent = 0.0f; // Static and kinematic sims have zero mass. diff --git a/src/broad_phase.c b/src/broad_phase.c index 2ec3ec90f..05015641a 100644 --- a/src/broad_phase.c +++ b/src/broad_phase.c @@ -372,7 +372,7 @@ void b2UpdateBroadPhasePairs( b2World* world ) return; } - b2TracyCZoneNC( update_pairs, "Pairs", b2_colorMagenta, true ); + b2TracyCZoneNC( update_pairs, "Pairs", b2_colorMediumSlateBlue, true ); b2StackAllocator* alloc = &world->stackAllocator; @@ -395,7 +395,9 @@ void b2UpdateBroadPhasePairs( b2World* world ) world->taskCount += 1; } - b2TracyCZoneNC( create_contacts, "Create Contacts", b2_colorGold, true ); + // todo_erin could start tree rebuild here + + b2TracyCZoneNC( create_contacts, "Create Contacts", b2_colorCoral, true ); // Single-threaded work // - Clear move flags diff --git a/src/constants.h b/src/constants.h index 447ed21e9..1959db6ca 100644 --- a/src/constants.h +++ b/src/constants.h @@ -7,7 +7,7 @@ extern float b2_lengthUnitsPerMeter; // Used to detect bad values. Positions greater than about 16km will have precision // problems, so 100km as a limit should be fine in all cases. -#define b2_huge ( 100000.0f * b2_lengthUnitsPerMeter ) +#define B2_HUGE ( 100000.0f * b2_lengthUnitsPerMeter ) // Maximum parallel workers. Used to size some static arrays. #define b2_maxWorkers 64 @@ -22,12 +22,12 @@ extern float b2_lengthUnitsPerMeter; #define b2_linearSlop ( 0.005f * b2_lengthUnitsPerMeter ) // Maximum number of simultaneous worlds that can be allocated -#define b2_maxWorlds 128 +#define B2_MAX_WORLDS 128 // The maximum rotation of a body per time step. This limit is very large and is used // to prevent numerical problems. You shouldn't need to adjust this. // @warning increasing this to 0.5f * b2_pi or greater will break continuous collision. -#define b2_maxRotation ( 0.25f * b2_pi ) +#define B2_MAX_ROTATION ( 0.25f * B2_PI ) // @warning modifying this can have a significant impact on performance and stability #define b2_speculativeDistance ( 4.0f * b2_linearSlop ) diff --git a/src/distance.c b/src/distance.c index 4332a19d9..874691d0b 100644 --- a/src/distance.c +++ b/src/distance.c @@ -781,8 +781,12 @@ b2CastOutput b2ShapeCast( const b2ShapeCastPairInput* input ) // Warning: writing to these globals significantly slows multithreading performance #if B2_TOI_DEBUG float b2_toiTime, b2_toiMaxTime; -int b2_toiCalls, b2_toiIters, b2_toiMaxIters; -int b2_toiRootIters, b2_toiMaxRootIters; +int b2_toiCalls, b2_toiDistanceIterations, b2_toiMaxDistanceIterations; +int b2_toiRootIterations, b2_toiMaxRootIterations; +int b2_toiFailedCount; +int b2_toiOverlappedCount; +int b2_toiHitCount; +int b2_toiSeparatedCount; #endif typedef enum b2SeparationType @@ -1008,14 +1012,18 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) output.state = b2_toiStateUnknown; output.t = input->tMax; - const b2DistanceProxy* proxyA = &input->proxyA; - const b2DistanceProxy* proxyB = &input->proxyB; - b2Sweep sweepA = input->sweepA; b2Sweep sweepB = input->sweepB; B2_ASSERT( b2IsNormalized( sweepA.q1 ) && b2IsNormalized( sweepA.q2 ) ); B2_ASSERT( b2IsNormalized( sweepB.q1 ) && b2IsNormalized( sweepB.q2 ) ); + // todo_erin + // c1 can be at the origin yet the points are far away + // b2Vec2 origin = b2Add(sweepA.c1, input->proxyA.points[0]); + + const b2DistanceProxy* proxyA = &input->proxyA; + const b2DistanceProxy* proxyB = &input->proxyB; + float tMax = input->tMax; float totalRadius = proxyA->radius + proxyB->radius; @@ -1027,7 +1035,7 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) float t1 = 0.0f; const int k_maxIterations = 20; - int iter = 0; + int distanceIterations = 0; // Prepare input for distance query. b2DistanceCache cache = { 0 }; @@ -1049,19 +1057,30 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) distanceInput.transformB = xfB; b2DistanceOutput distanceOutput = b2ShapeDistance( &cache, &distanceInput, NULL, 0 ); + distanceIterations += 1; +#if B2_TOI_DEBUG + b2_toiDistanceIterations += 1; +#endif + // If the shapes are overlapped, we give up on continuous collision. if ( distanceOutput.distance <= 0.0f ) { // Failure! output.state = b2_toiStateOverlapped; +#if B2_TOI_DEBUG + b2_toiOverlappedCount += 1; +#endif output.t = 0.0f; break; } - if ( distanceOutput.distance < target + tolerance ) + if ( distanceOutput.distance <= target + tolerance ) { // Victory! output.state = b2_toiStateHit; +#if B2_TOI_DEBUG + b2_toiHitCount += 1; +#endif output.t = t1; break; } @@ -1098,7 +1117,7 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) // resolving the deepest point. This loop is bounded by the number of vertices. bool done = false; float t2 = tMax; - int pushBackIter = 0; + int pushBackIterations = 0; for ( ;; ) { // Find the deepest point at t2. Store the witness point indices. @@ -1110,6 +1129,9 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) { // Victory! output.state = b2_toiStateSeparated; +#if B2_TOI_DEBUG + b2_toiSeparatedCount += 1; +#endif output.t = tMax; done = true; break; @@ -1131,6 +1153,9 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) if ( s1 < target - tolerance ) { output.state = b2_toiStateFailed; +#if B2_TOI_DEBUG + b2_toiFailedCount += 1; +#endif output.t = t1; done = true; break; @@ -1141,19 +1166,22 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) { // Victory! t1 should hold the TOI (could be 0.0). output.state = b2_toiStateHit; +#if B2_TOI_DEBUG + b2_toiHitCount += 1; +#endif output.t = t1; done = true; break; } // Compute 1D root of: f(x) - target = 0 - int rootIterCount = 0; + int rootIterationCount = 0; float a1 = t1, a2 = t2; for ( ;; ) { // Use a mix of the secant rule and bisection. float t; - if ( rootIterCount & 1 ) + if ( rootIterationCount & 1 ) { // Secant rule to improve convergence. t = a1 + ( target - s1 ) * ( a2 - a1 ) / ( s2 - s1 ); @@ -1164,10 +1192,10 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) t = 0.5f * ( a1 + a2 ); } - ++rootIterCount; + rootIterationCount += 1; #if B2_TOI_DEBUG - ++b2_toiRootIters; + ++b2_toiRootIterations; #endif float s = b2EvaluateSeparation( &fcn, indexA, indexB, t ); @@ -1191,45 +1219,43 @@ b2TOIOutput b2TimeOfImpact( const b2TOIInput* input ) s2 = s; } - if ( rootIterCount == 50 ) + if ( rootIterationCount == 50 ) { break; } } #if B2_TOI_DEBUG - b2_toiMaxRootIters = b2MaxInt( b2_toiMaxRootIters, rootIterCount ); + b2_toiMaxRootIterations = b2MaxInt( b2_toiMaxRootIterations, rootIterationCount ); #endif - ++pushBackIter; + pushBackIterations += 1; - if ( pushBackIter == b2_maxPolygonVertices ) + if ( pushBackIterations == b2_maxPolygonVertices ) { break; } } - ++iter; -#if B2_TOI_DEBUG - ++b2_toiIters; -#endif - if ( done ) { break; } - if ( iter == k_maxIterations ) + if ( distanceIterations == k_maxIterations ) { // Root finder got stuck. Semi-victory. output.state = b2_toiStateFailed; +#if B2_TOI_DEBUG + b2_toiFailedCount += 1; +#endif output.t = t1; break; } } #if B2_TOI_DEBUG - b2_toiMaxIters = b2MaxInt( b2_toiMaxIters, iter ); + b2_toiMaxDistanceIterations = b2MaxInt( b2_toiMaxDistanceIterations, distanceIterations ); float time = b2GetMilliseconds( &timer ); b2_toiMaxTime = b2MaxFloat( b2_toiMaxTime, time ); diff --git a/src/distance_joint.c b/src/distance_joint.c index cec457395..854c838cc 100644 --- a/src/distance_joint.c +++ b/src/distance_joint.c @@ -22,7 +22,7 @@ void b2DistanceJoint_SetLength( b2JointId jointId, float length ) b2JointSim* base = b2GetJointSimCheckType( jointId, b2_distanceJoint ); b2DistanceJoint* joint = &base->distanceJoint; - joint->length = b2ClampFloat( length, b2_linearSlop, b2_huge ); + joint->length = b2ClampFloat( length, b2_linearSlop, B2_HUGE ); joint->impulse = 0.0f; joint->lowerImpulse = 0.0f; joint->upperImpulse = 0.0f; @@ -53,8 +53,8 @@ void b2DistanceJoint_SetLengthRange( b2JointId jointId, float minLength, float m b2JointSim* base = b2GetJointSimCheckType( jointId, b2_distanceJoint ); b2DistanceJoint* joint = &base->distanceJoint; - minLength = b2ClampFloat( minLength, b2_linearSlop, b2_huge ); - maxLength = b2ClampFloat( maxLength, b2_linearSlop, b2_huge ); + minLength = b2ClampFloat( minLength, b2_linearSlop, B2_HUGE ); + maxLength = b2ClampFloat( maxLength, b2_linearSlop, B2_HUGE ); joint->minLength = b2MinFloat( minLength, maxLength ); joint->maxLength = b2MaxFloat( minLength, maxLength ); joint->impulse = 0.0f; @@ -532,13 +532,13 @@ void b2DrawDistanceJoint( b2DebugDraw* draw, b2JointSim* base, b2Transform trans draw->DrawSegment( b2Sub( pMin, offset ), b2Add( pMin, offset ), b2_colorLightGreen, draw->context ); } - if ( joint->maxLength < b2_huge ) + if ( joint->maxLength < B2_HUGE ) { // draw->DrawPoint(pMax, 4.0f, c3, draw->context); draw->DrawSegment( b2Sub( pMax, offset ), b2Add( pMax, offset ), b2_colorRed, draw->context ); } - if ( joint->minLength > b2_linearSlop && joint->maxLength < b2_huge ) + if ( joint->minLength > b2_linearSlop && joint->maxLength < B2_HUGE ) { draw->DrawSegment( pMin, pMax, b2_colorGray, draw->context ); } diff --git a/src/dynamic_tree.c b/src/dynamic_tree.c index 967e64d52..f8e416b5e 100644 --- a/src/dynamic_tree.c +++ b/src/dynamic_tree.c @@ -733,10 +733,10 @@ static void b2RemoveLeaf( b2DynamicTree* tree, int32_t leaf ) // the node pool. int32_t b2DynamicTree_CreateProxy( b2DynamicTree* tree, b2AABB aabb, uint64_t categoryBits, int32_t userData ) { - B2_ASSERT( -b2_huge < aabb.lowerBound.x && aabb.lowerBound.x < b2_huge ); - B2_ASSERT( -b2_huge < aabb.lowerBound.y && aabb.lowerBound.y < b2_huge ); - B2_ASSERT( -b2_huge < aabb.upperBound.x && aabb.upperBound.x < b2_huge ); - B2_ASSERT( -b2_huge < aabb.upperBound.y && aabb.upperBound.y < b2_huge ); + B2_ASSERT( -B2_HUGE < aabb.lowerBound.x && aabb.lowerBound.x < B2_HUGE ); + B2_ASSERT( -B2_HUGE < aabb.lowerBound.y && aabb.lowerBound.y < B2_HUGE ); + B2_ASSERT( -B2_HUGE < aabb.upperBound.x && aabb.upperBound.x < B2_HUGE ); + B2_ASSERT( -B2_HUGE < aabb.upperBound.y && aabb.upperBound.y < B2_HUGE ); int32_t proxyId = b2AllocateNode( tree ); b2TreeNode* node = tree->nodes + proxyId; @@ -775,8 +775,8 @@ int32_t b2DynamicTree_GetProxyCount( const b2DynamicTree* tree ) void b2DynamicTree_MoveProxy( b2DynamicTree* tree, int32_t proxyId, b2AABB aabb ) { B2_ASSERT( b2IsValidAABB( aabb ) ); - B2_ASSERT( aabb.upperBound.x - aabb.lowerBound.x < b2_huge ); - B2_ASSERT( aabb.upperBound.y - aabb.lowerBound.y < b2_huge ); + B2_ASSERT( aabb.upperBound.x - aabb.lowerBound.x < B2_HUGE ); + B2_ASSERT( aabb.upperBound.y - aabb.lowerBound.y < B2_HUGE ); B2_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); B2_ASSERT( b2IsLeaf( tree->nodes + proxyId ) ); @@ -793,8 +793,8 @@ void b2DynamicTree_EnlargeProxy( b2DynamicTree* tree, int32_t proxyId, b2AABB aa b2TreeNode* nodes = tree->nodes; B2_ASSERT( b2IsValidAABB( aabb ) ); - B2_ASSERT( aabb.upperBound.x - aabb.lowerBound.x < b2_huge ); - B2_ASSERT( aabb.upperBound.y - aabb.lowerBound.y < b2_huge ); + B2_ASSERT( aabb.upperBound.x - aabb.lowerBound.x < B2_HUGE ); + B2_ASSERT( aabb.upperBound.y - aabb.lowerBound.y < B2_HUGE ); B2_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); B2_ASSERT( b2IsLeaf( tree->nodes + proxyId ) ); diff --git a/src/geometry.c b/src/geometry.c index 7679e8f38..5f450f75c 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -16,11 +16,11 @@ _Static_assert( b2_maxPolygonVertices > 2, "must be 3 or more" ); bool b2IsValidRay( const b2RayCastInput* input ) { bool isValid = b2IsValidVec2( input->origin ) && b2IsValidVec2( input->translation ) && b2IsValidFloat( input->maxFraction ) && - 0.0f <= input->maxFraction && input->maxFraction < b2_huge; + 0.0f <= input->maxFraction && input->maxFraction < B2_HUGE; return isValid; } -static b2Vec2 b2ComputePolygonCentroid( const b2Vec2* vertices, int32_t count ) +static b2Vec2 b2ComputePolygonCentroid( const b2Vec2* vertices, int count ) { b2Vec2 center = { 0.0f, 0.0f }; float area = 0.0f; @@ -31,7 +31,7 @@ static b2Vec2 b2ComputePolygonCentroid( const b2Vec2* vertices, int32_t count ) const float inv3 = 1.0f / 3.0f; - for ( int32_t i = 1; i < count - 1; ++i ) + for ( int i = 1; i < count - 1; ++i ) { // Triangle edges b2Vec2 e1 = b2Sub( vertices[i], origin ); @@ -223,7 +223,7 @@ b2MassData b2ComputeCircleMass( const b2Circle* shape, float density ) float rr = shape->radius * shape->radius; b2MassData massData; - massData.mass = density * b2_pi * rr; + massData.mass = density * B2_PI * rr; massData.center = shape->center; // inertia about the local origin @@ -241,7 +241,7 @@ b2MassData b2ComputeCapsuleMass( const b2Capsule* shape, float density ) float length = b2Length( b2Sub( p2, p1 ) ); float ll = length * length; - float circleMass = density * ( b2_pi * radius * radius ); + float circleMass = density * ( B2_PI * radius * radius ); float boxMass = density * ( 2.0f * radius * length ); b2MassData massData; @@ -259,7 +259,7 @@ b2MassData b2ComputeCapsuleMass( const b2Capsule* shape, float density ) // I verified this formula by computing the convex hull of a 128 vertex capsule // half circle centroid - float lc = 4.0f * radius / ( 3.0f * b2_pi ); + float lc = 4.0f * radius / ( 3.0f * B2_PI ); // half length of rectangular portion of capsule float h = 0.5f * length; diff --git a/src/island.c b/src/island.c index 4f1b322ff..cdc7ab967 100644 --- a/src/island.c +++ b/src/island.c @@ -848,7 +848,7 @@ void b2SplitIsland( b2World* world, int baseId ) // are interacting with these data structures. void b2SplitIslandTask( int startIndex, int endIndex, uint32_t threadIndex, void* context ) { - b2TracyCZoneNC( split, "Split Island", b2_colorHoneydew, true ); + b2TracyCZoneNC( split, "Split Island", b2_colorOlive, true ); B2_MAYBE_UNUSED( startIndex ); B2_MAYBE_UNUSED( endIndex ); diff --git a/src/joint.c b/src/joint.c index f4cb992fa..67da93ac3 100644 --- a/src/joint.c +++ b/src/joint.c @@ -25,7 +25,7 @@ b2DistanceJointDef b2DefaultDistanceJointDef( void ) { b2DistanceJointDef def = { 0 }; def.length = 1.0f; - def.maxLength = b2_huge; + def.maxLength = B2_HUGE; def.internalValue = B2_SECRET_COOKIE; return def; } @@ -522,7 +522,7 @@ b2JointId b2CreateRevoluteJoint( b2WorldId worldId, const b2RevoluteJointDef* de b2RevoluteJoint empty = { 0 }; joint->revoluteJoint = empty; - joint->revoluteJoint.referenceAngle = b2ClampFloat( def->referenceAngle, -b2_pi, b2_pi ); + joint->revoluteJoint.referenceAngle = b2ClampFloat( def->referenceAngle, -B2_PI, B2_PI ); joint->revoluteJoint.linearImpulse = b2Vec2_zero; joint->revoluteJoint.axialMass = 0.0f; joint->revoluteJoint.springImpulse = 0.0f; @@ -533,8 +533,8 @@ b2JointId b2CreateRevoluteJoint( b2WorldId worldId, const b2RevoluteJointDef* de joint->revoluteJoint.dampingRatio = def->dampingRatio; joint->revoluteJoint.lowerAngle = b2MinFloat( def->lowerAngle, def->upperAngle ); joint->revoluteJoint.upperAngle = b2MaxFloat( def->lowerAngle, def->upperAngle ); - joint->revoluteJoint.lowerAngle = b2ClampFloat( joint->revoluteJoint.lowerAngle, -b2_pi, b2_pi ); - joint->revoluteJoint.upperAngle = b2ClampFloat( joint->revoluteJoint.upperAngle, -b2_pi, b2_pi ); + joint->revoluteJoint.lowerAngle = b2ClampFloat( joint->revoluteJoint.lowerAngle, -B2_PI, B2_PI ); + joint->revoluteJoint.upperAngle = b2ClampFloat( joint->revoluteJoint.upperAngle, -B2_PI, B2_PI ); joint->revoluteJoint.maxMotorTorque = def->maxMotorTorque; joint->revoluteJoint.motorSpeed = def->motorSpeed; joint->revoluteJoint.enableSpring = def->enableSpring; @@ -1266,7 +1266,7 @@ void b2DrawJoint( b2DebugDraw* draw, b2World* world, b2Joint* joint ) draw->DrawPoint( target, 4.0f, c1, draw->context ); draw->DrawPoint( pB, 4.0f, c1, draw->context ); - b2HexColor c2 = b2_colorGray8; + b2HexColor c2 = b2_colorLightGray; draw->DrawSegment( target, pB, c2, draw->context ); } break; @@ -1299,7 +1299,7 @@ void b2DrawJoint( b2DebugDraw* draw, b2World* world, b2Joint* joint ) { b2HexColor colors[b2_graphColorCount] = { b2_colorRed, b2_colorOrange, b2_colorYellow, b2_colorGreen, b2_colorCyan, b2_colorBlue, b2_colorViolet, b2_colorPink, - b2_colorChocolate, b2_colorGoldenrod, b2_colorCoral, b2_colorBlack }; + b2_colorChocolate, b2_colorGoldenRod, b2_colorCoral, b2_colorBlack }; int colorIndex = joint->colorIndex; if ( colorIndex != B2_NULL_INDEX ) diff --git a/src/math_functions.c b/src/math_functions.c index 38bfa5847..37aa18b4e 100644 --- a/src/math_functions.c +++ b/src/math_functions.c @@ -99,47 +99,47 @@ float b2Atan2( float y, float x ) // the same results on x64 and ARM using MSVC, GCC, and Clang. However, I don't trust // this result. // https://en.wikipedia.org/wiki/Bh%C4%81skara_I%27s_sine_approximation_formula -b2CosSin b2ComputeCosSin( float angle ) +b2CosSin b2ComputeCosSin( float radians ) { - // return ( b2CosSin ){ cosf( angle ), sinf( angle ) }; - - float x = b2UnwindLargeAngle( angle ); - float pi2 = b2_pi * b2_pi; - - b2Rot q; + float x = b2UnwindLargeAngle( radians ); + float pi2 = B2_PI * B2_PI; // cosine needs angle in [-pi/2, pi/2] - if ( x < -0.5f * b2_pi ) + float c; + if ( x < -0.5f * B2_PI ) { - float y = x + b2_pi; + float y = x + B2_PI; float y2 = y * y; - q.c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); + c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); } - else if ( x > 0.5f * b2_pi ) + else if ( x > 0.5f * B2_PI ) { - float y = x - b2_pi; + float y = x - B2_PI; float y2 = y * y; - q.c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); + c = -( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); } else { float y2 = x * x; - q.c = ( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); + c = ( pi2 - 4.0f * y2 ) / ( pi2 + y2 ); } // sine needs angle in [0, pi] + float s; if ( x < 0.0f ) { - float y = x + b2_pi; - q.s = -16.0f * y * ( b2_pi - y ) / ( 5.0f * pi2 - 4.0f * y * ( b2_pi - y ) ); + float y = x + B2_PI; + s = -16.0f * y * ( B2_PI - y ) / ( 5.0f * pi2 - 4.0f * y * ( B2_PI - y ) ); } else { - q.s = 16.0f * x * ( b2_pi - x ) / ( 5.0f * pi2 - 4.0f * x * ( b2_pi - x ) ); + s = 16.0f * x * ( B2_PI - x ) / ( 5.0f * pi2 - 4.0f * x * ( B2_PI - x ) ); } - q = b2NormalizeRot( q ); - return ( b2CosSin ){ q.c, q.s }; + float mag = sqrtf( s * s + c * c ); + float invMag = mag > 0.0 ? 1.0f / mag : 0.0f; + b2CosSin cs = { c * invMag, s * invMag }; + return cs; } b2Rot b2ComputeRotationBetweenUnitVectors(b2Vec2 v1, b2Vec2 v2) diff --git a/src/motor_joint.c b/src/motor_joint.c index 721e98974..4dd5defab 100644 --- a/src/motor_joint.c +++ b/src/motor_joint.c @@ -26,7 +26,7 @@ b2Vec2 b2MotorJoint_GetLinearOffset( b2JointId jointId ) void b2MotorJoint_SetAngularOffset( b2JointId jointId, float angularOffset ) { b2JointSim* joint = b2GetJointSimCheckType( jointId, b2_motorJoint ); - joint->motorJoint.angularOffset = b2ClampFloat( angularOffset, -b2_pi, b2_pi ); + joint->motorJoint.angularOffset = b2ClampFloat( angularOffset, -B2_PI, B2_PI ); } float b2MotorJoint_GetAngularOffset( b2JointId jointId ) diff --git a/src/prismatic_joint.c b/src/prismatic_joint.c index e60cabd85..8e604c40b 100644 --- a/src/prismatic_joint.c +++ b/src/prismatic_joint.c @@ -627,11 +627,11 @@ void b2DrawPrismaticJoint( b2DebugDraw* draw, b2JointSim* base, b2Transform tran b2Vec2 axis = b2RotateVector( transformA.q, joint->localAxisA ); - b2HexColor c1 = b2_colorGray7; + b2HexColor c1 = b2_colorGray; b2HexColor c2 = b2_colorGreen; b2HexColor c3 = b2_colorRed; b2HexColor c4 = b2_colorBlue; - b2HexColor c5 = b2_colorGray4; + b2HexColor c5 = b2_colorDimGray; draw->DrawSegment( pA, pB, c5, draw->context ); diff --git a/src/revolute_joint.c b/src/revolute_joint.c index 98b8eb09c..fdcef81d6 100644 --- a/src/revolute_joint.c +++ b/src/revolute_joint.c @@ -493,7 +493,7 @@ void b2DrawRevoluteJoint( b2DebugDraw* draw, b2JointSim* base, b2Transform trans b2Vec2 pA = b2TransformPoint( transformA, base->localOriginAnchorA ); b2Vec2 pB = b2TransformPoint( transformB, base->localOriginAnchorB ); - b2HexColor c1 = b2_colorGray7; + b2HexColor c1 = b2_colorGray; b2HexColor c2 = b2_colorGreen; b2HexColor c3 = b2_colorRed; @@ -513,7 +513,7 @@ void b2DrawRevoluteJoint( b2DebugDraw* draw, b2JointSim* base, b2Transform trans { float jointAngle = b2UnwindAngle( angle - joint->referenceAngle ); char buffer[32]; - snprintf( buffer, 32, " %.1f deg", 180.0f * jointAngle / b2_pi ); + snprintf( buffer, 32, " %.1f deg", 180.0f * jointAngle / B2_PI ); draw->DrawString( pC, buffer, draw->context ); } diff --git a/src/shape.c b/src/shape.c index 0698fc60e..2f4b5c562 100644 --- a/src/shape.c +++ b/src/shape.c @@ -521,14 +521,14 @@ float b2GetShapePerimeter( const b2Shape* shape ) { case b2_capsuleShape: return 2.0f * b2Length( b2Sub( shape->capsule.center1, shape->capsule.center2 ) ) + - 2.0f * b2_pi * shape->capsule.radius; + 2.0f * B2_PI * shape->capsule.radius; case b2_circleShape: - return 2.0f * b2_pi * shape->circle.radius; + return 2.0f * B2_PI * shape->circle.radius; case b2_polygonShape: { const b2Vec2* points = shape->polygon.vertices; int count = shape->polygon.count; - float perimeter = 2.0f * b2_pi * shape->polygon.radius; + float perimeter = 2.0f * B2_PI * shape->polygon.radius; B2_ASSERT( count > 0 ); b2Vec2 prev = points[count - 1]; for ( int i = 0; i < count; ++i ) @@ -645,7 +645,7 @@ b2ShapeExtent b2ComputeShapeExtent( const b2Shape* shape, b2Vec2 localCenter ) case b2_polygonShape: { const b2Polygon* poly = &shape->polygon; - float minExtent = b2_huge; + float minExtent = B2_HUGE; float maxExtentSqr = 0.0f; int count = poly->count; for ( int i = 0; i < count; ++i ) diff --git a/src/solver.c b/src/solver.c index f851bded7..17848488e 100644 --- a/src/solver.c +++ b/src/solver.c @@ -67,7 +67,7 @@ static void b2IntegrateVelocitiesTask( int startIndex, int endIndex, b2StepConte b2Vec2 gravity = context->world->gravity; float h = context->h; float maxLinearSpeed = context->maxLinearVelocity; - float maxAngularSpeed = b2_maxRotation * context->inv_dt; + float maxAngularSpeed = B2_MAX_ROTATION * context->inv_dt; float maxLinearSpeedSquared = maxLinearSpeed * maxLinearSpeed; float maxAngularSpeedSquared = maxAngularSpeed * maxAngularSpeed; @@ -490,7 +490,7 @@ static void b2SolveContinuous( b2World* world, int bodySimIndex ) static void b2FinalizeBodiesTask( int startIndex, int endIndex, uint32_t threadIndex, void* context ) { - b2TracyCZoneNC( finalize_bodies, "FinalizeBodies", b2_colorViolet, true ); + b2TracyCZoneNC( finalize_bodies, "Positions", b2_colorMediumSeaGreen, true ); b2StepContext* stepContext = context; b2World* world = stepContext->world; @@ -571,8 +571,8 @@ static void b2FinalizeBodiesTask( int startIndex, int endIndex, uint32_t threadI // Body is not sleepy body->sleepTime = 0.0f; - const float saftetyFactor = 0.5f; - if ( body->type == b2_dynamicBody && enableContinuous && maxVelocity * timeStep > saftetyFactor * sim->minExtent ) + const float safetyFactor = 0.5f; + if ( body->type == b2_dynamicBody && enableContinuous && maxVelocity * timeStep > safetyFactor * sim->minExtent ) { // This flag is only retained for debug draw sim->isFast = true; @@ -1764,7 +1764,7 @@ void b2Solve( b2World* world, b2StepContext* stepContext ) b2ValidateNoEnlarged( &world->broadPhase ); - b2TracyCZoneNC( broad_phase, "Broadphase", b2_colorPurple, true ); + b2TracyCZoneNC( broad_phase, "Broadphase", b2_colorFireBrick, true ); b2TracyCZoneNC( enlarge_proxies, "Enlarge Proxies", b2_colorDarkTurquoise, true ); @@ -1938,9 +1938,10 @@ void b2Solve( b2World* world, b2StepContext* stepContext ) // Island sleeping // This must be done last because putting islands to sleep invalidates the enlarged body bits. + // todo_erin figure out how to do this in parallel with tree refit if ( world->enableSleep == true ) { - b2TracyCZoneNC( sleep_islands, "Island Sleep", b2_colorGainsboro, true ); + b2TracyCZoneNC( sleep_islands, "Island Sleep", b2_colorLightSlateGray, true ); // Collect split island candidate for the next time step. No need to split if sleeping is disabled. B2_ASSERT( world->splitIslandId == B2_NULL_INDEX ); diff --git a/src/solver.h b/src/solver.h index a3a8609a2..ffe22c381 100644 --- a/src/solver.h +++ b/src/solver.h @@ -143,7 +143,7 @@ static inline b2Softness b2MakeSoft( float hertz, float zeta, float h ) return ( b2Softness ){ 0.0f, 1.0f, 0.0f }; } - float omega = 2.0f * b2_pi * hertz; + float omega = 2.0f * B2_PI * hertz; float a1 = 2.0f * zeta + h * omega; float a2 = h * omega * a1; float a3 = 1.0f / ( 1.0f + a2 ); diff --git a/src/types.c b/src/types.c index 2cb28e964..d4945a258 100644 --- a/src/types.c +++ b/src/types.c @@ -13,7 +13,7 @@ b2WorldDef b2DefaultWorldDef( void ) def.gravity.y = -10.0f; def.hitEventThreshold = 1.0f * b2_lengthUnitsPerMeter; def.restitutionThreshold = 1.0f * b2_lengthUnitsPerMeter; - def.contactPushoutVelocity = 3.0f * b2_lengthUnitsPerMeter; + def.contactPushVelocity = 3.0f * b2_lengthUnitsPerMeter; def.contactHertz = 30.0; def.contactDampingRatio = 10.0f; def.jointHertz = 60.0; diff --git a/src/weld_joint.c b/src/weld_joint.c index 15f9b3344..a305d0add 100644 --- a/src/weld_joint.c +++ b/src/weld_joint.c @@ -21,7 +21,7 @@ void b2WeldJoint_SetReferenceAngle( b2JointId jointId, float angleInRadians ) { B2_ASSERT( b2IsValidFloat( angleInRadians ) ); b2JointSim* joint = b2GetJointSimCheckType( jointId, b2_weldJoint ); - joint->weldJoint.referenceAngle = b2ClampFloat(angleInRadians, -b2_pi, b2_pi); + joint->weldJoint.referenceAngle = b2ClampFloat(angleInRadians, -B2_PI, B2_PI); } void b2WeldJoint_SetLinearHertz( b2JointId jointId, float hertz ) diff --git a/src/wheel_joint.c b/src/wheel_joint.c index b2a971dfc..9304cfc0c 100644 --- a/src/wheel_joint.c +++ b/src/wheel_joint.c @@ -522,10 +522,10 @@ void b2DrawWheelJoint( b2DebugDraw* draw, b2JointSim* base, b2Transform transfor b2Vec2 pB = b2TransformPoint( transformB, base->localOriginAnchorB ); b2Vec2 axis = b2RotateVector( transformA.q, joint->localAxisA ); - b2HexColor c1 = b2_colorGray7; + b2HexColor c1 = b2_colorGray; b2HexColor c2 = b2_colorGreen; b2HexColor c3 = b2_colorRed; - b2HexColor c4 = b2_colorGray4; + b2HexColor c4 = b2_colorDimGray; b2HexColor c5 = b2_colorBlue; draw->DrawSegment( pA, pB, c5, draw->context ); diff --git a/src/world.c b/src/world.c index 3302a385d..22b08c683 100644 --- a/src/world.c +++ b/src/world.c @@ -30,8 +30,8 @@ #include #include -_Static_assert( b2_maxWorlds > 0, "must be 1 or more" ); -b2World b2_worlds[b2_maxWorlds]; +_Static_assert( B2_MAX_WORLDS > 0, "must be 1 or more" ); +b2World b2_worlds[B2_MAX_WORLDS]; B2_ARRAY_SOURCE( b2BodyMoveEvent, b2BodyMoveEvent ); B2_ARRAY_SOURCE( b2ContactBeginTouchEvent, b2ContactBeginTouchEvent ); @@ -43,7 +43,7 @@ B2_ARRAY_SOURCE( b2TaskContext, b2TaskContext ); b2World* b2GetWorldFromId( b2WorldId id ) { - B2_ASSERT( 1 <= id.index1 && id.index1 <= b2_maxWorlds ); + B2_ASSERT( 1 <= id.index1 && id.index1 <= B2_MAX_WORLDS ); b2World* world = b2_worlds + ( id.index1 - 1 ); B2_ASSERT( id.index1 == world->worldId + 1 ); B2_ASSERT( id.revision == world->revision ); @@ -52,7 +52,7 @@ b2World* b2GetWorldFromId( b2WorldId id ) b2World* b2GetWorld( int index ) { - B2_ASSERT( 0 <= index && index < b2_maxWorlds ); + B2_ASSERT( 0 <= index && index < B2_MAX_WORLDS ); b2World* world = b2_worlds + index; B2_ASSERT( world->worldId == index ); return world; @@ -60,7 +60,7 @@ b2World* b2GetWorld( int index ) b2World* b2GetWorldLocked( int index ) { - B2_ASSERT( 0 <= index && index < b2_maxWorlds ); + B2_ASSERT( 0 <= index && index < B2_MAX_WORLDS ); b2World* world = b2_worlds + index; B2_ASSERT( world->worldId == index ); if ( world->locked ) @@ -88,11 +88,11 @@ static void b2DefaultFinishTaskFcn( void* userTask, void* userContext ) b2WorldId b2CreateWorld( const b2WorldDef* def ) { - _Static_assert( b2_maxWorlds < UINT16_MAX, "b2_maxWorlds limit exceeded" ); + _Static_assert( B2_MAX_WORLDS < UINT16_MAX, "B2_MAX_WORLDS limit exceeded" ); b2CheckDef( def ); int worldId = B2_NULL_INDEX; - for ( int i = 0; i < b2_maxWorlds; ++i ) + for ( int i = 0; i < B2_MAX_WORLDS; ++i ) { if ( b2_worlds[i].inUse == false ) { @@ -178,7 +178,7 @@ b2WorldId b2CreateWorld( const b2WorldDef* def ) world->hitEventThreshold = def->hitEventThreshold; world->restitutionThreshold = def->restitutionThreshold; world->maxLinearVelocity = def->maximumLinearVelocity; - world->contactPushoutVelocity = def->contactPushoutVelocity; + world->contactPushoutVelocity = def->contactPushVelocity; world->contactHertz = def->contactHertz; world->contactDampingRatio = def->contactDampingRatio; world->jointHertz = def->jointHertz; @@ -389,7 +389,7 @@ static void b2UpdateTreesTask( int startIndex, int endIndex, uint32_t threadInde B2_MAYBE_UNUSED( endIndex ); B2_MAYBE_UNUSED( threadIndex ); - b2TracyCZoneNC( tree_task, "Rebuild Trees", b2_colorSnow, true ); + b2TracyCZoneNC( tree_task, "Rebuild Trees", b2_colorFireBrick, true ); b2World* world = context; b2BroadPhase_RebuildTrees( &world->broadPhase ); @@ -432,8 +432,9 @@ static void b2Collide( b2StepContext* context ) b2TracyCZoneNC( collide, "Collide", b2_colorDarkOrchid, true ); - // Tasks that can be done in parallel with the narrow-phase + // Task that can be done in parallel with the narrow-phase // - rebuild the collision tree for dynamic and kinematic bodies to keep their query performance good + // todo_erin move this to start when contacts are being created world->userTreeTask = world->enqueueTaskFcn( &b2UpdateTreesTask, 1, 1, world, world->userTaskContext ); world->taskCount += 1; world->activeTaskCount += world->userTreeTask == NULL ? 0 : 1; @@ -504,7 +505,8 @@ static void b2Collide( b2StepContext* context ) contactSims = NULL; // Serially update contact state - b2TracyCZoneNC( contact_state, "Contact State", b2_colorCoral, true ); + // todo_erin bring this zone together with island merge + b2TracyCZoneNC( contact_state, "Contact State", b2_colorLightSlateGray, true ); // Bitwise OR all contact bits b2BitSet* bitSet = &world->taskContexts.data[0].contactStateBitSet; @@ -944,16 +946,16 @@ static void b2DrawWithBounds( b2World* world, b2DebugDraw* draw ) const float k_impulseScale = 1.0f; const float k_axisScale = 0.3f; - b2HexColor speculativeColor = b2_colorGray3; + b2HexColor speculativeColor = b2_colorGainsboro; b2HexColor addColor = b2_colorGreen; b2HexColor persistColor = b2_colorBlue; - b2HexColor normalColor = b2_colorGray9; + b2HexColor normalColor = b2_colorDimGray; b2HexColor impulseColor = b2_colorMagenta; b2HexColor frictionColor = b2_colorYellow; b2HexColor graphColors[b2_graphColorCount] = { b2_colorRed, b2_colorOrange, b2_colorYellow, b2_colorGreen, b2_colorCyan, b2_colorBlue, b2_colorViolet, b2_colorPink, - b2_colorChocolate, b2_colorGoldenrod, b2_colorCoral, b2_colorBlack }; + b2_colorChocolate, b2_colorGoldenRod, b2_colorCoral, b2_colorBlack }; int bodyCapacity = b2GetIdCapacity( &world->bodyIdPool ); b2SetBitCountAndClear( &world->debugBodySet, bodyCapacity ); @@ -1295,16 +1297,16 @@ void b2World_Draw( b2WorldId worldId, b2DebugDraw* draw ) const float k_axisScale = 0.3f; const float linearSlop = b2_linearSlop; - b2HexColor speculativeColor = b2_colorGray3; + b2HexColor speculativeColor = b2_colorLightGray; b2HexColor addColor = b2_colorGreen; b2HexColor persistColor = b2_colorBlue; - b2HexColor normalColor = b2_colorGray9; + b2HexColor normalColor = b2_colorDimGray; b2HexColor impulseColor = b2_colorMagenta; b2HexColor frictionColor = b2_colorYellow; b2HexColor colors[b2_graphColorCount] = { b2_colorRed, b2_colorOrange, b2_colorYellow, b2_colorGreen, b2_colorCyan, b2_colorBlue, b2_colorViolet, b2_colorPink, - b2_colorChocolate, b2_colorGoldenrod, b2_colorCoral, b2_colorBlack }; + b2_colorChocolate, b2_colorGoldenRod, b2_colorCoral, b2_colorBlack }; for ( int colorIndex = 0; colorIndex < b2_graphColorCount; ++colorIndex ) { @@ -1443,7 +1445,7 @@ b2ContactEvents b2World_GetContactEvents( b2WorldId worldId ) bool b2World_IsValid( b2WorldId id ) { - if ( id.index1 < 1 || b2_maxWorlds < id.index1 ) + if ( id.index1 < 1 || B2_MAX_WORLDS < id.index1 ) { return false; } @@ -1461,7 +1463,7 @@ bool b2World_IsValid( b2WorldId id ) bool b2Body_IsValid( b2BodyId id ) { - if ( id.world0 < 0 || b2_maxWorlds <= id.world0 ) + if ( id.world0 < 0 || B2_MAX_WORLDS <= id.world0 ) { // invalid world return false; @@ -1500,7 +1502,7 @@ bool b2Body_IsValid( b2BodyId id ) bool b2Shape_IsValid( b2ShapeId id ) { - if ( b2_maxWorlds <= id.world0 ) + if ( B2_MAX_WORLDS <= id.world0 ) { return false; } @@ -1532,7 +1534,7 @@ bool b2Shape_IsValid( b2ShapeId id ) bool b2Chain_IsValid( b2ChainId id ) { - if ( id.world0 < 0 || b2_maxWorlds <= id.world0 ) + if ( id.world0 < 0 || B2_MAX_WORLDS <= id.world0 ) { return false; } @@ -1564,7 +1566,7 @@ bool b2Chain_IsValid( b2ChainId id ) bool b2Joint_IsValid( b2JointId id ) { - if ( id.world0 < 0 || b2_maxWorlds <= id.world0 ) + if ( id.world0 < 0 || B2_MAX_WORLDS <= id.world0 ) { return false; } diff --git a/test/test_determinism.c b/test/test_determinism.c index 24585a2c7..44bc4a0a6 100644 --- a/test/test_determinism.c +++ b/test/test_determinism.c @@ -233,8 +233,8 @@ static int CrossPlatformTest(void) b2RevoluteJointDef jointDef = b2DefaultRevoluteJointDef(); jointDef.enableLimit = true; - jointDef.lowerAngle = -0.1f * b2_pi; - jointDef.upperAngle = 0.2f * b2_pi; + jointDef.lowerAngle = -0.1f * B2_PI; + jointDef.upperAngle = 0.2f * B2_PI; jointDef.enableSpring = true; jointDef.hertz = 0.5f; jointDef.dampingRatio = 0.5f; diff --git a/test/test_math.c b/test/test_math.c index 63fc55fe6..2ec3aa95b 100644 --- a/test/test_math.c +++ b/test/test_math.c @@ -15,7 +15,7 @@ int MathTest( void ) { for ( float t = -10.0f; t < 10.0f; t += 0.01f ) { - float angle = b2_pi * t; + float angle = B2_PI * t; b2Rot r = b2MakeRot( angle ); float c = cosf( angle ); float s = sinf( angle ); @@ -32,9 +32,9 @@ int MathTest( void ) float diff = b2AbsFloat( a - xn ); // The two results can be off by 360 degrees (-pi and pi) - if ( diff > b2_pi ) + if ( diff > B2_PI ) { - diff -= 2.0f * b2_pi; + diff -= 2.0f * B2_PI; } // The approximate atan2 is quite accurate diff --git a/test/test_shape.c b/test/test_shape.c index ab2b2a0ba..b02fe3071 100644 --- a/test/test_shape.c +++ b/test/test_shape.c @@ -19,9 +19,9 @@ static int ShapeMassTest( void ) { { b2MassData md = b2ComputeCircleMass( &circle, 1.0f ); - ENSURE_SMALL( md.mass - b2_pi, FLT_EPSILON ); + ENSURE_SMALL( md.mass - B2_PI, FLT_EPSILON ); ENSURE( md.center.x == 1.0f && md.center.y == 0.0f ); - ENSURE_SMALL( md.rotationalInertia - 1.5f * b2_pi, FLT_EPSILON ); + ENSURE_SMALL( md.rotationalInertia - 1.5f * B2_PI, FLT_EPSILON ); } { @@ -36,8 +36,8 @@ static int ShapeMassTest( void ) // Approximate capsule using convex hull b2Vec2 points[2 * N]; - float d = b2_pi / ( N - 1.0f ); - float angle = -0.5f * b2_pi; + float d = B2_PI / ( N - 1.0f ); + float angle = -0.5f * B2_PI; for ( int i = 0; i < N; ++i ) { points[i].x = 1.0f + radius * cosf( angle ); @@ -45,7 +45,7 @@ static int ShapeMassTest( void ) angle += d; } - angle = 0.5f * b2_pi; + angle = 0.5f * B2_PI; for ( int i = N; i < 2 * N; ++i ) { points[i].x = -1.0f + radius * cosf( angle ); diff --git a/test/test_world.c b/test/test_world.c index f5dcb8396..b29bfd674 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -296,7 +296,7 @@ int TestForAmy( void ) return 0; } -#define WORLD_COUNT ( b2_maxWorlds / 2 ) +#define WORLD_COUNT ( B2_MAX_WORLDS / 2 ) int TestWorldRecycle( void ) {