feat: Camera control

This commit is contained in:
Rendo 2026-08-03 03:07:31 +05:00
commit 8373b10ac1
3 changed files with 112 additions and 35 deletions

View file

@ -11,7 +11,7 @@ impl Plugin for GameViewPlugin {
app.add_systems(PreStartup, debug_setup_grid)
.init_resource::<CubeStages>()
.init_resource::<TileMaterials>()
.add_systems(Startup, (setup_view_cubes, scene.spawn()))
.add_systems(Startup, setup_view_cubes)
.add_systems(Update, update_cubes);
}
}
@ -84,38 +84,6 @@ pub fn setup_view_cubes(
}
}
pub fn scene() -> impl SceneList {
bsn_list![
camera(),
sun()
]
}
pub fn camera() -> impl Scene {
bsn! {
Camera3d
template(
|ctx| {
let grid = ctx.resource::<Grid>();
let center = grid.size.as_vec3() * 0.5;
Ok(Transform::from_xyz(
center.x + grid.size.x as f32 * 1.5,
grid.size.y as f32 * 1.5,
center.z + grid.size.z as f32 * 1.5).looking_at(center, Vec3::Y))
}
)
}
}
pub fn sun() -> impl Scene {
bsn!{
DirectionalLight {
illuminance: 8_000.0,
shadow_maps_enabled: false,
}
template_value(Transform::from_xyz(10.0, 30.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y))
}
}
pub fn cube(position: Vec3,index: usize,mesh: Handle<Mesh>) -> impl Scene {