From c57d94230e25b346810bfebd43c1acdccdb25c21 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 18 Sep 2023 21:46:06 +0100 Subject: [PATCH] Store the positive offset in planes --- csg/src/plane.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/csg/src/plane.rs b/csg/src/plane.rs index ac8d678..dbc4635 100644 --- a/csg/src/plane.rs +++ b/csg/src/plane.rs @@ -1,7 +1,8 @@ -use glam::{Mat3, Vec3}; +use glam::{Mat3, Vec3, Vec4}; use crate::math; +//? Should this be normalised or does that risk introducing fpp errors #[derive(Clone, Copy, Debug)] pub struct Plane { pub normal: Vec3, @@ -12,9 +13,13 @@ impl Plane { pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self { Self { normal, - offset: -point.dot(normal), + offset: point.dot(normal), } } + + pub fn into_vec4(&self) -> Vec4 { + glam::vec4(self.normal.x, self.normal.y, self.normal.z, -self.offset) + } } pub struct PlaneIntersection {