spheres: add material to Sphere.
This commit is contained in:
parent
81540cd484
commit
1cbfbc8641
@ -1,5 +1,5 @@
|
||||
use crate::tuples::Color;
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Material {
|
||||
pub color: Color,
|
||||
pub ambient: f32,
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
intersections::{Intersection, Intersections},
|
||||
materials::Material,
|
||||
matrices::Matrix4x4,
|
||||
rays::Ray,
|
||||
tuples::{dot, Tuple},
|
||||
EPSILON,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -11,12 +11,13 @@ use crate::{
|
||||
pub struct Sphere {
|
||||
// TODO(wathiede): cache inverse to speed up intersect.
|
||||
pub transform: Matrix4x4,
|
||||
pub material: Material,
|
||||
}
|
||||
|
||||
impl Default for Sphere {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::{matrices::Matrix4x4, spheres::Sphere};
|
||||
/// use rtchallenge::{materials::Material, matrices::Matrix4x4, spheres::Sphere};
|
||||
///
|
||||
/// // A sphere's default transform is the identity matrix.
|
||||
/// let s = Sphere::default();
|
||||
@ -27,10 +28,21 @@ impl Default for Sphere {
|
||||
/// let t = Matrix4x4::translation(2., 3., 4.);
|
||||
/// s.transform = t.clone();
|
||||
/// assert_eq!(s.transform, t);
|
||||
///
|
||||
/// // Default Sphere has the default material.
|
||||
/// assert_eq!(s.material, Material::default());
|
||||
/// // It can be overridden.
|
||||
/// let mut s = Sphere::default();
|
||||
/// let mut m = Material::default();
|
||||
/// m.ambient = 1.;
|
||||
/// s.material = m.clone();
|
||||
/// assert_eq!(s.material, m);
|
||||
|
||||
/// ```
|
||||
fn default() -> Sphere {
|
||||
Sphere {
|
||||
transform: Matrix4x4::identity(),
|
||||
material: Material::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user