-
Notifications
You must be signed in to change notification settings - Fork 7
/
show_in_cuboid.rs
41 lines (34 loc) · 1.4 KB
/
show_in_cuboid.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate kiss3d;
extern crate nalgebra;
extern crate rand;
extern crate spherical_cow;
use kiss3d::camera::ArcBall;
use kiss3d::light::Light;
use kiss3d::window::Window;
use nalgebra::{Point3, Translation3, UnitQuaternion, Vector3};
use rand::distributions::Uniform;
use spherical_cow::shapes::Cuboid;
fn main() {
// Pack spheres with radii between 0.05 and 0.1 into a cube with a halfspace of 1.5.
let boundary = Cuboid::new(1.5, 1.5, 1.5).unwrap();
let mut sizes = Uniform::new(0.05, 0.1);
let spheres = spherical_cow::pack_spheres(&boundary, &mut sizes).unwrap();
// Setup viewing environment.
let eye = Point3::new(3.5, 3.5, 3.5);
let at = Point3::origin();
let mut camera = ArcBall::new(eye, at);
let mut window = Window::new_with_size("Spherical Cow: Spheres in a cuboid", 1920, 1080);
window.set_light(Light::StickToCamera);
// Populate spheres into scene.
for sphere in spheres.iter() {
let mut scene_sphere = window.add_sphere(sphere.radius);
scene_sphere.set_color(rand::random(), rand::random(), rand::random());
scene_sphere.set_local_translation(Translation3::from(sphere.center.coords));
}
// Show result.
let rot = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), 0.014);
while !window.should_close() {
window.render_with_camera(&mut camera);
window.scene_mut().prepend_to_local_rotation(&rot);
}
}