Skip to content

Commit

Permalink
Save some triangles for everyone else, explain positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
mweatherley committed May 26, 2024
1 parent 461a2b5 commit ea46187
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion examples/math/random_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy::{
input::mouse::{MouseButtonInput, MouseMotion},
math::prelude::*,
prelude::*,
render::mesh::SphereKind,
};
use rand::{distributions::Distribution, SeedableRng};
use rand_chacha::ChaCha8Rng;
Expand Down Expand Up @@ -97,7 +98,13 @@ fn setup(
});

// Store the mesh and material for sample points in resources:
commands.insert_resource(PointMesh(meshes.add(Sphere::new(0.03))));
commands.insert_resource(PointMesh(
meshes.add(
Sphere::new(0.03)
.mesh()
.kind(SphereKind::Ico { subdivisions: 3 }),
),
));
commands.insert_resource(PointMaterial(materials.add(StandardMaterial {
base_color: Color::srgb(1.0, 0.8, 0.8),
metallic: 0.8,
Expand Down Expand Up @@ -172,6 +179,14 @@ fn handle_keypress(
},
SamplePoint,
));

// NOTE: The point is inside the cube created at setup just because of how the
// scene is constructed; in general, you would want to use something like
// `cube_transform.transform_point(sample)` to get the position of where the sample
// would be after adjusting for the position and orientation of the cube.
//
// If the spawned point also needed to follow the position of the cube as it moved,
// then making it a child entity of the cube would be a good approach.
}

// D => generate many samples
Expand Down Expand Up @@ -202,6 +217,9 @@ fn handle_keypress(
SamplePoint,
));
}

// NOTE: See the previous note above regarding the positioning of these samples
// relative to the transform of the cube containing them.
}

// M => toggle mode between interior and boundary.
Expand Down

0 comments on commit ea46187

Please sign in to comment.