0
所以我想用四元數和角度來控制我的相機,用我的鼠標。窗口座標到攝像機角度?
我積累的垂直/水平角度是這樣的:
void Camera::RotateCamera(const float offsetHorizontalAngle, const float offsetVerticalAngle)
{
mHorizontalAngle += offsetHorizontalAngle;
mHorizontalAngle = std::fmod(mHorizontalAngle, 360.0f);
mVerticalAngle += offsetVerticalAngle;
mVerticalAngle = std::fmod(mVerticalAngle, 360.0f);
}
,並計算我的方向是這樣的:
Mat4 Camera::Orientation() const
{
Quaternion rotation;
rotation = glm::angleAxis(mVerticalAngle, Vec3(1.0f, 0.0f, 0.0f));
rotation = rotation * glm::angleAxis(mHorizontalAngle, Vec3(0.0f, 1.0f, 0.0f));
return glm::toMat4(rotation);
}
和前向量,這是我需要的GLM ::的lookAt,像這個:
Vec3 Camera::Forward() const
{
return Vec3(glm::inverse(Orientation()) * Vec4(0.0f, 0.0f, -1.0f, 0.0f));
}
我認爲應該這樣做,但我不知道如何在我的示例遊戲中獲得實際角度?我所擁有的是當前和以前的鼠標在窗口座標中的位置..我怎樣才能從中獲得正確的角度?
編輯:第二個想法..我的「旋轉照相機()」不能正確;由於角度在達到360°之後重置,我正在經歷橡皮帶效應......所以我如何正確累積角度?我可以總結起來沒完沒了
這樣的精細的答案 –
的1 @MichaelIV阻止它男人,你讓我變紅......不,這只是證明(反過來)透視投影 - 它有助於圖形程序員理解背後的數學。 –
確實,沒有多少人試圖以詳細的方式解釋SO中的東西:) –