Skip to content

Commit

Permalink
I suppose macros should be UPPER_CASE
Browse files Browse the repository at this point in the history
Fixed enableSensorEvents comment
  • Loading branch information
erincatto committed Dec 9, 2024
1 parent 1c22ca2 commit b0cec6a
Show file tree
Hide file tree
Showing 45 changed files with 528 additions and 427 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion include/box2d/box2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,17 @@ 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
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
Expand Down
6 changes: 0 additions & 6 deletions include/box2d/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@

#include <stdbool.h>

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;

/**
Expand Down
93 changes: 47 additions & 46 deletions include/box2d/math_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 };
}

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit b0cec6a

Please sign in to comment.