Example #1
0
        public RaycastingProperties(float minRealDis, float maxRealDis, float minScreenH, float maxScreenH, float horizont)
        {
            this.min      = new Vector2(minRealDis, maxScreenH);
            this.max      = new Vector2(maxRealDis, minScreenH);
            this.horizont = horizont;

            Vector2Tuple tuple = Vector2.Reorganize(this.min, this.max);

            this.convert = new Line(tuple.A, tuple.B);
        }
Example #2
0
        public Vector2 RayCasting(Player player, float angle)
        {
            double radians = NumericExtensions.ToRadians((double)angle);
            float  cos     = (float)Math.Cos(radians) + player.Position.X;
            float  sin     = (float)Math.Sin(radians) + player.Position.Y;

            Vector2 ray       = new Vector2(cos, sin);
            Vector2 signalRay = Vector2.VectorDistance(player.Position, ray);

            Line playerLine = new Line(player.Position, ray);

            List <Vector2> intersections = new List <Vector2>();

            Vector2 finalPoint = null;

            foreach (intTuple item in this.edge)
            {
                Vector2Tuple points = Vector2.Reorganize(this.vertex [item.A],
                                                         this.vertex [item.B]);

                Line lineMap = new Line(points.A, points.B);

                Vector2 intersect = Line.Intersection(playerLine, lineMap);

                Vector2 signalIntersect = Vector2.VectorDistance(player.Position, intersect);

                bool signalX = float.IsNegative(signalRay.X) == float.IsNegative(signalIntersect.X);
                bool signalY = float.IsNegative(signalRay.Y) == float.IsNegative(signalIntersect.Y);

                bool XinLimit = intersect.X >= points.A.X && intersect.X <= points.B.X;
                bool YinLimit = intersect.Y >= points.A.Y && intersect.Y <= points.B.Y;

                if (signalX && signalY && XinLimit && YinLimit)
                {
                    intersections.Add(intersect);

                    if (finalPoint == null)
                    {
                        finalPoint = intersect;
                    }
                    else if (Vector2.Distance(intersect, player.Position) < Vector2.Distance(finalPoint, player.Position))
                    {
                        finalPoint = intersect;
                    }
                }
            }

            Console.WriteLine(finalPoint);
            return(finalPoint);
        }
        public static void plotLine(Vector2 a, Vector2 b, FrameBuffer frameBuffer, int grayScale)
        {
            Vector2Tuple vectors = Vector2.Reorganize(a, b);

            plotLineHigh(vectors.A, vectors.B, frameBuffer, grayScale);
        }