通过零参数构造函数生成的 glm::mat4 应该包含哪些值?

What values should a glm::mat4 made via a zero argument constructor contain?

通过零参数构造函数生成的 glm::mat4 应该包含哪些值?在 64 位 Windows 10 上,使用通过 vcpkg 安装的 64 位 GLM v0.9.9.0,glm::mat4() 的结果是一个用零填充的 4x4 矩阵。这与具有默认 GLM 的 64 位 Ubuntu 18.04 LTS 相同。

另一方面,我可以在 GLM 的 type_mat4x4.inl 顶部附近看到存在一个定义,该定义将内容设置为等于单位矩阵。 (这在我上面描述的两个构建中有条件地被排除在外。)虽然我的同事告诉我,在他的系统上调用 glm::mat4() 确实会产生一个单位矩阵。

这些差异是否反映了 GLM 最近的变化?也就是说,如果我们都使用最新版本的 GLM,差异会消失吗?或者,GLM 是否会在两个不同的系统上产生两个不同的结果?

来自GLM site

GLM provides classes and functions designed and implemented with the same naming conventions and functionalities than GLSL

GLSL spec

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.

因此,glm::mat4() 是全零矩阵,glm::mat4(1) 是单位矩阵。

在 0.9.9 之前的 GLM 版本中,您可以在 type_mat4x4.inl

中找到
#   if !GLM_HAS_DEFAULTED_FUNCTIONS || !defined(GLM_FORCE_NO_CTOR_INIT)
            template <typename T, precision P>
            GLM_FUNC_QUALIFIER tmat4x4<T, P>::tmat4x4()
            {
#           ifndef GLM_FORCE_NO_CTOR_INIT 
                this->value[0] = col_type(1, 0, 0, 0);
                this->value[1] = col_type(0, 1, 0, 0);
                this->value[2] = col_type(0, 0, 1, 0);
                this->value[3] = col_type(0, 0, 0, 1);
#           endif
            }
#   endif

this has changed in 0.9.9

#   if GLM_CONFIG_DEFAULTED_FUNCTIONS == GLM_DISABLE
        template<typename T, qualifier Q>
        GLM_FUNC_QUALIFIER GLM_CONSTEXPR mat<4, 4, T, Q>::mat()
#           if GLM_CONFIG_CTOR_INIT == GLM_CTOR_INITIALIZER_LIST
                : value{col_type(1, 0, 0, 0), col_type(0, 1, 0, 0), col_type(0, 0, 1, 0), col_type(0, 0, 0, 1)}
#           endif
        {
#           if GLM_CONFIG_CTOR_INIT == GLM_CTOR_INITIALISATION
                this->value[0] = col_type(1, 0, 0, 0);
                this->value[1] = col_type(0, 1, 0, 0);
                this->value[2] = col_type(0, 0, 1, 0);
                this->value[3] = col_type(0, 0, 0, 1);
#           endif
        }
# endif

换句话说:GLM 允许并且一直允许通过玩一些 #defines 来更改默认的 GLSL 初始化。否则,glm::mat4() 将始终为全零。