diff --git a/examples/gizmos/axes.rs b/examples/gizmos/axes.rs index 224d419b87827..41faff9a356b0 100644 --- a/examples/gizmos/axes.rs +++ b/examples/gizmos/axes.rs @@ -1,9 +1,11 @@ //! This example demonstrates the implementation and behavior of the axes gizmo. use bevy::prelude::*; use bevy::render::primitives::Aabb; -use rand::random; +use rand::{rngs::StdRng, Rng, SeedableRng}; use std::f32::consts::PI; +const TRANSITION_DURATION: f32 = 2.0; + fn main() { App::new() .add_plugins(DefaultPlugins) @@ -27,15 +29,20 @@ struct TransformTracking { /// The target transform of the cube during the move target_transform: Transform, - /// The progress of the cube during the move in percentage points - progress: u16, + /// The progress of the cube during the move in seconds + progress: f32, } +#[derive(Resource)] +struct SeededRng(StdRng); + fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { + let mut rng = StdRng::seed_from_u64(19878367467713); + // Lights... commands.spawn(PointLightBundle { point_light: PointLight { @@ -62,8 +69,8 @@ fn setup( ShowAxes, TransformTracking { initial_transform: default(), - target_transform: random_transform(), - progress: 0, + target_transform: random_transform(&mut rng), + progress: 0.0, }, )); @@ -76,8 +83,8 @@ fn setup( ShowAxes, TransformTracking { initial_transform: default(), - target_transform: random_transform(), - progress: 0, + target_transform: random_transform(&mut rng), + progress: 0.0, }, )); @@ -88,6 +95,8 @@ fn setup( transform: Transform::from_xyz(0., -2., 0.), ..default() }); + + commands.insert_resource(SeededRng(rng)); } // This system draws the axes based on the cube's transform, with length based on the size of @@ -100,19 +109,24 @@ fn draw_axes(mut gizmos: Gizmos, query: Query<(&Transform, &Aabb), With) { +fn move_cubes( + mut query: Query<(&mut Transform, &mut TransformTracking)>, + time: Res