Skip to main content
gamedev.net
🔒 Locked

Camera projection error

Started by Dan_ Jan 8, 2007 at 6:28 AM 0 replies 1.2k views
Original Post
Dan_
Dan_
I'm currently writing my own graphics engine, using Direct3D 9 and I've so far gotten it to load a mesh and textures and render them. But I'm having trouble with my camera class. Here is a screenshot of my engine loading room.x from the DirectX samples: Photobucket - Video and Image Hosting And I can move my camera left, but the perspective doesn't seem to change: Photobucket - Video and Image Hosting And when I move it further, then it gets these artifacts: Photobucket - Video and Image Hosting I have no idea why this error is happening. Here is the code for when I update the camera:
void CDirect3D9Camera::Update(void *pData)
{
	// View Matrix
	D3DXMatrixPerspectiveLH(&m_ViewMatrix, 
							m_Setup.fFOV,
							m_Setup.fAspect,
							m_Setup.fNearClip,
							m_Setup.fFarClip);
	// Projection Matrix
	D3DXMatrixLookAtLH(&m_ProjectionMatrix,
					   &D3DXVECTOR3(m_Position.x, m_Position.y, m_Position.z),
					   &D3DXVECTOR3(m_Target.x, m_Target.y, m_Target.z),
					   &D3DXVECTOR3(m_Up.x, m_Up.y, m_Up.z));

	if (pData)
		m_Setup.pDevice = (IDirect3DDevice9*)pData;

	m_Setup.pDevice->SetTransform(D3DTS_VIEW, &m_ViewMatrix);
	m_Setup.pDevice->SetTransform(D3DTS_PROJECTION, &m_ProjectionMatrix);
}
From the last picture, the values of the variables are as follows: fFOV = 1.5707964 // In other words, D3DX_PI*0.5 fAspect = 1.3333334 fNearClip = 1.0 fFarClip = 1000.0 m_Position = { 1.0000001, 0.0, 0.0 } m_Target = { 0.0, 0.0, 60.0 } m_Up = { 0.0, 1.0, 0.0 } I have no clue why I'm getting these errors. Any help would be appreciated.
Dan_
Dan_
Aha I fixed it!

It was a silly mistake on my part, I was setting the device's view matrix as the projection matrix, and vice versa.

Below is the fixed code for anyone who comes across this in a search:

void CDirect3D9Camera::Update(void *pData){	// Projection Matrix	D3DXMatrixPerspectiveLH(&m_ProjectionMatrix, 							m_Setup.fFOV,							m_Setup.fAspect,							m_Setup.fNearClip,							m_Setup.fFarClip);	// View Matrix	D3DXMatrixLookAtLH(&m_ViewMatrix,					   &D3DXVECTOR3(m_Position.x, m_Position.y, m_Position.z),					   &D3DXVECTOR3(m_Target.x, m_Target.y, m_Target.z),					   &D3DXVECTOR3(m_Up.x, m_Up.y, m_Up.z));	if (pData)		m_Setup.pDevice = (IDirect3DDevice9*)pData;	m_Setup.pDevice->SetTransform(D3DTS_VIEW, &m_ViewMatrix);	m_Setup.pDevice->SetTransform(D3DTS_PROJECTION, &m_ProjectionMatrix);}

Topic Locked

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

Sign in to reply to this topic.