glm::mat4 构造函数如何工作?

How does glm::mat4 constructor works?

这行代码是如何工作的?

glm::mat4 trans = glm::mat4(1.0f);

为什么我必须只传递一个浮点数,矩阵是什么样子的?

OpenGL Mathematics (GLM) API documentation is based on OpenGL Shading Language (GLSL) and refers to The OpenGL Shading Language specification.

5.4.2 Vector and Matrix Constructors

[...] If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix's diagonal, with the remaining components initialized to 0.0.

一个Identity matrix可以通过单个参数1.0初始化。
如果将 0.0 作为单个参数传递,则矩阵中的所有字段都是 0.0,这是毫无用处的。 默认构造函数未初始化矩阵的字段。

一般用一个矩阵(m)来变换一个向量(v' = m * v)。如果矩阵的所有域都是 0.0,则结果向量 (v') 的所有分量也都是 0.0。