From 35ef2082e2bcb59761c613bba2e46980f6a7bf01 Mon Sep 17 00:00:00 2001 From: Synis Date: Tue, 23 Mar 2021 18:47:31 +0100 Subject: [PATCH] Rotation primitive and some minor fixes --- world/src/site2/gen.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/world/src/site2/gen.rs b/world/src/site2/gen.rs index f59ba970fe..5b18172ea7 100644 --- a/world/src/site2/gen.rs +++ b/world/src/site2/gen.rs @@ -24,6 +24,7 @@ pub enum Primitive { // Not commutative Diff(Id, Id), // Operators + Rotate(Id, [Vec3; 3]), } pub enum Fill { @@ -59,7 +60,7 @@ impl Fill { - ((pos.z - aabb.min.z) as f32 + 0.5) / (aabb.max.z - aabb.min.z) as f32 }, Primitive::Cylinder(aabb) => { - aabb_contains(*aabb, pos) + (aabb.min.z..aabb.max.z).contains(&pos.z) && (pos .xy() .as_() @@ -68,7 +69,7 @@ impl Fill { < (aabb.size().w.min(aabb.size().h) as f32 / 2.0).powi(2) }, Primitive::Cone(aabb) => { - aabb_contains(*aabb, pos) + (aabb.min.z..aabb.max.z).contains(&pos.z) && pos .xy() .as_() @@ -103,6 +104,14 @@ impl Fill { Primitive::Diff(a, b) => { self.contains_at(tree, *a, pos) && !self.contains_at(tree, *b, pos) }, + Primitive::Rotate(prim, [x, y, z]) => { + let aabb = self.get_bounds(tree, *prim); + let diff = pos - (aabb.min + (x+y+z).map(|x| x.min(0))); + let new_x = Vec3::new(x.x, y.x, z.x); + let new_y = Vec3::new(x.y, y.y, z.y); + let new_z = Vec3::new(x.z, y.z, z.z); + self.contains_at(tree, *prim, aabb.min + (new_x * diff.x) + (new_y * diff.y) + (new_z * diff.z)) + }, } } @@ -170,6 +179,16 @@ impl Fill { |a, b| a.union(b), )?, Primitive::Diff(a, _) => self.get_bounds_inner(tree, *a)?, + Primitive::Rotate(prim, [x, y, z]) => { + let aabb = self.get_bounds_inner(tree, *prim)?; + let extent = (*x * aabb.size().w) + (*y * aabb.size().h) + (*z * aabb.size().d); + let new_min = aabb.min + extent.map(|x| x.min(0)); + let new_aabb: Aabb = Aabb { + min: new_min, + max: new_min + extent.map(|x| x.abs()), + }; + new_aabb + }, }) }