VisorZ VisorZ - 9 days ago 12
C++ Question

How are glm::vec3 and glm::mat4 initialised?

This is about understanding the glm source. I wanted to know if glm does zero initialise its classes and tried it. Yes,

glm::vec3
and
glm::mat4
are initialized, even without providing a constructor value. Then I wanted to understand how it is done and read the source of
glm::mat4
template.

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. 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
.


  • Where are the constructor definitions? How can I find them?

  • What is that explicit Null ctor for?

  • How is
    glm::mat4
    initialised to an identity matrix when I just write:
    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. There the ctor behaviour gets visible.

Answer
  • it's under "glm/detail/type_mat4x4.inl"
  • it's a constructor that does nothing, in 0.9.6.3 it becomes enum ctor{uninitialize}
  • It calls the default constructor

BTW, I can't download your version, this answer is base on 0.9.6.3

Comments