Beispiel #1
0
        /// <summary>
        /// Return an Entity that has a DisplayListCamera that contains point <paramref name="hitPoint"/>, or Null
        /// if none matches.
        /// </summary>
        public Entity HitTestCamera(float3 hitPoint)
        {
            // world to screen
            var         env = EntityManager.World.TinyEnvironment();
            DisplayInfo di  = env.GetConfigData <DisplayInfo>();

            Unity.Tiny.Core2D.Rect screenRect = new Unity.Tiny.Core2D.Rect(0.0f, 0.0f, (float)di.width, (float)di.height);
            float2 screenSize = new float2((float)di.width, (float)di.height);
            Entity r          = Entity.Null;
            float  bestDepth  = 0;

            Entities.ForEach((Entity e, ref Camera2D c2d, ref DisplayListCamera dlc, ref LocalToWorld t) =>
            {
                float2 window = TransformHelpers.WorldToWindow(this, e, hitPoint, screenSize);
                Unity.Tiny.Core2D.Rect cRect;
                if (c2d.rect.IsEmpty())
                {
                    cRect = new Unity.Tiny.Core2D.Rect(0, 0, 1, 1);
                }
                else
                {
                    cRect = c2d.rect;
                }
                Unity.Tiny.Core2D.Rect camRect = screenRect.Region(cRect);
                if (camRect.Contains(window))
                {
                    if (r == Entity.Null || c2d.depth > bestDepth)
                    {
                        r         = e;
                        bestDepth = c2d.depth;
                    }
                }
            });
            return(r);
        }
Beispiel #2
0
        private bool RoomIntersectExistingRooms(Room roomToAdd)
        {
            foreach (Room createdRoom in _rooms)
            {
                Unity.Tiny.Core2D.Rect r1 = new Unity.Tiny.Core2D.Rect(roomToAdd.startX, roomToAdd.startY, roomToAdd.width, roomToAdd.height);
                Unity.Tiny.Core2D.Rect r2 = new Unity.Tiny.Core2D.Rect(createdRoom.startX, createdRoom.startY, createdRoom.width, createdRoom.height);

                if ((r1.x < r2.x + r2.width) &&
                    (r1.x + r1.width > r2.x) &&
                    (r1.y < r2.y + r2.height) &&
                    (r1.y + r1.height > r2.y))
                {
                    return(true);
                }
            }
            return(false);
        }