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()));
        }
예제 #2
0
        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 Vector3(0, 2, 0)), Color.Red, true, false);

            p.NearClipPlane = new Plane(new Vector3(-0.1f, +0.1f, 1).Normalized, -0.4f);

            PlaneShape.MeshSize = 2;
            _debugRenderer.DrawShape(new PlaneShape(p.NearClipPlane.Value), new Pose(new Vector3(0, 2, 0)), Vector3.One, Color.Green, false, false);

            Matrix m = p.ToMatrix();

            for (int i = 0; i < 100000; i++)
            {
                Aabb aabb = p.ViewVolume.GetAabb(Pose.Identity);
                aabb.Minimum -= new Vector3(1);
                aabb.Maximum += new Vector3(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;

                Vector4 c = m * new Vector4(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 Vector3(x, y + 2, z), color, false);
            }
        }
        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()));
        }