Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么这不起作用(glm::make_mat4)?_C++_Opengl_Glm Math - Fatal编程技术网

C++ 为什么这不起作用(glm::make_mat4)?

C++ 为什么这不起作用(glm::make_mat4)?,c++,opengl,glm-math,C++,Opengl,Glm Math,我有以下代码: 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::normali

我有以下代码:

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)

这个错误出现在哪一行?当我删除行
glm::mat4 theMatrix=glm::make_mat4(矩阵)时,错误消失了啊,谢谢!但是float[16]和float[4][4]之间有什么区别呢?它们都是类型和大小相同的数组?一个是由16个float组成的数组,一个是由4个float组成的4个数组。前者将衰减为指向浮点的指针,后者将衰减为指向浮点的指针[4]。是的,它们尺寸相同,但类型不同。
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;