예제 #1
0
        /// <summary>
        /// Requires Col(3)==UnitW
        /// </summary>
        public Matrix4f AppendTranslation(Vector3f v)
        {
            Matrix4f result = this;

            result.row3 += new Vector4f(v, 0);
            return(result);
        }
예제 #2
0
        public static Matrix4f CreatePerspective2(float fx, float fy, float near, float far)
        {
            Matrix4f result = Matrix4f.Zero;

            result[0, 0] = fx;
            result[1, 1] = fy;
            result[2, 2] = (far + near) / (far - near);
            result[2, 3] = 2 * far * near / (near - far);
            result[3, 2] = -1;
            return(result);
        }
예제 #3
0
        public static Matrix4f operator *(Matrix4f mL, Matrix4f mR)
        {
            Matrix4f result = Matrix4f.Zero;

            for (int row = 0; row < 4; row++)
            {
                for (int col = 0; col < 4; col++)
                {
                    result[row, col] = mL.Row(row) * mL.Col(col);
                }
            }
            return(result);
        }
예제 #4
0
        public static Matrix4f CreateRotation(float angle, Vector3f axis)
        {
            Vector3f u      = axis.Normalized;
            float    c      = (float)Math.Cos(angle);
            float    s      = (float)Math.Sin(angle);
            Matrix4f result = Matrix4f.Identity;

            result[0, 0] = u.X * u.X + (1 - u.X * u.X) * c;
            result[0, 1] = u.X * u.Y * (1 - c) - u.Z * s;
            result[0, 2] = u.X * u.Z * (1 - c) + u.Y * s;
            result[1, 0] = u.X * u.Y * (1 - c) + u.Z * s;
            result[1, 1] = u.Y * u.Y + (1 - u.Y * u.Y) * c;
            result[1, 2] = u.Y * u.Z * (1 - c) - u.X * s;
            result[2, 0] = u.X * u.Z * (1 - c) - u.Y * s;
            result[2, 1] = u.Y * u.Z * (1 - c) + u.X * s;
            result[2, 2] = u.Z * u.Z + (1 - u.Z * u.Z) * c;
            return(result);
        }