Sign in to follow this  

How do you implement xnamath/directxmath in a d3dx10math-using framework?

This topic is 1968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[b]Long post ahead[/b](you should probably ignore the last 2 code snippets)

I searched trough the forums and noticed some old threads about people having troubles with ditching the D3DXVECTOR# values and working with the XMFLOAT# ones and there I saw a bunch of links with explanations from MSDN and the likes,so I got the basics of how to work around with them(using XMVECTOR for the intristic XM functions and XMFLOAT# for storage/same w/ XMMATRIX and XMFLOAT4X4).The problem is whenever I do anything with it I get a break point at some place in the xnamath header that doesn't really tell me anything.For instance when I just use a test variable like this:[CODE]
XMFLOAT4X4 test = XMFLOAT4X4(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);
XMMATRIX I = XMMatrixIdentity();
XMStoreFloat4x4(test, I);
[/CODE]It triggers a break point and the top 3 lines of the call stack are the calling of XMStoreFloat4x4(test,I); ,the next one is some "XMASSERT(pDestination);"line in xnamathconvert.inl:
[CODE]XMFINLINE VOID XMStoreFloat4x4
(
XMFLOAT4X4* pDestination,
CXMMATRIX M
)
{
#if defined(_XM_NO_INTRINSICS_) || defined(XM_NO_MISALIGNED_VECTOR_ACCESS)
XMStoreFloat4x4NC(pDestination, M);
#elif defined(_XM_SSE_INTRINSICS_)
XMASSERT(pDestination); // <<<<<<<THIS ONE
_mm_storeu_ps( &pDestination->_11, M.r[0] );
_mm_storeu_ps( &pDestination->_21, M.r[1] );
_mm_storeu_ps( &pDestination->_31, M.r[2] );
_mm_storeu_ps( &pDestination->_41, M.r[3] );
#else // _XM_VMX128_INTRINSICS_
#endif // _XM_VMX128_INTRINSICS_
}
[/CODE]The third and top call is at xnamathmisc.inl at ''__debugbreak();'' :
[CODE]XMINLINE VOID XMAssert
(
CONST CHAR* pExpression,
CONST CHAR* pFileName,
UINT LineNumber
)
{
CHAR aLineString[XMASSERT_LINE_STRING_SIZE];
CHAR* pLineString;
UINT Line;
aLineString[XMASSERT_LINE_STRING_SIZE - 2] = '0';
aLineString[XMASSERT_LINE_STRING_SIZE - 1] = '\0';
for (Line = LineNumber, pLineString = aLineString + XMASSERT_LINE_STRING_SIZE - 2;
Line != 0 && pLineString >= aLineString;
Line /= 10, pLineString--)
{
*pLineString = (CHAR)('0' + (Line % 10));
}
#ifndef NO_OUTPUT_DEBUG_STRING
OutputDebugStringA("Assertion failed: ");
OutputDebugStringA(pExpression);
OutputDebugStringA(", file ");
OutputDebugStringA(pFileName);
OutputDebugStringA(", line ");
OutputDebugStringA(pLineString + 1);
OutputDebugStringA("\r\n");
#else
DbgPrint("Assertion failed: %s, file %s, line %d\r\n", pExpression, pFileName, LineNumber);
#endif
[b] __debugbreak(); // <<<<<<THIS ONE[/b]
}

[/CODE]


(Same thing happens with vectors and xmfloats)

So XMStoreFloat4x4 calls XMASSERT,which somehow fails to execute,so it calls __debugbreak(); to trigger a break point?(excuse my ignorance here).But that doesn't really tell me why xnamath isn't working in my code.My CPU has xna math support for sure,since I can compile and run Frank Luna's XMMATRIX code without a problem and yet the same things he does crash when I try them in my code.The d3dx10math and the rest of the framework worked perfectly before I tried using xnamath.Here is Frank Luna's tutorial code:

XMMATRIX:
[CODE]#include <windows.h> // for FLOAT definition
#include <xnamath.h>
#include <iostream>
using namespace std;
// Overload the "<<" operators so that we can use cout to
// output XMVECTOR and XMMATRIX objects.
ostream& operator<<(ostream& os, FXMVECTOR v)
{
XMFLOAT4 dest;
XMStoreFloat4(&dest, v);
os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
return os;
}
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()
{
// Check support for SSE2 (Pentium4, AMD K8, and above).
if( !XMVerifyCPUSupport() )
{
cout << "xna math not supported" << endl;
return 0;
}
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);
XMMATRIX B = XMMatrixIdentity();
XMMATRIX C = A * B;
XMMATRIX D = XMMatrixTranspose(A);
XMVECTOR det = XMMatrixDeterminant(A);
XMMATRIX E = XMMatrixInverse(&det, A);
XMMATRIX F = A * E;

