Skip to content

Commit

Permalink
Collision shader calculate_vertices now returns an array instead of…
Browse files Browse the repository at this point in the history
… a vector
  • Loading branch information
white-axe committed Nov 23, 2023
1 parent 467360c commit 2591e6e
Showing 1 changed file with 51 additions and 56 deletions.
107 changes: 51 additions & 56 deletions crates/graphics/src/collision/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,69 +107,64 @@ impl Instances {
.collect_vec()
}

fn calculate_vertices() -> Vec<Vertex> {
let mut vertices = Vec::with_capacity(12);

fn calculate_vertices() -> [Vertex; 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
[
Vertex {
position: center,
direction: 1,
},
Vertex {
position: bottom_left,
direction: 1,
},
Vertex {
position: bottom_right,
direction: 1,
},
Vertex {
position: center,
direction: 2,
},
Vertex {
position: top_left,
direction: 2,
},
Vertex {
position: bottom_left,
direction: 2,
},
Vertex {
position: center,
direction: 4,
},
Vertex {
position: bottom_right,
direction: 4,
},
Vertex {
position: top_right,
direction: 4,
},
Vertex {
position: center,
direction: 8,
},
Vertex {
position: top_right,
direction: 8,
},
Vertex {
position: top_left,
direction: 8,
},
]
}

pub fn draw<'rpass>(&'rpass self, render_pass: &mut wgpu::RenderPass<'rpass>) {
Expand Down

0 comments on commit 2591e6e

Please sign in to comment.