Пример #1
0
        public static Matrix4F Ortho(float left, float right, float bottom, float top, float near, float far)
        {
            var matrix = default(Matrix4F);
            var rml    = right - left;
            var fmn    = far - near;
            var tmb    = top - bottom;

            // ReSharper disable CompareOfFloatsByEqualityOperator
            if (rml == 0.0 || fmn == 0.0 || tmb == 0.0)
            {
                throw new Exception("Invalid matrix");
            }

            var _1OverRml = 1.0f / rml;
            var _1OverFmn = 1.0f / fmn;
            var _1OverTmb = 1.0f / tmb;

            matrix.Row0 = Vector4f.Create(2.0f * _1OverRml, 0, 0, 0);
            matrix.Row1 = Vector4f.Create(0, 2.0f * _1OverTmb, 0, 0);
            matrix.Row2 = Vector4f.Create(0, 0, -2.0f * _1OverFmn, 0);
            matrix.Row3 = Vector4f.Create(
                -(right + left) * _1OverRml,
                -(top + bottom) * _1OverTmb,
                -(far + near) * _1OverFmn,
                1.0f
                );

            return(matrix);
        }
Пример #2
0
 public Vector4f Column(int n)
 {
     return(Vector4f.Create(Row0[n], Row1[n], Row2[n], Row3[n]));
 }