use bevy::prelude::*; use bevy_infinite_grid::{InfiniteGridBundle, InfiniteGridPlugin}; use camera_controller::{CameraController, CameraControllerPlugin}; fn main() { App::new() .add_plugins((DefaultPlugins, CameraControllerPlugin, InfiniteGridPlugin)) .add_systems(Startup, setup_system) .run(); } fn setup_system( mut commands: Commands, mut meshes: ResMut>, mut standard_materials: ResMut>, ) { commands.spawn(InfiniteGridBundle::default()); commands.spawn(( Camera3dBundle { transform: Transform::from_xyz(0.0, 4.37, 14.77), camera: Camera { hdr: true, ..default() }, ..default() }, CameraController::default(), )); commands.spawn(DirectionalLightBundle { transform: Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.) .looking_at(Vec3::ZERO, Vec3::Y), ..default() }); let mat = standard_materials.add(StandardMaterial::default()); // cube commands.spawn(PbrBundle { material: mat.clone(), mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), transform: Transform { translation: Vec3::new(3., 4., 0.), rotation: Quat::from_rotation_arc(Vec3::Y, Vec3::ONE.normalize()), scale: Vec3::splat(1.5), }, ..default() }); commands.spawn(PbrBundle { material: mat.clone(), mesh: meshes.add(Cuboid::from_size(Vec3::ONE).mesh()), transform: Transform::from_xyz(0.0, 2.0, 0.0), ..default() }); } // This is a simplified version of the camera controller used in bevy examples mod camera_controller { use bevy::{input::mouse::MouseMotion, prelude::*}; use std::f32::consts::*; pub const RADIANS_PER_DOT: f32 = 1.0 / 180.0; #[derive(Component)] pub struct CameraController { pub pitch: f32, pub yaw: f32, pub velocity: Vec3, } impl Default for CameraController { fn default() -> Self { Self { pitch: 0.0, yaw: 0.0, velocity: Vec3::ZERO, } } } pub struct CameraControllerPlugin; impl Plugin for CameraControllerPlugin { fn build(&self, app: &mut App) { app.add_systems(Update, camera_controller); } } fn camera_controller( time: Res