home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 4 / Example 4.11 / terrain.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-28  |  1.3 KB  |  67 lines

  1. #ifndef _TERRAIN_
  2. #define _TERRAIN_
  3.  
  4. #include <d3dx9.h>
  5. #include <vector>
  6. #include "heightmap.h"
  7. #include "debug.h"
  8. #include "shader.h"
  9. #include "object.h"
  10.  
  11. struct TERRAINVertex
  12. {
  13.     TERRAINVertex(){}
  14.     TERRAINVertex(D3DXVECTOR3 pos, D3DXVECTOR2 _uv1, D3DXVECTOR2 _uv2)
  15.     {
  16.         position = pos;
  17.         normal = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
  18.         uv1 = _uv1;
  19.         uv2 = _uv2;
  20.     }
  21.  
  22.     D3DXVECTOR3 position, normal;
  23.     D3DXVECTOR2 uv1, uv2;
  24.  
  25.     static const DWORD FVF;
  26. };
  27.  
  28. struct PATCH{
  29.     PATCH();
  30.     ~PATCH();
  31.     void Release();
  32.     HRESULT CreateMesh(HEIGHTMAP &hm, RECT source, IDirect3DDevice9* Dev);
  33.     void Render();
  34.  
  35.     IDirect3DDevice9* m_pDevice;
  36.     ID3DXMesh *m_pMesh;
  37. };
  38.  
  39. class TERRAIN{
  40.     friend class APPLICATION;
  41.     public:
  42.         TERRAIN();        
  43.         void Init(IDirect3DDevice9* Dev, INTPOINT _size);
  44.         void Release();
  45.         void GenerateRandomTerrain(int numPatches);
  46.         void CreatePatches(int numPatches);
  47.         void CalculateAlphaMaps();
  48.         void AddObject(int type, INTPOINT mappos);
  49.         void Render();
  50.  
  51.  
  52.     private:
  53.  
  54.         INTPOINT m_size;
  55.         IDirect3DDevice9* m_pDevice; 
  56.  
  57.         HEIGHTMAP *m_pHeightMap;
  58.         std::vector<PATCH*> m_patches;
  59.         std::vector<IDirect3DTexture9*> m_diffuseMaps;
  60.         std::vector<OBJECT> m_objects;
  61.         IDirect3DTexture9* m_pAlphaMap;
  62.         SHADER m_terrainPS;
  63.  
  64.         D3DMATERIAL9 m_mtrl;
  65. };
  66.  
  67. #endif