問題描述
為什麼 XMMatrixLookAtLH 會導致調試錯誤? (Why does XMMatrixLookAtLH result in a debug error?)
我正在使用 C++ 開發 DirectX 11 遊戲,我正在嘗試創建一個視圖矩陣,但是當我這樣做時,我收到以下調試錯誤:
Assertion failed!
Program: ...ate‑Direct3D11\Build\Debug\Template‑Direct3D11.exe
File: C:\Program Files (x86)\Windows Kits...\DirectX...rix.inl
Line: 1971
Expression: !XMVector3Equal(EyeDirection, XMVectorZero())
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts
(Press Retry to debug the application ‑ JIT must be enabled)'Template‑Direct3D11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\TextShaping.dll'.
Template‑Direct3D11.exe has triggered a breakpoint.
這是代碼:
DirectX::XMVECTOR eyePos = DirectX::XMVectorSet(0.f, 0.f, ‑2.f, 0.f);
DirectX::XMVECTOR lookAtPos = DirectX::XMVectorSet(0.f, 0.f, ‑2.f, 0.f);
DirectX::XMVECTOR upVector = DirectX::XMVectorSet(0.f, 1.f, 0.f, 0.f);
DirectX::XMMATRIX view = DirectX::XMMatrixLookAtLH(eyePos, lookAtPos, upVector); //Debug Error
我在網上找不到任何關於此的信息,因為似乎每個人的錯誤都與我不同。
有人可以幫忙嗎?
參考解法
方法 1:
The eyPos
and the lookAtPos
you are setting are the same value... The result is a 0‑length unit vector for direction.
DirectX::XMVectorSet
is not the best way to initialize a constant vector. Read the DirectXMath Programmer's Guide particularly the Getting Started guide.
(by BendedWills、Chuck Walbourn)