public static bool IsPointOnRay(HPoint p, HRay ray) { if (!HAccuracy.DoubleEqual(0, ((p - ray.Source) * (ray.Direction)).Length())) //is not on line(colinear) { return(false); } return(HAccuracy.DoubleGreater((p - ray.Source) % (ray.Direction), 0)); //is codirectional }
public Color TraceRay(HRay ray) { var collisions = new List <KeyValuePair <HPoint, ICollider> >(); foreach (ICollider collider in Colliders) { HPoint collisionPoint = collider.CollisionPoint(ray); if (collisionPoint != null) { collisions.Add(new KeyValuePair <HPoint, ICollider>(collisionPoint, collider)); } } collisions.Sort( (KeyValuePair <HPoint, ICollider> a, KeyValuePair <HPoint, ICollider> b) => (ray.Source - a.Key).Length().CompareTo((ray.Source - b.Key).Length())); return(collisions.Count == 0 ? Color.White : collisions[0].Value.ProcessCollision(this, collisions[0].Value, ray)); }
public HPoint CollisionPoint(HRay ray) { HPoint intersectionPoint = HGeometry.OldIntersectPlaneLine(A, B, C, ray.Source, ray.Source + ray.Direction); if (intersectionPoint == null) //no intersection point with plane { return(null); } if (!HGeometry.IsPointOnRay(intersectionPoint, ray)) //point is invisible { return(null); } double firstSquare = HGeometry.TriangleSquare(A, B, C); double secondSquare = HGeometry.TriangleSquare(A, B, intersectionPoint) + HGeometry.TriangleSquare(A, C, intersectionPoint) + HGeometry.TriangleSquare(C, B, intersectionPoint); return(HAccuracy.DoubleEqual(firstSquare, secondSquare) ? intersectionPoint : null); }
public HPoint CollisionNormal(HRay ray) { throw new System.NotImplementedException(); }
public Color ProcessCollision(HRender render, ICollider collider, HRay ray) { return(Shader(render, collider, ray)); }
public Color ProcessCollision(HRender render, ICollider collider, HRay ray) { throw new NotImplementedException(); }
public HPoint CollisionPoint(HRay ray) { throw new NotImplementedException(); }
public static Color SimpleRedShader(HRender render, ICollider collider, HRay ray) { return(Color.Red); }
public static Color SimpleBlackShader(HRender render, ICollider collider, HRay ray) { return(Color.Black); }