Add basic cylinder brush generator
This commit is contained in:
		
							parent
							
								
									901fb79ae6
								
							
						
					
					
						commit
						ebe6b317f2
					
				|  | @ -55,6 +55,38 @@ fn generate_pyramid_brush(position: Vec3, height: f32, side_count: u32) -> Brush | |||
|     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() { | ||||
|     let mut brush = generate_box_brush(Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 2.0, 1.0)); | ||||
|     brush.rebuild(); | ||||
|  | @ -67,4 +99,10 @@ fn main() { | |||
|     let vs = brush.get_vertices(); | ||||
| 
 | ||||
|     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:?}"); | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue