From f1849cdbc1ed62432293a95fa4df299892aae877 Mon Sep 17 00:00:00 2001 From: Godzil Date: Wed, 26 Feb 2020 16:08:34 +0000 Subject: [PATCH] Pow is way too slow. --- source/shapes/cone.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/source/shapes/cone.cpp b/source/shapes/cone.cpp index 9843a2d..b0fec00 100644 --- a/source/shapes/cone.cpp +++ b/source/shapes/cone.cpp @@ -55,16 +55,17 @@ Intersect Cone::localIntersect(Ray r) { Intersect ret; - double A = pow(r.direction.x, 2) - - pow(r.direction.y, 2) + - pow(r.direction.z, 2); + double A = (r.direction.x * r.direction.x) - + (r.direction.y * r.direction.y) + + (r.direction.z * r.direction.z); + double B = (2 * r.origin.x * r.direction.x) - (2 * r.origin.y * r.direction.y) + (2 * r.origin.z * r.direction.z); - double C = pow(r.origin.x, 2) - - pow(r.origin.y, 2) + - pow(r.origin.z, 2); + double C = (r.origin.x * r.origin.x) - + (r.origin.y * r.origin.y) + + (r.origin.z * r.origin.z); if ((fabs(A) <= getEpsilon()) && (fabs(B) >= getEpsilon())) { @@ -73,9 +74,7 @@ Intersect Cone::localIntersect(Ray r) } else if (fabs(A) >= getEpsilon()) { - - double disc = pow(B, 2) - 4 * A * C; - + double disc = (B * B) - 4 * A * C; if (disc >= 0) { double t0 = (-B - sqrt(disc)) / (2 * A);