Add basic cylinder brush generator

This commit is contained in:
Jarrod Doyle 2023-09-22 11:14:15 +01:00
parent 901fb79ae6
commit ebe6b317f2
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 38 additions and 0 deletions

View File

@ -55,6 +55,38 @@ fn generate_pyramid_brush(position: Vec3, height: f32, side_count: u32) -> Brush
Brush::new(&brush_planes) Brush::new(&brush_planes)
} }
fn generate_cylinder_brush(position: Vec3, height: f32, radius: f32, side_count: u32) -> Brush {
let mut brush_planes = vec![];
// Top/bottom planes
for normal in &[Vec3::Y, Vec3::NEG_Y] {
let point = position + *normal * (height * 0.5);
brush_planes.push(BrushPlane {
plane: Plane::from_point_normal(point, *normal),
..Default::default()
});
}
// Side planes
for i in 0..side_count {
let angle = (i as f32 / side_count as f32) * 360.0_f32.to_radians();
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, 0.0, 0.0);
let point = position + radius * normal;
brush_planes.push(BrushPlane {
plane: Plane::from_point_normal(point, normal),
..Default::default()
});
}
Brush::new(&brush_planes)
}
fn main() { fn main() {
let mut brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0)); let mut brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0));
brush.rebuild(); brush.rebuild();
@ -67,4 +99,10 @@ fn main() {
let vs = brush.get_vertices(); let vs = brush.get_vertices();
println!("Vertices: {vs:?}"); println!("Vertices: {vs:?}");
let mut brush = generate_cylinder_brush(Vec3::ZERO, 2.0, 1.0, 64);
brush.rebuild();
let vs = brush.get_vertices();
println!("Vertices: {vs:?}");
} }