public override Intersection Intersects(Ray ray) { double denom = Vector3.DotProduct(normal, ray.Direction); if (Math.Abs(denom) > 0.0001) { double t = Vector3.DotProduct(position - ray.Start, normal) / denom; if (t > 0.0005) return new Intersection(t, ray.PointAt(t), this, normal, null); } return Intersection.False; }
public override Intersection Intersects(Ray ray) { Vector3 T = ray.Start - Vertex0.Position; Vector3 P = Vector3.CrossProduct(ray.Direction, E2); Vector3 Q = Vector3.CrossProduct(T, E1); double denom = Vector3.DotProduct(P, E1); if (Math.Abs(denom) > 0.0001) { double u = Vector3.DotProduct(P, T) / denom; double v = Vector3.DotProduct(Q, ray.Direction) / denom; double t = Vector3.DotProduct(Q, E2) / denom; bool kl = denom < 0.0; if ((u >= 0.0 && u <= 1.0) && (v >= 0.0 && u + v <= 1.0)) return new Intersection(t, ray.PointAt(t), this, kl ? Normal : Normal.Negated, new Vector2(u, kl ? v : 1 - v)); // (kl ? v : 1-v) automatic texture flipping } return Intersection.False; }
public override Intersection Intersects(Ray ray) { double a = Vector3.DotProduct(ray.Direction, ray.Direction); double b = 2 * Vector3.DotProduct(ray.Direction, ray.Start - Position); Vector3 rayToCenter = ray.Start - Position; double c = Vector3.DotProduct(rayToCenter, rayToCenter) - radius2; double dis = b * b - 4 * a * c; if (dis >= 0.0) { double t = (-Math.Sqrt(dis) - b) / (2.0 * a); Vector3 point = ray.PointAt(t); return new Intersection(t, point, this, (point - Position).Normalized, null); } return Intersection.False; }