我已经看到很多关于这个主题的答案,但是当我试图让它发挥作用时......它没有。
curtarget = cameraPos + cameraFront;
cameraPos = cameraPos - curtarget;
GLfloat xoffset = 45.0f;
GLfloat cosa = cos(glm::radians(xoffset));
GLfloat sina = sin(glm::radians(xoffset));
newP.x = cameraPos.x*cosa - cameraPos.z*sina;//frontradius*cos(glm::radians(xoffset));
newP.z = cameraPos.x*sina + cameraPos.z*cosa;//frontradius*sin(glm::radians(xoffset));
newP.y = cameraPos.y;
cameraFront.x = cameraFront.x*cosa - cameraFront.z*sina;
cameraFront.z = cameraFront.x*sina + cameraFront.z*cosa;
cameraFront.y = cameraFront.y;
cameraPos = curtarget + newP;
lastalpha += xoffset;
view = glm::lookAt(cameraPos, cameraFront + cameraPos, cameraUp);
所以目标保持不变。最初,我有前(0,0,-1),cameraPos(0,0,3),所以目标(0,0,2)。然后我减去目标点(前两行仅用于旋转(0,0,1)向量,而不是(0,0,-1))并围绕中心旋转,然后再次添加。同时我旋转前点以使目标保持不变。但是,我得到了奇怪的数字。