protected override Intersections LocalIntersect(Ray ray) { var result = new Intersections(); IntersectCaps(ray, result); var a = ray.Direction.x * ray.Direction.x - ray.Direction.y * ray.Direction.y + ray.Direction.z * ray.Direction.z; var b = 2.0 * ray.Origin.x * ray.Direction.x - 2.0 * ray.Origin.y * ray.Direction.y + 2.0 * ray.Origin.z * ray.Direction.z; var c = ray.Origin.x * ray.Origin.x - ray.Origin.y * ray.Origin.y + ray.Origin.z * ray.Origin.z; if (a.IsEqual(0.0)) { if (!b.IsEqual(0.0)) { var t = -c / (2 * b); result.Add(new Intersection(t, this)); } return(result); } var disc = b * b - 4 * a * c; if (disc < 0.0) { return(result); } var t0 = (-b - Math.Sqrt(disc)) / (2 * a); var t1 = (-b + Math.Sqrt(disc)) / (2 * a); if (t0 > t1) { var temp = t0; t0 = t1; t1 = temp; } var y0 = ray.Origin.y + t0 * ray.Direction.y; if ((Minimum < y0) && (y0 < Maximum)) { result.Add(new Intersection(t0, this)); } var y1 = ray.Origin.y + t1 * ray.Direction.y; if ((Minimum < y1) && (y1 < Maximum)) { result.Add(new Intersection(t1, this)); } return(result); }
protected override Intersections LocalIntersect(Ray ray) { var results = new Intersections(); if (BoundsOf.Intersects(ray)) { var leftXs = Left.Intersect(ray); var rightXs = Right.Intersect(ray); results.Add(leftXs); results.Add(rightXs); } return(FilterIntersections(results)); }
public Intersections FilterIntersections(Intersections xs) { var inl = false; var inr = false; var result = new Intersections(); foreach (var i in xs) { var lhit = ChildContains(Left, i.Object); if (IntersectionAllowed(Operation, lhit, inl, inr)) { result.Add(i); } if (lhit) { inl = !inl; } else { inr = !inr; } } return(result); }
protected override Intersections LocalIntersect(Ray ray) { var results = new Intersections(); var dirCrossE2 = ray.Direction.Cross(E2); var det = E1.Dot(dirCrossE2); if (Math.Abs(det) < MathHelper.Epsilon) { return(results); } var f = 1.0 / det; var p1ToOrigin = new Vector(ray.Origin - P1); var u = f * p1ToOrigin.Dot(dirCrossE2); if ((u < 0) || (u > 1)) { return(results); } var originCrossE1 = p1ToOrigin.Cross(E1); var v = f * ray.Direction.Dot(originCrossE1); if ((v < 0) || (u + v > 1)) { return(results); } var t = f * E2.Dot(originCrossE1); results.Add(new Intersection(t, this, u, v)); return(results); }
protected override Intersections LocalIntersect(Ray ray) { var intersections = new Intersections(); CheckAxis(ray.Origin.x, ray.Direction.x, out double xtmin, out double xtmax); CheckAxis(ray.Origin.y, ray.Direction.y, out double ytmin, out double ytmax); CheckAxis(ray.Origin.z, ray.Direction.z, out double ztmin, out double ztmax); var tmin = Math.Max(xtmin, Math.Max(ytmin, ztmin)); var tmax = Math.Min(xtmax, Math.Min(ytmax, ztmax)); if (tmin <= tmax) { intersections.Add(new Intersection(tmin, this)); intersections.Add(new Intersection(tmax, this)); } return(intersections); }
private void IntersectCaps(Ray ray, Intersections xs) { if (!Closed || ray.Direction.y.IsEqual(0)) { return; } var t = (Minimum - ray.Origin.y) / ray.Direction.y; if (CheckCap(ray, t)) { xs.Add(new Intersection(t, this)); } t = (Maximum - ray.Origin.y) / ray.Direction.y; if (CheckCap(ray, t)) { xs.Add(new Intersection(t, this)); } }
public Intersections Intersect(Ray ray) { Intersections xs = new Intersections(); foreach (var obj in Objects) { var ret = obj.Intersect(ray); xs.Add(ret); } return(xs); }
protected override Intersections LocalIntersect(Ray ray) { var result = new Intersections(); var sphereToRay = new Vector(ray.Origin - Point.Zero); var a = ray.Direction.Dot(ray.Direction); var b = 2.0 * ray.Direction.Dot(sphereToRay); var c = sphereToRay.Dot(sphereToRay) - 1; var discriminant = b * b - 4 * a * c; if (discriminant < 0.0) { return(result); } else { result.Add(new Intersection((-b - Math.Sqrt(discriminant)) / (2 * a), this)); result.Add(new Intersection((-b + Math.Sqrt(discriminant)) / (2 * a), this)); } return(result); }
protected override Intersections LocalIntersect(Ray ray) { Intersections results = new Intersections(); if (BoundsOf.Intersects(ray)) { foreach (var obj in objects) { results.Add(obj.Intersect(ray)); } } return(results); }
protected override Intersections LocalIntersect(Ray ray) { var i = new Intersections(); if (Math.Abs(ray.Direction.y) < MathHelper.Epsilon) { return(i); } var t = -ray.Origin.y / ray.Direction.y; i.Add(new Intersection(t, this)); return(i); }