简体   繁体   English

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

[英]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::vec3glm::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

  • Where are the constructor definitions?构造函数定义在哪里? How can I find them?我怎样才能找到它们?
  • What is that explicit Null ctor for?那个显式的 Null ctor 是做什么用的?
  • How is 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.hppdetail/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>
  • it's under "glm/detail/type_mat4x4.inl"它在"glm/detail/type_mat4x4.inl"
  • it's a constructor that does nothing, in 0.9.6.3 it becomes enum ctor{uninitialize}它是一个什么都不做的构造函数,在0.9.6.3 中它变成了enum ctor{uninitialize}
  • It calls the default constructor它调用默认构造函数

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM