diff --git a/examples/demo.rs b/examples/demo.rs index 8ce9e88..a00727c 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -1,7 +1,6 @@ use bevy::{ - math::Vec3A, prelude::*, - render::primitives::{Aabb, Sphere}, + transform::TransformSystem, window::{CursorGrabMode, PrimaryWindow, Window, WindowMode}, }; use big_space::{ @@ -21,6 +20,10 @@ fn main() { .insert_resource(ClearColor(Color::BLACK)) .add_systems(Startup, (setup, ui_setup)) .add_systems(Update, (cursor_grab_system, ui_text_system)) + .add_systems( + PostUpdate, + highlight_nearest_sphere.after(TransformSystem::TransformPropagate), + ) .run() } @@ -34,11 +37,17 @@ fn setup( Camera3dBundle { transform: Transform::from_xyz(0.0, 0.0, 8.0) .looking_at(Vec3::new(0.0, 0.0, 0.0), Vec3::Y), + projection: Projection::Perspective(PerspectiveProjection { + near: 1e-16, + ..default() + }), ..default() }, GridCell::::default(), // All spatial entities need this component FloatingOrigin, // Important: marks this as the entity to use as the floating origin - CameraController::default().with_max_speed(10e35), // Built-in camera controller + CameraController::default() + .with_max_speed(10e35) + .with_smoothness(0.9, 0.8), // Built-in camera controller )); let mesh_handle = meshes.add( @@ -57,8 +66,8 @@ fn setup( }); let mut translation = Vec3::ZERO; - for i in 1..=37_i128 { - let j = 10_f32.powf(i as f32 - 10.0); + for i in -12..=27 { + let j = 10_f32.powf(i as f32); translation.x += j; commands.spawn(( PbrBundle { @@ -67,10 +76,6 @@ fn setup( transform: Transform::from_scale(Vec3::splat(j)).with_translation(translation), ..default() }, - Aabb::from(Sphere { - center: Vec3A::ZERO, - radius: j / 2.0, - }), GridCell::::default(), )); } @@ -93,7 +98,7 @@ fn ui_setup(mut commands: Commands) { TextBundle::from_section( "", TextStyle { - font_size: 18.0, + font_size: 28.0, color: Color::WHITE, ..default() }, @@ -109,6 +114,19 @@ fn ui_setup(mut commands: Commands) { )); } +fn highlight_nearest_sphere( + cameras: Query<&CameraController>, + objects: Query<&GlobalTransform>, + mut gizmos: Gizmos, +) { + let Some((entity, _)) = cameras.single().nearest_object() else { return }; + let Ok(transform) = objects.get(entity) else { return }; + let (scale, rotation, translation) = transform.to_scale_rotation_translation(); + gizmos + .sphere(translation, rotation, scale.x * 0.505, Color::RED) + .circle_segments(128); +} + fn ui_text_system( mut text: Query<&mut Text, With>, time: Res