官术网_书友最值得收藏!

Transpose

To transpose a matrix, flip every element of the matrix across its main diagonal. For example, the 2, 1 element would become the 1, 2 element. Elements where both subscripts are the same, such as 1, 1, will remain the same:

  1. Implement the transpose function in mat4.cpp. Don't forget to add the function declaration to mat4.h:

    #define M4SWAP(x, y) \

        {float t = x; x = y; y = t; }

    void transpose(mat4 &m) {

        M4SWAP(m.yx, m.xy);

        M4SWAP(m.zx, m.xz);

        M4SWAP(m.tx, m.xw);

        M4SWAP(m.zy, m.yz);

        M4SWAP(m.ty, m.yw);

        M4SWAP(m.tz, m.zw);

    }

  2. Create a transposed function in mat4.cpp. The transposed function modifies a matrix that is passed into it. Don't forget to add the function declaration to mat4.h:

    mat4 transposed(const mat4 &m) {

        return mat4(

            m.xx, m.yx, m.zx, m.tx,

            m.xy, m.yy, m.zy, m.ty,

            m.xz, m.yz, m.zz, m.tz,

            m.xw, m.yw, m.zw, m.tw

        );

    }

Transposing a matrix is useful if you need to convert a matrix from row-major to column-major or the other way around. In the next section, you will learn how to calculate the determinant of a square matrix.

主站蜘蛛池模板: 海阳市| 三明市| 新野县| 景宁| 都匀市| 晋江市| 蛟河市| 定边县| 栾川县| 铜山县| 米脂县| 紫金县| 富平县| 乐安县| 恩平市| 屏东市| 象山县| 德保县| 舟曲县| 庆元县| 苍梧县| 新源县| 清河县| 玉田县| 宜兴市| 苏尼特左旗| 天等县| 金湖县| 浦城县| 建德市| 颍上县| 余姚市| 留坝县| 阿图什市| 黔西县| 马山县| 胶州市| 汉沽区| 民丰县| 南川市| 庆元县|