Skip to main content
gamedev.net
🔒 Locked

Matrices

Started by Zoltan Oct 17, 2005 at 11:18 PM 8 replies 1.1k views
Original Post
Zoltan
Zoltan
I'm having a problem getting any of my direct3D matices working. I'm using direct3d 9.0. I set up d3d9, set some present parameters, created a device, created a vertex buffer, and rendered a triangle to the screen (in window mode). The triangle is visible in the top left corner of the window. But I can't move my camera by adjusting the view matrix. Also my projection matrix seems to be not working. If I change any of the values in D3DXMatrixPerspectiveFovLH() nothing happens on screen. m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); and m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_matView ); aren't transforming the camera. Has anybody ran into this problem before?
Zoltan
Zoltan
my World Transformation Matrices Don't even work! Any help would be great. Any suggestions?
Sneftel
Sneftel
You are applying the transformations **BEFORE** drawing, right?
Zoltan
Zoltan
yup...And my device must obviously be fine because the triangle is on screen... but device->SetTransformation doesn't do anything.
Armadon
Armadon
Normally when you are working with transformation matrices you will follow a simple pattern.

1. Create the view and projection matrices.
i.e.
D3DXMATRIX matProj, matView, matWorld;

D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, 4.0f/3.0f, 1.0f, 1000.0);
pDevice->SetTransform(D3DTS_PROJECTION, &matProj);
D3DXMatrixTranslation(&matView, 0.0f, 0.0f, -100.0f);
Direct3d.pDevice->SetTransform(D3DTS_VIEW, &matView)

2. You will then when you render update the world transformation matrix
i.e.
D3DXMatrixTranslation(&matWorld, 0.0f, 0.0f, 0.0f);

3. Then set the transformation matrix for the specific object and render the object.
i.e.
pDevice->SetTransform(D3DTS_WORLD, &matWorld);
//render your object

If you are following these steps you won't run in too many problems.
Just check that your matrices are containing the information specified. Any other advice is that I might give might be a bit obscure, if you can supply us with some source code we might be able to guide you in the right direction.

PS: Make sure that you are using the correct vertex format, this is very important and D3DFVF_XYZ is untransformed vertices and D3DFVF_XYZRHW is transformed which means no transformation matrix set will change the object being rendered's position. So if you want to use matrices to transform your objects use D3DFVF_XYZ.

I hope this helps.
Take care.
Zoltan
Zoltan
Thanks for the replies...this is my code. Tell me what I am doing wrong? I just want to change the camera position at the start...so I plug in different values into the view matrix vectors...but that doesn't work.

int D3D9::D3DInit(HWND hWnd){	RECT rect;	GetClientRect(hWnd, ▭);	if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )	{		return E_FAIL;	}		if((m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&m_d3ddm))!= D3D_OK)	{return 0;} 	ZeroMemory(&m_d3dpp,sizeof(D3DPRESENT_PARAMETERS));			m_d3dpp.Windowed = true;	m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;		m_d3dpp.BackBufferFormat = m_d3ddm.Format; 	m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;	m_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;	m_d3dpp.BackBufferCount = 1;	m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;	m_d3dpp.hDeviceWindow = hWnd;	//Let Direct3d manage the depth buffer	//m_d3dpp.EnableAutoDepthStencil = true;	//Set the depth buffer to 16 bits	//m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;			if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING,                                  &m_d3dpp, &m_pd3dDevice ) ) )	{		return E_FAIL;	}		//Create Vertex Buffer	if( FAILED( m_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),        0 /*Usage*/, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) )	{        return E_FAIL;	}			//Set ViewPort	ZeroMemory(&m_vp, sizeof(D3DVIEWPORT9));	m_vp.X      = rect.left;	m_vp.Y      = rect.top;	m_vp.Width  = rect.right;	m_vp.Height = rect.bottom;	m_vp.MinZ   = 0.0f;	m_vp.MaxZ   = 1.0f;	m_pd3dDevice->SetViewport(&m_vp);	//Set Projection Matrix	D3DXMATRIX matProj;	ZeroMemory(&matProj, sizeof(D3DXMATRIX));	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );	m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );	//Set View Matrix	D3DXVECTOR3 vEyePt   ( 0.0f, 3.0f,-5.0f );	D3DXVECTOR3 vLookatPt( 100.0f, 50.0f, 0.0f );	D3DXVECTOR3 vUpVec   ( 0.0f, 1.0f, 0.0f );	D3DXMatrixLookAtLH( &m_matView, &vEyePt, &vLookatPt, &vUpVec );	m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_matView );	return 1;}


[Edited by - Coder on October 18, 2005 6:30:28 AM]
Sneftel
Sneftel
You're not calling SetTransform for the view matrix.
Scythen
Scythen
I see that you modify m_matView but I dont see you sending it to the device?
Zoltan
Zoltan
Yah...I accidently took it out by mistake last compile...but I put it back in and it still doesn't work. I added this back in:
m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_matView );
jollyjeffers
jollyjeffers
Quote:
Original post by Armadon
PS: Make sure that you are using the correct vertex format, this is very important and D3DFVF_XYZ is untransformed vertices and D3DFVF_XYZRHW is transformed which means no transformation matrix set will change the object being rendered's position. So if you want to use matrices to transform your objects use D3DFVF_XYZ.

In light of Armadon's comment - what is your vertex format (and FVF)??

I'm wondering if, because of your comment about "The triangle is visible in the top left corner of the window", if you're using a D3DFVF_XYZRHW format and effectively disabling the transform/lighting [smile]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

Topic Locked

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

Sign in to reply to this topic.