I am new to directX programming and Visual C++ and I am having an issue migrating an example I found from xnamath.h to DirectXMath.h. I am using Visual Studio 2012.
The purpose of the code is simply to initialize a XMMATRIX and then display it in the console. The original code is shown below (it works just fine):
#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;
}
When I run the program it gives the following output:
A =
1 0 0 0
0 2 0 0
0 0 4 0
1 2 3 1
Press any key to continue . . .
However, when I change the headers to DirectXMath it no longer works:
#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;
}
When I try to compile I get an error with os << m(i, j) << "\t";
which says:
error C2064: term does not evaluate to a function taking 2 arguments
When I hover over the red squiggly line under m(i, j)
it tells me:
DirectX::CXMMATRIX m
Error: call of an object of a class type without appropriate operator() or conversion function to pointer-to-function type
Any advice would be greatly appreciated.
I changed the example code to use
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;
}
This will have the same effect as the old xnamath had.
It depends on the version you are using for DirectXMath, you can define _XM_NO_INTRINSICS_ to get the result you want. See http://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmmatrix(v=vs.85).aspx for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With