diff --git a/hello-world/src/test_scene.rs b/hello-world/src/test_scene.rs index 456de75..61f866d 100644 --- a/hello-world/src/test_scene.rs +++ b/hello-world/src/test_scene.rs @@ -5,6 +5,8 @@ use bevy::{ render::render_resource::{AsBindGroup, ShaderRef}, }; +use crate::orbit_cam::{self, OrbitCam}; + pub struct TestScenePlugin; impl Plugin for TestScenePlugin { @@ -14,10 +16,17 @@ impl Plugin for TestScenePlugin { prepass_enabled: true, ..default() }) - .add_systems(Startup, spawn_scene); + .add_systems(Startup, spawn_scene) + .add_systems( + Update, + move_plane_with_camera.after(orbit_cam::pan_orbit_camera), + ); } } +#[derive(Component)] +struct WorldGridPlane; + fn spawn_scene( mut cmd: Commands, mut meshes: ResMut>, @@ -53,16 +62,28 @@ fn spawn_scene( cmd.spawn(( MaterialMeshBundle { mesh: meshes.add(Mesh::from(shape::Plane { - size: 10_000.0, + size: 200.0, subdivisions: 0, })), material: mat_proc_grid.add(ProceduralGridMaterial {}), ..default() }, NotShadowCaster, + WorldGridPlane, )); } +fn move_plane_with_camera( + mut plane: Query<(&WorldGridPlane, &mut Transform)>, + camera: Query<&OrbitCam>, +) { + let &OrbitCam { focus, .. } = camera.single(); + let (_, mut xform) = plane.single_mut(); + + xform.translation.x = focus.x; + xform.translation.z = focus.z; +} + #[derive(AsBindGroup, Clone, TypePath, TypeUuid)] #[uuid = "CE331A13-F247-4F5B-A75E-670B2BD5776A"] struct ProceduralGridMaterial {}