Example #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);
        }