[英]How are glm::vec3 and glm::mat4 initialised?
This is about understanding the glm source.这是关于了解 glm 来源。 I wanted to know if glm does zero initialise its classes and tried it.
我想知道 glm 是否对它的类进行零初始化并尝试过。 Yes,
glm::vec3
and glm::mat4
are initialized, even without providing a constructor value.是的,
glm::vec3
和glm::mat4
被初始化,即使没有提供构造函数值。 Then I wanted to understand how it is done and read the source of glm::mat4
template.然后我想了解它是如何完成的并阅读
glm::mat4
模板的源代码。
There is this section:有这个部分:
...
enum ctor{null};
// Constructors
GLM_FUNC_DECL tmat4x4();
GLM_FUNC_DECL tmat4x4(tmat4x4 const & m);
GLM_FUNC_DECL explicit tmat4x4(ctor Null);
...
I can read there is a (void)
constructor (ctor) but without definition, so no {...}
section.我可以读到有一个
(void)
构造函数(ctor)但没有定义,所以没有{...}
部分。 And there is an explicit
ctor with 0
as parameter coming from first element of type enum ctor
, which of course gets index value 0
.并且有一个
explicit
ctor 以0
作为参数来自enum ctor
类型的第一个元素,当然它的索引值为0
。
glm::mat4
initialised to an identity matrix when I just write: glm::mat4 myMatrix;
glm::mat4
初始化为单位矩阵时,我只是写: glm::mat4 myMatrix;
Edit: browsing the more current source files on GitHub brings one from mat4x4.hpp
to detail/type_mat4x4.hpp
which #includes
the implementation details in type_mat4x4.inl .编辑:浏览在GitHub上更多的电流源文件带来了一个从
mat4x4.hpp
到detail/type_mat4x4.hpp
它#includes
的实现细节type_mat4x4.inl 。 There the ctor behaviour gets visible.在那里,ctor 行为变得可见。
It's not inialized by default anymore.它不再默认初始化。 Define GLM_FORCE_CTOR_INIT before your includes to force the initialization.
在包含之前定义 GLM_FORCE_CTOR_INIT 以强制初始化。 https://github.com/g-truc/glm/issues/809
https://github.com/g-truc/glm/issues/809
#define GLM_FORCE_CTOR_INIT
#include <glm/glm.hpp>
"glm/detail/type_mat4x4.inl"
"glm/detail/type_mat4x4.inl"
enum ctor{uninitialize}
enum ctor{uninitialize}
BTW, I can't download your version, this answer is base on 0.9.6.3顺便说一句,我无法下载您的版本,此答案基于0.9.6.3
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.