pub struct Collision {
pub body_i: usize,
pub body_j: usize,
pub contact_point: Vec3<f64>,
pub contact_normal: Vec3<f64>,
pub penetration_depth: f64,
}Expand description
Result of a collision query between two geometries.
Fields§
§body_i: usizeIndex of first body involved.
body_j: usizeIndex of the second body involved, or Collision::WORLD for the
static world (ground, terrain, any immovable half-space).
This is an in-band sentinel, kept for the moment because the whole
contact pipeline is written against it. Prefer
Collision::attachment_j over comparing to WORLD by hand: it
returns a phyz_model::Attachment, which makes the world a distinct
variant instead of a reserved index, and is what the Jacobian and
constraint APIs take. The hazard the typed form removes is that
usize::MAX looks like an ordinary index, so a stale one is silently
reinterpreted as “the world” and the contact quietly stops pushing back
on one side.
contact_point: Vec3<f64>Contact point in world frame.
contact_normal: Vec3<f64>Contact normal: the direction body_i must move to separate from
body_j, i.e. it points from j toward i.
Stated this way because the two producers used to disagree and only one
of them was ever exercised. find_ground_contacts emits +z for a
body resting on the ground — the separating direction for that body,
and the sense the contact solver is built around, since its
non-penetration row is J·v ≥ 0 with J = J_i − J_j.
find_contacts used to pass Manifold::normal straight through, and
that points from shape a toward shape b — the exact opposite. The
constraint therefore measured approach instead of separation and the
solver drove overlapping bodies together: a box dropped on a box sank
clean through it to full overlap, with four contacts detected the whole
way down. Invisible until bodies other than the feet had collision
geometry, because before that no body-body contact ever occurred.
penetration_depth: f64Penetration depth (positive = penetrating).
Implementations§
Source§impl Collision
impl Collision
Sourcepub const WORLD: usize = usize::MAX
pub const WORLD: usize = usize::MAX
The value of Collision::body_j that means “the static world”.
Named so the magic number appears once, here, instead of being spelled
usize::MAX at every comparison site — where it reads as a bounds
check rather than as a semantic test and is easy to get backwards.
Sourcepub fn attachment_j(&self) -> Attachment
pub fn attachment_j(&self) -> Attachment
Collision::body_j as a typed Attachment.
This is the accessor to reach for: it turns the sentinel into a variant
at the one place that knows the convention, so consumers never compare
an index against usize::MAX themselves.
Sourcepub fn is_world_j(&self) -> bool
pub fn is_world_j(&self) -> bool
Whether the second side of this contact is the static world.