Exemplo n.º 1
0
        public void GetScreenSizeWithOrthographic()
        {
            // Camera
              var projection = new OrthographicProjection();
              projection.SetOffCenter(0, 4, 0, 2);
              var camera = new Camera(projection);
              var cameraNode = new CameraNode(camera);
              cameraNode.PoseWorld = new Pose(new Vector3F(123, 456, -789), Matrix33F.CreateRotation(new Vector3F(1, -2, 3), MathHelper.ToRadians(75)));

              // 2:1 viewport
              var viewport = new Viewport(10, 10, 200, 100);

              // Test object
              var shape = new SphereShape();
              var geometricObject = new GeometricObject(shape);

              // Empty sphere at camera position.
              shape.Radius = 0;
              geometricObject.Pose = cameraNode.PoseWorld;
              Vector2F screenSize = GraphicsHelper.GetScreenSize(cameraNode, viewport, geometricObject);
              Assert.AreEqual(0, screenSize.X);
              Assert.AreEqual(0, screenSize.Y);

              // Empty sphere centered at near plane.
              shape.Radius = 0;
              geometricObject.Pose = cameraNode.PoseWorld * new Pose(new Vector3F(0.123f, -0.543f, -1));
              screenSize = GraphicsHelper.GetScreenSize(cameraNode, viewport, geometricObject);
              Assert.AreEqual(0, screenSize.X);
              Assert.AreEqual(0, screenSize.Y);

              // Create sphere which as a bounding sphere of ~1 unit diameter:
              // Since the bounding sphere is based on the AABB, we need to make the
              // actual sphere a bit smaller.
              shape.Radius = 1 / (2 * (float)Math.Sqrt(3)) + Numeric.EpsilonF;

              // Sphere at camera position.
              geometricObject.Pose = cameraNode.PoseWorld;
              screenSize = GraphicsHelper.GetScreenSize(cameraNode, viewport, geometricObject);
              Assert.IsTrue(Numeric.AreEqual(screenSize.X, 50.0f, 10f));
              Assert.IsTrue(Numeric.AreEqual(screenSize.Y, 50.0f, 10f));

              // Sphere at near plane.
              geometricObject.Pose = cameraNode.PoseWorld * new Pose(new Vector3F(0.123f, -0.543f, -1));
              screenSize = GraphicsHelper.GetScreenSize(cameraNode, viewport, geometricObject);
              Assert.IsTrue(Numeric.AreEqual(screenSize.X, 50.0f, 10f));
              Assert.IsTrue(Numeric.AreEqual(screenSize.Y, 50.0f, 10f));

              // Double distance --> same size
              geometricObject.Pose = cameraNode.PoseWorld * new Pose(new Vector3F(0.123f, -0.543f, -2));
              screenSize = GraphicsHelper.GetScreenSize(cameraNode, viewport, geometricObject);
              Assert.IsTrue(Numeric.AreEqual(screenSize.X, 50.0f, 10f));
              Assert.IsTrue(Numeric.AreEqual(screenSize.Y, 50.0f, 10f));
        }
        public void SetProjectionTest()
        {
            OrthographicProjection projection = new OrthographicProjection();
              projection.Set(4, 3, 2, 10);

              OrthographicProjection camera2 = new OrthographicProjection();
              camera2.Set(4, 3);
              camera2.Near = 2;
              camera2.Far = 10;

              OrthographicProjection camera3 = new OrthographicProjection
              {
            Left = -2,
            Right = 2,
            Bottom = -1.5f,
            Top = 1.5f,
            Near = 2,
            Far = 10,
              };

              Matrix44F expected = Matrix44F.CreateOrthographic(4, 3, 2, 10);
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection));
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera2));
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera3.ToMatrix44F()));
        }
