Glm quaternion slerp

Glm quaternion slerp

本文关键字:slerp quaternion Glm      更新时间:2023-10-16

我正在尝试使用 glm 中的四元数做 slerp。我正在使用

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

这些是我添加的库

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

但我无法让它工作。我添加了所有 glm 四元数 .hpp 的

错误是"四元数"必须是类名或命名空间。

在 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)

你可能想要一个分号在最后。

编辑:您可能还想使用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;
}

这在mix版本中不存在,否则是相同的。