Skip to content

Commit

Permalink
Chap 16: CSG
Browse files Browse the repository at this point in the history
  • Loading branch information
fremag committed Feb 26, 2024
1 parent d841fe2 commit 6e1b542
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ I'm learning Rust while working my way through Jamis Buck's
<details open>
<summary>Chapter 16: Constructive Solid Geometry</summary>

![csg](https://raw.githubusercontent.com/fremag/ray_tracer_rust/main/img/csg.png)
![csg](https://raw.githubusercontent.com/fremag/ray_tracer_rust/main/img/csg_scene.png)
</details>

<details open>
Expand Down
Binary file removed img/csg.png
Binary file not shown.
Binary file added img/csg_scene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ray-tracer-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
}

println!("Start...");
render(&CsgScene{},400, 400, "./img/csg.png");
render(&CsgScene{},400, 400, "./img/csg_scene.png");
println!("Done.")
}

Expand Down
7 changes: 4 additions & 3 deletions ray-tracer-cli/src/scenes/csg_scene.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ray_tracer_lib::camera::Camera;
use ray_tracer_lib::colors::Color;
use ray_tracer_lib::core::math::{PI};
use ray_tracer_lib::core::transform::{scaling, view_transform};
use ray_tracer_lib::core::transform::{rotation_y, scaling, translation, view_transform};
use ray_tracer_lib::core::tuple::{point, vector};
use ray_tracer_lib::lights::point_light::PointLight;
use ray_tracer_lib::material::Material;
Expand Down Expand Up @@ -42,8 +42,9 @@ impl Scene for CsgScene {
cube2.set_material(mat2.clone());

let csg = Csg::new(CsgOperation::Difference, cyl1, cube2);

world.objects.push(Object::new_csg(csg));
let mut obj_csg = Object::new_csg(csg);
obj_csg.set_transformation(&translation(0.0, 1.0, 0.0) * &rotation_y(90.0));
world.objects.push(obj_csg);

world
}
Expand Down

0 comments on commit 6e1b542

Please sign in to comment.