Fixes wrong formular at one place and reduces duplicates of the discriminant
This commit is contained in:
parent
f98e578f94
commit
c7f6974b58
1 changed files with 7 additions and 6 deletions
|
@ -28,16 +28,17 @@ bool Sphere::intersect(Ray &ray) const {
|
|||
|
||||
float t = INFINITY;
|
||||
|
||||
if (B * B - 4 * A * C < 0) {
|
||||
float discriminant = B * B - 4 * A * C;
|
||||
if (discriminant < 0) {
|
||||
return false;
|
||||
} else if (B * B - 4 + A * C == 0) {
|
||||
} else if (discriminant == 0) {
|
||||
t = -B / (2 * A);
|
||||
} else {
|
||||
float q {static_cast<float>([A, B, C](){
|
||||
} else { // discriminant > 0
|
||||
float q {static_cast<float>([B, discriminant](){
|
||||
if (B < 0) {
|
||||
return -0.5f * (B - sqrt(B * B - 4 * A * C));
|
||||
return -0.5f * (B - sqrt(discriminant));
|
||||
} else {
|
||||
return -0.5f * (B + sqrt(B * B - 4 * A * C));
|
||||
return -0.5f * (B + sqrt(discriminant));
|
||||
}
|
||||
}())};
|
||||
float t0 = q / A;
|
||||
|
|
Loading…
Reference in a new issue