Example #1
0
        private void Update(float updatePeriod)
        {
            float angle = -updatePeriod * 0.6f;

            stick = RotateLine(stick, angle);
            var minX = Math.Min(stick.Item1.X, stick.Item2.X);
            var maxX = Math.Max(stick.Item1.X, stick.Item2.X);
            var minY = Math.Min(stick.Item1.Y, stick.Item2.Y);
            var maxY = Math.Max(stick.Item1.Y, stick.Item2.Y);

            stickAABB = Box2dExtensions.CreateFromMinMax(minX, minY, maxX, maxY);
        }
Example #2
0
        /// <summary>
        /// Transforms elements coordinates relative to given canvas system into [0,1]² with y-axis heading upwards
        /// </summary>
        /// <param name="element">Input UIElement to transform relative to canvas</param>
        /// <param name="canvas">Input canvas for realative transformation</param>
        public static Box2D ConvertBounds(this UIElement element, Canvas canvas)
        {
            var p00         = new Point(0, 0);
            var p11         = p00 + (Vector)element.RenderSize;
            var leftTop     = (Vector)element.TranslatePoint(p00, canvas);
            var rightBottom = (Vector)element.TranslatePoint(p11, canvas);

            //flip y coordinate
            return(Box2dExtensions.CreateFromMinMax(
                       (float)leftTop.X, (float)(canvas.ActualHeight - rightBottom.Y),
                       (float)rightBottom.X, (float)(canvas.ActualHeight - leftTop.Y)));
        }