ft (wip): textures
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{f32::consts::PI, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
objects::{materials::traits::Material, traits::Hittable},
|
||||
@@ -45,8 +45,27 @@ impl Hittable for Circle {
|
||||
|
||||
let p = r.at(t);
|
||||
if (p - self.center).length() < self.radius {
|
||||
return Some(Hit::new(t, p, self.normal, self.material.clone(), self.normal.dot(&r.dir()) < 0.));
|
||||
let uv = self.to_uv(&p);
|
||||
return Some(Hit::new(
|
||||
t,
|
||||
p,
|
||||
self.normal,
|
||||
self.material.clone(),
|
||||
self.normal.dot(&r.dir()) < 0.,
|
||||
*uv.x(),
|
||||
*uv.y(),
|
||||
));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn to_uv(&self, point: &Vec3) -> Vec3 {
|
||||
let p = *point - self.center;
|
||||
// TODO: add rotated texture support
|
||||
return Vec3::new(
|
||||
0.5 + p.y().atan2(*p.x()) / (2. * PI),
|
||||
1. - (p.z() / self.radius).acos() / PI,
|
||||
0.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user