public void SetProjectionFieldOfViewTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.SetFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f); projection2.Near = 1; projection2.Far = 10; Projection projection3 = new PerspectiveProjection { Left = -2.0528009f / 2.0f, Right = 2.0528009f / 2.0f, Bottom = -1.1547005f / 2.0f, Top = 1.1547005f / 2.0f, Near = 1, Far = 10, }; Matrix44F expected = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), 16.0f / 9.0f, 1, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection3.ToMatrix44F())); }
public void SetProjectionTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.Set(4, 3, 2, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.Set(4, 3); projection2.Near = 2; projection2.Far = 10; Projection projection3 = new PerspectiveProjection { Left = -2, Right = 2, Bottom = -1.5f, Top = 1.5f, Near = 2, Far = 10, }; Matrix44F expected = Matrix44F.CreatePerspective(4, 3, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection3.ToMatrix44F())); }
public void SetProjectionOffCenterTest() { PerspectiveProjection projection = new PerspectiveProjection(); projection.SetOffCenter(0, 4, 1, 4, 2, 10); PerspectiveProjection projection2 = new PerspectiveProjection(); projection2.SetOffCenter(0, 4, 1, 4); projection2.Near = 2; projection2.Far = 10; Matrix44F expected = Matrix44F.CreatePerspectiveOffCenter(0, 4, 1, 4, 2, 10); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection)); Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection2.ToMatrix44F())); }
private void TestClippedProjection() { RandomHelper.Random = new Random(1234567); var p = new PerspectiveProjection(); p.SetOffCenter(-0.1f, 0.2f, -0.1f, 0.1f, 0.1f, 1); _debugRenderer.DrawViewVolume(p.ViewVolume, new Pose(new Vector3F(0, 2, 0)), Color.Red, true, false); p.NearClipPlane = new Plane(new Vector3F(-0.1f, +0.1f, 1).Normalized, -0.4f); PlaneShape.MeshSize = 2; _debugRenderer.DrawShape(new PlaneShape(p.NearClipPlane.Value), new Pose(new Vector3F(0, 2, 0)), Vector3F.One, Color.Green, false, false); Matrix44F m = p.ToMatrix44F(); for (int i = 0; i < 100000; i++) { Aabb aabb = p.ViewVolume.GetAabb(Pose.Identity); aabb.Minimum -= new Vector3F(1); aabb.Maximum += new Vector3F(1); float x = RandomHelper.Random.NextFloat(aabb.Minimum.X, aabb.Maximum.X); float y = RandomHelper.Random.NextFloat(aabb.Minimum.Y, aabb.Maximum.Y); float z = RandomHelper.Random.NextFloat(aabb.Minimum.Z, aabb.Maximum.Z); //if (RandomHelper.Random.NextBool()) // x = 0; //else // y = 0; Vector4F c = m * new Vector4F(x, y, z, 1); c /= c.W; Color color = Color.Orange; if (c.X < -1 || c.X > 1 || c.Y < -1 || c.Y > 1 || c.Z < 0 || c.Z > 1) { continue;// color = Color.Gray; } _debugRenderer.DrawPoint(new Vector3F(x, y + 2, z), color, false); } }