diff --git a/src/lib.rs b/src/lib.rs index e43021b..dd8e141 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -96,7 +96,7 @@ impl Core { } fn render(&self, output: &wgpu::Texture, args: &RedrawArgs) { - let mesh = mesh::generate(); + let mesh = mesh::generate(&args.shape); let mesh = faceted_mesh(&mesh); let mesh = render::Mesh::new(&self.device, &mesh); diff --git a/src/mesh.rs b/src/mesh.rs index f7e29db..414d4b2 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -7,21 +7,22 @@ pub struct Mesh { pub faces: Vec<[usize; 3]>, } -pub fn generate() -> Mesh { +pub fn generate(shape: &crate::ShapeArgs) -> Mesh { let mut vertices = Vec::::new(); let mut faces = Vec::<[usize; 3]>::new(); - let sides: usize = 24; - let layers = 12; - let base_layer = 4; - let diameter = 36.0; + let sides = shape.sides as usize; + let layers = (shape.layers_up + shape.layers_down) as usize; + let base_layer = shape.layers_down; + let diameter = shape.base_diameter; let radius = diameter / 2.; - let height = 120.; + let height = shape.height; let bottom_angle = (PI / sides as f32) * -(base_layer as f32); let top_angle = (PI / sides as f32) * (layers as f32 - base_layer as f32); let bottom_y = radius * bottom_angle.tan(); let top_y = radius * top_angle.tan(); let incline = height / (top_y - bottom_y); + let elevation = -height / 2. - incline * bottom_y; let base = vertices.len(); for side in 0..(sides - 2) { @@ -31,7 +32,7 @@ pub fn generate() -> Mesh { let angle = (PI / sides as f32) * (layer as f32 - base_layer as f32); let x = radius; let y = angle.tan() * x; - let z = incline * y; + let z = elevation + incline * y; for side in 0..sides { let angle = (2. * PI / sides as f32) * side as f32; let rot = Mat2::from_angle(angle); diff --git a/ui/src/main_window.cxx b/ui/src/main_window.cxx index 0bc77f0..245db4d 100644 --- a/ui/src/main_window.cxx +++ b/ui/src/main_window.cxx @@ -12,6 +12,9 @@ Hyperboloid::Hyperboloid(QWidget* parent) Hyperboloid::~Hyperboloid() = default; void Hyperboloid::updateView() { + const int max_layers = (m_ui->sides->value() - 1) / 2; + m_ui->layersUp->setMaximum(max_layers); + m_ui->layersDown->setMaximum(max_layers); const auto color = m_ui->inBackground->color(); const ShapeArgs shape { .sides = (std::uint32_t)m_ui->sides->value(), diff --git a/ui/src/main_window.ui b/ui/src/main_window.ui index c61cce4..9d91931 100644 --- a/ui/src/main_window.ui +++ b/ui/src/main_window.ui @@ -174,6 +174,9 @@ 11 + + 8 + @@ -188,6 +191,9 @@ 11 + + 4 +