示例#1
0
        public static void Draw(ISpriteBatch sb, Vector2 source, Vector2 dest, Color color)
        {
            var dist  = Vector2.Distance(source, dest);
            var angle = GetAngle(source, dest);

            // Get the length of the segments
            var segLen = dist / 6;

            if (segLen < 5.0f)
            {
                segLen = 5.0f;
            }
            if (segLen > 25.0f)
            {
                segLen = 25.0f;
            }

            // Primary line
            var tailLen = dist - (segLen / 2);
            var pDest   = source + (new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)) * tailLen);

            RenderLine.Draw(sb, source, pDest, color);

            // Arrow segment 1
            var ang1 = angle - MathHelper.PiOver4;
            var seg1 = dest - (new Vector2((float)Math.Cos(ang1), (float)Math.Sin(ang1)) * segLen);

            RenderLine.Draw(sb, dest, seg1, color);

            // Arrow segment 2
            var ang2 = angle + MathHelper.PiOver4;
            var seg2 = dest - (new Vector2((float)Math.Cos(ang2), (float)Math.Sin(ang2)) * segLen);

            RenderLine.Draw(sb, dest, seg2, color);

            // Arrow segment 3
            RenderLine.Draw(sb, seg1, seg2, color);
        }
示例#2
0
        /// <summary>
        /// Recursively draws the joints and bones of a skeleton.
        /// </summary>
        /// <param name="camera">Camera to use.</param>
        /// <param name="sb"><see cref="ISpriteBatch"/> to draw to.</param>
        /// <param name="selectedNode">SpriteBatch to draw to.</param>
        /// <param name="node">Current node being drawn.</param>
        /// <param name="colorIndex">Index of the color to use from the ColorList.</param>
        static void RecursiveDraw(ICamera2D camera, ISpriteBatch sb, SkeletonNode selectedNode, SkeletonNode node, int colorIndex)
        {
            // Find the color of the joint
            var color = _colorList[colorIndex];

            if (node == selectedNode)
            {
                color = _nodeColorSelected;
            }
            else if (node.Parent == null)
            {
                color = _nodeColorRoot;
            }

            // Draw the joint
            var scale  = 1f / camera.Scale;
            var origin = SkeletonNode.HalfJointVector;

            _joint.Draw(sb, node.Position, color, SpriteEffects.None, 0f, origin, scale);

            // Iterate through the children
            foreach (var child in node.Nodes)
            {
                colorIndex++;
                if (colorIndex == _colorList.Length)
                {
                    colorIndex = 0;
                }

                // Draw the bone to the child
                RenderLine.Draw(sb, node.Position, child.Position, _colorList[colorIndex], (1f / camera.Scale) * 2f);

                // Draw the child
                RecursiveDraw(camera, sb, selectedNode, child, colorIndex);
            }
        }