如何乘以C++中的4x4浮点矩阵?
我有一个简单的结构“mat4”,由float [4] [4]和* =组成,用于乘以4x4矩阵。这需要一个const MAT4 &“RHS”如下:如何乘以C++中的4x4浮点矩阵?
this->m[0][0] = this->m[0][0] * rhs[0][0] + this->m[0][1] * rhs[1][0] + this->m[0][2] * rhs[2][0] + this->m[0][3] * rhs[3][0]; this->m[0][1] = this->m[0][0] * rhs[0][1] + this->m[0][1] * rhs[1][1] + this->m[0][2] * rhs[2][1] + this->m[0][3] * rhs[3][1];
this->m[0][2] = this->m[0][0] * rhs[0][2] + this->m[0][1] * rhs[1][2] + this->m[0][2] * rhs[2][2] + this->m[0][3] * rhs[3][2];
this->m[0][3] = this->m[0][0] * rhs[0][3] + this->m[0][1] * rhs[1][3] + this->m[0][2] * rhs[2][3] + this->m[0][3] * rhs[3][3];
this->m[1][0] = this->m[1][0] * rhs[0][0] + this->m[1][1] * rhs[1][0] + this->m[1][2] * rhs[2][0] + this->m[1][3] * rhs[3][0];
this->m[1][1] = this->m[1][0] * rhs[0][1] + this->m[1][1] * rhs[1][1] + this->m[1][2] * rhs[2][1] + this->m[1][3] * rhs[3][1];
this->m[1][2] = this->m[1][0] * rhs[0][2] + this->m[1][1] * rhs[1][2] + this->m[1][2] * rhs[2][2] + this->m[1][3] * rhs[3][2];
this->m[1][3] = this->m[1][0] * rhs[0][3] + this->m[1][1] * rhs[1][3] + this->m[1][2] * rhs[2][3] + this->m[1][3] * rhs[3][3];
this->m[2][0] = this->m[2][0] * rhs[0][0] + this->m[2][1] * rhs[1][0] + this->m[2][2] * rhs[2][0] + this->m[2][3] * rhs[3][0];
this->m[2][1] = this->m[2][0] * rhs[0][1] + this->m[2][1] * rhs[1][1] + this->m[2][2] * rhs[2][1] + this->m[2][3] * rhs[3][1];
this->m[2][2] = this->m[2][0] * rhs[0][2] + this->m[2][1] * rhs[1][2] + this->m[2][2] * rhs[2][2] + this->m[2][3] * rhs[3][2];
this->m[2][3] = this->m[2][0] * rhs[0][3] + this->m[2][1] * rhs[1][3] + this->m[2][2] * rhs[2][3] + this->m[2][3] * rhs[3][3];
this->m[3][0] = this->m[3][0] * rhs[0][0] + this->m[3][1] * rhs[1][0] + this->m[3][2] * rhs[2][0] + this->m[3][3] * rhs[3][0];
this->m[3][1] = this->m[3][0] * rhs[0][1] + this->m[3][1] * rhs[1][1] + this->m[3][2] * rhs[2][1] + this->m[3][3] * rhs[3][1];
this->m[3][2] = this->m[3][0] * rhs[0][2] + this->m[3][1] * rhs[1][2] + this->m[3][2] * rhs[2][2] + this->m[3][3] * rhs[3][2];
this->m[3][3] = this->m[3][0] * rhs[0][3] + this->m[3][1] * rhs[1][3] + this->m[3][2] * rhs[2][3] + this->m[3][3] * rhs[3][3];
我只是想确认是否是正确与否 - 当我将两个矩阵相乘在C++(投影*视图矩阵)和将得到的矩阵交给着色器,屏幕上什么都没有显示出来。
但是,如果我分别给出着色器投影&查看矩阵,并将它们乘以GLSL - 那么它一切正常,结果如预期。
所以矩阵乘法函数一定有问题吗?
回答:
不应
this->m[0][1] = this->m[0][0] * rhs[0][1] + this->m[0][1] * rhs[1][1] + this->m[0][2] * rhs[2][1] + this->m[0][3] * rhs[3][1];
由RHS被乘以[1] [0] .. RHS [1] [3]?当你逐步浏览这些行时,你不会穿过rhs的列。
以上是 如何乘以C++中的4x4浮点矩阵? 的全部内容, 来源链接: utcz.com/qa/258696.html