示例#1
0
        public void GetBoundsOrthographic()
        {
            // Get bounds of AABB in clip space. (Used in OcclusionCulling.fx.)
            Vector3F cameraPosition = new Vector3F(100, -200, 345);
            Vector3F cameraForward  = new Vector3F(1, 2, 3).Normalized;
            Vector3F cameraUp       = new Vector3F(-1, 0.5f, -2).Normalized;

            Matrix44F view     = Matrix44F.CreateLookAt(cameraPosition, cameraPosition + cameraForward, cameraUp);
            Matrix44F proj     = Matrix44F.CreateOrthographic(16, 9, -10, 100);
            Matrix44F viewProj = proj * view;

            Vector3F center = new Vector3F();
            Vector3F halfExtent = new Vector3F();
            Aabb     aabb = new Aabb(center - halfExtent, center + halfExtent);
            Aabb     aabb0, aabb1;

            GetBoundsOrtho(aabb, viewProj, out aabb0);
            GetBoundsOrthoSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));

            center     = new Vector3F(-9, 20, -110);
            halfExtent = new Vector3F(5, 2, 10);
            aabb       = new Aabb(center - halfExtent, center + halfExtent);
            GetBoundsOrtho(aabb, viewProj, out aabb0);
            GetBoundsOrthoSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));
        }
示例#2
0
        public void GetBoundsPerspective()
        {
            // Get bounds of AABB in clip space. (Used in OcclusionCulling.fx.)
            // Note: Z = 0 or negative is handled conservatively. Point (0, 0, 0) is returned.
            Vector3F cameraPosition = new Vector3F(100, -200, 345);
            Vector3F cameraForward  = new Vector3F(1, 2, 3).Normalized;
            Vector3F cameraUp       = new Vector3F(-1, 0.5f, -2).Normalized;

            Matrix44F view     = Matrix44F.CreateLookAt(cameraPosition, cameraPosition + cameraForward, cameraUp);
            Matrix44F proj     = Matrix44F.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90), 16.0f / 9.0f, 1, 100);
            Matrix44F viewProj = proj * view;

            // Empty AABB at center of near plane.
            Vector3F center = cameraPosition + cameraForward;
            Vector3F halfExtent = new Vector3F();
            Aabb     aabb = new Aabb(center - halfExtent, center + halfExtent);
            Aabb     aabb0, aabb1;

            GetBoundsPersp(aabb, viewProj, out aabb0);
            GetBoundsPerspSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));

            // AABB inside frustum.
            center     = view.Inverse.TransformPosition(new Vector3F(2, -3, -50));
            halfExtent = new Vector3F(1, 6, 10);
            aabb       = new Aabb(center - halfExtent, center + halfExtent);
            GetBoundsPersp(aabb, viewProj, out aabb0);
            GetBoundsPerspSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));

            // Behind camera.
            center     = view.Inverse.TransformPosition(new Vector3F(2, -3, 50));
            halfExtent = new Vector3F(1, 6, 10);
            aabb       = new Aabb(center - halfExtent, center + halfExtent);
            GetBoundsPersp(aabb, viewProj, out aabb0);
            GetBoundsPerspSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));

            // Camera inside AABB.
            center     = view.Inverse.TransformPosition(new Vector3F(2, -3, -50));
            halfExtent = new Vector3F(100, 100, 100);
            aabb       = new Aabb(center - halfExtent, center + halfExtent);
            GetBoundsPersp(aabb, viewProj, out aabb0);
            GetBoundsPerspSmart(aabb, viewProj, out aabb1);
            Assert.IsTrue(Aabb.AreNumericallyEqual(aabb0, aabb1));
        }
示例#3
0
        public void AreNumericallyEqual()
        {
            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(), new Aabb()));
            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                   new Aabb(new Vector3F(1, 2, 3 + Numeric.EpsilonF / 2), new Vector3F(4, 5, 6))));
            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                   new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6 + Numeric.EpsilonF / 2))));
            Assert.IsFalse(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                    new Aabb(new Vector3F(1, 2, 3 + 10 * Numeric.EpsilonF), new Vector3F(4, 5, 6))));

            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(), new Aabb()));
            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                   new Aabb(new Vector3F(1, 2, 3.1f), new Vector3F(4, 5, 6)),
                                                   0.2f));
            Assert.IsTrue(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                   new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5.1f, 6)),
                                                   0.2f));
            Assert.IsFalse(Aabb.AreNumericallyEqual(new Aabb(new Vector3F(1, 2, 3), new Vector3F(4, 5, 6)),
                                                    new Aabb(new Vector3F(1, 2, 3.3f), new Vector3F(4, 5, 6)),
                                                    0.2f));
        }