From dc749aa7be83e73fa18e149bfd8cd5f0fb7168cd Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 25 Sep 2023 10:25:22 +0100 Subject: [PATCH] Remove double transpose --- csg/src/brush.rs | 19 +++++++++++++++++++ csg/src/plane.rs | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/csg/src/brush.rs b/csg/src/brush.rs index 1c1ec54..817c183 100644 --- a/csg/src/brush.rs +++ b/csg/src/brush.rs @@ -68,6 +68,25 @@ impl Brush { self.aabb.intersects(other.get_aabb()) } + pub fn planes_intersect_with(&self, other: &Brush) -> bool { + // TODO: Benchmark this + // Check our vertices against their planes + for pi in &self.raw_vertices { + if other.planes.iter().all(|bp| pi.in_halfspace_mat(&bp.plane)) { + return true; + } + } + + // Check their vertices against our planes + for pi in &other.raw_vertices { + if self.planes.iter().all(|bp| pi.in_halfspace_mat(&bp.plane)) { + return true; + } + } + + false + } + pub fn get_vertices(&self) -> Vec { self.vertices.clone() } diff --git a/csg/src/plane.rs b/csg/src/plane.rs index a503ce2..1d44852 100644 --- a/csg/src/plane.rs +++ b/csg/src/plane.rs @@ -110,7 +110,11 @@ impl PlaneIntersection { 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 m2 = glam::mat3( + self.planes[0].normal, + self.planes[1].normal, + self.planes[2].normal, + ); let d2 = m2.determinant(); let dist = d1 * d2;