我是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任何建议都将不胜感激。
发布于 2013-01-11 02:02:54
这取决于您使用的DirectXMath版本,您可以定义_XM_NO_INTRINSICS_来获得您想要的结果。有关更多信息,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmmatrix(v=vs.85).aspx
发布于 2013-07-29 12:27:37
我将示例代码更改为使用
ostream& operator<<(ostream& os, CXMMATRIX m)
{
for(int i = 0; i < 4; ++i)
{
for(int j = 0; j < 4; ++j)
os << m.r[i].m128_f32[j] << "\t";
os << endl;
}
return os;
}这将具有与旧的xnamath相同的效果。
发布于 2013-08-07 04:34:01
在Direct X 11+中,直接存取矩阵的能力,如
matrix (row, column)由于性能问题,已被删除。微软建议通过r成员访问这些值。我建议使用
XMStoreFloat4 (row, column)对于4x4矩阵,因此您不需要担心数据类型。
ostream& operator<< (ostream& os, CXMMATRIX m)
{
for (int i = 0; i < 4; i++)
{
XMVECTOR row = m.r[i];
XMFLOAT4 frow;
XMStoreFloat4(&frow, row);
os << frow.x << "\t" << frow.y << "\t" << frow.z << "\t" << frow.w << endl;
}
return os;
}使用_XM_NO_INTRINSICS_时要小心,因为这不仅仅影响访问矩阵值,可能会影响性能敏感代码的性能,并可能影响其他操作。DirectXMath是从XNAMath跳出来的.当升级旧代码时,这可能是一件痛苦的事情,但这是值得的。
https://stackoverflow.com/questions/14230546
复制相似问题