简体   繁体   English

Glm四元数slerp

[英]Glm quaternion slerp

I am trying to do slerp using quaternions in glm. 我试图在glm中使用四元数做slerp。 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 我添加了所有glm四元数.hpp

The error is "quaternion" must be a classname or namespace. 错误是“quaternion”必须是类名或命名空间。

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. 在GLM 0.9.4.6中搜索namespace quaternionquaternion::的所有文件quaternion::只在gtc/quaternion.hpp一条已注释掉的行。 All public GLM functionality is implemented directly in the glm namespace. 所有公共GLM功能都直接在glm命名空间中实现。 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. 实现细节存在于glm::detail ,偶尔也存在glm::_detail ,但是你不应该直接在这些命名空间中使用任何东西,因为它们在将来的版本中会有所变化。

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

This is not present in the mix version, which is otherwise identical. 这在mix版本中不存在,否则它是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM