💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef TERRAIN_HPP
  20. #define TERRAIN_HPP
  21. #include "navmesh.hpp"
  22. #include <emergent/emergent.hpp>
  23. using namespace Emergent;
  24. class Terrain
  25. {
  26. public:
  27. Terrain();
  28. ~Terrain();
  29. /**
  30. * Creates a flat terrain surface.
  31. *
  32. * @param columns Specifies the width of the terrain, in cells.
  33. * @param rows Specifies the depth of the terrain, in cells.
  34. * @param dimensions Specifies the dimensions of the terrain.
  35. */
  36. void create(int columns, int rows, const Vector3& dimensions);
  37. /// Loads a heightmap
  38. bool load(const std::string& filename);
  39. /// Returns the navmesh representing the terrain surface.
  40. const Navmesh* getSurfaceNavmesh() const;
  41. /// Returns the navmesh representing the terrain surface.
  42. Navmesh* getSurfaceNavmesh();
  43. /// Returns the navmesh representing the terrain subsurface.
  44. const Navmesh* getSubsurfaceNavmesh() const;
  45. /// Returns the navmesh representing the terrain subsurface.
  46. Navmesh* getSubsurfaceNavmesh();
  47. /// Returns the model representing the terrain surface.
  48. const Model* getSurfaceModel() const;
  49. /// Returns the model representing the terrain surface.
  50. Model* getSurfaceModel();
  51. /// Returns the model representing the terrain subsurface.
  52. const Model* getSubsurfaceModel() const;
  53. /// Returns the model representing the terrain subsurface.
  54. Model* getSubsurfaceModel();
  55. const Octree<Navmesh::Triangle*>* getSurfaceOctree() const;
  56. private:
  57. void createSurface();
  58. void createSubsurface();
  59. void calculateSurfaceNormals();
  60. int columns;
  61. int rows;
  62. Vector3 dimensions;
  63. // Surface
  64. std::size_t surfaceVertexSize;
  65. std::size_t surfaceVertexCount;
  66. std::size_t surfaceTriangleCount;
  67. std::size_t surfaceIndexCount;
  68. float* surfaceVertexData;
  69. std::uint32_t* surfaceIndexData;
  70. std::vector<Vector3> surfaceVertices;
  71. std::vector<std::size_t> surfaceIndices;
  72. GLuint surfaceVAO;
  73. GLuint surfaceVBO;
  74. GLuint surfaceIBO;
  75. //PhysicalMaterial surfaceMaterial;
  76. Model surfaceModel;
  77. Navmesh surfaceNavmesh;
  78. Octree<Navmesh::Triangle*>* surfaceOctree;
  79. // Subsurface
  80. std::size_t subsurfaceVertexSize;
  81. std::size_t subsurfaceVertexCount;
  82. std::size_t subsurfaceTriangleCount;
  83. std::size_t subsurfaceIndexCount;
  84. float* subsurfaceVertexData;
  85. std::uint32_t* subsurfaceIndexData;
  86. std::vector<Vector3> subsurfaceVertices;
  87. std::vector<std::size_t> subsurfaceIndices;
  88. GLuint subsurfaceVAO;
  89. GLuint subsurfaceVBO;
  90. GLuint subsurfaceIBO;
  91. //PhysicalMaterial subsurfaceMaterial;
  92. Model subsurfaceModel;
  93. Navmesh subsurfaceNavmesh;
  94. };
  95. inline Navmesh* Terrain::getSurfaceNavmesh()
  96. {
  97. return &surfaceNavmesh;
  98. };
  99. inline const Navmesh* Terrain::getSurfaceNavmesh() const
  100. {
  101. return &surfaceNavmesh;
  102. };
  103. inline Navmesh* Terrain::getSubsurfaceNavmesh()
  104. {
  105. return &subsurfaceNavmesh;
  106. };
  107. inline const Navmesh* Terrain::getSubsurfaceNavmesh() const
  108. {
  109. return &subsurfaceNavmesh;
  110. };
  111. inline const Model* Terrain::getSurfaceModel() const
  112. {
  113. return &surfaceModel;
  114. }
  115. inline Model* Terrain::getSurfaceModel()
  116. {
  117. return &surfaceModel;
  118. }
  119. inline const Model* Terrain::getSubsurfaceModel() const
  120. {
  121. return &subsurfaceModel;
  122. }
  123. inline Model* Terrain::getSubsurfaceModel()
  124. {
  125. return &subsurfaceModel;
  126. }
  127. inline const Octree<Navmesh::Triangle*>* Terrain::getSurfaceOctree() const
  128. {
  129. return surfaceOctree;
  130. }
  131. #endif // TERRAIN_HPP