Add basic pyramid brush generator
This commit is contained in:
		
							parent
							
								
									0cfb77804d
								
							
						
					
					
						commit
						1ffa8a9860
					
				|  | @ -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:?}"); | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue