first sphere
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -9,7 +9,21 @@ use crate::{
|
||||
ray::*
|
||||
};
|
||||
|
||||
fn hit_sphere(center: &Point3, radius: f64, r: &Ray) -> bool {
|
||||
let oc = r.origin() - *center;
|
||||
let a = r.direction().dot(&r.direction());
|
||||
let b = 2.0 * oc.dot(&r.direction());
|
||||
let c = oc.dot(&oc) - radius*radius;
|
||||
let discriminant = b*b - 4.0*a*c;
|
||||
|
||||
discriminant > 0.0
|
||||
}
|
||||
|
||||
fn ray_color(r: &Ray) -> Color {
|
||||
if hit_sphere(&Point3::new(0.0, 0.0, -1.0), 0.5, r) {
|
||||
return Color::new(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
let unit_direction: Vec3 = r.direction().unit_vector();
|
||||
let t = 0.5 * (unit_direction.y() + 1.0);
|
||||
//println!("{}", t);
|
||||
|
||||
Reference in New Issue
Block a user