New Scene struct
The scene is more than just a list of hittables. It's any and all hittables (so the list, yeah), and also the camera(s!) in the world. This doens't compile, however. More work will need to be done to untangle the other things that could previously see these scattered components.
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -4,7 +4,10 @@ mod renderer;
|
|||||||
mod scene;
|
mod scene;
|
||||||
|
|
||||||
use crate::primitives::Vec3;
|
use crate::primitives::Vec3;
|
||||||
use crate::scene::Camera;
|
use crate::scene::{
|
||||||
|
Camera,
|
||||||
|
Scene
|
||||||
|
};
|
||||||
use crate::renderer::RenderCommand;
|
use crate::renderer::RenderCommand;
|
||||||
|
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
@@ -24,12 +27,9 @@ fn main() {
|
|||||||
// random generator
|
// random generator
|
||||||
let mut small_rng = SmallRng::seed_from_u64(0);
|
let mut small_rng = SmallRng::seed_from_u64(0);
|
||||||
|
|
||||||
// world
|
// Scene (now includes camera)
|
||||||
let world = scene::random_scene(&mut small_rng);
|
let scene = Scene {
|
||||||
|
camera: Camera::new(
|
||||||
// camera
|
|
||||||
|
|
||||||
let cam = Camera::new(
|
|
||||||
Vec3::new(13.0, 2.0, 3.0), // lookfrom
|
Vec3::new(13.0, 2.0, 3.0), // lookfrom
|
||||||
Vec3::zero(), // lookat
|
Vec3::zero(), // lookat
|
||||||
Vec3::new(0.0, 1.0, 0.0), // vup
|
Vec3::new(0.0, 1.0, 0.0), // vup
|
||||||
@@ -37,7 +37,9 @@ fn main() {
|
|||||||
aspect_ratio,
|
aspect_ratio,
|
||||||
0.1, // aperture
|
0.1, // aperture
|
||||||
10.0, // dist_to_focus
|
10.0, // dist_to_focus
|
||||||
);
|
),
|
||||||
|
world: Scene::random_world(&mut small_rng)
|
||||||
|
};
|
||||||
|
|
||||||
// render
|
// render
|
||||||
// The render loop should now be a job submission mechanism
|
// The render loop should now be a job submission mechanism
|
||||||
|
|||||||
13
src/scene.rs
13
src/scene.rs
@@ -228,7 +228,14 @@ impl Camera {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn random_scene(srng: &mut SmallRng) -> Hittable {
|
|
||||||
|
pub struct Scene {
|
||||||
|
pub camera: Camera,
|
||||||
|
pub world: Hittable,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scene {
|
||||||
|
pub fn random_world(srng: &mut SmallRng) -> Hittable {
|
||||||
let mat_ground = Material::Lambertian { albedo: Vec3::new(0.5, 0.5, 0.5) };
|
let mat_ground = Material::Lambertian { albedo: Vec3::new(0.5, 0.5, 0.5) };
|
||||||
let mut world = Hittable::HittableList { hittables : Vec::<Hittable>::new() };
|
let mut world = Hittable::HittableList { hittables : Vec::<Hittable>::new() };
|
||||||
|
|
||||||
@@ -307,6 +314,6 @@ pub fn random_scene(srng: &mut SmallRng) -> Hittable {
|
|||||||
radius: 1.0,
|
radius: 1.0,
|
||||||
material: material3
|
material: material3
|
||||||
});
|
});
|
||||||
|
world
|
||||||
return world;
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user