四元数第一人称相机

Quaterion first person style camera

我的更新功能是添加绕视轴的旋转(滚动),增加超过 time.I 只想改变偏航和俯仰部分。

是我计算有误还是浮点精度?

m_orientation 是我的全局 Quaterion 来进行最后的轮换。 Q 的类型为 glm::quat。 V 是 glm::vec3

return [this](glm::vec2 ls, glm::vec2 rs, double dTime) {
    auto rightVec = m_orientation * V(1, 0, 0);
    Q q1 = glm::angleAxis(-rs.x * (float)dTime, V(0,1,0)); // yaw   
    Q q2 = glm::angleAxis(rs.y * (float)dTime, rightVec); // pitch

    auto roll = glm::roll(m_orientation);
    printf("%f\n", roll);

    m_orientation = q1 * m_orientation;
    m_orientation = q2 * m_orientation;


    m_position += m_orientation * V(1, 0, 0) * ls.x * (float)dTime * sensitivity; //sidewards 
    m_position += m_orientation * V(0, 0, -1) * ls.y * (float)dTime * sensitivity; //forwards
    buildViewMatrix();
};

通过 2 处更改解决

auto q2 = glm::angleAxis(rs.y * (float)dTime, V(1,0,0)); // pitch
m_orientation = q1 * m_orientation * q2;