Example #1
0
        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
        }
Example #2
0
        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));
        }
Example #3
0
        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);
        }
Example #4
0
 public HPoint CollisionNormal(HRay ray)
 {
     throw new System.NotImplementedException();
 }
Example #5
0
 public Color ProcessCollision(HRender render, ICollider collider, HRay ray)
 {
     return(Shader(render, collider, ray));
 }
Example #6
0
 public Color ProcessCollision(HRender render, ICollider collider, HRay ray)
 {
     throw new NotImplementedException();
 }
Example #7
0
 public HPoint CollisionPoint(HRay ray)
 {
     throw new NotImplementedException();
 }
Example #8
0
 public static Color SimpleRedShader(HRender render, ICollider collider, HRay ray)
 {
     return(Color.Red);
 }
Example #9
0
 public static Color SimpleBlackShader(HRender render, ICollider collider, HRay ray)
 {
     return(Color.Black);
 }