遊戲開發中的數學和物理算法(15):矩陣的加減法
Matrix3X3 addMatrices(Matrix3X3 a, Matrix3X3 b)
{
Matrix3X3 temp;
for(int i = 0;i<3;i++)
{
for(int j=0;j<3;j++)
{
temp.index[i][j] = (a.index[i][j] + b.index[i][j]);
}
}
return temp;
}
計算機中矩陣減法的實現:
Matrix4X4 subtractMatrices(Matrix4X4 a, Matrix4X4 b)
{
Matrix4X4 temp;
for(int i = 0;i<4;i++)
{
for(int j=0;j<4;j++)
{
temp.index[i][j] = (a.index[i][j] - b.index[i][j]);
}
}
return temp;
}