Ejemplo n.º 1
0
        public static SkeletonPoint DepthToSkeleton(Rectangle rect, byte[,,] depthData, int width,
        int height, CoordinateConverter mapper)
        {
            var aveDepth = 0.0;
              var count = 0;
              for (int y = rect.Top; y < rect.Top + rect.Height && y < height; y++)
            for (int x = rect.Left; x < rect.Left + rect.Width && x < width; x++) {
              if (x > 0 && y > 0) {
            aveDepth += depthData[y, x, 0];
            count++;
              }
            }

              var depth = PlayerDetector.ToWorldDepth(aveDepth / count);
              var center = rect.Center();
              var centerX = Math.Max(0, center.X);
              centerX = Math.Min(centerX, width);
              var centerY = Math.Max(0, center.Y);
              centerY = Math.Min(centerY, height);
              return mapper.MapDepthPointToSkeletonPoint((int)centerX, (int)centerY, depth);
        }
Ejemplo n.º 2
0
        public static void NormalizePoints(Point[] points, Rectangle rectangle)
        {
            if (rectangle.Height == 0 || rectangle.Width == 0)
                return;

            Matrix m = new Matrix();
            m.Translate(rectangle.Center().X, rectangle.Center().Y);

            if (rectangle.Width > rectangle.Height)
                m.Scale(1, 1f * rectangle.Width / rectangle.Height);
            else
                m.Scale(1f * rectangle.Height / rectangle.Width, 1);

            m.Translate(-rectangle.Center().X, -rectangle.Center().Y);
            m.TransformPoints(points);
        }
Ejemplo n.º 3
0
 protected GraphicsPath CreateTailPath(Rectangle rect, Point tailPosition)
 {
     GraphicsPath gpTail = new GraphicsPath();
     Point center = rect.Center();
     int rectAverageSize = (rect.Width + rect.Height) / 2;
     int tailWidth = (int)(TailWidthMultiplier * rectAverageSize);
     tailWidth = Math.Min(Math.Min(tailWidth, rect.Width), rect.Height);
     int tailOrigin = tailWidth / 2;
     int tailLength = (int)MathHelpers.Distance(center, tailPosition);
     gpTail.AddLine(0, -tailOrigin, 0, tailOrigin);
     gpTail.AddLine(0, tailOrigin, tailLength, 0);
     gpTail.CloseFigure();
     using (Matrix matrix = new Matrix())
     {
         matrix.Translate(center.X, center.Y);
         float tailDegree = MathHelpers.LookAtDegree(center, tailPosition);
         matrix.Rotate(tailDegree);
         gpTail.Transform(matrix);
     }
     return gpTail;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves the rectangles in which images should be placed in side-by-side mode
        /// </summary>
        public static void GetSplitModeImageRectangles(Rectangle clientRectangle, Size maxImageSize, out Rectangle rectangle1, out Rectangle rectangle2)
        {
            var halfRectangle = new Rectangle(clientRectangle.X, clientRectangle.Y, clientRectangle.Width / 2, clientRectangle.Height);
            var imageSize = maxImageSize.ConstrainedTo(halfRectangle.Size);
            var center1 = halfRectangle.Center();
            var center2 = new Point(center1.X + halfRectangle.Width, center1.Y);

            rectangle1 = new Rectangle(imageSize.CenteredAround(center1), imageSize);
            rectangle2 = new Rectangle(imageSize.CenteredAround(center2), imageSize);
            if (rectangle1.X - clientRectangle.X > MIN_BORDER)
            {
                int shift = rectangle1.X - clientRectangle.X - MIN_BORDER;
                rectangle1.X -= shift;
                rectangle2.X += shift;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Draws an arrow in the specified rectangle with the specified direction. Ratio is used on recursive calls
        /// withing this function to adjust the sizing of bidirectional arrows
        /// </summary>
        public static void DrawArrow(this Graphics graphics, Rectangle area, ArrowType arrowType, double ratio = 1.0 / 3.0)
        {
            if (arrowType == ArrowType.Bidi)
            {
                var halfSize = new Size(area.Width / 2, area.Height);
                graphics.DrawArrow(new Rectangle(area.Location, halfSize), ArrowType.Left, 2 * ratio);
                graphics.DrawArrow(new Rectangle(new Point(area.Center().X, area.Location.Y), halfSize), ArrowType.Right, 2 * ratio);
                return;
            }

            var oldMode = graphics.SmoothingMode;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            float bodyHeight = area.Height / 3;
            float headWidth = (area.Width * ratio).Rounded();
            float bodyWidth = area.Width - headWidth;

            PointF[] points =
            {
                new PointF(area.Left, area.Top + bodyHeight),
                new PointF(area.Left + bodyWidth, area.Top + bodyHeight),
                new PointF(area.Left + bodyWidth, area.Top),
                new PointF(area.Right, area.Top + (area.Height / 2)),
                new PointF(area.Left + bodyWidth, area.Bottom),
                new PointF(area.Left + bodyWidth, area.Bottom - bodyHeight),
                new PointF(area.Left, area.Bottom - bodyHeight),
            };

            if (arrowType == ArrowType.Left)
            {
                PointF center = area.Center();
                for (int i = 0; i < points.Length; i++)
                    points[i].X += (2 * (center.X - points[i].X));
            }

            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddPolygon(points);
                graphics.FillPath(Brushes.Black, path);
                graphics.DrawPath(crossPen, path);
            }

            graphics.SmoothingMode = oldMode;
        }
Ejemplo n.º 6
0
        protected override void Tick(Graphics graphics, Rectangle camera)
        {
            graphics.DrawImageUnscaled(_boardBitmap, -camera.X, -camera.Y);

            var center = camera.Center();
            var screencenter = new Vector2(camera.Width / 2.0f, camera.Height / 2.0f);
            foreach (var pointable in EntitiesOfType<IPointable>())
            {
                var delta = pointable.Position - center;
                var dist = Math.Min(camera.Width, camera.Height) / 2 - 10;
                if (Math.Abs(delta.X) > dist || Math.Abs(delta.Y) > dist)
                {
                    graphics.DrawPolygon(pointable.Pen, new[]
                                                        {
                                                            (screencenter + delta.Normalized * dist).Point,
                                                            (screencenter + Vector2.FromTheta(delta.Theta + 0.2f) * dist).Point,
                                                            (screencenter + Vector2.FromTheta(delta.Theta - 0.2f) * dist).Point
                                                        });
                }
            }
        }