PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Rendering/ModelTests/ModelViewer.cs

#
C# | 137 lines | 93 code | 15 blank | 29 comment | 6 complexity | 3ddba7a827ebd0f84d8e1f5900db5ced MD5 | raw file
Possible License(s): Apache-2.0
  1. using System.Collections.Generic;
  2. using Delta.ContentSystem.Rendering;
  3. using Delta.Engine;
  4. using Delta.InputSystem;
  5. using Delta.Rendering.Basics.Drawing;
  6. using Delta.Rendering.Basics.Fonts;
  7. using Delta.Rendering.Cameras;
  8. using Delta.Rendering.Models;
  9. using Delta.Utilities;
  10. using Delta.Utilities.Datatypes;
  11. using Delta.Utilities.Datatypes.Advanced;
  12. using NUnit.Framework;
  13. namespace Delta.Rendering.ModelTests
  14. {
  15. /// <summary>
  16. /// Model viewer
  17. /// </summary>
  18. [Category("Visual")]
  19. internal class ModelViewer
  20. {
  21. #region Start (Static)
  22. /// <summary>
  23. /// Start
  24. /// </summary>
  25. [Test]
  26. public static void Start()
  27. {
  28. ModelViewer demo = new ModelViewer();
  29. // Start up the scene
  30. Application.Start(delegate
  31. {
  32. demo.Run();
  33. });
  34. }
  35. #endregion
  36. #region Private
  37. #region meshes (Private)
  38. /// <summary>
  39. /// The list of all meshes which are available by the content system.
  40. /// </summary>
  41. private readonly List<Mesh> meshes;
  42. #endregion
  43. #region currentMeshSelectionIndex (Private)
  44. /// <summary>
  45. /// The current index for the mesh (of the "meshes" list) that we draw
  46. /// </summary>
  47. private int currentMeshSelectionIndex;
  48. #endregion
  49. #region groundMesh (Private)
  50. /// <summary>
  51. /// Mesh for the ground for the rest of the models to stand on.
  52. /// </summary>
  53. private Mesh groundMesh = null;
  54. #endregion
  55. #region wasTouchPressed (Private)
  56. /// <summary>
  57. /// Was touch pressed
  58. /// </summary>
  59. private bool wasTouchPressed;
  60. #endregion
  61. #endregion
  62. #region Constructors
  63. /// <summary>
  64. /// Create model viewer
  65. /// </summary>
  66. public ModelViewer()
  67. {
  68. meshes = new List<Mesh>();
  69. new LookAtCamera(new Vector(0, -5, 5));
  70. // Set the light direction (copied from the level data)
  71. //Note: Added 100 to Z to make light come more from the top, looks
  72. // better for most normal mapping surfaces!
  73. Light.Direction = new Vector(-161.771f, -52.202f, 25 + 84.163f);
  74. Light.Direction.Normalize();
  75. string[] contentNames = MeshData.GetAllContentNames();
  76. foreach (string name in contentNames)
  77. {
  78. meshes.Add(new Mesh(name));
  79. }
  80. if (contentNames.Length == 0)
  81. {
  82. Log.Warning("There are no mesh files in the Content! " +
  83. "Only adding default box now. Make sure to add some meshes " +
  84. "to the Content!");
  85. meshes.Add(Mesh.CreateBox("", 5, 5, 5, MaterialData.Default));
  86. }
  87. currentMeshSelectionIndex = 0;
  88. }
  89. #endregion
  90. #region Run (Public)
  91. /// <summary>
  92. /// Run
  93. /// </summary>
  94. [Test]
  95. public void Run()
  96. {
  97. if (Input.Keyboard.SpaceReleased ||
  98. wasTouchPressed &&
  99. Input.Touch.TouchIsPressed == false)
  100. {
  101. currentMeshSelectionIndex++;
  102. currentMeshSelectionIndex %= meshes.Count;
  103. }
  104. wasTouchPressed = Input.Touch.TouchIsPressed;
  105. Mesh currentMesh = meshes[currentMeshSelectionIndex];
  106. currentMesh.Draw();
  107. Font.DrawTopLeftInformation(
  108. "Modelname: " + currentMesh.Name + "\n" +
  109. "Material: " + currentMesh.Material);
  110. // If no ground mesh was found, just display the grid
  111. if (groundMesh == null)
  112. {
  113. Grid.Draw();
  114. }
  115. else
  116. {
  117. groundMesh.Draw();
  118. }
  119. }
  120. #endregion
  121. }
  122. }