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

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.

主站蜘蛛池模板: 集贤县| 潮州市| 天全县| 绍兴县| 敦煌市| 梨树县| 临武县| 韶关市| 冷水江市| 青龙| 呼伦贝尔市| 招远市| 喀什市| 景泰县| 广平县| 娱乐| 金堂县| 义乌市| 亳州市| 林西县| 云林县| 三明市| 阳西县| 龙海市| 青河县| 洞口县| 辛集市| 山东省| 桐庐县| 横山县| 辽宁省| 广安市| 毕节市| 石渠县| 弥渡县| 四子王旗| 红桥区| 中山市| 临泽县| 收藏| 大理市|