D3DXMATRIX matProj;
FLOAT fAspect = GfxSys.HorzSize / (FLOAT)GfxSys.VertSize;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
// Set up the default texture states
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP );
g_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE ); // False
// HACK Make a light... (doesnt show up)
D3DLIGHT8 Light;
D3DCOLORVALUE color;
D3DVECTOR Vector;
Vector.x = 0.0f;
Vector.y = -10.0f;
Vector.z = 0.0f;
color.r = 155.0f;
color.g = 155.0f;
color.b = 255.0f;
color.a = 255.0f;
Light.Type = D3DLIGHT_POINT;
//color = D3DCOLOR_COLORVALUE(255,255,255,255);
Light.Diffuse = color;
Light.Specular = color;
Light.Ambient = color;
Light.Position = Vector;
//Light.Direction
Light.Range = 100.0f;
Light.Falloff = 1.0f;
Light.Attenuation0 = 10.0f;
Light.Attenuation1 = 10.0f;
Light.Attenuation2 = 10.0f;
Light.Theta = 5.0f;
Light.Phi = D3DX_PI;
g_pd3dDevice->SetLight(0, &Light);
g_pd3dDevice->LightEnable(0, true);
This is what call to rotate the terrain...
//-----------------------------------------------------------------------------
// Name: FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
// the scene.
//-----------------------------------------------------------------------------
HRESULT FrameMove()
{
// Get the eye and lookat points from the camera''s path
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXVECTOR3 vEyePt;
D3DXVECTOR3 vLookatPt;
//float m_fTime = g_fCalcDelta
static int i = 0;
i++;
if(i > 1000) i = 0;
float m_fTime;
m_fTime = float(i) / 1000;
vEyePt.x = 30.0f*cosf( 0.8f * ( m_fTime ) );
vEyePt.z = 30.0f*sinf( 0.8f * ( m_fTime ) );
vEyePt.y = 4 + HeightField( vEyePt.x, vEyePt.z );
vLookatPt.x = 30.0f*cosf( 0.8f * ( m_fTime + 0.5f ) );
vLookatPt.z = 30.0f*sinf( 0.8f * ( m_fTime + 0.5f ) );
vLookatPt.y = vEyePt.y - 1.0f;
// Set the app view matrix for normal viewing
D3DXMATRIX matView;
D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
return S_OK;
}
I load and render the xfile like so...
// Load the x file (on init)...
lpMesh = new CD3DMesh();
HRESULT hr = lpMesh->Create( g_pd3dDevice, _T("Terrain.x");
if(FAILED(hr))
{
delete lpMesh;
return false;
}
lpMesh->RestoreDeviceObjects(g_pD3dDevice);
// Render the mesh (per frame)
lpMesh->Render( g_pd3dDevice );
A few questions...
1) Is the initial matrix the main world matrix? Do all other matrixes reside within the world matrix?
2) To move the camera do I move a matrix or do I move the camera (If I have one)?
3) How big (in x,y,z float values) is the world matrix?
4) Why isnt my light working? Which values are incorrect?
Thanks in advance.
Downloads, D3DXSprite tutorial, New platform game: .-= The ZeroOne Realm =-.