View Full Version : GLMath assignment to swizzle doesn't work ?

jbacon

01-10-2010, 07:42 AM

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

01-10-2010, 07:53 AM

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

Groovounet

01-10-2010, 12:45 PM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.