Glm四元数slerp

jam*_*456 4 c++ opengl

我试图在glm中使用四元数做slerp.我在用

glm::quat interpolatedquat = quaternion::mix(quat1,quat2,0.5f)
Run Code Online (Sandbox Code Playgroud)

这些是我添加的库

#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;
Run Code Online (Sandbox Code Playgroud)

但我无法让它发挥作用.我添加了所有glm四元数.hpp

错误是"quaternion"必须是类名或命名空间.

bcr*_*ist 10

搜索GLM 0.9.4.6中的所有文件,namespace quaternionquaternion::仅产生gtc/quaternion.hpp已注释掉的单行.所有公共GLM功能都直接在glm命名空间中实现.实现细节存在于glm::detail或偶尔存在glm::_detail,但您不应直接在这些命名空间中使用任何内容,因为它们在将来的版本中可能会发生变化.

不使用每个模块/扩展的子名称空间.因此,您只需要:

glm::quat interpolatedquat = glm::mix(quat1,quat2,0.5f)
Run Code Online (Sandbox Code Playgroud)

你最后可能想要一个分号.

编辑:您也可能还想使用glm::slerp而不是glm::mix因为它有额外的检查,以确保采取最短的路径:

// 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;
}
Run Code Online (Sandbox Code Playgroud)

这在mix版本中不存在,否则相同.