fork download
  1. #include "EDE_GridSceneNode.h"
  2. #include <stdio.h>
  3.  
  4.  
  5. /*
  6.   ##############################
  7. # Setting Up the Cell Struct #
  8. ##############################
  9. */
  10.  
  11. EDE_GridSceneNode::Cell::Cell()
  12. {
  13. this->topLeft = vector3df();
  14. this->topRight = vector3df();
  15. this->bottomLeft = vector3df();
  16. this->bottomRight = vector3df();
  17. this->id = 0;
  18. this->visible = false;
  19. }
  20.  
  21. EDE_GridSceneNode::Cell::Cell(vector3df topLeft, vector3df topRight, vector3df bottomLeft, vector3df bottomRight, int id, bool visible)
  22. {
  23. this->id = id;
  24. this->visible = visible;
  25.  
  26. this->bottomLeft = bottomLeft;
  27. this->bottomRight = bottomRight;
  28. this->topLeft = topLeft;
  29. this->topRight = topRight;
  30. this->center = (bottomLeft + bottomRight + topLeft + topRight) / 4;
  31.  
  32. meshBuffer = NULL;
  33. meshBuffer = new CDynamicMeshBuffer(EVT_STANDARD, EIT_16BIT);
  34. setDefaultMaterial();
  35. }
  36.  
  37. EDE_GridSceneNode::Cell::~Cell()
  38. {
  39.  
  40. }
  41.  
  42. void EDE_GridSceneNode::Cell::setDefaultMaterial()
  43. {
  44. if (!meshBuffer)
  45. return;
  46.  
  47. meshBuffer->getMaterial().Wireframe = false;
  48. meshBuffer->getMaterial().Lighting = false;
  49. meshBuffer->getMaterial().Thickness = 1;
  50. meshBuffer->getMaterial().FogEnable = false;
  51. meshBuffer->getMaterial().ZWriteEnable = true;
  52. meshBuffer->getMaterial().ZBuffer = true;
  53. meshBuffer->getMaterial().BackfaceCulling = true;
  54. meshBuffer->getMaterial().AntiAliasing = false;
  55. }
  56.  
  57. void EDE_GridSceneNode::Cell::RenderCell(IVideoDriver* driver, SColor color = SColor(255, 255, 255, 255))
  58. {
  59. if (!visible)
  60. return;
  61.  
  62.  
  63. driver->setMaterial(meshBuffer->getMaterial());
  64. driver->setTransform(ETS_WORLD, matrix4());
  65. // Draw the Box
  66. driver->draw3DLine(topLeft, topRight, color); // TopLeft -> TopRight
  67. driver->draw3DLine(bottomLeft, bottomRight, color); // BottomLeft -> BottomRight
  68. driver->draw3DLine(topLeft, bottomLeft, color); // TopLeft -> BottomLeft
  69. driver->draw3DLine(topRight, bottomRight, color); // TopRight -> BottomRight
  70.  
  71. }
  72.  
  73. /*
  74. ##############################
  75. # Setting Up the Grid Class #
  76. ##############################
  77. */
  78. EDE_GridSceneNode::EDE_GridSceneNode(ISceneNode* parent, ISceneManager* smgr, s32 id)
  79. : scene::ISceneNode(parent, smgr, id)
  80. {
  81. gridCells = NULL;
  82. }
  83.  
  84. void EDE_GridSceneNode::init( int width, int height, vector3df gridPos, float cellSize)
  85. {
  86. this->width = width;
  87. this->height = height;
  88. this->gridPos = gridPos;
  89. this->cellSize = cellSize;
  90.  
  91. // Setting Up my 2D Grid Array
  92. gridCells = new Cell*[width];
  93. for (int i = 0; i < width; i++)
  94. gridCells[i] = new Cell[height];
  95. }
  96.  
  97. void EDE_GridSceneNode::createGridFlat(float cellSize)
  98. {
  99. for (int z = 0; z < height; z++)
  100. {
  101. for (int x = 0; x < width; x++)
  102. {
  103. vector3df v1 = vector3df((gridPos.X * (x+1)) + (x*cellSize), gridPos.Y, (gridPos.Z * (z+1)) + (z*cellSize));
  104. vector3df v2 = vector3df((gridPos.X * (x+1)) + (x*cellSize) + cellSize, gridPos.Y, (gridPos.Z * (z+1)) + (z*cellSize));
  105. vector3df v3 = vector3df((gridPos.X * (x+1)) + (x*cellSize), gridPos.Y, (gridPos.Z * (z+1)) + (z*cellSize) + cellSize);
  106. vector3df v4 = vector3df((gridPos.X * (x+1)) + (x*cellSize) + cellSize, gridPos.Y, (gridPos.Z * (z+1)) + (z*cellSize) + cellSize);
  107.  
  108. gridCells[x][z] = Cell(v1, v2, v3, v4, z + x, true);
  109.  
  110. }
  111. }
  112. }
  113.  
  114. void EDE_GridSceneNode::createGridOnTerrain(ISceneNode* terrainSceneNode, float cellSize)
  115. {
  116.  
  117. }
  118.  
  119. void EDE_GridSceneNode::renderGrid(IVideoDriver* driver, SColor color)
  120. {
  121. for (int z = 0; z < height; z++)
  122. {
  123. for (int x = 0; x < width; x++)
  124. {
  125. gridCells[x][z].RenderCell(driver, color);
  126. }
  127. }
  128. }
  129.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty