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

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.

主站蜘蛛池模板: 靖边县| 凯里市| 乃东县| 汶川县| 抚松县| 盐边县| 酉阳| 虹口区| 广东省| 宁陕县| 富锦市| 南岸区| 张掖市| 阿拉善盟| 南澳县| 滨州市| 栾川县| 车致| 阿瓦提县| 库尔勒市| 兴海县| 永昌县| 马山县| 金湖县| 通道| 六盘水市| 青浦区| 玉屏| 山阳县| 西林县| 都昌县| 苏尼特右旗| 武清区| 房产| 永德县| 宿松县| 蒲江县| 凤翔县| 高邮市| 思南县| 乌鲁木齐市|