|
1 | 1 | use crate::color::Color; |
2 | | -use crate::ray::Ray; |
3 | 2 | use crate::sphere::Sphere; |
4 | | -use crate::vector::Vec3; |
| 3 | +use crate::util::{ray::Ray, vector::Vec3}; |
5 | 4 |
|
6 | 5 | pub fn circles() -> Vec<Sphere> { |
7 | 6 | vec![ |
| 7 | + // Blue |
8 | 8 | Sphere { |
9 | | - center: Vec3::new(600.0, 300.0, 500.0), |
10 | | - radius: 150.0, |
| 9 | + center: Vec3::new(800.0, 400.0, 400.0), |
| 10 | + radius: 250.0, |
| 11 | + color: Color::new(0.0, 0.0, 1.0), |
| 12 | + }, |
| 13 | + // Red |
| 14 | + Sphere { |
| 15 | + center: Vec3::new(800.0, 400.0, 150.0), |
| 16 | + radius: 50.0, |
11 | 17 | color: Color::new(1.0, 0.0, 0.0), |
12 | 18 | }, |
13 | | - // Circle { |
14 | | - // center: Vec3::new(500.0, 500.0, 500.0), |
15 | | - // radius: 150.0, |
16 | | - // color: Color::new(0.0, 1.0, 0.0), |
17 | | - // }, |
18 | | - // Circle { |
19 | | - // center: Vec3::new(700.0, 500.0, 500.0), |
20 | | - // radius: 150.0, |
21 | | - // color: Color::new(0.0, 0.0, 1.0), |
22 | | - // }, |
| 19 | + // Light Blue left |
| 20 | + Sphere { |
| 21 | + center: Vec3::new(710.0, 310.0, 330.0), |
| 22 | + radius: 150.0, |
| 23 | + color: Color::new(0.0, 1.0, 1.0), |
| 24 | + }, |
| 25 | + // Light Blue right |
| 26 | + Sphere { |
| 27 | + center: Vec3::new(890.0, 310.0, 330.0), |
| 28 | + radius: 150.0, |
| 29 | + color: Color::new(0.0, 1.0, 1.0), |
| 30 | + }, |
| 31 | + // Lime left |
| 32 | + Sphere { |
| 33 | + center: Vec3::new(650.0, 250.0, 150.0), |
| 34 | + radius: 50.0, |
| 35 | + color: Color::new(0.0, 1.0, 0.0), |
| 36 | + }, |
| 37 | + // Lime right |
| 38 | + Sphere { |
| 39 | + center: Vec3::new(950.0, 250.0, 150.0), |
| 40 | + radius: 50.0, |
| 41 | + color: Color::new(0.0, 1.0, 0.0), |
| 42 | + }, |
23 | 43 | ] |
24 | 44 | } |
25 | 45 |
|
26 | 46 | pub fn get_pixel(point: &Vec3) -> Color { |
27 | | - let mut color = Color::new(1.0, 1.0, 1.0); |
| 47 | + let mut color = Color::new(0.0, 0.0, 0.0); |
28 | 48 | let ray = Ray::new(*point, Vec3::new(0.0, 0.0, 1.0)); |
| 49 | + let mut lambda = f32::INFINITY; |
29 | 50 |
|
30 | 51 | for sphere in &circles() { |
31 | | - if sphere.contains(point) { |
32 | | - color = color + sphere.color; |
| 52 | + if let Some(l) = sphere.get_lambda(&ray) { |
| 53 | + if l < lambda { |
| 54 | + lambda = l; |
| 55 | + color = sphere.color; |
| 56 | + } |
33 | 57 | } |
34 | 58 | } |
35 | 59 |
|
|
0 commit comments