Ejemplo n.º 1
0
 public ResultFindDistance(bool start, float shorTest, float rLen, ObjectLight closestBlock)
 {
     Start        = start;
     ShorTest     = shorTest;
     RLen         = rLen;
     ClosestBlock = closestBlock;
 }
Ejemplo n.º 2
0
        public ResultFindDistance FindDistance(Light light, ObjectLight block, float angle, float rLen, bool start, float shorTest, ObjectLight closestBlock)
        {
            var x = 0.0f;
            var y = 0.0f;

            if (typeof(Circle) == block.GetType())
            {
                var o = (Circle)block;

                y = (block.Y + o.Radius) - light.Position.Y;
                x = (block.X + o.Radius) - light.Position.X;
            }
            else if (typeof(Block) == block.GetType())
            {
                var o = (Block)block;

                y = (block.Y + o.Width / 2) - light.Position.Y;
                x = (block.X + o.Height / 2) - light.Position.X;
            }

            var dist = (float)Math.Sqrt((y * y) + (x * x));

            if (light.Radius >= dist)
            {
                var rads     = angle * (float)(Math.PI / 180);
                var pointPos = new Vec2(light.Position.X, light.Position.Y);

                pointPos.X += (float)(Math.Cos(rads) * dist);
                pointPos.Y += (float)(Math.Sin(rads) * dist);

                bool isIntersect = false;
                if (typeof(Circle) == block.GetType())
                {
                    var o = (Circle)block;


                    if (pointPos.X > o.Position.X && pointPos.X < o.Position.X + o.Radius * 2 &&
                        pointPos.Y > o.Position.Y && pointPos.Y < o.Position.Y + o.Radius * 2)
                    {
                        isIntersect = true;
                    }
                }
                else if (typeof(Block) == block.GetType())
                {
                    var o = (Block)block;

                    if (pointPos.X > o.Position.X && pointPos.X < o.Position.X + o.Width &&
                        pointPos.Y > o.Position.Y && pointPos.Y < o.Position.Y + o.Height)
                    {
                        isIntersect = true;
                    }
                }

                if (isIntersect)
                {
                    if (start || dist < shorTest)
                    {
                        start        = false;
                        shorTest     = dist;
                        rLen         = dist;
                        closestBlock = block;
                    }

                    return(new ResultFindDistance(start, shorTest, rLen, closestBlock));
                }
            }

            return(new ResultFindDistance(start, shorTest, rLen, closestBlock));
        }