Jump to content

  • Log In with Google      Sign In   
  • Create Account


Veil

Member Since 29 Apr 2012
Offline Last Active Aug 10 2012 02:21 PM
-----

Topics I've Started

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

27 July 2012 - 09:45 PM

Long post ahead(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:
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);
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:
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_
}
The third and top call is at xnamathmisc.inl at ''__debugbreak();'' :
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]
}



(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:
#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;
}

XMVECTOR:
#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;
}

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?

What is the best method for planet generation in a playable game(if any)?

08 June 2012 - 06:17 PM

I'll be working on a game this summer and I need to be able to fly a spaceship into a huge planet and land on the surface.Now I got the ''fly space ship'' part,but I have no idea how to generate a planet.As far as I know procedural planets are way too heavy to be used in a game.For instance I get stable frame rates on the new Alien vs Predator game on highest setting,but every ''Procedural Planet Engine'' I've tried has FPS drops and yet the terrain just doesn't look all that good.Are there any other good methods on simulating a planet?Like maybe having different zones/levels for each height level from the atmosphere to the surface and while in space the planet being a premade 3d model?Or maybe I haven't stumbled on a good procedural planet example.I'm not really sure how to write one tho,so I can't judge.

What can cause visual studio to be unable to compile a Directx11 project?

07 June 2012 - 01:15 AM

When I played around with sample Directx9 projects from tutorial sites,they would run with no problem,but whenever I try to compile a Directx11 project,I get

error MSB6006: "cmd.exe" exited with code 9009

Is there a way to fix this?Do I need some kind of patch for VS?
(I'm using Visual Studio 2010 on Windows 7 64 bit.)

How do you manipulate individual pixels in a texture in Direct3D on the CPU?

31 May 2012 - 03:35 PM

I know that in Allegro it's

BITMAP* tex[10];
int& pixel(BITMAP* bmp, int x, int y)
{
    return ((int**)(bmp->line))[y][x];
}

but what's the syntax for this in DirectX?

Can anyone suggest a formula to smear and blur cubes on a bitmap?

30 May 2012 - 08:36 AM

I am trying to create a blendmap on the CPU once at program start and then used it in the shader.So far I've done the first(left) picture,however I need to smear and blur it like the second(right) picture.The program basically makes a 2d array of random square types(red,green,blue) and paints the 1st picture.Now I have to make it smear and blur,so when used as a blendmap in the game,it would look more smooth and realistic,since squares look ugly.
Attached File  example.jpg   113.73KB   33 downloads

PARTNERS