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