quad.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //---------------------------------------------------------------------------
  2. //
  3. // Quad.h -- File contains class definitions for the Terrain Quads
  4. //
  5. // MechCommander 2
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef QUAD_H
  11. #define QUAD_H
  12. //---------------------------------------------------------------------------
  13. // Include Files
  14. #ifndef DQUAD_H
  15. #include "dquad.h"
  16. #endif
  17. #ifndef DVERTEX_H
  18. #include "dvertex.h"
  19. #endif
  20. #ifndef DSTD_H
  21. #include "dstd.h"
  22. #endif
  23. //---------------------------------------------------------------------------
  24. typedef struct _TerrainUVData
  25. {
  26. float minU;
  27. float minV;
  28. float maxU;
  29. float maxV;
  30. } TerrainUVData;
  31. typedef struct _MineResult
  32. {
  33. DWORD mineData;
  34. void init (void)
  35. {
  36. mineData = 0;
  37. }
  38. void setMine (DWORD pos, unsigned char data)
  39. {
  40. DWORD result = (data << (pos << 1));
  41. mineData |= result;
  42. }
  43. DWORD getMine(DWORD pos)
  44. {
  45. DWORD result = (mineData >> (pos << 1)) & (0x3);
  46. return result;
  47. }
  48. } MineResult;
  49. class TerrainQuad
  50. {
  51. //Data Members
  52. //-------------
  53. public:
  54. VertexPtr vertices[4]; //Pointers to vertices defining this tile.
  55. DWORD terrainHandle; //Handle to texture to draw.
  56. DWORD terrainDetailHandle; //Handle to detail texture to draw.
  57. DWORD waterHandle; //Handle to water texture to draw.
  58. DWORD waterDetailHandle; //Handle to Water Detail texture to draw.
  59. DWORD overlayHandle; //Handle to overlay texture to draw.
  60. DWORD uvMode; //Is this a top or bottom triangle?
  61. MineResult mineResult; //Is there a mine or exploded mine in this cell on this tile?
  62. TerrainUVData uvData; //Stores the min and max UVs for this face.
  63. bool isCement; //Need to know if this tile is cement for a number of reasons
  64. static float rainLightLevel; //How much to darken terrain based on rain
  65. static DWORD lighteningLevel; //How much to lighten terrain based on lightening.
  66. static DWORD mineTextureHandle; //Handle to the mine textures.
  67. static DWORD blownTextureHandle;
  68. #ifdef _DEBUG
  69. bool selected; //Debug to show which triangle I am on.
  70. #endif
  71. //Member Functions
  72. //-----------------
  73. public:
  74. void init (void)
  75. {
  76. for (int i=0;i<4;i++)
  77. vertices[i] = NULL;
  78. terrainHandle = 0xffffffff;
  79. terrainDetailHandle = 0xffffffff;
  80. waterHandle = 0xffffffff;
  81. waterDetailHandle = 0xffffffff;
  82. uvMode = 0;
  83. uvData.maxU = uvData.minU = uvData.minV = uvData.maxV = 0.0f;
  84. mineResult.init();
  85. isCement = false;
  86. }
  87. TerrainQuad (void)
  88. {
  89. init();
  90. }
  91. void destroy (void)
  92. {
  93. }
  94. ~TerrainQuad (void)
  95. {
  96. destroy();
  97. }
  98. long init (VertexPtr v0, VertexPtr v1, VertexPtr v2, VertexPtr v3);
  99. void setupTextures (void);
  100. void draw (void);
  101. void drawMine (void);
  102. void drawLine (void);
  103. void drawDebugCellLine (void);
  104. void drawLOSLine (void);
  105. void drawWater (void);
  106. };
  107. //---------------------------------------------------------------------------
  108. #endif