代码之家  ›  专栏  ›  技术社区  ›  user2023370

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

  •  1
  • user2023370  · 技术社区  · 7 年前

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

    另一方面,我可以看到接近GLM的顶部 type_mat4x4.inl 存在一个将内容设置为单位矩阵的定义。(这在我上面描述的两个构建中是有条件排除的)我的同事告诉我 在他的系统上确实产生了一个单位矩阵。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Ripi2 user10587824    7 年前

    GLM site

    GLM提供了用

    以及 GLSL spec

    如果矩阵构造函数只有一个标量参数,则为 其余组件初始化为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允许并且一直允许通过使用一些 #define glm::mat4() 永远都是零。