Exemplo n.º 1
0
		public void TestZoom1_XOnly_ZDirection()
		{
			double aspectRatio = 1.0;
			double cameraDistanceOriginal = 1000;
			double zNear = 100;
			double zFar = 10000;
			double widthByZNear = 0.5;
			double distanceFactor = 0.75;
			PointD3D targetPosition = new PointD3D(0, 0, 0);
			VectorD3D targetToEye = new VectorD3D(0, 0, cameraDistanceOriginal);
			VectorD3D cameraUpVector = new VectorD3D(0, 1, 0);
			VectorD3D targetToWorldPoint = new VectorD3D(200, 0, 0);

			PointD3D cameraPosition = targetPosition + targetToEye;
			PointD3D worldPoint = targetPosition + targetToWorldPoint;

			Assert.AreEqual(0, VectorD3D.DotProduct(targetToEye, targetToWorldPoint), "The test must be set up in a way that targetToEye and targetToWorldPoint are perpendicular to each other");

			var cameraO = new PerspectiveCamera(cameraUpVector, cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

			var screenO = cameraO.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			Assert.AreEqual(0.0, screenO.Y, "Test must be set up so that screen.Y is always zero");

			var cameraN = cameraO.ZoomByGettingCloserToTarget(distanceFactor, screenO.X, screenO.Y, aspectRatio);

			var screenN = cameraN.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			Assert.AreEqual(screenO.X, screenN.X, 1E-3);
			Assert.AreEqual(screenO.Y, screenN.Y, 1E-3);
		}
Exemplo n.º 2
0
        public void TestZoom1_XY()
        {
            double aspectRatio            = 1.0;
            double cameraDistanceOriginal = 1000;
            double zNear          = 100;
            double zFar           = 10000;
            double widthByZNear   = 0.5;
            double distanceFactor = 0.75;
            var    cameraPosition = new PointD3D(0, 0, cameraDistanceOriginal);
            var    targetPosition = new PointD3D(0, 0, 0);
            var    worldPoint     = new PointD3D(200, 200, 0);

            var cameraO = new PerspectiveCamera(new VectorD3D(0, 1, 0), cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

            var screenO = cameraO.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

            var cameraN = cameraO.ZoomByGettingCloserToTarget(distanceFactor, screenO.X, screenO.Y, aspectRatio);

            var screenN = cameraN.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

            Assert.AreEqual(screenO.X, screenN.X, 1E-3);
            Assert.AreEqual(screenO.Y, screenN.Y, 1E-3);
        }
Exemplo n.º 3
0
		public void TestZoom1_XY()
		{
			double aspectRatio = 1.0;
			double cameraDistanceOriginal = 1000;
			double zNear = 100;
			double zFar = 10000;
			double widthByZNear = 0.5;
			double distanceFactor = 0.75;
			PointD3D cameraPosition = new PointD3D(0, 0, cameraDistanceOriginal);
			PointD3D targetPosition = new PointD3D(0, 0, 0);
			PointD3D worldPoint = new PointD3D(200, 200, 0);

			var cameraO = new PerspectiveCamera(new VectorD3D(0, 1, 0), cameraPosition, targetPosition, zNear, zFar, widthByZNear * zNear);

			var screenO = cameraO.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			var cameraN = cameraO.ZoomByGettingCloserToTarget(distanceFactor, screenO.X, screenO.Y, aspectRatio);

			var screenN = cameraN.GetViewProjectionMatrix(aspectRatio).Transform(worldPoint);

			Assert.AreEqual(screenO.X, screenN.X, 1E-3);
			Assert.AreEqual(screenO.Y, screenN.Y, 1E-3);
		}