james456
james456

Reputation: 137

Glm quaternion slerp

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.

Upvotes: 6

Views: 7889

Answers (1)

bcrist
bcrist

Reputation: 1530

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.

Upvotes: 13

Related Questions