PageRenderTime 161ms CodeModel.GetById 80ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/Rendering/CameraTests/FreeCameraTests.cs

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