Browse Source

Last commit before leaving

Ghastrod 1 year ago
parent
commit
e4910a8ab1
2 changed files with 34 additions and 1 deletions
  1. 3 1
      src/lib.rs
  2. 31 0
      src/simple_plane.rs

+ 3 - 1
src/lib.rs

@@ -26,6 +26,7 @@ use winit::{
     window::{Window, WindowBuilder},
 };
 
+use crate::simple_plane::generate_vertices_and_colors;
 use crate::simple_plane::very_simple_plane;
 
 
@@ -360,7 +361,8 @@ impl<'a> State<'a> {
 
         //let vert = generate_jamie_plane(3);
 
-        let vert = very_simple_plane(1, 0.5);
+        //let vert = very_simple_plane(1, 0.5);
+        let vert = generate_vertices_and_colors(1, 1, 1);
         println!("{:?}", vert);
 
         // Create a buffer with the vertex data

+ 31 - 0
src/simple_plane.rs

@@ -111,3 +111,34 @@ pub fn very_simple_plane(divisions: u32, width: f32) -> Vec<Vertex> {
 
     plane
 }
+
+//Gemini version
+pub fn generate_vertices_and_colors(
+    largeur: u32,
+    hauteur: u32,
+    subdivisions: u32,
+) -> Vec<Vertex> {
+    let total_vertices = (subdivisions + 1) * (subdivisions + 1);
+
+    let mut vertices: Vec<Vertex> = Vec::with_capacity(total_vertices as usize);
+
+    for i in 0..=subdivisions {
+        for j in 0..=subdivisions {
+            let step_x = largeur as f32 / (subdivisions as f32 + 1.0);
+            let step_y = hauteur as f32 / (subdivisions as f32 + 1.0);
+            let x = step_x * i as f32;
+            let y = step_y * j as f32;
+
+            let gray = (i as f32 + j as f32) / ((subdivisions + 1) as f32 * 2.0) as f32;
+
+            let vertex = Vertex {
+                position: [x, 0.0, y], // Adjust Z component as needed
+                color: [gray, gray, gray],
+            };
+            vertices.push(vertex);
+        }
+    }
+
+    vertices
+}
+