繁体   English   中英

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

[英]Why does this not work (glm::make_mat4)?

我有以下代码:

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]传递给期望pointer to 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM