我有这个代码:
glm::mat4 aLookAt(const glm::vec3& Eye, const glm::vec3& Center, const glm::vec3& Up)
{
glm::vec3 Z = glm::normalize(Eye - Center);
glm::vec3 Y = Up;
glm::vec3 X = glm::normalize(glm::cross(Y, Z));
Y = glm::normalize(glm::cross(Z, X));
float Matrix[4][4];
Matrix[0][0] = X.x;
Matrix[1][0] = X.y;
Matrix[2][0] = X.z;
Matrix[3][0] = (float)glm::dot(-X, Eye);
Matrix[0][1] = Y.x;
Matrix[1][1] = Y.y;
Matrix[2][1] = Y.z;
Matrix[3][1] = (float)glm::dot(-Y, Eye);
Matrix[0][2] = Z.x;
Matrix[1][2] = Z.y;
Matrix[2][2] = Z.z;
Matrix[3][2] = (float)glm::dot(Z, Eye);
Matrix[0][3] = 0;
Matrix[1][3] = 0;
Matrix[2][3] = 0;
Matrix[3][3] = 1.0f;
glm::mat4 theMatrix = glm::make_mat4(Matrix);
return theMatrix;
}
但是每当我尝试编译它时,它都会出现以下错误:
为什么?这次我真的没有预料到错误..
最佳答案
编译器告诉你原因。您正在将 float[4][4]
传递给需要 float 指针
的方法:
template<typename T >
detail::tmat4x4< T > make_mat4 (T const *const ptr)
这些类型不兼容。您需要一个 float[16]
来代替:
float Matrix[16];
Matrix[0] = X.x;
Matrix[1] = X.y;
Matrix[2] = X.z;
Matrix[3] = (float)glm::dot(-X, Eye);
Matrix[4] = Y.x;
Matrix[5] = Y.y;
Matrix[6] = Y.z;
Matrix[7] = (float)glm::dot(-Y, Eye);
Matrix[8] = Z.x;
Matrix[9] = Z.y;
Matrix[10] = Z.z;
Matrix[11] = (float)glm::dot(Z, Eye);
Matrix[12] = 0;
Matrix[13] = 0;
Matrix[14] = 0;
Matrix[15] = 1.0f;
关于c++ - 为什么这不起作用(glm::make_mat4)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49990547/