Jump to content
  • Advertisement
Sign in to follow this  
basgoossen

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

This topic is 4471 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

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!