Skip to content

Commit

Permalink
Friction and restitution mixing rules (#811)
Browse files Browse the repository at this point in the history
get/set max linear velocity
  • Loading branch information
erincatto authored Sep 30, 2024
1 parent e7cb9f0 commit b864f53
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 238 deletions.
10 changes: 5 additions & 5 deletions include/box2d/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@
*/

/// Prototype for user allocation function
/// @param size the allocation size in bytes
/// @param alignment the required alignment, guaranteed to be a power of 2
/// @param size the allocation size in bytes
/// @param alignment the required alignment, guaranteed to be a power of 2
typedef void* b2AllocFcn( unsigned int size, int alignment );

/// Prototype for user free function
/// @param mem the memory previously allocated through `b2AllocFcn`
/// @param mem the memory previously allocated through `b2AllocFcn`
typedef void b2FreeFcn( void* mem );

/// Prototype for the user assert callback. Return 0 to skip the debugger break.
typedef int b2AssertFcn( const char* condition, const char* fileName, int lineNumber );

/// This allows the user to override the allocation functions. These should be
/// set during application startup.
/// set during application startup.
B2_API void b2SetAllocator( b2AllocFcn* allocFcn, b2FreeFcn* freeFcn );

/// @return the total bytes allocated by Box2D
B2_API int b2GetByteCount( void );

/// Override the default assert callback
/// @param assertFcn a non-null assert callback
/// @param assertFcn a non-null assert callback
B2_API void b2SetAssertFcn( b2AssertFcn* assertFcn );

/// Version numbering scheme.
Expand Down
172 changes: 89 additions & 83 deletions include/box2d/box2d.h

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions include/box2d/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ typedef struct b2Hull b2Hull;
*/

/// The maximum number of vertices on a convex polygon. Changing this affects performance even if you
/// don't use more vertices.
/// don't use more vertices.
#define b2_maxPolygonVertices 8

/// Low level ray-cast input data
Expand All @@ -43,8 +43,8 @@ typedef struct b2RayCastInput
} b2RayCastInput;

/// Low level shape cast input in generic form. This allows casting an arbitrary point
/// cloud wrap with a radius. For example, a circle is a single point with a non-zero radius.
/// A capsule is two points with a non-zero radius. A box is four points with a zero radius.
/// cloud wrap with a radius. For example, a circle is a single point with a non-zero radius.
/// A capsule is two points with a non-zero radius. A box is four points with a zero radius.
typedef struct b2ShapeCastInput
{
/// A point cloud to cast
Expand Down Expand Up @@ -106,7 +106,7 @@ typedef struct b2Circle
} b2Circle;

