Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jRaskell

World Transform not working for me...

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

I've got my textured quad working without much trouble, but now I'm trying to translate and rotate it with the world transform, and it's not working for me. Even when I took the code out of the Matrices tutorial sample code, it just doesn't work. The exe runs, and I still see my textured quad, but it won't rotate, it won't move, it won't do anything it wasn't already doing before I tried transforming it. My init call
HRESULT init_d3d(HWND hWnd){
	
	if(FAILED(g_pd3d = Direct3DCreate9(D3D_SDK_VERSION)))
		return E_FAIL;

	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	if(FAILED(g_pd3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice)))
		return E_FAIL;
	
	//g_pd3dDevice->SetVertexShader(NULL);

	//g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );


	CUSTOMVERTEX vertices[] =
	{
		{ -10.0f,  10.0f, 0.5f, 1.0f, 0xffffff00, 0.0f, 1.0f }, // x, y, z, rhw, color

		{ -10.0f, -10.0f, 0.5f, 1.0f, 0xffffffff, 0.0f, 0.0f },
		{ 10.0f, 10.0f, 0.5f, 1.0f, 0xff0000ff, 1.0f, 1.0f },
		{ 10.0f, -10.0f, 0.5f, 1.0f, 0xffffffff, 1.0f, 0.0f},
	};

	g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX),
         0 /* Usage */, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL );

	VOID* pVertices;
	g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 );
	memcpy( pVertices, &vertices, sizeof(vertices) );
	g_pVB->Unlock();


	//g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

	//g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);

	//g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

	//g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	//g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

	
	if(FAILED( D3DXCreateTextureFromFile(g_pd3dDevice, "texture.jpg", &g_pTexture)))
		return E_FAIL;

	return TRUE;


}
 
My render call
void Render(){

    D3DXMATRIXA16 matWorld;
	int x = 0;

	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
	// Begin the scene.

	g_pd3dDevice->BeginScene();

	//SetupMatrices();

	D3DXMatrixTranslation( &matWorld, 20.0f, 20.0f, 0.0f);
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );


    g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
    g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
	// Rendering of scene objects happens here.

	//g_pd3dDevice->SetTexture(0, g_pTexture);


	g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );



	// End the scene.

	g_pd3dDevice->EndScene();
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

}
 
The conditional on the SetTransform was just to see if it stepped inside the if when debugging, and the call returns successfully. I'm at a loss here. There are no errors, no flaky behavior other than a complete LACK of behavior. It runs exactly the same with or without the transform. [edited by - jraskell on April 13, 2004 9:21:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
You are using transformed vertexes. You need to get rid of the rhw part. You will also need to set up the view and projection matrix.

http://www.drunkenhyena.com/cgi-bin/view_article.pl?article=14

Share this post


Link to post
Share on other sites
Yup, that sorta worked.

At least, when I pulled out the rhw, everything disappeared. When I rearranged my vertice points though, I got the quad back, but it''s just all black now, not textured or colored. Here''s my new vertex buffer


CUSTOMVERTEX vertices[] =
{
{ -10.0f, -10.0f, 0.5f, 0xffffff00, 0.0f, 1.0f }, // x, y, z, color, u, v

{ -10.0f, 10.0f, 0.5f, 0xffffffff, 0.0f, 0.0f },
{ 10.0f, -10.0f, 0.5f, 0xff0000ff, 1.0f, 1.0f },
{ 10.0f, 10.0f, 0.5f, 0xffffffff, 1.0f, 0.0f},
};



The order of the list is
bottom left corner
top left corner
bottom right corner
top right corner

I had to flip the Y of the original list to get the quad to render, but I don''t see why the texture and colors aren''t being rendered.

I''m using SetupMatrices from the sample with some very minor changes right now, as listed below...

VOID SetupMatrices()
{
// For our world matrix, we will just rotate the object about the y-axis.

D3DXMATRIXA16 matWorld;

int x = 0;
// Set up the rotation matrix to generate 1 full rotation (2*PI radians)

// every 1000 ms. To avoid the loss of precision inherent in very high

// floating point numbers, the system time is modulated by the rotation

// period before conversion to a radian angle.

UINT iTime = timeGetTime() % 5000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 5000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
//D3DXMatrixTranslation( &matWorld, 20.0f, 20.0f, 0.0f);

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

// Set up our view matrix. A view matrix can be defined given an eye point,

// a point to lookat, and a direction for which way is up. Here, we set the

// eye five units back along the z-axis and up three units, look at the

// origin, and define "up" to be in the y-direction.

D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-50.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

// For the projection matrix, we set up a perspective transform (which

// transforms geometry from 3D view space to 2D viewport space, with

// a perspective divide making objects smaller in the distance). To build

// a perpsective transform, we need the field of view (1/4 pi is common),

// the aspect ratio, and the near and far clipping planes (which define at

// what distances geometry should be no longer be rendered).

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}

Share this post


Link to post
Share on other sites

  • 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!