【发布时间】:2013-12-26 02:41:09
【问题描述】:
我有一个使用 DirectXMath API 的相机类:
__declspec(align(16)) class Camera
{
public:
XMVECTOR Translation;
XMMATRIX Rotation;
XMVECTOR Scale;
XMMATRIX Transform;
XMFLOAT3 RotAngles;
XMMATRIX ProjectionMatrix;
float Width;
float Height;
float NearZ;
float FarZ;
float AspectRatio;
float FieldOfView;
Camera()
{
Translation = XMVectorZero();
Rotation = XMMatrixIdentity();
Scale = XMVectorSplatOne();
Transform = XMMatrixIdentity();
Width = 800;
Height = 600;
NearZ = 0.1f;
FarZ = 100.0f;
AspectRatio = 800 / 600;
FieldOfView = (XM_PIDIV4);
ProjectionMatrix = XMMatrixPerspectiveFovLH(FieldOfView, AspectRatio, NearZ, FarZ);
}
void Update()
{
Rotation = XMMatrixRotationRollPitchYaw(RotAngles.x, RotAngles.y, RotAngles.z);
XMMATRIX scaleM = XMMatrixScalingFromVector(Scale);
XMMATRIX translationM = XMMatrixTranslationFromVector(Translation);
Transform = scaleM * Rotation * translationM;
}
XMMATRIX GetViewMatrix()
{
XMVECTOR Eye;
XMVECTOR At;
XMVECTOR Up;
Eye = Translation;
At = Translation + Transform.r[2];
Up = Transform.r[1];
return(XMMatrixLookAtLH(Eye, At, Up));
}
XMMATRIX GetViewProjectionMatrix()
{
return(XMMatrixTranspose(GetViewMatrix() * ProjectionMatrix));
}
};
当我将 GetViewProjectionMatrix() 的结果存储在 XMFLOAT4X4 中并将其更新到常量缓冲区时,当我使用键盘移动/旋转相机时,几何图形会被撕裂或根本不显示。我已经隔离相机出现变形/消失几何的问题,但我不知道问题出在哪里。我的意思是投影矩阵不会错,它只是 1 个函数调用,所以很可能是视图矩阵。有人能告诉我吗我问题出在哪里?我尝试了乘法顺序的不同组合/转置两者/仅转置一个/任何东西。它永远无法正常工作。
【问题讨论】:
标签: c++ graphics matrix directxmath