From 1ffa8a986018799718bf01c64293b174cb23d7cd Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 22 Sep 2023 09:54:31 +0100 Subject: [PATCH] Add basic pyramid brush generator --- editor/src/main.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/editor/src/main.rs b/editor/src/main.rs index 7d63486..3f83e63 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -31,9 +31,45 @@ fn generate_box_brush(position: Vec3, extent: Vec3) -> Brush { } } +/// Position is center of base plane +fn generate_pyramid_brush(position: Vec3, height: f32, side_count: u32) -> Brush { + let tip = position + Vec3::Y * height; + let base_plane = Plane::from_point_normal(position, Vec3::NEG_Y); + + let mut brush_planes = vec![BrushPlane { + plane: base_plane, + ..Default::default() + }]; + + for i in 0..side_count { + let angle = (i as f32 / side_count as f32) * 360.0_f32.to_radians(); + dbg!(angle); + let rot_mat = Mat3::from_cols( + Vec3::new(angle.cos(), 0.0, -angle.sin()), + Vec3::Y, + Vec3::new(angle.sin(), 0.0, angle.cos()), + ); + let normal = rot_mat * Vec3::new(1.0, 1.0, 0.0); + dbg!(normal); + + brush_planes.push(BrushPlane { + plane: Plane::from_point_normal(tip, normal), + ..Default::default() + }); + } + + Brush { + planes: brush_planes, + } +} + fn main() { let brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0)); let vs = brush.get_vertices(); println!("Vertices: {vs:?}"); + + let vs = generate_pyramid_brush(Vec3::ZERO, 1.0, 4).get_vertices(); + + println!("Vertices: {vs:?}"); }