Skip to content

Commit

Permalink
Merge pull request #86 from Jondolf/global-contact-position
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf authored Jul 18, 2023
2 parents e50f6ab + 8f67bb2 commit c2f83fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/collision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ pub struct Contact {
/// Second entity in the contact.
pub entity2: Entity,
/// Contact point on the first entity in local coordinates.
pub point1: Vector,
pub local_point1: Vector,
/// Contact point on the second entity in local coordinates.
pub local_point2: Vector,
/// Contact point on the first entity in global coordinates.
pub point1: Vector,
/// Contact point on the second entity in global coordinates.
pub point2: Vector,
/// Contact normal from contact point 1 to 2 in world coordinates.
pub normal: Vector,
Expand Down Expand Up @@ -58,8 +62,10 @@ pub(crate) fn compute_contact(
return Some(Contact {
entity1,
entity2,
point1: contact.point1.into(),
point2: contact.point2.into(),
local_point1: contact.point1.into(),
local_point2: contact.point2.into(),
point1: position1 + rotation1.rotate(contact.point1.into()),
point2: position2 + rotation2.rotate(contact.point2.into()),
normal: rotation1.rotate(contact.normal1.into()),
penetration: -contact.dist,
});
Expand Down
4 changes: 2 additions & 2 deletions src/constraints/penetration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ impl XpbdConstraint<2> for PenetrationConstraint {
impl PenetrationConstraint {
/// Creates a new [`PenetrationConstraint`] with the given bodies and contact data.
pub fn new(body1: &RigidBodyQueryItem, body2: &RigidBodyQueryItem, contact: Contact) -> Self {
let local_r1 = contact.point1 - body1.center_of_mass.0;
let local_r2 = contact.point2 - body2.center_of_mass.0;
let local_r1 = contact.local_point1 - body1.center_of_mass.0;
let local_r2 = contact.local_point2 - body2.center_of_mass.0;

let world_r1 = body1.rotation.rotate(local_r1);
let world_r2 = body2.rotation.rotate(local_r2);
Expand Down

0 comments on commit c2f83fd

Please sign in to comment.