Exemplo n.º 3
0
        public void SetProjectionTest()
        {
            Matrix44F projectionMatrix = Matrix44F.CreateOrthographicOffCenter(1, 4, 2, 5, 6, 11);
              OrthographicProjection orthographicProjection = new OrthographicProjection();
              orthographicProjection.Set(projectionMatrix);
              CameraInstance cameraInstance = new CameraInstance(new Camera(orthographicProjection));

              Assert.AreEqual(Vector3F.Zero, cameraInstance.PoseWorld.Position);
              Assert.AreEqual(Matrix33F.Identity, cameraInstance.PoseWorld.Orientation);
              Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Width));
              Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Height));
              Assert.That(Numeric.AreEqual(1f, cameraInstance.Camera.Projection.AspectRatio));
              Assert.That(Numeric.AreEqual(6, cameraInstance.Camera.Projection.Near));
              Assert.That(Numeric.AreEqual(11, cameraInstance.Camera.Projection.Far));
              Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Left));
              Assert.That(Numeric.AreEqual(4, cameraInstance.Camera.Projection.Right));
              Assert.That(Numeric.AreEqual(2, cameraInstance.Camera.Projection.Bottom));
              Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Top));
              Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Depth));
              Assert.That(Matrix44F.AreNumericallyEqual(orthographicProjection, cameraInstance.Camera.Projection));
              Assert.That(Matrix44F.AreNumericallyEqual(orthographicProjection.Inverse, cameraInstance.Camera.Projection.Inverse));
              Assert.IsNotNull(cameraInstance.BoundingShape);

              PerspectiveProjection perspectiveProjection = new PerspectiveProjection();
              perspectiveProjection.Inverse = Matrix44F.CreatePerspectiveOffCenter(1, 5, 2, 5, 1, 10).Inverse;
              cameraInstance = new CameraInstance(new Camera(perspectiveProjection));

              Assert.AreEqual(Vector3F.Zero, cameraInstance.PoseWorld.Position);
              Assert.AreEqual(Matrix33F.Identity, cameraInstance.PoseWorld.Orientation);
              Assert.That(Numeric.AreEqual(MathHelper.ToRadians(33.690067f), cameraInstance.Camera.Projection.FieldOfViewX));
              Assert.That(Numeric.AreEqual(MathHelper.ToRadians(15.255119f), cameraInstance.Camera.Projection.FieldOfViewY));
              Assert.That(Numeric.AreEqual(4, cameraInstance.Camera.Projection.Width));
              Assert.That(Numeric.AreEqual(3, cameraInstance.Camera.Projection.Height));
              Assert.That(Numeric.AreEqual(4.0f / 3.0f, cameraInstance.Camera.Projection.AspectRatio));
              Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Left));
              Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Right));
              Assert.That(Numeric.AreEqual(2, cameraInstance.Camera.Projection.Bottom));
              Assert.That(Numeric.AreEqual(5, cameraInstance.Camera.Projection.Top));
              Assert.That(Numeric.AreEqual(1, cameraInstance.Camera.Projection.Near));
              Assert.That(Numeric.AreEqual(10, cameraInstance.Camera.Projection.Far));
              Assert.That(Numeric.AreEqual(9, cameraInstance.Camera.Projection.Depth));
              Assert.IsNotNull(cameraInstance.BoundingShape);
        }
        public void SetProjectionOffCenterTest()
        {
            OrthographicProjection projection = new OrthographicProjection();
              projection.SetOffCenter(0, 4, 1, 4, 2, 10);

              OrthographicProjection camera2 = new OrthographicProjection();
              camera2.SetOffCenter(0, 4, 1, 4);
              camera2.Near = 2;
              camera2.Far = 10;

              Projection camera3 = new OrthographicProjection
              {
            Left = 0,
            Right = 4,
            Bottom = 1,
            Top = 4,
            Near = 2,
            Far = 10,
              };

              Matrix44F expected = Matrix44F.CreateOrthographicOffCenter(0, 4, 1, 4, 2, 10);
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, projection));
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera2));
              Assert.IsTrue(Matrix44F.AreNumericallyEqual(expected, camera3.ToMatrix44F()));
        }