四元数旋转问题,物体轴不与物体一起旋转

时间:2015-03-01 02:11:29

标签: c++ 3d rotation quaternions euler-angles

假设我有一个对象,该对象有一个四元数来表示它的方向。

目前,我可以在没有万向节锁定的情况下在所有3个轴上旋转,但是,任何轴上的每个旋转应该旋转其他2个旋转轴。

我的意思是,如果我将一个物体朝向相机倾斜,但是然后将物体偏转90度,投掷物体仍将相对于之前的位置旋转,而不是现在的位置。

以下是我的问题的视觉示例: enter image description here

我使用四元数而不是欧拉旋转,因为这些物体可以在所有3个轴上旋转,而我想要万向锁/达到奇点

我像这样旋转对象的方向四元数:

orientation = Quaternion(Vector(0,1,0),angle) * orientation;

然后我触发重建对象的向量,并将其应用于它们(在相对于3D空间原点转换对象之后):

Quaternion Point = Quaternion(( orientation * (Vertex) ) * (orientation.inverse()));

vertices[x] = QVector3D(round(Point.v.x),round(Point.v.y),round(Point.v.z));

当我将四元数乘以其他四元数时,这就是乘法运算符的函数:

Quaternion Quaternion::operator*(Quaternion& q) const
{
    Quaternion r;

    //"w" is the angle, "v" is the vector
    r.w = w*q.w - glm::dot(v, q.v);
    r.v = v*q.w + q.v*w + glm::cross(v,q.v);
    //r.normalize();

    return r;
}

我向上帝发誓,我只是张贴,因为这个话题令我困惑不已。巩固这个系统将使我非常高兴。

0 个答案:

没有答案
相关问题