Add helper functions to determine if an intersection is in the half-space of a given plane
This commit is contained in:
parent
c64384c362
commit
8fa3c40240
|
@ -72,6 +72,31 @@ impl PlaneIntersection {
|
||||||
Vec3::from_slice(&vs)
|
Vec3::from_slice(&vs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn in_halfspace_mat(&self, plane: &Plane) -> bool {
|
||||||
|
// "Distance" and side of the point defined by plane against the plane defined
|
||||||
|
// by the 3 points of the intersection planes.
|
||||||
|
//* Note that the sign is dependant on the winding order of the intersection planes
|
||||||
|
let m1 = glam::mat4(
|
||||||
|
self.planes[0].into_vec4(),
|
||||||
|
self.planes[1].into_vec4(),
|
||||||
|
self.planes[2].into_vec4(),
|
||||||
|
plane.into_vec4(),
|
||||||
|
);
|
||||||
|
let d1 = m1.determinant();
|
||||||
|
|
||||||
|
// We can resolve the winding order problem by multiplying by the normal matrix determinant
|
||||||
|
let m2 = self.get_matrix().transpose();
|
||||||
|
let d2 = m2.determinant();
|
||||||
|
let dist = d1 * d2;
|
||||||
|
|
||||||
|
//* Note: dist is only euclidean accurate if all the normals are normalised :)
|
||||||
|
dist < math::EPSILON
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn in_halfspace(&self, plane: &Plane) -> bool {
|
||||||
|
plane.normal.dot(self.get_intersection_point()) - plane.offset <= math::EPSILON
|
||||||
|
}
|
||||||
|
|
||||||
fn get_matrix(&self) -> Mat3 {
|
fn get_matrix(&self) -> Mat3 {
|
||||||
glam::mat3(
|
glam::mat3(
|
||||||
self.planes[0].normal,
|
self.planes[0].normal,
|
||||||
|
|
Loading…
Reference in New Issue