[C++][WIN32][DirectX] world matrix transform not responding

Started by
4 comments, last by basgoossen 17 years, 8 months ago
hello, This week i started out on c++ and direct3d, so in that case i'd consider me as a NOOB (tnx). with a lot of experience in object oriented programming, the switch to c++ doesn't cause trouble. but i'm having a bit trouble on Direct3d. drawing primitives directly to the screen works ok, but now i wanted to ad the famous matrices (view, projection and world). all compiles and runs quite well without any error's or info tags from the d3ddebug mode regarding this problem. but for some reason nothing happends to the result on screen. i was following the Drunken Hyena tutorial on this.

HRESULT createWorld(IDirect3DDevice9 *d3d_device, int window_width, int window_height )
{
HRESULT hr;
D3DXVECTOR3 eye_vector,lookat_vector,up_vector;
D3DXMATRIX view_matrix;
D3DXMATRIX projection_matrix;
D3DXMATRIX world_matrix;
float aspect;

	aspect=((float)window_width / (float)window_height);

	eye_vector=D3DXVECTOR3( 0.0f, 0.0f,-8.0f );

	lookat_vector=D3DXVECTOR3( 0.0f, 0.0f, 0.0f );

	up_vector=D3DXVECTOR3(0.0f,1.0f,0.0f);

	D3DXMatrixLookAtLH(&view_matrix,
					  &eye_vector,
					  &lookat_vector,
					  &up_vector);

	hr = d3d_device->SetTransform(D3DTS_VIEW,&view_matrix);
	if(FAILED(hr))
	{
		return(hr);
	}

	D3DXMatrixPerspectiveFovLH(&projection_matrix,
                              D3DX_PI/4,
                              aspect,
                              1.0f,
                              100.0f );

	hr = d3d_device->SetTransform(D3DTS_PROJECTION, &projection_matrix);
	if(FAILED(hr))
	{
		return(hr);
	}

	D3DXMatrixIdentity(&world_matrix);

	hr = d3d_device->SetTransform(D3DTS_WORLD,&world_matrix);
	if(FAILED(hr))
	{
		return(hr);
	}
	
	hr = d3d_device->SetRenderState(D3DRS_LIGHTING,FALSE);

	return(hr);
}

if more of the source is needed to tackle the result please let me know. rendering is not effected, whether i call the routine or not. Thanks in advance
It's all about 1's and 0' beïng in the right place at the right time.
Advertisement
What are you trying to render? And what result are you getting on screen if that code changes nothing? Are you seeing just an empty screen?
just an idea:
Perhaps your mesh is bigger than you expect and your camera is inside the mesh. That might be the case if you´re seeing nothing. To test for that I´d try the following:
in the call to D3DDevice::Clear(...) specify some color that does not normally appear on your scene otherwise (magenta for example). See if your screen is filled with that color then. If it is, try disabling backface culling, if you´re inside the mesh, the backfaces should be rendered anyway and you should see something different than the color you specified for Clear(...).
Perhaps backface culling alone is your problem, but I don´t think so, as you said it worked fine without the matrices.

That is just a guess, because you didn´t mention what you´re actually seeing on screen. I guess a more thorough description of what you´re trying to render and what error you get might help ;)

Perhaps that helped already
good luck
at this point i render a two triangle square (TRIANGLESTRIP), build from ex.: rhw_vector a it appeers on the screen,

ex.:struct rhw_vector{    float x,y,z,rhw;    DWORD color; }ex.:rhw_vector square[] = {    {150,150,0,0xFFFF0000},    {150,250,0,0xFF00FFFF},    {250,150,0,0xFF00FF00},    {250,250,0,0xFF0000FF}};


this is the way i created it drawing it on the screen (maybe te order is slightly different for the culling), but with the world matrix set, i would have expected to be able to do:

rhw_vector square[] = {    {-1,-1,0,0xFFFF0000},    {-1,1,0,0xFF00FFFF},    {1,-1,0,0xFF00FF00},    {1,1,0,0xFF0000FF}};


and have it centered and scaled on the screen, like told and shown in the tutorial, but nothing happends, the last square draws as a dot in the upper left corner (logic when nothing happends), and the first draws as if drawn on the screen.
It's all about 1's and 0' beïng in the right place at the right time.
As you´re using a x,y,z and rhw, I suppose you use D3DFVF_XYZRHW, too?
Quote:from the DirectX SDK Docs
D3DFVF_XYZRHW
Vertex format includes the position of a transformed vertex. This flag cannot be used with the D3DFVF_XYZ or D3DFVF_NORMAL flags.

That means: If you´re using XYZRHW you´re specifying already transformed vertices, so they won´t be transformed again. If you want to have your vertices transformed you should use D3DFVF_XYZ instead. That means you would have to have two different vertex structs: The one for D3DFVF_XYZRHW will need one float more than the one for D3DFVF_XYZ. Of course you´d need to use the fitting FVF for both of these structs while rendering.

Hope that helped
Thanks a lot, i suppose that would be the problem, i can't test till this aftrenoon 19:00 GMT+1, but that seems very acceptable.
thanks a lot again.
It's all about 1's and 0' beïng in the right place at the right time.

This topic is closed to new replies.

Advertisement