float FoV = initialFoV - 5;
//(*it)->getParent()->getPosition() + (*it)->getOrientationQuat() * (*it)->getPosition();
glm::vec3 lookAt = carPosition;
glm::vec3 temp;
temp.x = spaceShip->orientation.y;
temp.y = spaceShip->orientation.x;
temp.z = spaceShip->orientation.z;
glm::vec3 cameraposition = carPosition + glm::quat(temp) * position;
ProjectionMatrix = glm::perspective(FoV, 4.0f / 3.0f, 0.1f, 100.0f);
ViewMatrix = glm::lookAt(
cameraposition, // Camera is here
lookAt, // and looks here : at the same position, plus "direction"
vec3(0, 1, 0) // Head is up (set to 0,-1,0 to look upside-down)
);
如您所见,我们构建了第三人称相机,这台相机正在追逐我们的飞机。但是当我们的飞机进行循环时,相机会在中途翻转。所以一切都是颠倒的。我们如何确保相机不会翻转?