D3D X file -> buffer depth?
Hi,
I'm having a major problem. I can't figure out why the following happens:
--Screenshot of the visual problem: http://mm2.dacris.com/vehicle.jpg
1. I load a mesh from a file.
2. I set matrices to "standard" values, similar to those in the Direct3D samples.
3. I set lights, materials, and all else.
4. I render the mesh.
Problem when testing the program:
The mesh loads correctly, the materials and lights show up correctly. However, for some bizarrely odd reason, the car (the mesh that I loaded) is "flattened out" in the sense that all faces are shown at pretty much the same depth. I have set the auto stencil & depth buffer to enabled and bit depth 16. What am I doing wrong? Here's the code:
{
char file[260];
sprintf(file, "%s\\Vehicles\\Geometry\\%s.x", g_TempDir, player.vehicle.name);
Car *mesh;
mesh = new Car();
mesh->LoadMesh(file);
// Setup render state
dx8.pd3dDevice->Clear ( 0 , NULL , D3DCLEAR_ZBUFFER , D3DCOLOR_ARGB ( 0, 0 , 0 , 0 ) , 1.0f, 0 ) ; // a workaround I tried to implement
dx8.pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
dx8.pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
dx8.pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
dx8.pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
dx8.pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
// Setup the light
D3DLIGHT8 light;
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = light.Diffuse.g = light.Diffuse.b = 1.0f;
light.Specular.r = light.Specular.g = light.Specular.b = 0.0f;
light.Ambient.r = light.Ambient.g = light.Ambient.b = 0.3f;
light.Position = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &D3DXVECTOR3( 0.3f, -1.0f, 1.0f ) );
light.Attenuation0 = light.Attenuation1 = light.Attenuation2 = 0.0f;
light.Range = sqrtf(FLT_MAX);
dx8.pd3dDevice->SetLight(0, &light );
dx8.pd3dDevice->LightEnable(0, TRUE );
FLOAT fAspect = 1.0;
D3DXMATRIX matProj;
D3DXMATRIX matWorld;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0,
500);
D3DXMatrixTranslation( &matWorld, 0,
0,
0);
D3DXMATRIX matTemp;
D3DXMatrixRotationY(&matTemp, (D3DX_PI/16)*g_CarPos);
g_CarPos--;
if(g_CarPos == -33)
g_CarPos = 0;
D3DXMatrixMultiply(&matWorld, &matTemp, &matWorld);
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0, 2,-10),
&D3DXVECTOR3( 0, 0, 0 ),
&D3DXVECTOR3( 0, 1, 0 ) );
dx8.pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
dx8.pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
dx8.pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
mesh->Render();
mesh->UnloadMesh();
}
Thanks in advance.
Edited by - dacrisxp on October 19, 2001 4:30:41 PM
You''re not starting with an identity matrix to with when calculating the matrices:
D3DXMATRIX matProj;
D3DXMATRIX matWorld;
D3DXMATRIX matTemp;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f,
500.0f);
// Set an identity to start with
D3DXMatrixIdentity(&matWorld);
// use time based rotation
// Always rotate first, then translate
D3DXMatrixRotationY(&matTemp, (float)timeGetTime() / 1000.0f);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTemp);
D3DXMatrixTranslation(&matTemp, 0.0f, 0.0f, 0.0f);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTemp);
Always try to specify float values by using a trailing decimal point and f data type specifier (0.0f for example). Also, your far clipping range should be set higher - some video cards work directly off this number and act wierd if the number is not high enough (regardless if z-buffering is enabled or not).
Also, use the value D3DZB_TRUE instead of TRUE in z-buffer enabling render state (just to be politically correct).
Jim Adams
Author - "Programming Role-Playing Games With DirectX 8.0"
Jim Adams
home.att.net/~rpgbook
Programming Role-Playing Games with DirectX 8
D3DXMATRIX matProj;
D3DXMATRIX matWorld;
D3DXMATRIX matTemp;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f,
500.0f);
// Set an identity to start with
D3DXMatrixIdentity(&matWorld);
// use time based rotation
// Always rotate first, then translate
D3DXMatrixRotationY(&matTemp, (float)timeGetTime() / 1000.0f);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTemp);
D3DXMatrixTranslation(&matTemp, 0.0f, 0.0f, 0.0f);
D3DXMatrixMultiply(&matWorld, &matWorld, &matTemp);
Always try to specify float values by using a trailing decimal point and f data type specifier (0.0f for example). Also, your far clipping range should be set higher - some video cards work directly off this number and act wierd if the number is not high enough (regardless if z-buffering is enabled or not).
Also, use the value D3DZB_TRUE instead of TRUE in z-buffer enabling render state (just to be politically correct).
Jim Adams
Author - "Programming Role-Playing Games With DirectX 8.0"
Jim Adams
home.att.net/~rpgbook
Programming Role-Playing Games with DirectX 8
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement