Reputation: 11037
What values should a glm::mat4 made via a zero argument constructor contain? On 64-bit Windows 10, using 64-bit GLM v0.9.9.0 installed via vcpkg, the result of glm::mat4()
is a 4x4 matrix filled with zeros. This is the same on 64-bit Ubuntu 18.04 LTS with default GLM.
On the other hand, I can see near the top of GLM's type_mat4x4.inl
that a definition exists which sets the contents equal to the identity matrix. (This is conditionally excluded on the two builds I describe above.) My colleague though has informed me that a call to glm::mat4()
on his system does produce an identity matrix.
Do such differences reflect a recent change in GLM? That is, would the differences disappear if we all used the latest version of GLM? Or, is it by design that GLM would produce two different results on two different systems?
Upvotes: 4
Views: 5372
Reputation: 7198
From GLM site:
GLM provides classes and functions designed and implemented with the same naming conventions and functionalities than GLSL
And GLSL spec
If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix’s diagonal, with the remaining components initialized to 0.0.
So, glm::mat4()
is all-zeroes matrix and glm::mat4(1)
is the identity matrix.
In GLM versions before 0.9.9 you can find in 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
# 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
In other words: GLM allows and have always allowed to change the default GLSL initialization by playing with some #define
s. If not, glm::mat4()
will always be all-zeroes.
Upvotes: 6