為什麼 XMMatrixLookAtLH 會導致調試錯誤? (Why does XMMatrixLookAtLH result in a debug error?)


問題描述

為什麼 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 BendedWillsChuck Walbourn)

參考文件

  1. Why does XMMatrixLookAtLH result in a debug error? (CC BY‑SA 2.5/3.0/4.0)

#matrix #direct3d11 #directx-11 #C++ #directx






相關問題

BLAS 子程序 dgemm、dgemv 和 ddot 不適用於標量? (BLAS subroutines dgemm, dgemv and ddot doesn't work with scalars?)

為什麼我們需要維護自己的矩陣來轉換遊戲對象? (Why we need to maintain our own matrices to transform Game objects?)

R 高斯消除和 qr 分解 (R Gaussian Elimination and qr factorization)

生成尺寸為 8x8 的正定矩陣 (Generating Positive definite matrix of dimensions 8x8)

替代在此 Ruby 代碼中使用基於時間間隔分配標籤的巨型 if/else (Alternative to using a giant if/else in this Ruby code that assigns labels based on the time interval)

如何創建一個行矩陣,其元素是我的 while 循環的迭代 (How to create a row matrix whose elements are the iterations of my while loop)

在Matlab中找到矩陣中相同元素的開始索引和結束索引 (Find the Start Index and End Index of the same Element in a Matrix in Matlab)

用 Matlab 寫一個方程(矩陣大小) (writing an equation with Matlab (Matrix size))

使用 numpy 或 pandas 從元組列表中為二元組創建頻率矩陣 (Create a frequency matrix for bigrams from a list of tuples, using numpy or pandas)

如何在循環和 if 語句中使用遞歸公式 (How to use recursive formula in loop and if statement)

如何從 p 值矩陣中獲得緊湊的字母顯示? (How to get a compact letter display from a matrix of p-values?)

刺激基質上的液體流動 (Stimulating Liquid Flow on Matrix)







留言討論