WH3DInit.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:2k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "StdAfx.h"
  2. C3DInit::C3DInit()
  3. {
  4. CWHDXGraphicWindow* pxDXGWnd = GetDXGWindowPtr();
  5. assert(pxDXGWnd);
  6. m_pd3dDevice = pxDXGWnd->Get3DDevice();
  7. ZeroMemory(&m_matWorld, sizeof(D3DMATRIX));
  8. ZeroMemory(&m_matView, sizeof(D3DMATRIX));
  9. ZeroMemory(&m_matProj, sizeof(D3DMATRIX));
  10. ZeroMemory(&m_mtrl, sizeof(D3DMATERIAL7));
  11. }
  12. C3DInit::~C3DInit()
  13. {
  14. }
  15. HRESULT C3DInit::InitDeviceObjects()
  16. {
  17. // 泅犁 800*600拳搁俊 嘎霸 3D 谅钎拌甫 汲沥茄促.
  18.   D3DVECTOR vEyePt    = D3DVECTOR(0, 0, -300.0f);
  19.     D3DVECTOR vLookatPt = D3DVECTOR(0, 0, 0);
  20.     D3DVECTOR vUpVec    = D3DVECTOR(0, 1, 0);
  21.     D3DUtil_SetIdentityMatrix(m_matWorld);
  22.     D3DUtil_SetViewMatrix(m_matView, vEyePt, vLookatPt, vUpVec);
  23.     D3DUtil_SetProjectionMatrix(m_matProj, g_PI/2, float(600.0f/800.0f), -1.0f, 1.0f);
  24.     m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,      &m_matWorld);
  25.     m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_VIEW,       &m_matView);
  26.     m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &m_matProj);
  27. D3DUtil_InitMaterial(m_mtrl);
  28.     m_pd3dDevice->SetMaterial(&m_mtrl);
  29. // RenderState狼 檬扁蔼 汲沥.
  30. m_pd3dDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, 0xFFFFFFFF);
  31.     m_pd3dDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE); 
  32. m_pd3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE); 
  33. m_pd3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, D3DZB_FALSE);
  34. m_pd3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_SOLID);
  35. // m_pd3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME);
  36. m_pd3dDevice->SetRenderState(D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD);
  37.     // TextureStageState狼 檬扁蔼 汲沥.
  38. m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
  39.     m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); 
  40.     m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP,   D3DTOP_MODULATE);
  41.     m_pd3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_POINT); 
  42.     m_pd3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_POINT);
  43. m_pd3dDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTFP_NONE);
  44.     return S_OK;
  45. }