如何解码存储 glm::value_ptr() 返回值的变量值?

How to decode the value of the variable that stores the value returned from glm::value_ptr()?

如果我有这段代码:

glm::mat4 someMatrix(1.0f);

GLfloat * a = glm::value_ptr(someMatrix);

如何解码变量 'a' 中的值。我知道这个值是 someMatrix 但出于好奇,我可以通过解码变量 a 来获得相同的 Matrix 值吗?我试过这个:

std::cout<<"value: "<< a <<"\n";   // It throws me the address : 0x7fff609e91f0
std::cout<<"value: "<< *a <<"\n"; // It gives me this value: 8.88612e-39

但我不知道如何获取矩阵及其值。这个问题可能毫无意义,因为显然我已经知道矩阵的值,但出于好奇我想知道是否可以解码。反正。提前致谢。

"decoding" 我假设您指的是读取矩阵的每个单独元素。

如果是为了打印你可以这样做:

glm::mat4 someMatrix(1.0f);
std::cout << glm::to_string(someMatrix) << std::endl;

如果你坚持使用glm::value_ptr的结果。

glm::mat4 someMatrix(1.0f);
GLfloat *a = glm::value_ptr(someMatrix);

for (int j = 0; j < 4; ++j) {
    for (int i = 0; i < 4; ++i) {
        std::cout << a[j * 4 + i] << " ";
    }
    std::cout << std::endl;
}

someMatrix 将打印:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1