/Rendering/BasicTests/Tutorials.cs
C# | 279 lines | 178 code | 18 blank | 83 comment | 2 complexity | 75bfd6ca9ac63afba91f922f3c3e8c37 MD5 | raw file
Possible License(s): Apache-2.0
- using Delta.Engine;
- using Delta.InputSystem;
- using Delta.Rendering.Basics.Drawing;
- using Delta.Rendering.Basics.Materials;
- using Delta.Rendering.Cameras;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using NUnit.Framework;
-
- namespace Delta.Rendering.BasicTests
- {
- /// <summary>
- /// Basic rendering tutorials, use the SampleBrowser to test them easily.
- /// This class provides a great list of tutorials to start with
- /// when you're new to the Delta Engine. Either use the SampleBrowser or
- /// simply comment in the tutorial call in the Main method and press F5.
- /// </summary>
- public class Tutorials
- {
- #region DrawLines (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 1: Draw Lines
- /// Difficulty: Easy
- /// Description: Draw two simple lines on the screen using the Line class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial1.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawLines()
- {
- Application.Start(delegate
- {
- Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
- Line.Draw(new Point(1, 0), new Point(0, 1), Color.Green);
- });
- }
- #endregion
-
- #region DrawRotatingRectangle (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 2: Draw Rotating Rectangle
- /// Difficulty: Easy
- /// Description: Draw a simple rotating rectangle using the Rectangle
- /// class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial2.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawRotatingRectangle()
- {
- Application.Start(delegate
- {
- Rect.DrawOutline(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f),
- Color.Yellow, Time.CurrentExactTime * 15f);
- });
- }
- #endregion
-
- #region DrawCircle (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 3: Draw Circle
- /// Difficulty: Easy
- /// Description: Draw a simple circle using the Circle class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial3.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawCircle()
- {
- Application.Start(delegate
- {
- Circle.DrawOutline(Point.Half, 0.05f, Color.Yellow);
- });
- }
- #endregion
-
- #region DrawAxis (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 4: Draw Axis
- /// Difficulty: Easy
- /// Description: Draw a simple 3d axis using the Line class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial4.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawAxis()
- {
- // Activate a normal LookAt camera so we can "see" the 3d space.
- new LookAtCamera(new Vector(65f, 40f, 20f)).Activate();
- Application.Start(delegate
- {
- Line.Draw(Vector.Zero, new Vector(10f, 0f, 0f), Color.Red);
- Line.Draw(Vector.Zero, new Vector(0f, 10f, 0f), Color.Blue);
- Line.Draw(Vector.Zero, new Vector(0f, 0f, 10f), Color.Green);
- });
- }
- #endregion
-
- #region DrawSphereOutline (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 5: Draw Sphere
- /// Difficulty: Easy
- /// Description: Draw a simple 3d sphere using the Sphere class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial5.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawSphereOutline()
- {
- // Activate a normal LookAt camera so we can "see" the 3d space.
- new LookAtCamera(new Vector(75f, 50f, 20f)).Activate();
- Application.Start(delegate
- {
- Sphere.DrawOutline(Vector.Zero, 20f, Color.Yellow);
- });
- }
- #endregion
-
- #region DrawFilledBox (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 6: Draw Box
- /// Difficulty: Easy
- /// Description: Draw a simple 3d box using the Box class.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial6.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawFilledBox()
- {
- // Activate a normal LookAt camera so we can "see" the 3d space.
- new LookAtCamera(new Vector(65f, 40f, 20f)).Activate();
- Application.Start(delegate
- {
- Box.DrawOutline(new Vector(-5f, -5f, -5f),
- new Vector(5f, 5f, 5f), Color.Yellow);
-
- Box.DrawFilled(new Vector(-4f, -4f, -4f), new Vector(4f, 4f, 4f),
- Color.Red);
-
- //test mulitple boxes:
- //Box.DrawFilled(new Vector(6f, -4f, -4f), new Vector(14f, 4f, 4f),
- // Color.Green);
- });
- }
- #endregion
-
- #region DrawDefaultMaterial (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 7: Draw Default Material
- /// Difficulty: Easy
- /// Description: Draw the default fallback material (one line of code ^^).
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial7.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawDefaultMaterial()
- {
- Application.Start(delegate
- {
- Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
- });
- }
- #endregion
-
- #region DrawColoredDefaultMaterial (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 8: Draw Colored Default Material
- /// Difficulty: Easy
- /// Description: Draw a simple default material, blended with red color.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial8.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawColoredDefaultMaterial()
- {
- Material2DColored material = Material2DColored.Default.Clone();
- material.BlendColor = Color.Red;
-
- Application.Start(delegate
- {
- material.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
- });
- }
- #endregion
-
- #region DrawImage (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 9: Load and Draw Image
- /// Difficulty: Easy
- /// Description: Draw a simple image after loading it from content.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial9.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawImage()
- {
- Material2D material = new Material2D("DeltaEngineLogo");
- float zooming = 1.5f;
- Input.Commands[Command.CameraZoomIn].Add(delegate
- {
- zooming += 2.0f * Time.Delta;
- });
- Input.Commands[Command.CameraZoomOut].Add(delegate
- {
- zooming -= 2.0f * Time.Delta;
- });
-
- Application.Start(delegate
- {
- material.Draw(Rectangle.FromCenter(Point.Half,
- material.Size * zooming));
- });
- }
- #endregion
-
- #region DrawAnimatedImage (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 10: Draw Animated Image
- /// Difficulty: Easy
- /// Description: Draw a simple animated image after loading it from
- /// content.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial10.png
- /// </summary>
- [Test, Category("Visual")]
- public static void DrawAnimatedImage()
- {
- Material2D material = new Material2D("ImageAnimation");
- Assert.True(material.IsAnimated);
-
- Application.Start(delegate
- {
- material.Draw(new Rectangle(0.2f, 0.35f, 0.6f, 0.3f));
- });
- }
- #endregion
-
- #region TestSimpleTiles (Static)
- /// <summary>
- /// Tutorial: Basic Rendering Tutorial 11: Test simple tile system
- /// Difficulty: Easy
- /// Description: Draw a 5x5 grid of tiles with grass, mud and sand as a
- /// very simple prototype for a tile-based 2D game.
- /// Image: http://DeltaEngine.net/Icons/RenderingTutorial11.png
- /// </summary>
- [Test, Category("Visual")]
- public static void TestSimpleTiles()
- {
- var grass = new Material2D("GrassTile");
- var mud = new Material2D("MudTile");
- var sand = new Material2D("SandTile");
-
- // Note: A real tile should be more than just a link to materials
- var tile = new[,]
- {
- {
- grass, grass, grass, grass, grass,
- },
- {
- grass, sand, sand, sand, mud,
- },
- {
- sand, sand, grass, sand, mud,
- },
- {
- sand, grass, grass, mud, mud,
- },
- {
- sand, sand, sand, mud, mud,
- },
- };
- Rectangle renderGrid = Rectangle.FromCenter(Point.Half, new Size(0.7f));
-
- Application.Start(delegate
- {
- // Show a 5x5 tile grid
- for (int y = 0; y < tile.GetLength(0); y++)
- {
- for (int x = 0; x < tile.GetLength(1); x++)
- {
- tile[y, x].Draw(renderGrid.GetInnerRectangle(
- new Rectangle(x * 0.2f, y * 0.2f, 0.2f, 0.2f)));
- }
- }
- });
- }
- #endregion
- }
- }