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

Adding matrices

Two matrices can be added together by component. To add two matrices together, sum their respective components and store the result in a new matrix. Matrix addition can be used with scalar multiplication to interpolate or blend between multiple matrices. Later, you will learn how to use this property to implement animation skinning.

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

mat4 operator+(const mat4& a, const mat4& b) {

    return mat4(

        a.xx+b.xx, a.xy+b.xy, a.xz+b.xz, a.xw+b.xw,

        a.yx+b.yx, a.yy+b.yy, a.yz+b.yz, a.yw+b.yw,

        a.zx+b.zx, a.zy+b.zy, a.zz+b.zz, a.zw+b.zw,

        a.tx+b.tx, a.ty+b.ty, a.tz+b.tz, a.tw+b.tw

    );

}

Matrix addition is simple but it will play a big role in displaying an animated mesh. In the next section, you will learn how to scale a matrix by a scalar value.

主站蜘蛛池模板: 黑水县| 佛教| 林芝县| 科技| 彭州市| 屏山县| 河池市| 邛崃市| 交口县| 彭阳县| 凤凰县| 宁德市| 溧水县| 视频| 应城市| 贡觉县| 沾化县| 科技| 宝应县| 托里县| 精河县| 临漳县| 武宁县| 宁海县| 太谷县| 建湖县| 密山市| 林甸县| 东丽区| 巴林右旗| 塔河县| 丹阳市| 凤城市| 浙江省| 湖口县| 恭城| 汉中市| 古浪县| 班戈县| 海丰县| 福清市|