Skip to main content
gamedev.net
🔒 Locked

Problem with Setting transformations

Started by MarauderX 1 reply 250+ views
Original Post
MarauderX
MarauderX
Could some one please tell me what I'm doing wrong? The SetTransform funtions don't work. I do see my two triangles, but I also want them to rotate. I searched the internet, the documentation and two books, but I can't find a solution. With kind regards, MarauderX

void DoSomething(void)
{
	CUSTOMVERTEX vertices[] =
	{
		{ 150.0f,  50.0f, 0.5f, 1.0f, 0xffff0000, }, // RED x, y, z, rhw, color
		{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, }, // GREEN
		{  50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, }, // CYAN
		{ 150.0f, 450.0f, 0.5f, 1.0f, 0xffffffff, }, // WHITE

	};

	// for this post: I'm putting stuff in a buffer here (no problems)

	while(true)
	{
		if (::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			// do something
		}
		else
		{

			
			D3DXVECTOR3 vEyePt   ( 0.0f, 3.0f,-5.0f );
			D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
			D3DXVECTOR3 vUpVec   ( 0.0f, 1.0f, 0.0f );
			D3DXMATRIXA16 matView;
			D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
			pDevice->SetTransform( D3DTS_VIEW, &matView );


			D3DXMATRIX matProj;
			D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
			pDevice->SetTransform( D3DTS_PROJECTION, &matProj );

			pDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1.0f,0);

			pDevice->BeginScene();

			D3DXMATRIX matWorld;
			D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );
			pDevice->SetTransform( D3DTS_WORLD, &matWorld );


			pDevice->SetStreamSource( 0, vBuffer, 0, sizeof(CUSTOMVERTEX) );
			pDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

			pDevice->SetIndices(iBuffer);

			pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2);

			pDevice->EndScene();
			pDevice->Present(0, 0, 0, 0);

		}
	}
}



Agony
Agony
When you use D3DFVF_XYZRHW, the RHW part is essentially telling Direct3D that your vertices are already transformed into pixel coordinates, so all vertex transformations are completely ignored. Instead, you want to use D3DFVF_XYZ, and take out the RHW component.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
Sevans
Sevans
Just to add to the last reply, the RHW stands for Reciprocal of the Homogenous W. If you have taken some advanced mathematics you may not what this is. If not, don't worry about it. You will just need to know how to use it when you decide to do 2D coordinates. It represents the distance of the viewpoint to the vertex along the Z axis (since 2D in DirectX8.0+ is really done with 3D libs). When doing 2d coords you can almost always safely set this to 1.0f.

Hope this helps some :)

-sevans
-Sevans

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.