use crate::math::{Pose, Real, Vector};
use crate::shape::SubShapeId;
use core::mem;
#[derive(Debug, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Deserialize, rkyv::Serialize)
)]
pub struct Contact {
pub point1: Vector,
pub point2: Vector,
pub normal1: Vector,
pub normal2: Vector,
pub dist: Real,
pub subshape1: SubShapeId,
pub subshape2: SubShapeId,
}
impl Contact {
#[inline]
pub fn new(
point1: Vector,
point2: Vector,
normal1: Vector,
normal2: Vector,
dist: Real,
) -> Self {
Contact {
point1,
point2,
normal1,
normal2,
dist,
subshape1: 0,
subshape2: 0,
}
}
#[inline]
pub fn with_subshapes(mut self, subshape1: SubShapeId, subshape2: SubShapeId) -> Self {
self.subshape1 = subshape1;
self.subshape2 = subshape2;
self
}
}
impl Contact {
#[inline]
pub fn flip(&mut self) {
mem::swap(&mut self.point1, &mut self.point2);
mem::swap(&mut self.normal1, &mut self.normal2);
mem::swap(&mut self.subshape1, &mut self.subshape2);
}
#[inline]
pub fn flipped(mut self) -> Self {
self.flip();
self
}
#[inline]
pub fn transform_by_mut(&mut self, pos1: &Pose, pos2: &Pose) {
self.point1 = pos1 * self.point1;
self.point2 = pos2 * self.point2;
self.normal1 = pos1.rotation * self.normal1;
self.normal2 = pos2.rotation * self.normal2;
}
pub fn transform1_by_mut(&mut self, pos: &Pose) {
self.point1 = pos * self.point1;
self.normal1 = pos.rotation * self.normal1;
}
}