finish cube
This commit is contained in:
parent
a3e0b9a0c5
commit
5c971d0288
1 changed files with 70 additions and 23 deletions
93
src/scene.rs
93
src/scene.rs
|
@ -23,68 +23,115 @@ impl Scene {
|
|||
pub unsafe fn prepare_data(&mut self, instance: &vulkanalia::Instance, device: &vulkanalia::Device, data: &AppData) -> Result<()> {
|
||||
|
||||
let grid_size = 1000;
|
||||
//todo use the 14 vertice box method. Not using geometry shaders seems to be faster... make this a setting?
|
||||
// have cube elements with a method asking for vertices, while giving a primitive type -> method for preferred primitive type as well as one collecting all primitives
|
||||
for x_index in -grid_size..grid_size {
|
||||
for y_index in -grid_size..grid_size {
|
||||
let index = self.vertices.len();
|
||||
// 0 top left far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
self.indices.push(index as u32);
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
self.indices.push(index as u32 + 1);
|
||||
// 1 top right far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
self.indices.push(index as u32 + 2);
|
||||
// 2 top left near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 3 top right near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, 0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
self.indices.push(index as u32 + 2);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 3);
|
||||
}
|
||||
}
|
||||
|
||||
for x_index in -grid_size..grid_size {
|
||||
for y_index in -grid_size..grid_size {
|
||||
let index = self.vertices.len();
|
||||
// 4 bottom left far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 + 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 5 bottom right far
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 + 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 6 bottom left near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 - 0.5, y_index as f32 - 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
// 7 bottom right near
|
||||
self.vertices.push(vertex::Vertex::new(
|
||||
vec3(x_index as f32 + 0.5, y_index as f32 - 0.5, -0.5),
|
||||
vec3(0.0, 1.0, 0.0),
|
||||
vec2(0.0, 0.0)
|
||||
));
|
||||
|
||||
|
||||
// top
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 2);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32);
|
||||
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 0);
|
||||
|
||||
// bottom
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// left
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 2);
|
||||
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 2);
|
||||
self.indices.push(index as u32 + 4);
|
||||
|
||||
// right
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 5);
|
||||
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// near
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 2);
|
||||
|
||||
self.indices.push(index as u32 + 3);
|
||||
self.indices.push(index as u32 + 6);
|
||||
self.indices.push(index as u32 + 7);
|
||||
|
||||
// far
|
||||
self.indices.push(index as u32 + 0);
|
||||
self.indices.push(index as u32 + 1);
|
||||
self.indices.push(index as u32 + 4);
|
||||
|
||||
self.indices.push(index as u32 + 5);
|
||||
self.indices.push(index as u32 + 4);
|
||||
self.indices.push(index as u32 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue