💿🐜 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.

162 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 "../materials.hpp"
  23. #include <emergent/emergent.hpp>
  24. using namespace Emergent;
  25. class Terrain
  26. {
  27. public:
  28. Terrain();
  29. ~Terrain();
  30. /**
  31. * Creates a flat terrain surface.
  32. *
  33. * @param columns Specifies the width of the terrain, in cells.
  34. * @param rows Specifies the depth of the terrain, in cells.
  35. * @param dimensions Specifies the dimensions of the terrain.
  36. */
  37. void create(int columns, int rows, const Vector3& dimensions);
  38. /// Loads a heightmap
  39. bool load(const std::string& filename);
  40. /// Returns the navmesh representing the terrain surface.
  41. const Navmesh* getSurfaceNavmesh() const;
  42. /// Returns the navmesh representing the terrain surface.
  43. Navmesh* getSurfaceNavmesh();
  44. /// Returns the navmesh representing the terrain subsurface.
  45. const Navmesh* getSubsurfaceNavmesh() const;
  46. /// Returns the navmesh representing the terrain subsurface.
  47. Navmesh* getSubsurfaceNavmesh();
  48. /// Returns the model representing the terrain surface.
  49. const Model* getSurfaceModel() const;
  50. /// Returns the model representing the terrain surface.
  51. Model* getSurfaceModel();
  52. /// Returns the model representing the terrain subsurface.
  53. const Model* getSubsurfaceModel() const;
  54. /// Returns the model representing the terrain subsurface.
  55. Model* getSubsurfaceModel();
  56. const Octree<Navmesh::Triangle*>* getSurfaceOctree() const;
  57. private:
  58. void createSurface();
  59. void createSubsurface();
  60. void calculateSurfaceNormals();
  61. int columns;
  62. int rows;
  63. Vector3 dimensions;
  64. // Surface
  65. std::size_t surfaceVertexSize;
  66. std::size_t surfaceVertexCount;
  67. std::size_t surfaceTriangleCount;
  68. std::size_t surfaceIndexCount;
  69. float* surfaceVertexData;
  70. std::uint32_t* surfaceIndexData;
  71. std::vector<Vector3> surfaceVertices;
  72. std::vector<std::size_t> surfaceIndices;
  73. GLuint surfaceVAO;
  74. GLuint surfaceVBO;
  75. GLuint surfaceIBO;
  76. PhysicalMaterial surfaceMaterial;
  77. Model surfaceModel;
  78. Navmesh surfaceNavmesh;
  79. Octree<Navmesh::Triangle*>* surfaceOctree;
  80. // Subsurface
  81. std::size_t subsurfaceVertexSize;
  82. std::size_t subsurfaceVertexCount;
  83. std::size_t subsurfaceTriangleCount;
  84. std::size_t subsurfaceIndexCount;
  85. float* subsurfaceVertexData;
  86. std::uint32_t* subsurfaceIndexData;
  87. std::vector<Vector3> subsurfaceVertices;
  88. std::vector<std::size_t> subsurfaceIndices;
  89. GLuint subsurfaceVAO;
  90. GLuint subsurfaceVBO;
  91. GLuint subsurfaceIBO;
  92. PhysicalMaterial subsurfaceMaterial;
  93. Model subsurfaceModel;
  94. Navmesh subsurfaceNavmesh;
  95. };
  96. inline Navmesh* Terrain::getSurfaceNavmesh()
  97. {
  98. return &surfaceNavmesh;
  99. };
  100. inline const Navmesh* Terrain::getSurfaceNavmesh() const
  101. {
  102. return &surfaceNavmesh;
  103. };
  104. inline Navmesh* Terrain::getSubsurfaceNavmesh()
  105. {
  106. return &subsurfaceNavmesh;
  107. };
  108. inline const Navmesh* Terrain::getSubsurfaceNavmesh() const
  109. {
  110. return &subsurfaceNavmesh;
  111. };
  112. inline const Model* Terrain::getSurfaceModel() const
  113. {
  114. return &surfaceModel;
  115. }
  116. inline Model* Terrain::getSurfaceModel()
  117. {
  118. return &surfaceModel;
  119. }
  120. inline const Model* Terrain::getSubsurfaceModel() const
  121. {
  122. return &subsurfaceModel;
  123. }
  124. inline Model* Terrain::getSubsurfaceModel()
  125. {
  126. return &subsurfaceModel;
  127. }
  128. inline const Octree<Navmesh::Triangle*>* Terrain::getSurfaceOctree() const
  129. {
  130. return surfaceOctree;
  131. }
  132. #endif // TERRAIN_HPP