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.12 / terrain.h < prev   
Encoding:
C/C++ Source or Header  |  2006-06-29  |  1.9 KB  |  94 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. struct MAPTILE{
  40.     MAPTILE()    //Set everything to 0
  41.     {
  42.         m_type = m_set = 0; 
  43.         m_height = m_cost = 0.0f;
  44.         m_walkable = false;
  45.  
  46.         for(int i=0;i<8;i++)
  47.             m_neighbors[i] = NULL;
  48.     }
  49.  
  50.     int m_type, m_set;
  51.     float m_height, m_cost;
  52.     bool m_walkable;
  53.     MAPTILE* m_neighbors[8];
  54.  
  55.     //... more to come ...//
  56. };
  57.  
  58. class TERRAIN{
  59.     friend class APPLICATION;
  60.     public:
  61.         TERRAIN();        
  62.         void Init(IDirect3DDevice9* Dev, INTPOINT _size);
  63.         void Release();
  64.         void GenerateRandomTerrain(int numPatches);
  65.         void CreatePatches(int numPatches);
  66.         void CalculateAlphaMaps();
  67.         void AddObject(int type, INTPOINT mappos);
  68.         void Render();
  69.  
  70.         //Pathfinding
  71.         bool Within(INTPOINT p);    //Test if a point is within the bounds of the terrain
  72.         void InitPathfinding();
  73.         MAPTILE* GetTile(int x, int y);
  74.         MAPTILE* GetTile(INTPOINT p){return GetTile(p.x, p.y);}
  75.  
  76.         //Public variables
  77.         MAPTILE *m_pMaptiles;
  78.  
  79.     private:
  80.  
  81.         INTPOINT m_size;
  82.         IDirect3DDevice9* m_pDevice; 
  83.  
  84.         HEIGHTMAP *m_pHeightMap;
  85.         std::vector<PATCH*> m_patches;
  86.         std::vector<IDirect3DTexture9*> m_diffuseMaps;
  87.         std::vector<OBJECT> m_objects;
  88.         IDirect3DTexture9* m_pAlphaMap;
  89.         SHADER m_terrainPS;
  90.  
  91.         D3DMATERIAL9 m_mtrl;
  92. };
  93.  
  94. #endif