PageRenderTime 73ms CodeModel.GetById 40ms app.highlight 11ms RepoModel.GetById 19ms app.codeStats 0ms

/Rendering/BasicTests/Tutorials.cs

#
C# | 279 lines | 178 code | 18 blank | 83 comment | 2 complexity | 75bfd6ca9ac63afba91f922f3c3e8c37 MD5 | raw file
  1using Delta.Engine;
  2using Delta.InputSystem;
  3using Delta.Rendering.Basics.Drawing;
  4using Delta.Rendering.Basics.Materials;
  5using Delta.Rendering.Cameras;
  6using Delta.Utilities;
  7using Delta.Utilities.Datatypes;
  8using NUnit.Framework;
  9
 10namespace Delta.Rendering.BasicTests
 11{
 12	/// <summary>
 13	/// Basic rendering tutorials, use the SampleBrowser to test them easily.
 14	/// This class provides a great list of tutorials to start with
 15	/// when you're new to the Delta Engine. Either use the SampleBrowser or
 16	/// simply comment in the tutorial call in the Main method and press F5.
 17	/// </summary>
 18	public class Tutorials
 19	{
 20		#region DrawLines (Static)
 21		/// <summary>
 22		/// Tutorial: Basic Rendering Tutorial 1: Draw Lines
 23		/// Difficulty: Easy
 24		/// Description: Draw two simple lines on the screen using the Line class.
 25		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial1.png
 26		/// </summary>
 27		[Test, Category("Visual")]
 28		public static void DrawLines()
 29		{
 30			Application.Start(delegate
 31			{
 32				Line.Draw(new Point(0, 0), new Point(1, 1), Color.Red);
 33				Line.Draw(new Point(1, 0), new Point(0, 1), Color.Green);
 34			});
 35		}
 36		#endregion
 37
 38		#region DrawRotatingRectangle (Static)
 39		/// <summary>
 40		/// Tutorial: Basic Rendering Tutorial 2: Draw Rotating Rectangle
 41		/// Difficulty: Easy
 42		/// Description: Draw a simple rotating rectangle using the Rectangle
 43		/// class.
 44		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial2.png
 45		/// </summary>
 46		[Test, Category("Visual")]
 47		public static void DrawRotatingRectangle()
 48		{
 49			Application.Start(delegate
 50			{
 51				Rect.DrawOutline(new Rectangle(0.4f, 0.4f, 0.2f, 0.2f),
 52					Color.Yellow, Time.CurrentExactTime * 15f);
 53			});
 54		}
 55		#endregion
 56
 57		#region DrawCircle (Static)
 58		/// <summary>
 59		/// Tutorial: Basic Rendering Tutorial 3: Draw Circle
 60		/// Difficulty: Easy
 61		/// Description: Draw a simple circle using the Circle class.
 62		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial3.png
 63		/// </summary>
 64		[Test, Category("Visual")]
 65		public static void DrawCircle()
 66		{
 67			Application.Start(delegate
 68			{
 69				Circle.DrawOutline(Point.Half, 0.05f, Color.Yellow);
 70			});
 71		}
 72		#endregion
 73
 74		#region DrawAxis (Static)
 75		/// <summary>
 76		/// Tutorial: Basic Rendering Tutorial 4: Draw Axis
 77		/// Difficulty: Easy
 78		/// Description: Draw a simple 3d axis using the Line class.
 79		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial4.png
 80		/// </summary>
 81		[Test, Category("Visual")]
 82		public static void DrawAxis()
 83		{
 84			// Activate a normal LookAt camera so we can "see" the 3d space.
 85			new LookAtCamera(new Vector(65f, 40f, 20f)).Activate();
 86			Application.Start(delegate
 87			{
 88				Line.Draw(Vector.Zero, new Vector(10f, 0f, 0f), Color.Red);
 89				Line.Draw(Vector.Zero, new Vector(0f, 10f, 0f), Color.Blue);
 90				Line.Draw(Vector.Zero, new Vector(0f, 0f, 10f), Color.Green);
 91			});
 92		}
 93		#endregion
 94
 95		#region DrawSphereOutline (Static)
 96		/// <summary>
 97		/// Tutorial: Basic Rendering Tutorial 5: Draw Sphere
 98		/// Difficulty: Easy
 99		/// Description: Draw a simple 3d sphere using the Sphere class.
100		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial5.png
101		/// </summary>
102		[Test, Category("Visual")]
103		public static void DrawSphereOutline()
104		{
105			// Activate a normal LookAt camera so we can "see" the 3d space.
106			new LookAtCamera(new Vector(75f, 50f, 20f)).Activate();
107			Application.Start(delegate
108			{
109				Sphere.DrawOutline(Vector.Zero, 20f, Color.Yellow);
110			});
111		}
112		#endregion
113
114		#region DrawFilledBox (Static)
115		/// <summary>
116		/// Tutorial: Basic Rendering Tutorial 6: Draw Box
117		/// Difficulty: Easy
118		/// Description: Draw a simple 3d box using the Box class.
119		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial6.png
120		/// </summary>
121		[Test, Category("Visual")]
122		public static void DrawFilledBox()
123		{
124			// Activate a normal LookAt camera so we can "see" the 3d space.
125			new LookAtCamera(new Vector(65f, 40f, 20f)).Activate();
126			Application.Start(delegate
127			{
128				Box.DrawOutline(new Vector(-5f, -5f, -5f),
129					new Vector(5f, 5f, 5f), Color.Yellow);
130
131				Box.DrawFilled(new Vector(-4f, -4f, -4f), new Vector(4f, 4f, 4f),
132					Color.Red);
133
134				//test mulitple boxes:
135				//Box.DrawFilled(new Vector(6f, -4f, -4f), new Vector(14f, 4f, 4f),
136				//	Color.Green);
137			});
138		}
139		#endregion
140
141		#region DrawDefaultMaterial (Static)
142		/// <summary>
143		/// Tutorial: Basic Rendering Tutorial 7: Draw Default Material
144		/// Difficulty: Easy
145		/// Description: Draw the default fallback material (one line of code ^^).
146		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial7.png
147		/// </summary>
148		[Test, Category("Visual")]
149		public static void DrawDefaultMaterial()
150		{
151			Application.Start(delegate
152			{
153				Material2D.Default.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
154			});
155		}
156		#endregion
157
158		#region DrawColoredDefaultMaterial (Static)
159		/// <summary>
160		/// Tutorial: Basic Rendering Tutorial 8: Draw Colored Default Material
161		/// Difficulty: Easy
162		/// Description: Draw a simple default material, blended with red color.
163		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial8.png
164		/// </summary>
165		[Test, Category("Visual")]
166		public static void DrawColoredDefaultMaterial()
167		{
168			Material2DColored material = Material2DColored.Default.Clone();
169			material.BlendColor = Color.Red;
170
171			Application.Start(delegate
172			{
173				material.Draw(new Rectangle(0.2f, 0.2f, 0.6f, 0.6f));
174			});
175		}
176		#endregion
177
178		#region DrawImage (Static)
179		/// <summary>
180		/// Tutorial: Basic Rendering Tutorial 9: Load and Draw Image
181		/// Difficulty: Easy
182		/// Description: Draw a simple image after loading it from content.
183		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial9.png
184		/// </summary>
185		[Test, Category("Visual")]
186		public static void DrawImage()
187		{
188			Material2D material = new Material2D("DeltaEngineLogo");
189			float zooming = 1.5f;
190			Input.Commands[Command.CameraZoomIn].Add(delegate
191			{
192				zooming += 2.0f * Time.Delta;
193			});
194			Input.Commands[Command.CameraZoomOut].Add(delegate
195			{
196				zooming -= 2.0f * Time.Delta;
197			});
198
199			Application.Start(delegate
200			{
201				material.Draw(Rectangle.FromCenter(Point.Half,
202					material.Size * zooming));
203			});
204		}
205		#endregion
206
207		#region DrawAnimatedImage (Static)
208		/// <summary>
209		/// Tutorial: Basic Rendering Tutorial 10: Draw Animated Image
210		/// Difficulty: Easy
211		/// Description: Draw a simple animated image after loading it from
212		/// content.
213		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial10.png
214		/// </summary>
215		[Test, Category("Visual")]
216		public static void DrawAnimatedImage()
217		{
218			Material2D material = new Material2D("ImageAnimation");
219			Assert.True(material.IsAnimated);
220
221			Application.Start(delegate
222			{
223				material.Draw(new Rectangle(0.2f, 0.35f, 0.6f, 0.3f));
224			});
225		}
226		#endregion
227
228		#region TestSimpleTiles (Static)
229		/// <summary>
230		/// Tutorial: Basic Rendering Tutorial 11: Test simple tile system
231		/// Difficulty: Easy
232		/// Description: Draw a 5x5 grid of tiles with grass, mud and sand as a
233		/// very simple prototype for a tile-based 2D game.
234		/// Image: http://DeltaEngine.net/Icons/RenderingTutorial11.png
235		/// </summary>
236		[Test, Category("Visual")]
237		public static void TestSimpleTiles()
238		{
239			var grass = new Material2D("GrassTile");
240			var mud = new Material2D("MudTile");
241			var sand = new Material2D("SandTile");
242
243			// Note: A real tile should be more than just a link to materials
244			var tile = new[,]
245			{
246				{
247					grass, grass, grass, grass, grass,
248				},
249				{
250					grass, sand, sand, sand, mud,
251				},
252				{
253					sand, sand, grass, sand, mud,
254				},
255				{
256					sand, grass, grass, mud, mud,
257				},
258				{
259					sand, sand, sand, mud, mud,
260				},
261			};
262			Rectangle renderGrid = Rectangle.FromCenter(Point.Half, new Size(0.7f));
263
264			Application.Start(delegate
265			{
266				// Show a 5x5 tile grid
267				for (int y = 0; y < tile.GetLength(0); y++)
268				{
269					for (int x = 0; x < tile.GetLength(1); x++)
270					{
271						tile[y, x].Draw(renderGrid.GetInnerRectangle(
272							new Rectangle(x * 0.2f, y * 0.2f, 0.2f, 0.2f)));
273					}
274				}
275			});
276		}
277		#endregion
278	}
279}