|
|
@ -44,6 +44,24 @@ export default class Sphere { |
|
|
|
// TODO: Return an Intersection or null if there was no hit. In case
|
|
|
|
// TODO: of two hits, return the one closer to the start point of
|
|
|
|
// TODO: the ray.
|
|
|
|
|
|
|
|
let c = Math.pow(ray.origin.dot(ray.direction),2) - ray.origin.dot(ray.origin) + Math.pow(this.radius,2); |
|
|
|
// hier oben noch nicht berechenenm da c negativ sein kann und dann wurzel nicht funktioniert
|
|
|
|
|
|
|
|
if(c < 0) { |
|
|
|
return null; |
|
|
|
} else if(c == 0) { |
|
|
|
return new Intersection(t1, ); //schnittpunkt ist origin + direction * t
|
|
|
|
|
|
|
|
} else { |
|
|
|
let t1 = - ray.origin.dot(ray.direction) + Math.sqrt( Math.pow(ray.origin.dot(ray.direction),2) - ray.origin.dot(ray.origin) + Math.pow(this.radius,2)); |
|
|
|
let t2 = - ray.origin.dot(ray.direction) - Math.sqrt( Math.pow(ray.origin.dot(ray.direction),2) - ray.origin.dot(ray.origin) + Math.pow(this.radius,2)); |
|
|
|
|
|
|
|
if(t1 < t2) { |
|
|
|
return null; |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |