grid size scale with zoom

This commit is contained in:
RustyStriker 2022-08-24 23:03:11 +03:00
parent f43cf6728b
commit ad05e6d1f2
2 changed files with 55 additions and 2 deletions

View file

@ -29,8 +29,8 @@ pub fn spawn_grid(
) {
coms.spawn().insert_bundle(MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1000.0 })).into(),
transform: Transform::from_xyz(0.0, 0.0, 0.0),
mesh: meshes.add(Mesh::from(shape::Plane { size: 1000.0 })).into(),
transform: Transform::from_rotation(Quat::from_rotation_x(std::f32::consts::FRAC_PI_2)),
material: mats.add(GridMaterial { width: 2.0, size: Vec2::splat(15.0), visible: 1 }),
..default()
});
@ -40,11 +40,15 @@ pub fn update_grid_shader(
snap_grid: Res<crate::SnapGrid>,
handles: Query<&Handle<GridMaterial>>,
mut mats: ResMut<Assets<GridMaterial>>,
projection: Query<&OrthographicProjection, With<MainCamera>>,
) {
let zoom = projection.get_single().map(|p| p.scale).unwrap_or(1.0);
for h in handles.iter() {
if let Some(mut m) = mats.get_mut(h) {
m.size = Vec2::new(snap_grid.width, snap_grid.height);
m.visible = snap_grid.visible as u32;
m.width = zoom;
}
}
}