In chapter 04 file sceneproj.tex line 47 zero matrix
pfaloutsos opened this issue · comments
mat4() should be mat(1.0f). The original generates a zero matrix.
The default constructor produces the identity matrix. Example:
mat4 m;
for( int r = 0; r < 4; r++ ) {
for( int c = 0; c < 4; c++ ) {
cout << m[c][r] << " ";
}
cout << endl;
}
Output:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
I get the same result for the code you posted. However for the code below I '0's:
mat4 projScaleTrans = glm::translate(mat4(), vec3(0.5f)) * glm::scale(mat4(1.0f), vec3(0.5f));
for( int r = 0; r < 4; r++ ) {
for( int c = 0; c < 4; c++ ) {
cout << projScaleTrans[c][r] << " ";
}
cout << endl;
}
Output:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
And no projected texture appears on the object. If I change mat4() to mat4(1.0f) then I get the correct result.
That's odd, I ran the same code and I got:
0.5 0 0 0.5
0 0.5 0 0.5
0 0 0.5 0.5
0 0 0 1
What version of GLM are you using? If it's an older version, perhaps try the latest?
I use glm 0.9.4 on OSX 10.13.3. it must be my set up. I checked with my students that run it on Windows and none of them face this issue. I guess we can close this issue. Thank you for your prompt responses though!
Ok. Thanks.
It turns out that as of GLM 0.9.9.0, the default constructor no longer initializes it to the identity matrix. We need to find all instances that rely on this and fix them.
Main development on these examples is moving to the 3rd edition: https://github.com/PacktPublishing/OpenGL-4-Shading-Language-Cookbook-Third-Edition
If you find any additional problems, related to this GLM issue, please either move to the 3rd edition, or file a pull request.