cout << "A = " << endl << A << endl;
cout << "B = " << endl << B << endl;
cout << "C = A*B = " << endl << C << endl;
cout << "D = transpose(A) = " << endl << D << endl;
cout << "det = determinant(A) = " << det << endl << endl;
cout << "E = inverse(A) = " << endl << E << endl;
cout << "F = A*E = " << endl << F << endl;

system("pause");
return 0;
}
[/CODE]

XMVECTOR:
[CODE]
#include <windows.h> // for FLOAT definition
#include <xnamath.h>
#include <iostream>
using namespace std;
// Overload the "<<" operators so that we can use cout to
// output XMVECTOR objects.
ostream& operator<<(ostream& os, FXMVECTOR v)
{
XMFLOAT4 dest;
XMStoreFloat4(&dest, v);
os << "(" << dest.x << ", " << dest.y << ", " << dest.z << ", " << dest.w << ")";
return os;
}

int main()
{
cout.setf(ios_base::boolalpha);
// Check support for SSE2 (Pentium4, AMD K8, and above).
if( !XMVerifyCPUSupport() )
{
cout << "xna math not supported" << endl;
return 0;
}

XMVECTOR p = XMVectorSet(2.0f, 2.0f, 1.0f, 0.0f);
XMVECTOR q = XMVectorSet(2.0f, -0.5f, 0.5f, 0.1f);
XMVECTOR u = XMVectorSet(1.0f, 2.0f, 4.0f, 8.0f);
XMVECTOR v = XMVectorSet(-2.0f, 1.0f, -3.0f, 2.5f);
XMVECTOR w = XMVectorSet(0.0f, XM_PIDIV4, XM_PIDIV2, XM_PI);
cout << "XMVectorAbs(v) = " << XMVectorAbs(v) << endl;
cout << "XMVectorCos(w) = " << XMVectorCos(w) << endl;
cout << "XMVectorLog(u) = " << XMVectorLog(u) << endl;
cout << "XMVectorExp(p) = " << XMVectorExp(p) << endl;

cout << "XMVectorPow(u, p) = " << XMVectorPow(u, p) << endl;
cout << "XMVectorSqrt(u) = " << XMVectorSqrt(u) << endl;

cout << "XMVectorSwizzle(u, 2, 2, 1, 3) = "
<< XMVectorSwizzle(u, 2, 2, 1, 3) << endl;
cout << "XMVectorSwizzle(u, 2, 1, 0, 3) = "
<< XMVectorSwizzle(u, 2, 1, 0, 3) << endl;
cout << "XMVectorMultiply(u, v) = " << XMVectorMultiply(u, v) << endl;
cout << "XMVectorSaturate(q) = " << XMVectorSaturate(q) << endl;
cout << "XMVectorMin(p, v = " << XMVectorMin(p, v) << endl;
cout << "XMVectorMax(p, v) = " << XMVectorMax(p, v) << endl;
system("pause");
return 0;
}
[/CODE]

And one last thing just to make sure I got this straight - for shaders when you want to pass say..a constant buffer with a matrix in it,you use XMFLOAT4X4 and not XMMATRIX,right?

Share this post


Link to post
Share on other sites
Both of Luna's two examples (I copy/pasted your snippets into Visual Studio 2010 compile and run fine on my machine.

Your example at top requires the address of the XMMATRIX in the XMStoreFloat4x4 call, but with the address operator (&test) it works fine. This really shouldn't be the problem as the code shouldn't even compile without that operator.

Share this post


Link to post
Share on other sites
Ok it seems I found the problem - for some reason XMMATRIX can't be used as extern XMMATRIX * testmatrix and it causes it to crash I had the habit of making a lot of things extern,guess I'll change them to normal now

Edit: I am the original poster,but here I wasn't allowed to use Facebook when I wrote this thread.Does that violate some terms?If so,I apologize to the moderators for not remembering the rights and terms.

Share this post


Link to post
Share on other sites

This topic is 1968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this