PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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