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

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.

主站蜘蛛池模板: 鹤峰县| 城步| 长乐市| 大田县| 渝北区| 招远市| 体育| 昌黎县| 化州市| 积石山| 修武县| 哈巴河县| 兴文县| 宽甸| 宜阳县| 板桥市| 定襄县| 正阳县| 孟州市| 手游| 阜新市| 永安市| 阿城市| 鸡东县| 准格尔旗| 祁门县| 滨州市| 松滋市| 柘荣县| 临颍县| 嘉定区| 图木舒克市| 屯留县| 鞍山市| 岑巩县| 鹤峰县| 海城市| 云阳县| 临泉县| 汉沽区| 乃东县|