Added basic plane struct

This commit is contained in:
bijan2005 2020-11-30 08:08:23 -05:00
parent 09def56768
commit 7eb6f48fef
3 changed files with 44 additions and 2 deletions

View file

@ -14,6 +14,10 @@ This list may be changed or extended in the future.
- [x] Sphere intersection test - [x] Sphere intersection test
- [x] Sphere normal generation - [x] Sphere normal generation
- [x] Color mapping on spheres - [x] Color mapping on spheres
- [ ] Plane objects
- [ ] Plane struct
- [ ] Plane intersection test
- [ ] Color mapping on planes
- [ ] Triangle objects - [ ] Triangle objects
- [ ] Triangle struct - [ ] Triangle struct
- [ ] Triangle intersection test - [ ] Triangle intersection test
@ -36,4 +40,3 @@ This list may be changed or extended in the future.
- [ ] Transparency - [ ] Transparency
- [ ] Simple transparency - [ ] Simple transparency
- [ ] Refraction - [ ] Refraction

38
src/object/plane.rs Normal file
View file

@ -0,0 +1,38 @@
extern crate nalgebra as na;
use na::*;
use na::geometry::Point3;
use crate::types::*;
pub struct Plane {
pub center: Point3<f32>,
pub normal: Unit<Vector3<f32>>,
pub texture: Box<dyn Fn(f32, f32) -> Color>
}
impl Plane {
pub fn new<F: 'static>(center: Point3<f32>, normal: Vector3<f32>, texture: F) -> Self
where F: Fn(f32, f32) -> Color
{
Plane {
center: center,
normal: Unit::new_normalize(normal),
texture: Box::new(texture)
}
}
pub fn new_solid(center: Point3<f32>, normal: Vector3<f32>, color: Color) -> Self
{ Plane::new(center, normal, move |_, _| color) }
pub fn intersect(&self, ray: Ray) -> Option<f32> {
unimplemented!()
}
pub fn getcolor(&self, point: Point3<f32>) -> Color {
unimplemented!()
}
pub fn normal(&self, point: Point3<f32>) -> Unit<Vector3<f32>> { self.normal }
}

View file

@ -25,7 +25,8 @@ impl Sphere {
} }
} }
pub fn new_solid(x: f32, y: f32, z: f32, radius: f32, color: Color) -> Self { Sphere::new(x, y, z, radius, Box::new(move |_, _| color)) } pub fn new_solid(x: f32, y: f32, z: f32, radius: f32, color: Color) -> Self
{ Sphere::new(x, y, z, radius, move |_, _| color) }
// Determines if a ray intersects the circle. // Determines if a ray intersects the circle.
// If so, returns the distance to the intersection point. // If so, returns the distance to the intersection point.