/// <summary> /// Draws the grid. /// </summary> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="Camera2D"/> describing the view.</param> public void Draw(ISpriteBatch sb, ICamera2D camera) { if (sb == null) { Debug.Fail("sb is null."); return; } if (sb.IsDisposed) { Debug.Fail("sb is disposed."); return; } if (camera == null) { Debug.Fail("camera is null."); return; } var p1 = new Vector2(); var p2 = new Vector2(); var min = camera.Min; var max = camera.Max; var size = camera.Size; min -= new Vector2(min.X % Size.X, min.Y % Size.Y); // Vertical lines p1.Y = (float)Math.Round(min.Y); p2.Y = (float)Math.Round(p1.Y + size.Y + 32); for (var x = min.X; x < max.X; x += Size.X) { p1.X = (float)Math.Round(x); p2.X = (float)Math.Round(x); RenderLine.Draw(sb, p1, p2, Color, 1.1f); // Note: 1.1f is used for thickness instead of 1.0f since at 1.0f, it will sometimes vanish. The SFML implementation is buggy. } // Horizontal lines p1.X = (float)Math.Round(camera.Min.X); p2.X = (float)Math.Round(p1.X + size.X + 32); for (var y = min.Y; y < max.Y; y += Size.Y) { p1.Y = (float)Math.Round(y); p2.Y = (float)Math.Round(y); RenderLine.Draw(sb, p1, p2, Color, 1.1f); } }
/// <summary> /// Draws the grid. /// </summary> /// <param name="sb">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="camera">The <see cref="Camera2D"/> describing the view.</param> public void Draw(ISpriteBatch sb, ICamera2D camera) { if (sb == null) { Debug.Fail("sb is null."); return; } if (sb.IsDisposed) { Debug.Fail("sb is disposed."); return; } if (camera == null) { Debug.Fail("camera is null."); return; } var p1 = new Vector2(); var p2 = new Vector2(); var min = camera.Min; var max = camera.Max; var size = camera.Size; min -= new Vector2(min.X % Size.X, min.Y % Size.Y); // Vertical lines p1.Y = min.Y; p2.Y = p1.Y + size.Y + 32; for (var x = min.X; x < max.X; x += Size.X) { p1.X = x; p2.X = x; RenderLine.Draw(sb, p1, p2, Color); } // Horizontal lines p1.X = camera.Min.X; p2.X = p1.X + size.X + 32; for (var y = min.Y; y < max.Y; y += Size.Y) { p1.Y = y; p2.Y = y; RenderLine.Draw(sb, p1, p2, Color); } }
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); }
/// <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); } }