|
@@ -1,47 +1,28 @@
|
|
|
use std::vec;
|
|
use std::vec;
|
|
|
|
|
|
|
|
|
|
+use glam::vec3;
|
|
|
|
|
+
|
|
|
use crate::vertex::Vertex;
|
|
use crate::vertex::Vertex;
|
|
|
|
|
|
|
|
-pub fn generate_simple_plane()->Vec<Vertex>{
|
|
|
|
|
|
|
+pub fn generate_simple_plane(width: f32, division: u32)->Vec<Vertex>{
|
|
|
let mut vertices: Vec<Vertex> = vec![];
|
|
let mut vertices: Vec<Vertex> = vec![];
|
|
|
|
|
+ let triangle_side = width / division as f32;
|
|
|
|
|
|
|
|
- let vert1 = Vertex{
|
|
|
|
|
- position: [-0.5, -0.5, 0.0],
|
|
|
|
|
- color: [1.0, 0.0, 0.0],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let vert2 = Vertex{
|
|
|
|
|
- position: [0.5, -0.5, 0.0],
|
|
|
|
|
- color: [0.0, 1.0, 0.0],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let vert3 = Vertex{
|
|
|
|
|
- position: [0.5, 0.5, 0.0],
|
|
|
|
|
- color: [1.0, 1.0, 1.0],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let vert4 = Vertex{
|
|
|
|
|
- position: [0.5, 0.5, 0.0],
|
|
|
|
|
- color: [0.0, 0.0, 1.0],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- let vert5 = Vertex{
|
|
|
|
|
- position: [-0.5, 0.5, 0.0],
|
|
|
|
|
- color: [1.0, 1.0, 1.0],
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ let (mut row, mut column) = (0, 0);
|
|
|
|
|
|
|
|
- let vert6 = Vertex{
|
|
|
|
|
- position: [-0.5, -0.5, 0.0],
|
|
|
|
|
- color: [1.0, 1.0, 1.0],
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ while row < (division + 1) {
|
|
|
|
|
+ while column < (division + 1){
|
|
|
|
|
+ let vec3 = vec3((column as f32) * triangle_side, 0.0, (row as f32) * -triangle_side );
|
|
|
|
|
|
|
|
- // Reordered for counter-clockwise rendering
|
|
|
|
|
- vertices.push(vert1);
|
|
|
|
|
- vertices.push(vert2);
|
|
|
|
|
- vertices.push(vert3);
|
|
|
|
|
- vertices.push(vert4);
|
|
|
|
|
- vertices.push(vert5);
|
|
|
|
|
- vertices.push(vert6);
|
|
|
|
|
|
|
+ let vert1 = Vertex{
|
|
|
|
|
+ position : [vec3.x, vec3.y, vec3.z],
|
|
|
|
|
+ color: [1.0, 1.0, 1.0]
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
+ vertices.push(vert1);
|
|
|
|
|
+ column = column + 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ row = row + 1;
|
|
|
|
|
+ }
|
|
|
return vertices
|
|
return vertices
|
|
|
}
|
|
}
|