box2d_rs/
b2_common.rs

1/// Global tuning constants based on meters-kilograms-seconds (MKS) units.
2use std::assert;
3use std::f32::consts::PI;
4use crate::b2_settings::*;
5
6#[cfg(debug_assertions)]
7pub const B2_DEBUG:bool = true;
8
9#[cfg(not(debug_assertions))]
10pub const B2_DEBUG:bool = false;
11
12pub fn b2_not_used<T>(_x: T) {}
13pub fn b2_assert(a: bool) {
14    assert!(a);
15}
16
17pub const B2_MAX_FLOAT: f32 = std::f32::MAX;
18pub const B2_EPSILON: f32 = std::f32::EPSILON;
19pub const B2_PI: f32 = std::f32::consts::PI;
20
21// Collision
22
23/// The maximum number of contact points between two convex shapes. Do
24/// not change this value.
25pub const B2_MAX_MANIFOLD_POINTS: usize = 2;
26
27/// This is used to fatten AABBs in the dynamic tree. This allows proxies
28/// to move by a small amount without triggering a tree adjustment.
29/// This is in meters.
30pub const B2_AABB_EXTENSION: f32 = 0.1 * B2_LENGTH_UNITS_PER_METER;
31
32/// This is used to fatten AABBs in the dynamic tree. This is used to predict
33/// the future position based on the current displacement.
34/// This is a dimensionless multiplier.
35pub const B2_AABB_MULTIPLIER: f32 = 4.0;
36
37/// A small length used as a collision and constraint tolerance. Usually it is
38/// chosen to be numerically significant, but visually insignificant. In meters.
39pub const  B2_LINEAR_SLOP: f32 = 0.005 * B2_LENGTH_UNITS_PER_METER;
40
41/// A small angle used as a collision and constraint tolerance. Usually it is
42/// chosen to be numerically significant, but visually insignificant.
43pub const B2_ANGULAR_SLOP: f32 = 2.0 / 180.0 * PI;
44
45/// The radius of the polygon/edge shape skin. This should not be modified. Making
46/// this smaller means polygons will have an insufficient buffer for continuous collision.
47/// Making it larger may create artifacts for vertex collision.
48pub const B2_POLYGON_RADIUS: f32 = 2.0 * B2_LINEAR_SLOP;
49
50/// Maximum number of sub-steps per contact in continuous physics simulation.
51pub const B2_MAX_SUB_STEPS: usize = 8;
52
53// Dynamics
54
55/// Maximum number of contacts to be handled to solve a TOI impact.
56pub const B2_MAX_TOICONTACTS: usize = 32;
57
58/// The maximum linear position correction used when solving constraints. This helps to
59/// prevent overshoot. Meters.
60pub const B2_MAX_LINEAR_CORRECTION: f32 = 0.2 * B2_LENGTH_UNITS_PER_METER;
61
62/// The maximum angular position correction used when solving constraints. This helps to
63/// prevent overshoot.
64pub const B2_MAX_ANGULAR_CORRECTION: f32 = 8.0 / 180.0 * PI;
65
66/// The maximum linear translation of a body per step. This limit is very large and is used
67/// to prevent numerical problems. You shouldn't need to adjust self_. Meters.
68pub const B2_MAX_TRANSLATION: f32 = 2.0 * B2_LENGTH_UNITS_PER_METER;
69pub const B2_MAX_TRANSLATION_SQUARED: f32 = B2_MAX_TRANSLATION * B2_MAX_TRANSLATION;
70
71/// The maximum angular velocity of a body. This limit is very large and is used
72/// to prevent numerical problems. You shouldn't need to adjust self_.
73pub const B2_MAX_ROTATION: f32 = 0.5 * PI;
74pub const B2_MAX_ROTATION_SQUARED: f32 = B2_MAX_ROTATION * B2_MAX_ROTATION;
75
76/// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so
77/// that overlap is removed in one time step. However using values close to 1 often lead
78/// to overshoot.
79pub const B2_BAUMGARTE: f32 = 0.2;
80pub const B2_TOI_BAUMGARTE: f32 = 0.75;
81
82// Sleep
83
84/// The time that a body must be still before it will go to sleep.
85pub const B2_TIME_TO_SLEEP: f32 = 0.5;
86
87/// A body cannot sleep if its linear velocity is above this tolerance.
88pub const B2_LINEAR_SLEEP_TOLERANCE: f32 = 0.01 * B2_LENGTH_UNITS_PER_METER;
89
90/// A body cannot sleep if its angular velocity is above this tolerance.
91pub const B2_ANGULAR_SLEEP_TOLERANCE: f32 = 2.0 / 180.0 * PI;