Walkmesh.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <Ogre.h>
  17. #include <vector>
  18. /**
  19. * A triangle of a walkmesh.
  20. */
  21. struct WalkmeshTriangle{
  22. /**
  23. * Constructor.
  24. */
  25. WalkmeshTriangle():
  26. a(0, 0, 0),
  27. b(0, 0, 0),
  28. c(0, 0, 0),
  29. locked(false)
  30. {
  31. access_side[0] = -1;
  32. access_side[1] = -1;
  33. access_side[2] = -1;
  34. }
  35. /**
  36. * A side of the triangle.
  37. */
  38. Ogre::Vector3 a;
  39. /**
  40. * A side of the triangle.
  41. */
  42. Ogre::Vector3 b;
  43. /**
  44. * A side of the triangle.
  45. */
  46. Ogre::Vector3 c;
  47. /**
  48. * @todo Understand and document.
  49. */
  50. int access_side[3];
  51. /**
  52. * Indicates if the triangle is locked (if it's walkable).
  53. */
  54. bool locked;
  55. };
  56. namespace QGears{
  57. typedef Ogre::SharedPtr<class WalkmeshFile> WalkmeshFilePtr;
  58. }
  59. class Walkmesh{
  60. public:
  61. /**
  62. * Constructor.
  63. */
  64. Walkmesh();
  65. /**
  66. * Destructor.
  67. */
  68. virtual ~Walkmesh();
  69. /**
  70. * Updates the walkmesh with debug information.
  71. */
  72. void UpdateDebug();
  73. /**
  74. * Deletes all the triangles in the walkmesh.
  75. */
  76. void Clear();
  77. /**
  78. * Adds a triangle to the walkmesh.
  79. *
  80. * @param triangle[in] Triangle to add.
  81. */
  82. void AddTriangle(const WalkmeshTriangle& triangle);
  83. /**
  84. * @todo Understand and document.
  85. *
  86. * @param triangle[in] Triangle.
  87. * @param side[in] The side index in the triangle.
  88. * @return @todo.
  89. */
  90. int GetAccessSide(unsigned int triangle_id, unsigned char side) const;
  91. /**
  92. * Retrieves the first side of a triangle.
  93. *
  94. * @param triangle_id[in] ID of the triangle.
  95. * @return The side of the triangle. Ogre::Vector3::ZERO if the
  96. * triangle doesn't exist.
  97. */
  98. const Ogre::Vector3& GetA(unsigned int triangle_id) const;
  99. /**
  100. * Retrieves the second side of a triangle.
  101. *
  102. * @param triangle_id[in] ID of the triangle.
  103. * @return The side of the triangle. Ogre::Vector3::ZERO if the
  104. * triangle doesn't exist.
  105. */
  106. const Ogre::Vector3& GetB(unsigned int triangle_id) const;
  107. /**
  108. * Retrieves the third side of a triangle.
  109. *
  110. * @param triangle_id[in] ID of the triangle.
  111. * @return The side of the triangle. Ogre::Vector3::ZERO if the
  112. * triangle doesn't exist.
  113. */
  114. const Ogre::Vector3& GetC(unsigned int triangle_id) const;
  115. /**
  116. * Counts the triangles in the walkmesh.
  117. *
  118. * @return The number of triangles in the walkmesh.
  119. */
  120. int GetNumberOfTriangles() const;
  121. /**
  122. * Locks or unlocks a triangle.
  123. *
  124. * @param triangle_id[in] ID of the triangle.
  125. * @param lock[in] True to lock, false to unlock.
  126. */
  127. void LockWalkmesh(unsigned int triangle_id, bool lock);
  128. /**
  129. * Checks if a triangle is locked.
  130. *
  131. * @param triangle_id[in] ID of the trinagle.
  132. * @return True if the triangle is locked, false otherwise.
  133. */
  134. bool IsLocked(unsigned int triangle_id) const;
  135. /**
  136. * Loads a walkmesh from a file.
  137. *
  138. * @param walkmesh[in] Walkmesh file.
  139. */
  140. virtual void load(const QGears::WalkmeshFilePtr &walkmesh);
  141. private:
  142. /**
  143. * The list of triangles.
  144. */
  145. std::vector<WalkmeshTriangle> triangles_;
  146. };