public override bool intersect(Ray ray, Intersection intersection) { double vd; double vx; double vy; Vector3D orig = ray.Location.subNew(position());; Vector3D dir = ray.direction(); /* Check if the ray lies parallel to the plane */ vd = ng.dot(dir); if ((vd > -RaytracerPhotonmapping.SceneConstants.EPSILON) && (vd < RaytracerPhotonmapping.SceneConstants.EPSILON)) { return(false); } /* Check if ray intersects plane */ double t = -((ng.x() * orig.x()) + (ng.y() * orig.y()) + (ng.z() * orig.z()) + d) / vd; if (t < RaytracerPhotonmapping.SceneConstants.EPSILON) { return(false); } /* Check if intersection is inside the triangle */ switch (dropAxis) { case 0: vx = (orig.y() + (dir.y() * t)) - v0.p.y(); vy = (orig.z() + (dir.z() * t)) - v0.p.z(); break; case 1: vx = (orig.x() + (dir.x() * t)) - v0.p.x(); vy = (orig.z() + (dir.z() * t)) - v0.p.z(); break; default: vx = (orig.x() + (dir.x() * t)) - v0.p.x(); vy = (orig.y() + (dir.y() * t)) - v0.p.y(); break; } double u = (edge2x * vy) - (edge2y * vx); if ((u < 0.0) || (u > 1.0)) { return(false); } double v = (edge1y * vx) - (edge1x * vy); if ((v < 0.0) || ((u + v) > 1.0)) { return(false); } Vector3D intersectionPoint; intersectionPoint = ray.direction().scaleNew(t); intersectionPoint.add(ray.Location); intersection.IntersectionPoint = intersectionPoint; intersection.IntersectedObject = this; intersection.Lambda = t; return(true); }
public virtual bool intersect(Ray ray, Intersection intersection) { return(false); }
public override bool intersect(Ray ray, Intersection intersection) { Vector3D location, direction; double a, b, c, d; location = ray.Location.subNew(position()); direction = ray.direction().scaleNew(invRadius()); location.scale(invRadius()); a = direction.sqrNorm(); b = direction.dot(location); c = location.sqrNorm() - 1; d = (b * b) - a * c; if (d < 0) { return(false); } try { Vector3D intersectionPoint; double invA, l1, l2, lambda; invA = 1.0 / a; l1 = (-b + System.Math.Sqrt(d)) * invA; l2 = (-b - System.Math.Sqrt(d)) * invA; if (l1 >= RaytracerPhotonmapping.SceneConstants.EPSILON && l2 >= RaytracerPhotonmapping.SceneConstants.EPSILON) { lambda = (l1 < l2)?l1:l2; } else if (l1 >= RaytracerPhotonmapping.SceneConstants.EPSILON) { lambda = l1; } else if (l2 >= RaytracerPhotonmapping.SceneConstants.EPSILON) { lambda = l2; } else { return(false); } intersectionPoint = ray.direction().scaleNew(lambda); intersectionPoint.add(ray.Location); intersection.IntersectionPoint = intersectionPoint; intersection.IntersectedObject = this; intersection.Lambda = lambda; return(true); } catch (System.ArithmeticException e) { System.Console.Out.WriteLine(e); return(false); } }