2016-04-29 98 views
0

我的更新功能是圍繞視圖軸(滾動)添加旋轉,隨着時間的推移而增加。我只想改變偏航和俯仰部分。Quaterion第一人稱風格相機

是我的計算錯誤還是浮點精度?

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(); 
}; 

回答

0

用2解決改變

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