Skip to content

Commit 159fe52

Browse files
committed
Slow down the many_cubes example (#4117)
# Objective - After #4015, the `many_cubes` example could introduce discomfort in some cases ## Solution - Slow down the camera, add space between the cubes https://user-images.githubusercontent.com/8672791/156898412-0fcd29b4-63b1-4e11-bf52-7ec40cb8f932.mp4
1 parent cf46baa commit 159fe52

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

examples/3d/many_cubes.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,37 @@ fn setup(
2828
});
2929
for x in 0..WIDTH {
3030
for y in 0..HEIGHT {
31+
// introduce spaces to break any kind of moiré pattern
32+
if x % 10 == 0 || y % 10 == 0 {
33+
continue;
34+
}
3135
// cube
3236
commands.spawn_bundle(PbrBundle {
3337
mesh: mesh.clone_weak(),
3438
material: material.clone_weak(),
35-
transform: Transform::from_xyz((x as f32) * 2.0, (y as f32) * 2.0, 0.0),
39+
transform: Transform::from_xyz((x as f32) * 2.5, (y as f32) * 2.5, 0.0),
3640
..default()
3741
});
3842
commands.spawn_bundle(PbrBundle {
3943
mesh: mesh.clone_weak(),
4044
material: material.clone_weak(),
4145
transform: Transform::from_xyz(
42-
(x as f32) * 2.0,
43-
HEIGHT as f32 * 2.0,
44-
(y as f32) * 2.0,
46+
(x as f32) * 2.5,
47+
HEIGHT as f32 * 2.5,
48+
(y as f32) * 2.5,
4549
),
4650
..Default::default()
4751
});
4852
commands.spawn_bundle(PbrBundle {
4953
mesh: mesh.clone_weak(),
5054
material: material.clone_weak(),
51-
transform: Transform::from_xyz((x as f32) * 2.0, 0.0, (y as f32) * 2.0),
55+
transform: Transform::from_xyz((x as f32) * 2.5, 0.0, (y as f32) * 2.5),
5256
..Default::default()
5357
});
5458
commands.spawn_bundle(PbrBundle {
5559
mesh: mesh.clone_weak(),
5660
material: material.clone_weak(),
57-
transform: Transform::from_xyz(0.0, (x as f32) * 2.0, (y as f32) * 2.0),
61+
transform: Transform::from_xyz(0.0, (x as f32) * 2.5, (y as f32) * 2.5),
5862
..Default::default()
5963
});
6064
}
@@ -66,7 +70,7 @@ fn setup(
6670
mesh,
6771
material,
6872
transform: Transform {
69-
translation: Vec3::new(0.0, HEIGHT as f32 * 2.0, 0.0),
73+
translation: Vec3::new(0.0, HEIGHT as f32 * 2.5, 0.0),
7074
scale: Vec3::splat(5.0),
7175
..Default::default()
7276
},
@@ -87,8 +91,8 @@ fn setup(
8791
// System for rotating the camera
8892
fn move_camera(time: Res<Time>, mut camera_query: Query<&mut Transform, With<Camera>>) {
8993
let mut camera_transform = camera_query.single_mut();
90-
camera_transform.rotate(Quat::from_rotation_z(time.delta_seconds() * 0.5));
91-
camera_transform.rotate(Quat::from_rotation_x(time.delta_seconds() * 0.5));
94+
camera_transform.rotate(Quat::from_rotation_z(time.delta_seconds() * 0.15));
95+
camera_transform.rotate(Quat::from_rotation_x(time.delta_seconds() * 0.15));
9296
}
9397

9498
// System for printing the number of meshes on every tick of the timer

0 commit comments

Comments
 (0)