Trait truster::shape::Shape [−][src]
pub trait Shape { fn transform(&self) -> &Matrix; fn set_transform(&mut self, transform: Matrix); fn transform_inverse(&self) -> &Matrix; fn material(&self) -> &Material; fn set_material(&mut self, material: Material); fn local_intersect(&self, ray: &Ray) -> Vec<Intersection>; fn local_normal_at(&self, point: Tuple) -> Tuple; fn intersect(&self, ray: &Ray) -> Vec<Intersection> { ... } fn normal_at(&self, point: Tuple) -> Tuple { ... } }
Expand description
Represents a 3D shape with all methods to be able to render it, as well as methods for transforming it, and giving it a material.
Shape::transform should return the shape’s transform. Shape::set_transform should set it’s transform. Shape::transform_inverse should return the shape’s transform’s inverse.
Shape::material should return the shape’s material. Shape::set_material should set it’s material.
Shape::local_intersect should return a list of all intersections ray
makes with the
implementation of Shape. The list should be sorted according to the distances (t
value) of
the intersections. Intersections behind ray
should also be in the list, but with a negative
distance. This means they are at the front of the list. The intersections should be in local
space. This means they should be calculated as if the shape where not transformed. The
calculations for the transformation happen in Shape::intersect, which should not be
overwritten.
Shape::local_normal_at should return the surface normal of shape at point
. The caller is
responsible for making sure point
is on the surface the shape. The resulting vector should
be normalized. The normal should be in local space. This means they should be calculated as if
the shape where not transformed. The calculations for the transformation happen in
Shape::normal_at, which should not be overwritten.
Required methods
fn set_transform(&mut self, transform: Matrix)
fn transform_inverse(&self) -> &Matrix
fn set_material(&mut self, material: Material)
fn local_intersect(&self, ray: &Ray) -> Vec<Intersection>
fn local_normal_at(&self, point: Tuple) -> Tuple
Provided methods
fn intersect(&self, ray: &Ray) -> Vec<Intersection>