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

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.

主站蜘蛛池模板: 碌曲县| 固镇县| 连云港市| 中卫市| 伽师县| 冷水江市| 沐川县| 无为县| 瑞昌市| 苏尼特右旗| 临安市| 乌鲁木齐县| 南京市| 乐东| 建湖县| 桑日县| 东山县| 冷水江市| 望奎县| 甘德县| 辉县市| 福州市| 大埔区| 张家港市| 江孜县| 鹤岗市| 昆明市| 赤城县| 通许县| 习水县| 临江市| 隆安县| 武义县| 遵义市| 鹿泉市| 十堰市| 博白县| 嘉义县| 如东县| 搜索| 阿合奇县|