Quaternion to matrix using glm

I am trying to convert quat to glm in mat4.

My code is:

#include <iostream> #include<glm/glm.hpp> #include<glm/gtc/quaternion.hpp> #include<glm/common.hpp> using namespace std; int main() { glm::mat4 MyMatrix=glm::mat4(); glm::quat myQuat; myQuat=glm::quat(0.707107,0.707107,0.00,0.000); glm::mat4 RotationMatrix = quaternion::toMat4(myQuat); for(int i=0;i<4;++i) { for(int j=0;j<4;++j) { cout<<RotationMatrix[i][j]<<" "; } cout<<"\n"; } return 0; } 

When I run the program, it shows the error "error:" quaternion has not been declared. "

Can anyone help me with this?

+6
source share
2 answers

Add include:

 #include <glm/gtx/quaternion.hpp> 

And fix the toMat4 namespace:

 glm::mat4 RotationMatrix = glm::toMat4(myQuat); 

glm::toMat4() exists in the gtx/quaternion.hpp file, which you can see has only the glm namespace.


As well as a side note, starting with C ++ 14, nested namespaces (e.g. glm :: quaternion :: toMat4) are not allowed .

+8
source

In addition to the meepzh answer, this can also be done as follows:

 glm::mat4 RotationMatrix = glm::mat4_cast(myQuat); 

which does not require #include <glm/gtx/quaternion.hpp>

0
source

All Articles