Пример #1
0
        /*
         * Calculates the pespective screensize
         */

        public float GetScreenSize()
        {
            var tan      = GonioFactory.GetTrigonometricByDegrees(_fieldOfView / 2, Trigonometric.Tangent);
            var halfSize = tan * _far;

            return(halfSize * 2);
        }
Пример #2
0
        /*
         * Returns a 3D rotation matrix, over a vector, or a vector through the origin
         */
        public static Matrix Get3DRotationMatrix(float alpha, Vector rotationVector, Point translateOver = null)
        {
            Matrix rotationMatrix = new Matrix(4, 4);

            rotationMatrix.MakeIdentityMatrix();

            if (translateOver != null)
            {
                Matrix translation =
                    GetTranslationMatrix(-translateOver.GetX(), -translateOver.GetY(), -translateOver.GetZ(), true);
                translation.Multiply(rotationMatrix);
                rotationMatrix = translation;
            }

            float t1        = GonioFactory.GetArcTrigonometricByRadians(rotationVector.GetZ(), rotationVector.GetX(), Trigonometric.Tangent2);
            var   yRotation = MatrixFactory.Rotate3DYAxis(t1, true);

            yRotation.Multiply(rotationMatrix);
            rotationMatrix = yRotation;

            float newX      = (float)Math.Sqrt(rotationVector.GetX() * rotationVector.GetX() + rotationVector.GetZ() * rotationVector.GetZ());
            float t2        = GonioFactory.GetArcTrigonometricByRadians(rotationVector.GetY(), newX, Trigonometric.Tangent2);
            var   zRotation = MatrixFactory.Rotate3DZAxis(t2, true);

            zRotation.Multiply(rotationMatrix);
            rotationMatrix = zRotation;

            Matrix rotate = MatrixFactory.Rotate3DXAxis(GonioFactory.DegreesToRadians(alpha), false);

            rotate.Multiply(rotationMatrix);
            rotationMatrix = rotate;

            var reverseZRotation = MatrixFactory.Rotate3DZAxis(t2, false);

            reverseZRotation.Multiply(rotationMatrix);
            rotationMatrix = reverseZRotation;

            var reverseYRotation = MatrixFactory.Rotate3DYAxis(t1, false);

            reverseYRotation.Multiply(rotationMatrix);
            rotationMatrix = reverseYRotation;

            if (translateOver != null)
            {
                Matrix translation = GetTranslationMatrix(translateOver.GetX(), translateOver.GetY(), translateOver.GetZ(), true);
                translation.Multiply(rotationMatrix);
                rotationMatrix = translation;
            }

            return(rotationMatrix);
        }
Пример #3
0
        /*
         * Returns a 2D rotation matrix.
         */
        public static Matrix Rotate2D(float alpha)
        {
            Matrix rotationMatrix = new Matrix(2, 2);

            float cos = GonioFactory.GetTrigonometricByDegrees(alpha, Trigonometric.Cosine);
            float sin = GonioFactory.GetTrigonometricByDegrees(alpha, Trigonometric.Sine);

            float[,] data =
            {
                { cos, -sin },
                { sin, cos  }
            };

            rotationMatrix.SetData(data);

            return(rotationMatrix);
        }
Пример #4
0
        /*
         * Returns a 3D matrix based on the Z axis
         */
        public static Matrix Rotate3DZAxis(float alpha, bool reverse)
        {
            Matrix rotationMatrix = new Matrix(4, 4);

            float cos = GonioFactory.GetTrigonometricByRadians(alpha, Trigonometric.Cosine);
            float sin = GonioFactory.GetTrigonometricByRadians(alpha, Trigonometric.Sine);

            if (reverse)
            {
                sin = -sin;
            }

            float[,] data =
            {
                { cos, -sin, 0, 0 },
                { sin, cos,  0, 0 },
                {   0,    0, 1, 0 },
                {   0,    0, 0, 1 }
            };

            rotationMatrix.SetData(data);

            return(rotationMatrix);
        }
Пример #5
0
        /*
         * Calculates the scale based on the fieldofview and the near variable
         */
        public float GetScale()
        {
            var rad = GonioFactory.DegreesToRadians(_fieldOfView);

            return(_near * GonioFactory.GetTrigonometricByRadians(rad * 0.5f, Trigonometric.Tangent));
        }