Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glm quaternion slerp

Tags:

c++

opengl

I am trying to do slerp using quaternions in glm. I am using

glm::quat interpolatedquat = quaternion::mix(quat1,quat2,0.5f)

These are the libraries I added

#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/norm.hpp>
#include <glm\glm.hpp>
#include <glm\glm\glm.hpp>
using namespace glm;

But I can't get it to work. I added all the glm quaternion .hpp's

The error is "quaternion" must be a classname or namespace.

like image 735
james456 Avatar asked Dec 19 '22 22:12

james456


1 Answers

A search of all files in GLM 0.9.4.6 for namespace quaternion or quaternion:: yields only a single line in gtc/quaternion.hpp which has been commented out. All public GLM functionality is implemented directly in the glm namespace. Implementation details exist in glm::detail and occasionally glm::_detail, but you should never use anything in these namespaces directly, as they are subject to change in future versions.

Subnamespaces for each module/extension are not used. Therefore, you just need:

glm::quat interpolatedquat = glm::mix(quat1,quat2,0.5f)

And you probably want a semicolon at the end there.

Edit: You will also probably also want to use glm::slerp instead of glm::mix as it has an extra check to ensure that the shortest path is taken:

// If cosTheta < 0, the interpolation will take the long way around the sphere. 
// To fix this, one quat must be negated.
if (cosTheta < T(0))
{
    z        = -y;
    cosTheta = -cosTheta;
}

This is not present in the mix version, which is otherwise identical.

like image 105
bcrist Avatar answered Dec 22 '22 12:12

bcrist