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