@Override public boolean shadowHit(Ray ray, float tSubZero, float tSub1, float time) { Vector3D direction = ((Vector3D) ray.getDistanceVector()); Vector3D temp = ray.getOrigin().subtract(origin); float a = direction.getDotProduct(direction); float b = 2 * direction.getDotProduct(temp); float c = (float) (temp.getDotProduct(temp) - (radius * radius)); float discriminant = b * b - 4 * a * c; if (discriminant > 0) { double sqrtd = Math.sqrt(discriminant); float tVal = (float) ((-b - sqrtd) / (2 * a)); if (tVal < tSubZero) { tVal = (float) ((-b + sqrtd) / (2 * a)); } if (tVal < tSubZero || tVal > tSub1) { return false; } return true; } return false; }
@Override public boolean hit(Ray ray, double tSubZero, double tSubOne, float time) { Vector3D d = ((Vector3D) ray.getDistanceVector()); Vector3D originCenter = ray.getOrigin().subtract(origin); float a = d.getDotProduct(d); float b = 2 * d.getDotProduct(originCenter); float c = (float) (originCenter.getDotProduct(originCenter) - (radius * radius)); float discriminant = b * b - 4 * a * c; if (discriminant > 0) { double sqrtd = Math.sqrt(discriminant); float tVal = (float) ((-b - sqrtd) / (2 * a)); if (tVal < tSubZero) { tVal = (float) ((-b + sqrtd) / (2 * a)); } if (tVal < tSubZero || tVal > tSubOne) { return false; } t = tVal; return true; } return false; }