spheres: add transform member to Sphere
This commit is contained in:
parent
9f22d820e7
commit
87bf924094
@ -1,12 +1,37 @@
|
||||
use crate::{
|
||||
intersections::Intersection,
|
||||
matrices::Matrix4x4,
|
||||
rays::Ray,
|
||||
tuples::{dot, Tuple},
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq)]
|
||||
/// Sphere represents the unit-sphere (radius of unit 1.) at the origin 0., 0., 0.
|
||||
pub struct Sphere {}
|
||||
pub struct Sphere {
|
||||
pub transform: Matrix4x4,
|
||||
}
|
||||
|
||||
impl Default for Sphere {
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use rtchallenge::{matrices::Matrix4x4, spheres::Sphere};
|
||||
///
|
||||
/// // A sphere's default transform is the identity matrix.
|
||||
/// let s = Sphere::default();
|
||||
/// assert_eq!(s.transform, Matrix4x4::identity());
|
||||
///
|
||||
/// // It can be changed by directly setting the transform member.
|
||||
/// let mut s = Sphere::default();
|
||||
/// let t = Matrix4x4::translate(2., 3., 4.);
|
||||
/// s.transform = t.clone();
|
||||
/// assert_eq!(s.transform, t);
|
||||
/// ```
|
||||
fn default() -> Sphere {
|
||||
Sphere {
|
||||
transform: Matrix4x4::identity(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Intersect a ray with a sphere.
|
||||
///
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user