我需要计算基于相机位置、Y旋转和Z旋转的观察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);
}
有没有人能够分享一下这个的秘密?
CamBoundingFrustrum
是一个类,而不是结构体。这意味着每帧创建一个“新”的对象会给垃圾收集器带来很多垃圾。处理由于相机移动/旋转而导致的视锥体变化的预期方式是仅更新(每帧)一次在相机最初创建时创建的BoundingFrustum对象的Matrix属性。 - Steve H