diff --git a/csg/src/plane.rs b/csg/src/plane.rs index 03d0f04..ebaf997 100644 --- a/csg/src/plane.rs +++ b/csg/src/plane.rs @@ -72,6 +72,31 @@ impl PlaneIntersection { 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 { glam::mat3( self.planes[0].normal,