rtchallenge: remove disable-inverse-cache feature.
This commit is contained in:
parent
eaae65712b
commit
0c7bbae4a3
@ -8,7 +8,6 @@ edition = "2018"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "float-as-double" ]
|
default = [ "float-as-double" ]
|
||||||
disable-inverse-cache = []
|
|
||||||
float-as-double = []
|
float-as-double = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -235,18 +235,17 @@ impl Camera {
|
|||||||
/// Tuple::vector((2. as Float).sqrt() / 2., 0., -(2. as Float).sqrt() / 2.)
|
/// Tuple::vector((2. as Float).sqrt() / 2., 0., -(2. as Float).sqrt() / 2.)
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "disable-inverse-cache"))]
|
|
||||||
pub fn ray_for_pixel(&self, px: usize, py: usize) -> Ray {
|
pub fn ray_for_pixel(&self, px: usize, py: usize) -> Ray {
|
||||||
// The offset from the edge of the canvas to the pixel's corner.
|
// The offset from the edge of the canvas to the pixel's corner.
|
||||||
let xoffset = (px as Float + 0.5) * self.pixel_size;
|
let xoffset = (px as Float + 0.5) * self.pixel_size;
|
||||||
let yoffset = (py as Float + 0.5) * self.pixel_size;
|
let yoffset = (py as Float + 0.5) * self.pixel_size;
|
||||||
|
|
||||||
// The untransformed coordinates of the pixle in world space.
|
// The untransformed coordinates of the pixel in world space.
|
||||||
// (Remember that the camera looks toward -z, so +x is to the left.)
|
// (Remember that the camera looks toward -z, so +x is to the left.)
|
||||||
let world_x = self.half_width - xoffset;
|
let world_x = self.half_width - xoffset;
|
||||||
let world_y = self.half_height - yoffset;
|
let world_y = self.half_height - yoffset;
|
||||||
|
|
||||||
// Using the camera matrix, transofmrm the canvas point and the origin,
|
// Using the camera matrix, transform the canvas point and the origin,
|
||||||
// and then compute the ray's direction vector.
|
// and then compute the ray's direction vector.
|
||||||
// (Remember that the canvas is at z>=-1).
|
// (Remember that the canvas is at z>=-1).
|
||||||
let pixel = self.inverse_transform * Tuple::point(world_x, world_y, -1.);
|
let pixel = self.inverse_transform * Tuple::point(world_x, world_y, -1.);
|
||||||
@ -255,26 +254,6 @@ impl Camera {
|
|||||||
|
|
||||||
Ray::new(origin, direction)
|
Ray::new(origin, direction)
|
||||||
}
|
}
|
||||||
#[cfg(feature = "disable-inverse-cache")]
|
|
||||||
pub fn ray_for_pixel(&self, px: usize, py: usize) -> Ray {
|
|
||||||
// The offset from the edge of the canvas to the pixel's corner.
|
|
||||||
let xoffset = (px as Float + 0.5) * self.pixel_size;
|
|
||||||
let yoffset = (py as Float + 0.5) * self.pixel_size;
|
|
||||||
|
|
||||||
// The untransformed coordinates of the pixle in world space.
|
|
||||||
// (Remember that the camera looks toward -z, so +x is to the left.)
|
|
||||||
let world_x = self.half_width - xoffset;
|
|
||||||
let world_y = self.half_height - yoffset;
|
|
||||||
|
|
||||||
// Using the camera matrix, transofmrm the canvas point and the origin,
|
|
||||||
// and then compute the ray's direction vector.
|
|
||||||
// (Remember that the canvas is at z>=-1).
|
|
||||||
let pixel = self.transform.inverse() * Tuple::point(world_x, world_y, -1.);
|
|
||||||
let origin = self.transform.inverse() * Tuple::point(0., 0., 0.);
|
|
||||||
let direction = (pixel - origin).normalize();
|
|
||||||
|
|
||||||
Ray::new(origin, direction)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use camera to render an image of the given world.
|
/// Use camera to render an image of the given world.
|
||||||
/// # Examples
|
/// # Examples
|
||||||
|
|||||||
@ -318,7 +318,6 @@ impl Shape {
|
|||||||
/// Tuple::vector(0., 1., 0.)
|
/// Tuple::vector(0., 1., 0.)
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[cfg(not(feature = "disable-inverse-cache"))]
|
|
||||||
pub fn normal_at(&self, world_point: Tuple) -> Tuple {
|
pub fn normal_at(&self, world_point: Tuple) -> Tuple {
|
||||||
let object_point = self.inverse_transform * world_point;
|
let object_point = self.inverse_transform * world_point;
|
||||||
let object_normal = match self.geometry {
|
let object_normal = match self.geometry {
|
||||||
@ -330,18 +329,6 @@ impl Shape {
|
|||||||
world_normal.w = 0.;
|
world_normal.w = 0.;
|
||||||
world_normal.normalize()
|
world_normal.normalize()
|
||||||
}
|
}
|
||||||
#[cfg(feature = "disable-inverse-cache")]
|
|
||||||
pub fn normal_at(&self, world_point: Tuple) -> Tuple {
|
|
||||||
let object_point = self.transform.inverse() * world_point;
|
|
||||||
let object_normal = match self.geometry {
|
|
||||||
Geometry::Sphere => object_point - Tuple::point(0., 0., 0.),
|
|
||||||
Geometry::Plane => Tuple::vector(0., 1., 0.),
|
|
||||||
Geometry::TestShape(_) => todo!("test shape normal"),
|
|
||||||
};
|
|
||||||
let mut world_normal = self.transform.inverse().transpose() * object_normal;
|
|
||||||
world_normal.w = 0.;
|
|
||||||
world_normal.normalize()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn transform(&self) -> Matrix4x4 {
|
pub fn transform(&self) -> Matrix4x4 {
|
||||||
self.transform
|
self.transform
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user