/// A solid capsule can be viewed as two semicircles connected
/// by a rectangle.
/// by a rectangle.
typedef struct b2Capsule
{
/// Local center of the first semicircle
Expand All @@ -123,8 +123,8 @@ typedef struct b2Capsule
/// the left of each edge.
/// Polygons have a maximum number of vertices equal to b2_maxPolygonVertices.
/// In most cases you should not need many vertices for a convex polygon.
/// @warning DO NOT fill this out manually, instead use a helper function like
/// b2MakePolygon or b2MakeBox.
/// @warning DO NOT fill this out manually, instead use a helper function like
/// b2MakePolygon or b2MakeBox.
typedef struct b2Polygon
{
/// The polygon vertices
Expand Down Expand Up @@ -263,7 +263,7 @@ B2_API b2CastOutput b2ShapeCastSegment( const b2ShapeCastInput* input, const b2S
B2_API b2CastOutput b2ShapeCastPolygon( const b2ShapeCastInput* input, const b2Polygon* shape );

/// A convex hull. Used to create convex polygons.
/// @warning Do not modify these values directly, instead use b2ComputeHull()
/// @warning Do not modify these values directly, instead use b2ComputeHull()
typedef struct b2Hull
{
/// The final points of the hull
Expand All @@ -280,7 +280,7 @@ typedef struct b2Hull
/// - less than 3 points
/// - more than b2_maxPolygonVertices points
/// This welds close points and removes collinear points.
/// @warning Do not modify a hull once it has been computed
/// @warning Do not modify a hull once it has been computed
B2_API b2Hull b2ComputeHull( const b2Vec2* points, int32_t count );

/// This determines if a hull is valid. Checks for:
Expand Down Expand Up @@ -337,7 +337,7 @@ typedef struct b2DistanceProxy
} b2DistanceProxy;

/// Used to warm start b2Distance. Set count to zero on first call or
/// use zero initialization.
/// use zero initialization.
typedef struct b2DistanceCache
{
/// The number of stored simplex points
Expand Down Expand Up @@ -401,7 +401,7 @@ typedef struct b2Simplex

/// Compute the closest points between two shapes represented as point clouds.
/// b2DistanceCache cache is input/output. On the first call set b2DistanceCache.count to zero.
/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these.
B2_API b2DistanceOutput b2ShapeDistance( b2DistanceCache* cache, const b2DistanceInput* input, b2Simplex* simplexes,
int simplexCapacity );

Expand Down Expand Up @@ -484,15 +484,15 @@ B2_API b2TOIOutput b2TimeOfImpact( const b2TOIInput* input );
typedef struct b2ManifoldPoint
{
/// Location of the contact point in world space. Subject to precision loss at large coordinates.
/// @note Should only be used for debugging.
/// @note Should only be used for debugging.
b2Vec2 point;

/// Location of the contact point relative to bodyA's origin in world space
/// @note When used internally to the Box2D solver, this is relative to the center of mass.
/// @note When used internally to the Box2D solver, this is relative to the center of mass.
b2Vec2 anchorA;

/// Location of the contact point relative to bodyB's origin in world space
/// @note When used internally to the Box2D solver, this is relative to the center of mass.
/// @note When used internally to the Box2D solver, this is relative to the center of mass.
b2Vec2 anchorB;

/// The separation of the contact point, negative if penetrating
Expand All @@ -505,7 +505,7 @@ typedef struct b2ManifoldPoint
float tangentImpulse;

/// The maximum normal impulse applied during sub-stepping
/// This could be a bool to indicate the point is confirmed (may be a speculative point)
/// This could be a bool to indicate the point is confirmed (may be a speculative point)
float maxNormalImpulse;

/// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is
Expand Down Expand Up @@ -603,7 +603,7 @@ B2_API b2Manifold b2CollideChainSegmentAndPolygon( const b2ChainSegment* segment
#define b2_defaultCategoryBits ( 1 )

/// Convenience mask bits to use when you don't need collision filtering and just want
/// all results.
/// all results.
#define b2_defaultMaskBits ( UINT64_MAX )

/// A node in the dynamic tree. This is private data placed here for performance reasons.
Expand Down Expand Up @@ -720,12 +720,12 @@ typedef float b2TreeRayCastCallbackFcn( const b2RayCastInput* input, int32_t pro
/// The callback also performs the any collision filtering. This has performance
/// roughly equal to k * log(n), where k is the number of collisions and n is the
/// number of proxies in the tree.
/// Bit-wise filtering using mask bits can greatly improve performance in some scenarios.
/// @param tree the dynamic tree to ray cast
/// Bit-wise filtering using mask bits can greatly improve performance in some scenarios.
/// @param tree the dynamic tree to ray cast
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1)
/// @param maskBits filter bits: `bool accept = (maskBits & node->categoryBits) != 0;`
/// @param maskBits filter bits: `bool accept = (maskBits & node->categoryBits) != 0;`
/// @param callback a callback class that is called for each proxy that is hit by the ray
/// @param context user context that is passed to the callback
/// @param context user context that is passed to the callback
B2_API void b2DynamicTree_RayCast( const b2DynamicTree* tree, const b2RayCastInput* input, uint64_t maskBits,
b2TreeRayCastCallbackFcn* callback, void* context );

Expand All @@ -741,11 +741,11 @@ typedef float b2TreeShapeCastCallbackFcn( const b2ShapeCastInput* input, int32_t
/// The callback also performs the any collision filtering. This has performance
/// roughly equal to k * log(n), where k is the number of collisions and n is the
/// number of proxies in the tree.
/// @param tree the dynamic tree to ray cast
/// @param tree the dynamic tree to ray cast
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
/// @param maskBits filter bits: `bool accept = (maskBits & node->categoryBits) != 0;`
/// @param maskBits filter bits: `bool accept = (maskBits & node->categoryBits) != 0;`
/// @param callback a callback class that is called for each proxy that is hit by the shape
/// @param context user context that is passed to the callback
/// @param context user context that is passed to the callback
B2_API void b2DynamicTree_ShapeCast( const b2DynamicTree* tree, const b2ShapeCastInput* input, uint64_t maskBits,
b2TreeShapeCastCallbackFcn* callback, void* context );

Expand Down
18 changes: 9 additions & 9 deletions include/box2d/math_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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.
/// function in the standard library is not cross platform deterministic.
B2_API float b2Atan2( float y, float x );

/// @return the minimum of two floats
Expand Down Expand Up @@ -279,7 +279,7 @@ B2_INLINE b2Vec2 b2Normalize( b2Vec2 v )
}

/// Convert a vector into a unit vector if possible, otherwise returns the zero vector. Also
/// outputs the length.
/// outputs the length.
B2_INLINE b2Vec2 b2GetLengthAndNormalize( float* length, b2Vec2 v )
{
*length = b2Length( v );
Expand All @@ -303,8 +303,8 @@ B2_INLINE b2Rot b2NormalizeRot( b2Rot q )
}

/// Integration rotation from angular velocity
/// @param q1 initial rotation
/// @param deltaAngle the angular displacement in radians
/// @param q1 initial rotation
/// @param deltaAngle the angular displacement in radians
B2_INLINE b2Rot b2IntegrateRotation( b2Rot q1, float deltaAngle )
{
// dc/dt = -omega * sin(t)
Expand Down Expand Up @@ -363,9 +363,9 @@ B2_INLINE b2Rot b2NLerp( b2Rot q1, b2Rot q2, float t )
}

/// Compute the angular velocity necessary to rotate between two rotations over a give time
/// @param q1 initial rotation
/// @param q2 final rotation
/// @param inv_h inverse time step
/// @param q1 initial rotation
/// @param q2 final rotation
/// @param inv_h inverse time step
B2_INLINE float b2ComputeAngularVelocity( b2Rot q1, b2Rot q2, float inv_h )
{
// ds/dt = omega * cos(t)
Expand Down Expand Up @@ -609,8 +609,8 @@ B2_API bool b2AABB_IsValid( b2AABB aabb );

/// Box2D bases all length units on meters, but you may need different units for your game.
/// You can set this value to use different units. This should be done at application startup
/// and only modified once. Default value is 1.
/// @warning This must be modified before any calls to Box2D
/// and only modified once. Default value is 1.
/// @warning This must be modified before any calls to Box2D
B2_API void b2SetLengthUnitsPerMeter( float lengthUnits );

/// Get the current length units per meter.
Expand Down
Loading

0 comments on commit b864f53

Please sign in to comment.