private Vector3 GetMousePositionCartesianCoordinates(Vector3 mousePositionUnitCoordinates)
        {
            //we will get the mouse position by linearly interpolating between the cartesian coordinates of the frustrum edges. we will consider the plane of the frustrum at the graphical analysis location.
            float zDistance = Math.Abs(camera.position.Z - iterativeFunction.position.Z);

            //frustrum width, height:
            float frustrumHalfHeight = zDistance * Convert.ToSingle(Math.Tan(fieldOfView * 0.5f));
            float frustrumHalfWidth  = frustrumHalfHeight * ((float)width / height);

            float leftScreenEdge   = camera.position.X - frustrumHalfWidth;
            float rightScreenEdge  = camera.position.X + frustrumHalfWidth;
            float bottomScreenEdge = camera.position.Y - frustrumHalfHeight;
            float topScreenEdge    = camera.position.Y + frustrumHalfHeight;

            return(new Vector3(Mathematics.Lerp(mousePositionUnitCoordinates.X, leftScreenEdge, rightScreenEdge), -Mathematics.Lerp(mousePositionUnitCoordinates.Y, bottomScreenEdge, topScreenEdge), 0));
        }
Exemple #2
0
        //determine and load a transformation matrix that manipulates the complex coordinates of the quad.
        private void PrepareInstance(Vector2 mousePositionUnitCoordinates, float mouseWheelDelta, Fractal fractal)
        {
            float   stepPercent          = 1 - (2 * mouseWheelDelta / 100f);
            Vector2 mousePositionComplex = new Vector2(Mathematics.Lerp(mousePositionUnitCoordinates.X, fractal.domain[0].X, fractal.domain[1].X), -Mathematics.Lerp(mousePositionUnitCoordinates.Y, fractal.domain[0].Y, fractal.domain[3].Y));



            Vector2 bottomLeft  = Mathematics.Lerp(stepPercent, mousePositionComplex, fractal.domain[0]);
            Vector2 bottomRight = Mathematics.Lerp(stepPercent, mousePositionComplex, fractal.domain[1]);
            Vector2 topRight    = Mathematics.Lerp(stepPercent, mousePositionComplex, fractal.domain[2]);
            Vector2 topLeft     = Mathematics.Lerp(stepPercent, mousePositionComplex, fractal.domain[3]);

            float xScale = Math.Abs(bottomRight.X - bottomLeft.X);
            float yScale = Math.Abs(topLeft.Y - bottomLeft.Y);

            Matrix4 transformationMatrix = Mathematics.CreateTransformationMatrix(new Vector3(bottomLeft.X, bottomLeft.Y, 0), xScale, yScale);

            mandelbrotShader.LoadTransformationMatrix(transformationMatrix);

            fractal.domain[0] = bottomLeft;
            fractal.domain[1] = bottomRight;
            fractal.domain[2] = topRight;
            fractal.domain[3] = topLeft;
        }