Я программирую игру на С#, используя движок XNA3.1. Однако у меня есть небольшая проблема с моей камерой, в основном моя камера имеет тенденцию «переворачиваться», когда она поворачивается более чем на 180 градусов по крену (когда камера достигает 180 градусов, она, кажется, переворачивается обратно на 0 градусов). Код для получения матрицы представления выглядит следующим образом:
Globals.g_GameProcessingInfo.camera.viewMat = Matrix.CreateLookAt(Globals.g_GameProcessingInfo.camera.target.pos, Globals.g_GameProcessingInfo.camera.LookAt, up); //Calculate the view matrix
Переменная Globals.g_GameProcessingInfo.camera.LookAt представляет собой позицию на 1 единицу непосредственно перед камерой относительно вращения камеры, а переменная «вверх» получается с помощью следующей функции:
static Vector3 GetUp() //Get the up Vector of the camera
{
Vector3 up = Vector3.Zero;
Quaternion quat = Quaternion.Identity;
Quaternion.CreateFromYawPitchRoll(Globals.g_GameProcessingInfo.camera.target.rot.Y, Globals.g_GameProcessingInfo.camera.target.rot.X, Globals.g_GameProcessingInfo.camera.target.rot.Z, out quat);
up.X = 2 * quat.X * quat.Y - 2 * quat.W * quat.Z; //Set the up x-value based on the orientation of the camera
up.Y = 1 - 2 * quat.X * quat.Z - 2 * quat.Z * quat.Z; //Set the up y-value based on the orientation of the camera
up.Z = 2 * quat.Z * quat.Y + 2 * quat.W * quat.X; //Set the up z-value based on the orientation of the camera
return up; //Return the up Vector3
}

