我是directX編程和Visual C++的新手,我遇到了將從xnamath.h中找到的示例遷移到DirectXMath.h的問題。我正在使用Visual Studio 2012.XMMATRIX運算符()與xnamath.h一起使用,但不能與DirectXMath.h一起使用
代碼的目的僅僅是初始化XMMATRIX,然後將其顯示在控制檯中。原來的代碼如下所示(它工作得很好):
#include <windows.h>
#include <xnamath.h>
#include <iostream>
using namespace std;
ostream& operator<<(ostream& os, CXMMATRIX m)
{
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 4; ++j)
os << m(i, j) << "\t";
os << endl;
}
return os;
}
int main()
{
XMMATRIX A(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 4.0f, 0.0f,
1.0f, 2.0f, 3.0f, 1.0f);
cout << "A = " << endl << A << endl;
return 0;
}
當我運行它提供了以下輸出方案:
A =
1 0 0 0
0 2 0 0
0 0 4 0
1 2 3 1
Press any key to continue . . .
但是,當我改變了頭不再DirectXMath它工作原理:
#include <windows.h>
#include <iostream>
#include <DirectXMath.h>
#include <DirectXPackedVector.h>
using namespace DirectX;
using namespace DirectX::PackedVector;
using namespace std;
ostream& operator<<(ostream& os, CXMMATRIX m)
{
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 4; ++j)
os << m(i, j) << "\t";
os << endl;
}
return os;
}
int main()
{
XMMATRIX A(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 4.0f, 0.0f,
1.0f, 2.0f, 3.0f, 1.0f);
cout << "A = " << endl << A << endl;
return 0;
}
當我嘗試編譯我得到os << m(i, j) << "\t";
一個錯誤,說:
error C2064: term does not evaluate to a function taking 2 arguments
當我將鼠標懸停在紅色波浪線m(i, j)
下它告訴我:
DirectX::CXMMATRIX m
Error: call of an object of a class type without appropriate operator() or conversion function to pointer-to-function type
任何意見將不勝感激。
感謝您的幫助。 – Brooks