Add basic pyramid brush generator

This commit is contained in:
Jarrod Doyle 2023-09-22 09:54:31 +01:00
parent 0cfb77804d
commit 1ffa8a9860
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 36 additions and 0 deletions

View File

@ -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() { fn main() {
let brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0)); 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(); let vs = brush.get_vertices();
println!("Vertices: {vs:?}"); println!("Vertices: {vs:?}");
let vs = generate_pyramid_brush(Vec3::ZERO, 1.0, 4).get_vertices();
println!("Vertices: {vs:?}");
} }