Struct TrackedContact

Source
pub struct TrackedContact<Data> {
    pub local_p1: Point<f32>,
    pub local_p2: Point<f32>,
    pub dist: f32,
    pub fid1: PackedFeatureId,
    pub fid2: PackedFeatureId,
    pub data: Data,
}
Expand description

A single contact point between two shapes.

A TrackedContact represents a single point of contact between two shapes, with enough information to track the contact across multiple frames and identify which geometric features (vertices, edges, faces) are in contact.

§Understanding Contact Points

Each contact point consists of:

  • Two contact positions (one on each shape, in local coordinates)
  • A distance value (negative = penetrating, positive = separated)
  • Feature IDs that identify which part of each shape is in contact
  • Optional user data for tracking contact-specific information

§Local vs World Space

Contact points are stored in local space (the coordinate system of each shape). This is important because:

  • Shapes can move and rotate, but local coordinates remain constant
  • Contact tracking works by comparing feature IDs and local positions
  • To get world-space positions, transform the local points by the shape’s position

§Distance Convention

The dist field uses the following convention:

  • dist < 0.0: Shapes are penetrating (overlapping). The absolute value is the penetration depth.
  • dist == 0.0: Shapes are exactly touching.
  • dist > 0.0: Shapes are separated. This happens when using contact prediction.

§Example: Basic Contact Query

use parry3d::query::{ContactManifold, TrackedContact};
use parry3d::query::details::contact_manifold_ball_ball;
use parry3d::shape::Ball;
use parry3d::math::Isometry;

// Two balls, one slightly overlapping the other
let ball1 = Ball::new(1.0);
let ball2 = Ball::new(1.0);
let pos12 = Isometry::translation(1.5, 0.0, 0.0); // Overlapping by 0.5

let mut manifold = ContactManifold::<(), ()>::new();
contact_manifold_ball_ball(&pos12, &ball1, &ball2, 0.0, &mut manifold);

if let Some(contact) = manifold.points.first() {
    println!("Penetration depth: {}", -contact.dist);
    println!("Contact on ball1 (local): {:?}", contact.local_p1);
    println!("Contact on ball2 (local): {:?}", contact.local_p2);
}

§Example: Converting to World Space

use parry3d::query::{ContactManifold, TrackedContact};
use parry3d::query::details::contact_manifold_ball_ball;
use parry3d::shape::Ball;
use parry3d::math::Isometry;

let ball1 = Ball::new(1.0);
let ball2 = Ball::new(1.0);

// Position shapes in world space
let pos1 = Isometry::translation(0.0, 0.0, 0.0);
let pos2 = Isometry::translation(1.5, 0.0, 0.0);
let pos12 = pos1.inverse() * pos2; // Relative position

let mut manifold = ContactManifold::<(), ()>::new();
contact_manifold_ball_ball(&pos12, &ball1, &ball2, 0.0, &mut manifold);

if let Some(contact) = manifold.points.first() {
    // Convert local positions to world space
    let world_p1 = pos1 * contact.local_p1;
    let world_p2 = pos2 * contact.local_p2;

    println!("Contact in world space:");
    println!("  On ball1: {:?}", world_p1);
    println!("  On ball2: {:?}", world_p2);
}

§Feature IDs

The fid1 and fid2 fields identify which geometric features are in contact:

  • For a ball: Always the face (surface)
  • For a box: Could be a vertex, edge, or face
  • For a triangle: Could be a vertex, edge, or the face

These IDs are used to track contacts across frames. If the same feature IDs appear in consecutive frames, it’s likely the same physical contact point.

Fields§

§local_p1: Point<f32>

The contact point in the local-space of the first shape.

This is the point on the first shape’s surface (or interior if penetrating) that is closest to or in contact with the second shape.

§local_p2: Point<f32>

The contact point in the local-space of the second shape.

This is the point on the second shape’s surface (or interior if penetrating) that is closest to or in contact with the first shape.

§dist: f32

The signed distance between the two contact points.

  • Negative values indicate penetration (shapes are overlapping)
  • Positive values indicate separation (used with contact prediction)
  • Zero means the shapes are exactly touching

The magnitude represents the distance along the contact normal.

§fid1: PackedFeatureId

The feature ID of the first shape involved in the contact.

This identifies which geometric feature (vertex, edge, or face) of the first shape is involved in this contact. Used for contact tracking across frames.

§fid2: PackedFeatureId

The feature ID of the second shape involved in the contact.

This identifies which geometric feature (vertex, edge, or face) of the second shape is involved in this contact. Used for contact tracking across frames.

§data: Data

User-data associated to this contact.

This can be used to store any additional information you need to track per-contact, such as:

  • Accumulated impulses for warm-starting in physics solvers
  • Contact age or lifetime
  • Material properties or friction state
  • Custom identifiers or flags

Implementations§

Source§

impl<Data: Default + Copy> TrackedContact<Data>

Source

pub fn new( local_p1: Point<f32>, local_p2: Point<f32>, fid1: PackedFeatureId, fid2: PackedFeatureId, dist: f32, ) -> Self

Creates a new tracked contact.

§Arguments
  • local_p1 - Contact point on the first shape (in its local space)
  • local_p2 - Contact point on the second shape (in its local space)
  • fid1 - Feature ID of the first shape (which part is in contact)
  • fid2 - Feature ID of the second shape (which part is in contact)
  • dist - Signed distance between the contact points (negative = penetrating)

The contact data is initialized to its default value.

§Example
use parry3d::query::TrackedContact;
use parry3d::shape::PackedFeatureId;
use parry3d::math::Point;

let contact = TrackedContact::<()>::new(
    Point::new(1.0, 0.0, 0.0),  // Point on shape 1
    Point::new(-1.0, 0.0, 0.0), // Point on shape 2
    PackedFeatureId::face(0),    // Face 0 of shape 1
    PackedFeatureId::face(0),    // Face 0 of shape 2
    -0.1,                         // Penetration depth of 0.1
);

assert_eq!(contact.dist, -0.1);
Source

pub fn flipped( local_p1: Point<f32>, local_p2: Point<f32>, fid1: PackedFeatureId, fid2: PackedFeatureId, dist: f32, flipped: bool, ) -> Self

Creates a new tracked contact where its input may need to be flipped.

Source

pub fn copy_geometry_from(&mut self, contact: Self)

Copy to self the geometric information from contact.

Trait Implementations§

Source§

impl<Data: Clone> Clone for TrackedContact<Data>

Source§

fn clone(&self) -> TrackedContact<Data>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Data: Debug> Debug for TrackedContact<Data>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Data: Copy> Copy for TrackedContact<Data>

Auto Trait Implementations§

§

impl<Data> Freeze for TrackedContact<Data>
where Data: Freeze,

§

impl<Data> RefUnwindSafe for TrackedContact<Data>
where Data: RefUnwindSafe,

§

impl<Data> Send for TrackedContact<Data>
where Data: Send,

§

impl<Data> Sync for TrackedContact<Data>
where Data: Sync,

§

impl<Data> Unpin for TrackedContact<Data>
where Data: Unpin,

§

impl<Data> UnwindSafe for TrackedContact<Data>
where Data: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.