Terrain.h
上传用户:whgydz
上传日期:2007-01-12
资源大小:2259k
文件大小:2k
源码类别:

其他书籍

开发平台:

HTML/CSS

  1. // Terrain.h: interface for the CTerrain class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_)
  5. #define AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <d3dx8.h>
  10. #include "Helper.h"
  11. //Define a FVF for our terrain
  12. #define TERRAIN_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)
  13. class CTerrain  
  14. {
  15. private:
  16. //Define a custom vertex for our terrain
  17. struct TERRAIN_CUSTOMVERTEX
  18. {
  19. FLOAT x, y, z; //Position of vertex in 3D space
  20. FLOAT nx, ny, nz; //Lighting Normal
  21. FLOAT tu, tv; //Texture coordinates
  22. };
  23. public:
  24. bool SetMaterial(D3DCOLORVALUE rgbaDiffuse, D3DCOLORVALUE rgbaAmbient, D3DCOLORVALUE rgbaSpecular, D3DCOLORVALUE rgbaEmissive, float rPower);
  25. bool SetTexture(const char* szTextureFilePath);
  26. bool SetSize(WORD wRows, WORD wCols, float rTileSize, WORD wMaxHeight);
  27. DWORD Render();
  28. CTerrain(LPDIRECT3DDEVICE8 pD3DDevice, WORD wRows = 10, WORD wCols = 10, float rTileSize = 10.0, WORD wMaxHeight = 15);
  29. virtual ~CTerrain();
  30. private:
  31. bool CreateIndexBuffer();
  32. D3DXVECTOR3 GetTriangeNormal(D3DXVECTOR3* vVertex1, D3DXVECTOR3* vVertex2, D3DXVECTOR3* vVertex3);
  33. bool UpdateVertices();
  34. HRESULT CreateVertexBuffer();
  35. LPDIRECT3DDEVICE8 m_pD3DDevice;
  36. LPDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
  37. LPDIRECT3DTEXTURE8 m_pTexture;
  38. D3DMATERIAL8 m_matMaterial;
  39. LPDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
  40. WORD m_wRows;
  41. WORD m_wCols;
  42. WORD m_wMaxHeight;
  43. float m_rTileSize;
  44. DWORD m_dwNumOfVertices;
  45. DWORD m_dwNumOfIndices;
  46. DWORD m_dwNumOfPolygons;
  47. };
  48. #endif // !defined(AFX_TERRAIN_H__605B63BD_B46A_44BF_A2F2_573132F97949__INCLUDED_)