如果我有这个代码段:
glm::mat4 someMatrix(1.0f);
GLfloat * a = glm::value_ptr(someMatrix);
如何解码变量'a'中的值。我知道值是someMatrix,但是好奇心的jus是可能的,我可以通过解码变量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
但我不知道如何获得矩阵及其值。这个问题可能毫无意义,因为显然我已经知道矩阵的价值,但仅仅是为了好奇心我想知道是否可以解码。无论如何。提前谢谢。
答案 0 :(得分:1)
通过“解码”我假设你指的是阅读矩阵的每个单独元素。
如果是为了打印,你可以这样做:
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