Skip to content

add getter for contact_id field of SolverContact #824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bcolloran
Copy link

Adds a simple getter for the contact_id field of SolverContact. (Alternatively, could set that field to pub instead of pub(crate).)

My use case is that I need to access the local coords of a contact relative to each collider involved in the contact. To get that date, I need the contact_id to look up the entry in contact_pair.manifolds[i].points that corresponds to a specific SolverContact, because the SolverContact only has the world space position of the contact point. Example:

     narrow_phase
    .contact_pairs_with(this_handle)
    .filter(|contact_pair| {
        // filter out pairs that are not active
        contact_pair.has_any_active_contact
    })
    .flat_map(move |contact_pair| {
      

        let this_is_1 = contact_pair.collider1 == this_handle;
        let manifold = &contact_pair.manifolds[0];

        manifold.data.solver_contacts.iter().map(move |contact| {
            let contact_point = manifold.points[contact.contact_id() as usize];
            (
                contact_point.local_p1,
                contact_point.local_p2,
                manifold.local_n1,
                contact_point.dist,
                manifold.data.rigid_body2,
                contact_pair.collider2,
            )
        }
    })

Near as I can tell, this should not be a risky change, but then again I'm not sure why this field wasn't pub in the first place, so there may be some detail I'm not aware of.

Please LMK if any changes are needed! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant