jbacon
January 10, 2010, 6:42am
1
Hi there,
I notice that the following doesn’t seem to work:
mat4 mat;
mat[3].xyz = vec3( 10.0f, 10.0f, 10.0f );
Is this due to my compilationsettings, or is it not a feature of GLM ?
I figured GLM has a full GLSL implementation, and since you can do this in GLSL, it should work…
anyone ?
thanks,
Jochem
jbacon
January 10, 2010, 6:53am
2
hmm, looking at type_vec4.inl in GLMath-0.8.4.0 I see:
template <typename valType>
inline tvec3<valType> tvec4<valType>::swizzle(comp x, comp y, comp z) const {
return tvec3<valType>(
(*this)[x],
(*this)[y],
(*this)[z]);
}
this creates a new instance of a vec4 and so doesn’t offer access to the members of a vec4, which doesn’t comply with GLSL spec 1.20.8 (page 34, “The component group notation can occur on the left hand side of an expression.” ) as GLM claims.
J
#include <glm/setup.hpp>
#define GLM_SWIZZLE GLM_SWIZZLE_XYZW
#include <glm/glm.hpp>
int main()
{
glm::vec4 v1(1, 2, 3, 4);
glm::vec4 v2;
glm::vec4 v3;
glm::vec4 v4;
v2.wyxz = v1.zyxw;
v3 = v1.xzyw;
v4.xzyw = v1;
return 0;
}
And that will work.
I’m not sure if I can advice to use it… that’s why the feature isn’t able by default.
xyzw is actually a #define which can bring some compatibility with OSs or software libraries.