1
    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)
                       );

如您所见,我们构建了第三人称相机,这台相机正在追逐我们的飞机。但是当我们的飞机进行循环时,相机会在中途翻转。所以一切都是颠倒的。我们如何确保相机不会翻转?

4

1 回答 1

0

我们通过计算而不是设置它来修复它。

glm::vec3 cameraposition = carPosition + glm::quat(temp) * position;
ProjectionMatrix = glm::perspective(FoV, 4.0f / 3.0f, 0.1f, 100.0f);

glm::mat4 RotationMatrix        = eulerAngleYXZ(carDirection.x, carDirection.y, carDirection.z);
glm::vec4 up = RotationMatrix * glm::vec4(0,1,0,0);
glm::vec3 up3(up);

ViewMatrix       = glm::lookAt(
                            cameraposition,     // Camera is here
                            lookAt,                                     // and looks here : at the same position, plus "direction"
                            up3                             // Head is up (set to 0,-1,0 to look upside-down)
                       );
于 2013-07-12T09:04:28.093 回答