CgExamples.Gl_14_bulge.buildPerspectiveMatrix C# (CSharp) Метод

buildPerspectiveMatrix() статический приватный Метод

static private buildPerspectiveMatrix ( double fieldOfView, double aspectRatio, double zNear, double zFar, float &m ) : void
fieldOfView double
aspectRatio double
zNear double
zFar double
m float
Результат void
        static void buildPerspectiveMatrix(double fieldOfView,
                                   double aspectRatio,
                                   double zNear, double zFar,
                                   ref float[] m)
        {
            double sine, cotangent, deltaZ;
            double radians = fieldOfView / 2.0 * Math.PI / 180.0;

            deltaZ = zFar - zNear;
            sine = Math.Sin(radians);
            /* Should be non-zero to avoid division by zero. */
            Debug.Assert(deltaZ != 0);
            Debug.Assert(sine != 0);
            Debug.Assert(aspectRatio != 0);
            cotangent = Math.Cos(radians) / sine;

            m[0 * 4 + 0] = (float)(cotangent / aspectRatio);
            m[1 * 4 + 0] = 0.0f;
            m[2 * 4 + 0] = 0.0f;
            m[3 * 4 + 0] = 0.0f;

            m[0 * 4 + 1] = 0.0f;
            m[1 * 4 + 1] = (float)cotangent;
            m[2 * 4 + 1] = 0.0f;
            m[3 * 4 + 1] = 0.0f;

            m[0 * 4 + 2] = 0.0f;
            m[1 * 4 + 2] = 0.0f;
            m[2 * 4 + 2] = (float)(-(zFar + zNear) / deltaZ);
            m[3 * 4 + 2] = (float)(-2 * zNear * zFar / deltaZ);

            m[0 * 4 + 3] = 0.0f;
            m[1 * 4 + 3] = 0.0f;
            m[2 * 4 + 3] = -1f;
            m[3 * 4 + 3] = 0f;
        }