所以我基本上写了一个链接到3D对象的相机类(我已经将它作为.obj文件加载到我的程序中)。
相机是第三人。
当我写这个时我得到错误:
World *= XMMatrixTranslation(XMVectorGetX(position), m_y, XMVectorGetZ(position)); //LAST MODIFICATION BEFORE BREAK
原始代码是:
World = XMMatrixScaling(m_xscale, m_yscale, m_zscale);
World *= XMMatrixRotationX(XMConvertToRadians(m_xangle));
World *= XMMatrixRotationY(XMConvertToRadians(m_yangle));
World *= XMMatrixRotationZ(XMConvertToRadians(m_zangle));
World *= XMMatrixTranslation(m_x, m_y, m_z); //LINE THAT GETS MODIFIED
另外:
XMVECTOR position = XMVector3TransformCoord(cam->GetCharPos(), World);
其中 cam-> GetCharPos()是XMVECTOR(0.0f,0.0f,0.0f,0.0f),World是一个XMMATRIX,它有一个位置(每次移动都会改变) ),比方说,(1.0f,0.0f,0.0f)// x,y和z位置
所以从理论上讲,位置向量得到的XM向量为(1.0f,0.0f,0.0f,0.0f)//我调试了它。
此外,我想知道是什么原因造成这种类型的错误?除了导致它在这里破坏我的代码的原因。因为我知道它们至少是这个错误的4个版本:
assert(!XMVector3Equal(EyeDirection, XMVectorZero()));
assert(!XMVector3IsInfinite(EyeDirection));
assert(!XMVector3Equal(UpDirection, XMVectorZero()));
assert(!XMVector3IsInfinite(UpDirection));
答案 0 :(得分:0)
The problem lies in the line of code :
XMVECTOR position = XMVector3TransformCoord(cam->GetCharPos(), World);
With the way XMVECTOR and XMMATRIX work, it won't let you store the value of XMVector3TransformCoord(cam->GetCharPos(), World) directly into the XMVECTOR position.
To fix this i wrote:
cam->GetCharPos() = XMVector3TransformCoord(cam->GetCharPos(), World);
Since i m updating a default XMVECTOR ( Remember, cam->GetCharPos() was set to (0.0f, 0.0f, 0.0f, 0.0f) ) from a XMMATRIX, i then copied it's content to my position XMVECTOR. This enables me to manipulate it without breaking the XNAlibrary