我是 DirectX 编程和 Visual C++ 的新手,在将我从 xnamath.h 找到的示例迁移到 DirectXMath.h 时遇到问题。我正在使用 Visual Studio 2012。
代码的目的只是初始化一个 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
任何建议将不胜感激。