Skip to content

Commit 73324a7

Browse files
authored
Rolling resistance (erincatto#876)
Added rolling resistance. Rolling resistance is a static resistance with a constraint, so it can work on ramps. The resistance scales based on the contact normal forces and the radius of the shape. Added tangent speed to all shapes for conveyor belts, etc. Added b2SurfaceMaterial to support separate properties for each segment of a chain shape.
1 parent cad8599 commit 73324a7

43 files changed

Lines changed: 1029 additions & 445 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,2565.3
3-
2,1533.85
4-
3,1053.01
5-
4,865.702
6-
5,748.989
7-
6,658.623
8-
7,613.633
9-
8,578.973
2+
1,2528.51
3+
2,1460.58
4+
3,1004.38
5+
4,822.484
6+
5,712.691
7+
6,638.201
8+
7,583.016
9+
8,540.158
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,1584.03
3-
2,841.862
4-
3,598.747
5-
4,471.697
6-
5,396.306
7-
6,347.983
8-
7,309.086
9-
8,308.832
2+
1,1579.54
3+
2,849.264
4+
3,591.984
5+
4,466.064
6+
5,393.207
7+
6,347.593
8+
7,305.863
9+
8,305.205
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,2663.34
3-
2,1407.85
4-
3,934.506
5-
4,725.271
6-
5,590.288
7-
6,502.513
8-
7,422.693
9-
8,395.369
2+
1,2592.03
3+
2,1412.01
4+
3,953.71
5+
4,731.394
6+
5,601.527
7+
6,511.144
8+
7,441.201
9+
8,393.566

benchmark/amd7950x_avx2/rain.csv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,6526.9
3-
2,4017.74
4-
3,3052.28
5-
4,2493.5
6-
5,2149.12
7-
6,1911.45
8-
7,1735.97
9-
8,1625.71
2+
1,6462.19
3+
2,3806.63
4+
3,2907
5+
4,2413.23
6+
5,2069.53
7+
6,1852.14
8+
7,1671.47
9+
8,1547.16

benchmark/amd7950x_avx2/smash.csv

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,1562.06
3-
2,1020.55
4-
3,781.193
5-
4,661.318
6-
5,580.115
7-
6,530.502
8-
7,489.672
9-
8,467.998
2+
1,1533.42
3+
2,981.749
4+
3,763.27
5+
4,642.928
6+
5,574.053
7+
6,527.394
8+
7,492.883
9+
8,468.971
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,4106.89
3-
2,2635.21
4-
3,1986.32
5-
4,1614.21
6-
5,1420.63
7-
6,1272.06
8-
7,1157.16
9-
8,1091.25
2+
1,4126.1
3+
2,2491.09
4+
3,1918.78
5+
4,1543.11
6+
5,1360.84
7+
6,1216.53
8+
7,1110.95
9+
8,1043.96
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
threads,ms
2-
1,1613.69
3-
2,1061.88
4-
3,810.738
5-
4,670.874
6-
5,578.959
7-
6,519.473
8-
7,479.842
9-
8,437.851
2+
1,1624.23
3+
2,1028.59
4+
3,796.538
5+
4,651.347
6+
5,563.763
7+
6,510.42
8+
7,468.899
9+
8,445.968

include/box2d/collision.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,18 @@ typedef struct b2ManifoldPoint
535535
/// @note Box2D uses speculative collision so some contact points may be separated.
536536
typedef struct b2Manifold
537537
{
538-
/// The manifold points, up to two are possible in 2D
539-
b2ManifoldPoint points[2];
540-
541538
/// The unit normal vector in world space, points from shape A to bodyB
542539
b2Vec2 normal;
543540

541+
/// Angular impulse applied for rolling resistance. N * m * s = kg * m^2 / s
542+
float rollingImpulse;
543+
544+
/// The manifold points, up to two are possible in 2D
545+
b2ManifoldPoint points[2];
546+
544547
/// The number of contacts points, will be 0, 1, or 2
545548
int pointCount;
549+
546550
} b2Manifold;
547551

548552
/// Compute the contact manifold between two circles

include/box2d/types.h

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,11 @@ typedef struct b2ShapeDef
346346
float restitution;
347347

348348
/// The rolling resistance usually in the range [0,1].
349-
/// todo
350349
float rollingResistance;
351350

351+
/// The tangent speed for conveyor belts
352+
float tangentSpeed;
353+
352354
/// User material identifier. This is passed with query results and to friction and restitution
353355
/// combining functions. It is not used internally.
354356
int material;
@@ -394,6 +396,35 @@ typedef struct b2ShapeDef
394396
/// @ingroup shape
395397
B2_API b2ShapeDef b2DefaultShapeDef( void );
396398

399+
/// Surface materials allow chain shapes to have per segment surface properties.
400+
/// @ingroup shape
401+
typedef struct b2SurfaceMaterial
402+
{
403+
/// The Coulomb (dry) friction coefficient, usually in the range [0,1].
404+
float friction;
405+
406+
/// The coefficient of restitution (bounce) usually in the range [0,1].
407+
/// https://en.wikipedia.org/wiki/Coefficient_of_restitution
408+
float restitution;
409+
410+
/// The rolling resistance usually in the range [0,1].
411+
float rollingResistance;
412+
413+
/// The tangent speed for conveyor belts
414+
float tangentSpeed;
415+
416+
/// User material identifier. This is passed with query results and to friction and restitution
417+
/// combining functions. It is not used internally.
418+
int material;
419+
420+
/// Custom debug draw color.
421+
uint32_t customColor;
422+
} b2SurfaceMaterial;
423+
424+
/// Use this to initialize your surface material
425+
/// @ingroup shape
426+
B2_API b2SurfaceMaterial b2DefaultSurfaceMaterial( void );
427+
397428
/// Used to create a chain of line segments. This is designed to eliminate ghost collisions with some limitations.
398429
/// - chains are one-sided
399430
/// - chains have no mass and should be used on static bodies
@@ -420,28 +451,19 @@ typedef struct b2ChainDef
420451
/// The point count, must be 4 or more.
421452
int count;
422453

423-
/// The friction coefficient, usually in the range [0,1].
424-
float friction;
425-
426-
/// The restitution (elasticity) usually in the range [0,1].
427-
float restitution;
454+
/// Surface materials for each segment. These are cloned.
455+
const b2SurfaceMaterial* materials;
428456

429-
/// User material identifier. This is passed with query results and to friction and restitution
430-
/// combining functions. It is not used internally.
431-
int material;
457+
/// The material count. Must be 1 or count. This allows you to provide one
458+
/// material for all segments or a unique material per segment.
459+
int materialCount;
432460

433461
/// Contact filtering data.
434462
b2Filter filter;
435463

436-
/// Custom debug draw color.
437-
uint32_t customColor;
438-
439464
/// Indicates a closed chain formed by connecting the first and last points
440465
bool isLoop;
441466

442-
/// Generate events when a sensor overlaps this chain
443-
bool enableSensorEvents;
444-
445467
/// Used internally to detect a valid definition. DO NOT SET.
446468
int internalValue;
447469
} b2ChainDef;

samples/car.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void Car::Spawn( b2WorldId worldId, b2Vec2 position, float scale, float hertz, f
5353

5454
shapeDef.density = 2.0f / scale;
5555
shapeDef.friction = 1.5f;
56+
shapeDef.rollingResistance = 0.1f;
5657

5758
bodyDef.position = b2Add( { -1.0f * scale, 0.35f * scale }, position );
5859
bodyDef.allowFastRotation = true;

0 commit comments

Comments
 (0)