示例#1
0
        private bool IntersectsChildContent(CanvasRootControl child, ref Ray ray, out Vector2 childSpaceLocation)
        {
            // Inline bounds calculations (it will reuse world matrix)
            OrientedBoundingBox bounds = new OrientedBoundingBox();

            bounds.Extents = new Vector3(child.Size * 0.5f, Mathf.Epsilon);
            Matrix world;

            child.Canvas.GetWorldMatrix(out world);
            Matrix offset;

            Matrix.Translation(bounds.Extents.X, bounds.Extents.Y, 0, out offset);
            Matrix.Multiply(ref offset, ref world, out bounds.Transformation);

            // Hit test
            Vector3 hitPoint;

            if (bounds.Intersects(ref ray, out hitPoint))
            {
                // Transform world-space hit point to canvas local-space
                Vector3 localHitPoint;
                world.Invert();
                Vector3.Transform(ref hitPoint, ref world, out localHitPoint);

                childSpaceLocation = new Vector2(localHitPoint);
                return(child.ContainsPoint(ref childSpaceLocation));
            }

            childSpaceLocation = Vector2.Zero;
            return(false);
        }
示例#2
0
        private bool IntersectsChildContent(CanvasRootControl child, ref Ray ray, out Float2 childSpaceLocation)
        {
            // Inline bounds calculations (it will reuse world matrix)
            var bounds = new OrientedBoundingBox
            {
                Extents = new Vector3(child.Size * 0.5f, Mathf.Epsilon)
            };

            child.Canvas.GetWorldMatrix(out var world);
            Matrix.Translation((float)bounds.Extents.X, (float)bounds.Extents.Y, 0, out var offset);
            Matrix.Multiply(ref offset, ref world, out var boxWorld);
            boxWorld.Decompose(out bounds.Transformation);

            // Hit test
            if (bounds.Intersects(ref ray, out Vector3 hitPoint))
            {
                // Transform world-space hit point to canvas local-space
                world.Invert();
                Vector3.Transform(ref hitPoint, ref world, out Vector3 localHitPoint);

                childSpaceLocation = new Float2(localHitPoint);
                return(child.ContainsPoint(ref childSpaceLocation));
            }

            childSpaceLocation = Float2.Zero;
            return(false);
        }