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

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.

主站蜘蛛池模板: 紫金县| 图木舒克市| 汶川县| 华安县| 孝感市| 重庆市| 曲麻莱县| 天津市| 石林| 岐山县| 山丹县| 广元市| 山东省| 江源县| 永登县| 垫江县| 平昌县| 漳浦县| 鄂托克前旗| 安溪县| 江山市| 盐山县| 德江县| 宜丰县| 搜索| 东平县| 和田市| 大新县| 肃南| 偃师市| 晋宁县| 武穴市| 类乌齐县| 尼玛县| 翁牛特旗| 娱乐| 上林县| 健康| 即墨市| 盐边县| 永宁县|