Skip to content

Commit

Permalink
Remove extra vertices from collision shader
Browse files Browse the repository at this point in the history
  • Loading branch information
white-axe committed Nov 23, 2023
1 parent c5aa8f7 commit 467360c
Showing 1 changed file with 62 additions and 65 deletions.
127 changes: 62 additions & 65 deletions crates/graphics/src/collision/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Instances {
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
});

let vertices = Self::calculate_vertices(passages.xsize(), passages.ysize());
let vertices = Self::calculate_vertices();
let vertex_buffer =
render_state
.device
Expand Down Expand Up @@ -107,70 +107,67 @@ impl Instances {
.collect_vec()
}

fn calculate_vertices(width: usize, height: usize) -> Vec<Vertex> {
let mut vertices = Vec::with_capacity(width * height * 12);

for (y, x) in (0..height).cartesian_product(0..width) {
let rect =
egui::Rect::from_min_size(egui::pos2(x as f32, y as f32), egui::vec2(32., 32.));
let center = glam::vec3(rect.center().x, rect.center().y, 0.);
let top_left = glam::vec3(rect.left_top().x, rect.left_top().y, 0.);
let top_right = glam::vec3(rect.right_top().x, rect.right_top().y, 0.);
let bottom_left = glam::vec3(rect.left_bottom().x, rect.left_bottom().y, 0.);
let bottom_right = glam::vec3(rect.right_bottom().x, rect.right_bottom().y, 0.);

vertices.push(Vertex {
position: center,
direction: 1,
});
vertices.push(Vertex {
position: bottom_left,
direction: 1,
});
vertices.push(Vertex {
position: bottom_right,
direction: 1,
});

vertices.push(Vertex {
position: center,
direction: 2,
});
vertices.push(Vertex {
position: top_left,
direction: 2,
});
vertices.push(Vertex {
position: bottom_left,
direction: 2,
});

vertices.push(Vertex {
position: center,
direction: 4,
});
vertices.push(Vertex {
position: bottom_right,
direction: 4,
});
vertices.push(Vertex {
position: top_right,
direction: 4,
});

vertices.push(Vertex {
position: center,
direction: 8,
});
vertices.push(Vertex {
position: top_right,
direction: 8,
});
vertices.push(Vertex {
position: top_left,
direction: 8,
});
}
fn calculate_vertices() -> Vec<Vertex> {
let mut vertices = Vec::with_capacity(12);

let rect = egui::Rect::from_min_size(egui::pos2(0., 0.), egui::vec2(32., 32.));
let center = glam::vec3(rect.center().x, rect.center().y, 0.);
let top_left = glam::vec3(rect.left_top().x, rect.left_top().y, 0.);
let top_right = glam::vec3(rect.right_top().x, rect.right_top().y, 0.);
let bottom_left = glam::vec3(rect.left_bottom().x, rect.left_bottom().y, 0.);
let bottom_right = glam::vec3(rect.right_bottom().x, rect.right_bottom().y, 0.);

vertices.push(Vertex {
position: center,
direction: 1,
});
vertices.push(Vertex {
position: bottom_left,
direction: 1,
});
vertices.push(Vertex {
position: bottom_right,
direction: 1,
});

vertices.push(Vertex {
position: center,
direction: 2,
});
vertices.push(Vertex {
position: top_left,
direction: 2,
});
vertices.push(Vertex {
position: bottom_left,
direction: 2,
});

vertices.push(Vertex {
position: center,
direction: 4,
});
vertices.push(Vertex {
position: bottom_right,
direction: 4,
});
vertices.push(Vertex {
position: top_right,
direction: 4,
});

vertices.push(Vertex {
position: center,
direction: 8,
});
vertices.push(Vertex {
position: top_right,
direction: 8,
});
vertices.push(Vertex {
position: top_left,
direction: 8,
});

vertices
}
Expand Down

0 comments on commit 467360c

Please sign in to comment.