View Full Version : glm & quaternions

04-03-2010, 05:03 PM

I try to use quaternions provided by glm but I have somes problems... I do that:

m_WorldPose.Orientation = poseParent->Orientation * m_Orientation;note : they are all glm::quat
I included glm/glm.hpp and glm/gtc/quaternion.hpp

I try to compile and I get that:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'glm::detail::thalf' (or there is no acceptable conversion)
1> c:\users\charlie\documents\visual studio 2008\projects\in55\3d_engine\glm-\glm\gtc\quaternion.hpp(58): could be 'glm::detail::tquat<valType> &amp;glm::detail::tquat<valType>::operator =(const glm::detail::tquat<valType> &amp;)'
1> with
1> [
1> valType=float
1> ]
1> while trying to match the argument list '(glm::gtc::quaternion::quat, glm::detail::thalf)'I have no idea where it comes from, I hope it will be more clear fo you :)

Thanks for your help!


04-03-2010, 06:32 PM
Chances are that you expect to do a quaternion cross project.
For such operation you should use the function glm::cross:

m_WorldPose.Orientation = glm::cross(poseParent->Orientation, m_Orientation);

Quaternion has cross and dot product just like vectors.
GLM follows GLSL convention as much as possible so that quaternion uses the same rule than GLSL vectors and defines 2 function, cross and dot.

With GLSL you can transform your vector like this:

mat4 m;
vec4 v;
v = m * v;

GLM follows the same rule for matrices and vectors product and extend it to quaternion:

quat q;
vec4 v;
v = q * v;

Hope this help!

04-05-2010, 04:54 AM
Ach... can't believe I did it ^^'.
Thanks for taking time to answer that!

Other little problem: I can't use operator== to compare vectors.
glm::vec3 test(1.0f, 2.0f, 3.0f);
glm::vec3 test2(4.0f, 5.0f, 6.0f);
if(test == test2)
return true;
I get that:
Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'glm::core::type::vector::vec3' (or there is no acceptable conversion) c:\...\src\corerectangle.cpp 186
I tried to include glm/virtrev/equal_operator.hpp but it didn't change anything.

Thanks for your help ^^.

04-05-2010, 03:28 PM
GLSL doesn't define == for vectors so as GLM.

Plus == on vector doesn't mean much.
You probably expect the behavior of the following code:

if(glm::all(glm::equal(test, test3)))
return true;

equal return a bvec3 (vector of 3 boolean components) and all return comparent the components of this bvec3 all together and return true is all the component are true.