1

Lets say we have:

Vector3 vec;//has some random values
Matrix4x4 mat;//has some random values as well

Now I want to multiply them to get a Vector3 out of it.

Vector3 mult = vec * mat;

Would this function fulfill that:

void Matrix4x4::Transform( Vector3 &oPoint )
{
    float fX = oPoint.GetX();
    float fY = oPoint.GetY();
    float fZ = oPoint.GetZ();

    oPoint.SetX( fX * this->matrix[0][0] + fY * this->matrix[0][1] + fZ * this->matrix[0][2] + this->matrix[0][3]);
    oPoint.SetY( fX * this->matrix[1][0] + fY * this->matrix[1][1] + fZ * this->matrix[1][2] + this->matrix[1][3]);
    oPoint.SetZ( fX * this->matrix[2][0] + fY * this->matrix[2][1] + fZ * this->matrix[2][2] + this->matrix[2][3]);
}

If not, can you lead me in the right direction.

4

1 回答 1

1

你的代码似乎没问题。我假设,当您使用 OpenGL 时,您的矩阵按列优先顺序排列,并且当您想在 4x4 矩阵上乘以大小为 3 的向量时,您的第四个向量坐标为1.

但是,由于您显然是在做计算机图形学,由于同质坐标,您应该使用大小为 4 的向量。我也不太明白,为什么要在矩阵上乘向量,反之亦然。

于 2012-10-04T16:38:27.440 回答