/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
- using Delta.Engine;
- using Delta.Rendering.Cameras;
- using Delta.Rendering.Models;
- using Delta.Utilities.Datatypes;
- using Delta.InputSystem;
- using Delta.InputSystem.Devices;
- using Delta.Utilities.Helpers;
-
- namespace Delta.Rendering.CameraTests
- {
- using Delta.Rendering.Basics.Drawing;
- using Delta.Rendering.Basics.Fonts;
-
- using NUnit.Framework;
-
- /// <summary>
- /// All unit tests for free cameras.
- /// </summary>
- public class FreeCameraTests
- {
- #region TestUpdateProjectionMatrix
- /// <summary>
- /// Test from BFoxX from the Forum to test changing camera values.
- /// </summary>
- [Test]
- public static void TestUpdateProjectionMatrix()
- {
- BaseCamera cam = new FreeCamera(new Vector(0, -10, 0));
- cam.Target = new Vector(0, 0, 0);
- cam.FieldOfView = MathHelper.DegreeToRadians(90);
- cam.NearPlane = 1; //work
- cam.FarPlane = 10; //work
- var halfSize = new Vector(3, 3, 3);
-
- string text;
- Application.Start(delegate
- {
- Grid.Draw();
- text = ScreenSpace.InternalViewProjection3D.Translation.ToString();
- //Look after zoom (unzoom)
- //if camera 0 -10 0 TranslationZ 10
- //ater
- //if camera 0 -10 0 TranslationZ 8.1818 ----
-
- var point = new Point(0f, 0.5f);
- text += "\n Position" + cam.Position;
- text += "\n FarPlane" + cam.FarPlane;
- text += "\n Point in" + point;
- Ray ray = ScreenSpace.GetRayFromScreenPoint(point);
- Vector end = ray.Direction + ray.Position;
- point = new Point(end.X, end.Z);
- text += "\n Point on grid" + point;
-
- Vector vector = ScreenSpace.Project(new Vector(point.X, 0, point.Y));
- text += "\n vector" + vector;
-
- ray = ScreenSpace.GetRayFromScreenPoint(new Point(vector.X, vector.Y));
- end = ray.Direction + ray.Position;
- point = new Point(end.X, end.Z);
- text += "\n 2 Point on grid" + point;
-
- vector = ScreenSpace.Project(new Vector(point.X, 0, point.Y));
- text += "\n vector" + vector;
-
- Font.DrawTopLeftInformation(text);
-
- if (Input.Keyboard.IsReleased(InputButton.A))
- {
- cam.Position -= new Vector(0, 0.01f, 0);
- cam.UpdateProjectionMatrix();
- cam.FarPlane = -cam.Position.Y;
- cam.UpdateProjectionMatrix();
- }
- if (Input.Keyboard.IsReleased(InputButton.S))
- {
- cam.Position += new Vector(0, 0.01f, 0);
- cam.UpdateProjectionMatrix();
- cam.FarPlane = -cam.Position.Y;
- cam.UpdateProjectionMatrix();
- }
- });
- }
- #endregion
- }
- }