我需要的是根据相机位置、Y 旋转和 Z 旋转来计算我的lookat 3d 矢量在哪里,我会假设任何大于 0 的数字都足以让相机的距离可以看到。
这是我用来控制相机并计算视图和投影矩阵等的静态类。
涉及职位和轮换的班级成员:
public static Vector3 Position { get; set; } //Publicly available for use outside the class
public static Vector3 Rotation { get; set; }
private static Vector3 camPos = new Vector3(0.0f, 200.0f, 300.0f); //However we work with these for manipulation of values
private static Vector3 camTarget = new Vector3(0, 0, -1200.0f);
private static float rotY = 0, rotZ = 0; //I believe that these are the correct axis following the right hand catasian coordinate system
我的相机的更新功能:
public static void Update()
{
//Controls here
//Update Position here
Position = camPos;
//Update camTarget based on Position, rotY and rotZ <- Need help with this bit
//After calculating camTarget update Rotation
Rotation = camTarget;
UpdateMatrices();
}
UpdateMatrices() 处理所有其他事情并按应有的方式工作,但在这里它只是以防万一您想看到它:
public static void UpdateMatrices()
{
Matrix rotationMatrix = Matrix.CreateRotationX(MathHelper.ToRadians(90));
Vector3 transformedReference = Vector3.Transform(Vector3.Forward, rotationMatrix);
View = Matrix.CreateLookAt(Position, Rotation, Vector3.Forward);
Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspectRatio, nearClip, farClip);
World = Matrix.Identity;
CamBoundingFrustrum = new BoundingFrustum(View * Projection);
}
有人愿意分享这个秘密吗?