-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathraytracing.rs
More file actions
32 lines (27 loc) · 632 Bytes
/
raytracing.rs
File metadata and controls
32 lines (27 loc) · 632 Bytes
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
struct Ray {
origin: Vec3,
direction: Vec3,
}
impl Ray {
fn point_at_parameter(&self, t: f32) -> Vec3 {
self.origin + t * self.direction
}
}
struct HitRecord {
t: f32,
p: Vec3,
normal: Vec3,
}
trait Hitable {
fn hit(&self, ray: &Ray, t_min: f32, t_max: f32) -> Option<HitRecord>;
}
struct Sphere {
center: Vec3,
radius: f32,
}
impl Hitable for Sphere {
fn hit(&self, ray: &Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
let oc = ray.origin - self.center;
let a = dot(&ray.direction, &ray.direction);
let b = dot(&oc, &ray.direction);
let