glm::vec3和glm::mat4如何初始化?

3
这是关于理解glm源代码的问题。我想知道glm是否会对其类进行零初始化,并尝试了一下。是的,即使没有提供构造函数值,glm :: vec3 glm :: mat4 也会被初始化。然后我想了解它是如何实现的,并阅读了glm :: mat4 模板的源代码。
有这个部分:
...
enum ctor{null};

// Constructors
GLM_FUNC_DECL tmat4x4();
GLM_FUNC_DECL tmat4x4(tmat4x4 const & m);
GLM_FUNC_DECL explicit tmat4x4(ctor Null);
...

我看到一个没有定义的 (void) 构造函数(ctor),所以没有 {...} 部分。还有一个显式的构造函数,使用 enum ctor 类型的第一个元素 0 作为参数,当然得到索引值 0
  • 构造函数定义在哪里?我该如何找到它们?
  • 那个显式的 Null 构造函数是用来做什么的?
  • 当我只写 glm::mat4 myMatrix; 时,glm::mat4 怎样初始化为单位矩阵?

编辑:在 GitHub 上浏览更多当前的源文件,从 mat4x4.hppdetail/type_mat4x4.hpp,其中 #includetype_mat4x4.inl中包含实现细节。在那里,构造函数的行为变得可见。


你可能使用了错误的标签,应该是 [tag:glm-math]。 - undefined
谢谢,已经修改了。 - undefined
3个回答

6

1
  • 它在"glm/detail/type_mat4x4.inl"
  • 这是一个什么也不做的构造函数,在0.9.6.3中变成了enum ctor{uninitialize}
  • 它调用默认构造函数

顺便说一句,我无法下载你的版本,这个答案是基于0.9.6.3版本的。


谷歌把我导向了旧版本的9.2。我刚刚更新到了9.8.3。GLM手册PDF清楚地解释了初始化规则。现在GLM代码也容易理解了:ctor()实现的:tmat4x4()很容易展示了初始化,ifndef GLM_FORCE_NO_CTOR_INIT.... - undefined
在0.9.8版本中,似乎仍然是默认初始化的,而在GitHub的主分支上不再是这种情况。 - undefined

1
glm::mat4x4 view{ 2 / (right - left), 0, 0, 0,
            0, 2 / (top - bottom), 0, 0,
            0, 0, -2 / (farplane - nearplane), 0,
            -((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((farplane + nearplane) / (farplane - nearplane)), 1
        };


glm::mat4 view{ 2 / (right - left), 0, 0, 0,
            0, 2 / (top - bottom), 0, 0,
            0, 0, -2 / (farplane - nearplane), 0,
            -((right + left) / (right - left)), -((top + bottom) / (top - bottom)), -((farplane + nearplane) / (farplane - nearplane)), 1
        };

glm::uvec4 ViewPort(0,0,0,0);

glm::vec3 Origin(0.0f, 0.0f, 0.0f);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接