예제 #1
0
        /** @return Matrice di scalatura anisotropica */
        public static Mat4 Scaling(float sx, float sy, float sz)
        {
            Mat4 n = Identity();

            n.SetElement(0, 0, sx);
            n.SetElement(1, 1, sy);
            n.SetElement(2, 2, sz);

            return(n);
        }
예제 #2
0
        /** @return Matrice di traslazione */
        public static Mat4 Translation(float dx, float dy, float dz)
        {
            Mat4 n = Identity();

            n.SetElement(0, 3, dx);
            n.SetElement(1, 3, dy);
            n.SetElement(2, 3, dz);

            return(n);
        }
예제 #3
0
        /** @return Matrice di rotazione rispetto all'asse Z */
        public static Mat4 RotatationZ(float angleDegrees)
        {
            Mat4  n = Identity();
            float s = (float)Math.Sin(angleDegrees * (PI / 180f));
            float c = (float)Math.Cos(angleDegrees * (PI / 180f));

            n.SetElement(0, 0, c);
            n.SetElement(0, 1, +s);
            n.SetElement(1, 0, -s);
            n.SetElement(1, 1, c);

            return(n);
        }
예제 #4
0
        ///** @return Matrice per centrare in (0,0,0) un'AABB */
        //public static Mat4 CenterAABB(AABB aabb)
        //{
        //    Mat4 m = Mat4.Identity();

        //    m = m.Dot(Mat4.Translation(-aabb.center().x(), -aabb.center().y(), -aabb.center().z())
        //    );
        //    return m;
        //}

        /** @return Inversa della matrice di proiezione prospettica */
        public static Mat4 InversePerspective(float focal, float near, float far)
        {
            Mat4 res = Identity();

            float A = (far + near) / (focal * (near - far));
            float B = (2 * far * near) / (focal * (near - far));

            res.SetElement(2, 2, 0);
            res.SetElement(3, 2, 1 / B);
            res.SetElement(2, 3, -focal);
            res.SetElement(3, 3, focal * A / B);

            return(res);
        }
예제 #5
0
        /** @return Matrice di proiezione prospettica che rimappa z da [near .. far] a [-1 .. +1] */
        public static Mat4 Perspective(float focal, float near, float far)
        {
            Mat4 res = Identity();

            float A = (far + near) / (focal * (near - far));
            float B = (2 * far * near) / (focal * (near - far));

            res.SetElement(3, 3, 0);
            res.SetElement(3, 2, -1 / focal);
            res.SetElement(2, 2, A);
            res.SetElement(2, 3, B);

            return(res);
        }
예제 #6
0
        /**
         * Prodotto tra matrici
         * @param m2 seconda matrice
         * @return matrice risultante this*m2
         */
        public Mat4 Dot(Mat4 m2)
        {
            Mat4 n = new Mat4();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    n.SetElement(i, j,
                                 this.Row(i).Dot(m2.Column(j))
                                 );
                }
            }

            return(n);
        }
예제 #7
0
        /**
         * Prodotto tra matrici
         * @param m2 seconda matrice
         * @return matrice risultante this*m2
         */
        public Mat4 Dot(Mat4 m2)
        {
            Mat4 n = new Mat4();

            for (int i = 0; i < 4; i++)
                for (int j = 0; j < 4; j++)
                    n.SetElement(i, j,
                            this.Row(i).Dot(m2.Column(j))
                    );

            return n;
        }