Store the positive offset in planes

This commit is contained in:
Jarrod Doyle 2023-09-18 21:46:06 +01:00
parent 9dbcb2b811
commit c57d94230e
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,8 @@
use glam::{Mat3, Vec3}; use glam::{Mat3, Vec3, Vec4};
use crate::math; use crate::math;
//? Should this be normalised or does that risk introducing fpp errors
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct Plane { pub struct Plane {
pub normal: Vec3, pub normal: Vec3,
@ -12,9 +13,13 @@ impl Plane {
pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self { pub fn from_point_normal(point: Vec3, normal: Vec3) -> Self {
Self { Self {
normal, 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 { pub struct PlaneIntersection {