PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Rendering/CameraTests/FreeCameraTests.cs

#
C# | 85 lines | 65 code | 10 blank | 10 comment | 2 complexity | 24efec485385295f08d31842c854ec39 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Engine;
  2. using Delta.Rendering.Cameras;
  3. using Delta.Rendering.Models;
  4. using Delta.Utilities.Datatypes;
  5. using Delta.InputSystem;
  6. using Delta.InputSystem.Devices;
  7. using Delta.Utilities.Helpers;
  8. namespace Delta.Rendering.CameraTests
  9. {
  10. using Delta.Rendering.Basics.Drawing;
  11. using Delta.Rendering.Basics.Fonts;
  12. using NUnit.Framework;
  13. /// <summary>
  14. /// All unit tests for free cameras.
  15. /// </summary>
  16. public class FreeCameraTests
  17. {
  18. #region TestUpdateProjectionMatrix
  19. /// <summary>
  20. /// Test from BFoxX from the Forum to test changing camera values.
  21. /// </summary>
  22. [Test]
  23. public static void TestUpdateProjectionMatrix()
  24. {
  25. BaseCamera cam = new FreeCamera(new Vector(0, -10, 0));
  26. cam.Target = new Vector(0, 0, 0);
  27. cam.FieldOfView = MathHelper.DegreeToRadians(90);
  28. cam.NearPlane = 1; //work
  29. cam.FarPlane = 10; //work
  30. var halfSize = new Vector(3, 3, 3);
  31. string text;
  32. Application.Start(delegate
  33. {
  34. Grid.Draw();
  35. text = ScreenSpace.InternalViewProjection3D.Translation.ToString();
  36. //Look after zoom (unzoom)
  37. //if camera 0 -10 0 TranslationZ 10
  38. //ater
  39. //if camera 0 -10 0 TranslationZ 8.1818 ----
  40. var point = new Point(0f, 0.5f);
  41. text += "\n Position" + cam.Position;
  42. text += "\n FarPlane" + cam.FarPlane;
  43. text += "\n Point in" + point;
  44. Ray ray = ScreenSpace.GetRayFromScreenPoint(point);
  45. Vector end = ray.Direction + ray.Position;
  46. point = new Point(end.X, end.Z);
  47. text += "\n Point on grid" + point;
  48. Vector vector = ScreenSpace.Project(new Vector(point.X, 0, point.Y));
  49. text += "\n vector" + vector;
  50. ray = ScreenSpace.GetRayFromScreenPoint(new Point(vector.X, vector.Y));
  51. end = ray.Direction + ray.Position;
  52. point = new Point(end.X, end.Z);
  53. text += "\n 2 Point on grid" + point;
  54. vector = ScreenSpace.Project(new Vector(point.X, 0, point.Y));
  55. text += "\n vector" + vector;
  56. Font.DrawTopLeftInformation(text);
  57. if (Input.Keyboard.IsReleased(InputButton.A))
  58. {
  59. cam.Position -= new Vector(0, 0.01f, 0);
  60. cam.UpdateProjectionMatrix();
  61. cam.FarPlane = -cam.Position.Y;
  62. cam.UpdateProjectionMatrix();
  63. }
  64. if (Input.Keyboard.IsReleased(InputButton.S))
  65. {
  66. cam.Position += new Vector(0, 0.01f, 0);
  67. cam.UpdateProjectionMatrix();
  68. cam.FarPlane = -cam.Position.Y;
  69. cam.UpdateProjectionMatrix();
  70. }
  71. });
  72. }
  73. #endregion
  74. }
  75. }