Remove some old code that was already commented out
This commit is contained in:
parent
a785eb796f
commit
6639ed813b
|
|
@ -24,42 +24,6 @@ impl<T: RealField> Sphere<T> {
|
||||||
|
|
||||||
impl<T: RealField> Intersect<T> for Sphere<T> {
|
impl<T: RealField> Intersect<T> for Sphere<T> {
|
||||||
fn intersect<'a>(&'a self, ray: &Ray<T>) -> Option<IntersectionInfo<T>> {
|
fn intersect<'a>(&'a self, ray: &Ray<T>) -> Option<IntersectionInfo<T>> {
|
||||||
/*let ray_origin_to_sphere_centre = self.centre - ray.origin;
|
|
||||||
let radius_squared = self.radius * self.radius;
|
|
||||||
let is_inside_sphere = ray_origin_to_sphere_centre.norm_squared() <= radius_squared;
|
|
||||||
// t0/p0 is the point on the ray that's closest to the centre of the sphere
|
|
||||||
// ray.direction is normalized, so it's not necessary to divide by its length.
|
|
||||||
let t0 = ray_origin_to_sphere_centre.dot(&ray.direction);
|
|
||||||
if !is_inside_sphere && t0 < T::zero() {
|
|
||||||
// Sphere is behind ray origin
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
// Squared distance between ray origin and sphere centre
|
|
||||||
let d0_squared = (ray_origin_to_sphere_centre).norm_squared();
|
|
||||||
// p0, ray.origin and sphere.centre form a right triangle, with p0 at the right corner,
|
|
||||||
// Squared distance petween p0 and sphere centre, using Pythagoras
|
|
||||||
let p0_dist_from_centre_squared = d0_squared - t0 * t0;
|
|
||||||
if p0_dist_from_centre_squared > radius_squared {
|
|
||||||
// Sphere is in front of ray but ray misses
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let p0_dist_from_centre =p0_dist_from_centre_squared.sqrt();
|
|
||||||
// Two more right triangles are formed by p0, the sphere centre, and the two places
|
|
||||||
// where the ray intersects the sphere. (Or the ray may be a tangent to the sphere
|
|
||||||
// in which case these triangles are degenerate. Here we use Pythagoras again to find
|
|
||||||
.// find the distance between p0 and the two intersection points.
|
|
||||||
let delta = (radius_squared - p0_dist_from_centre_squared).sqrt();
|
|
||||||
let distance = if is_inside_sphere {
|
|
||||||
// radius origin is inside sphere
|
|
||||||
t0 + delta
|
|
||||||
} else {
|
|
||||||
t0 - delta
|
|
||||||
};
|
|
||||||
let location = ray.point_at(distance);
|
|
||||||
let normal = (location - self.centre).normalize();
|
|
||||||
let tangent = normal.cross(&Vector3::z_axis());
|
|
||||||
let cotangent = normal.cross(&tangent);
|
|
||||||
let retro = -ray.direction;*/
|
|
||||||
let two: T = convert(2.0);
|
let two: T = convert(2.0);
|
||||||
let four: T = convert(4.0);
|
let four: T = convert(4.0);
|
||||||
let r_o = ray.origin.coords;
|
let r_o = ray.origin.coords;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue