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

124 lines
3.2 KiB

  1. /*
  2. * Copyright (C) 2021 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 ANTKEEPER_SCENE_LOD_GROUP_HPP
  20. #define ANTKEEPER_SCENE_LOD_GROUP_HPP
  21. #include "scene/object.hpp"
  22. #include "geom/aabb.hpp"
  23. #include <list>
  24. #include <vector>
  25. namespace scene {
  26. class camera;
  27. class lod_group: public object<lod_group>
  28. {
  29. public:
  30. typedef geom::aabb<float> aabb_type;
  31. /**
  32. * Creates a LOD group.
  33. *
  34. * @param level_count Number of detail levels in the group.
  35. */
  36. lod_group(std::size_t level_count);
  37. /// Creates a LOD group with one level of detail.
  38. lod_group();
  39. /**
  40. * Resizes the LOD group to accommodate the specified number of detail levels.
  41. *
  42. * @param level_count Number of desired detail levels in the group.
  43. */
  44. void resize(std::size_t level_count);
  45. /**
  46. * Selects the appropriate level of detail for a camera.
  47. *
  48. * @param camera Camera for which the LOD should be selected.
  49. * @return Selected level of detail.
  50. */
  51. std::size_t select_lod(const camera& camera) const;
  52. /**
  53. * Adds an object to the LOD group.
  54. *
  55. * @param level Level of detail of the object to add.
  56. * @param object Object to add.
  57. */
  58. void add_object(std::size_t level, object_base* object);
  59. /**
  60. * Removes an object from the LOD group.
  61. *
  62. * @param level Level of detail of the object to remove.
  63. * @param object Object to remove.
  64. */
  65. void remove_object(std::size_t level, object_base* object);
  66. /**
  67. * Removes all objects with the specified level of detail.
  68. *
  69. * @param level Level of detail of the objects to remove.
  70. */
  71. void remove_objects(std::size_t level);
  72. virtual const bounding_volume_type& get_bounds() const;
  73. /// Returns the number of detail levels in the group.
  74. std::size_t get_level_count() const;
  75. /**
  76. * Returns a list containing all objects in the LOD group with the specified detail level.
  77. *
  78. * @param level Level of detail.
  79. * @return List of all objects in the group with the specified detail level.
  80. */
  81. const std::list<object_base*>& get_objects(std::size_t level) const;
  82. private:
  83. void update_bounds();
  84. virtual void transformed();
  85. aabb_type bounds;
  86. std::vector<std::list<object_base*>> levels;
  87. };
  88. inline const typename object_base::bounding_volume_type& lod_group::get_bounds() const
  89. {
  90. return bounds;
  91. }
  92. inline std::size_t lod_group::get_level_count() const
  93. {
  94. return levels.size();
  95. }
  96. inline const std::list<object_base*>& lod_group::get_objects(std::size_t level) const
  97. {
  98. return levels[level];
  99. }
  100. } // namespace scene
  101. #endif // ANTKEEPER_SCENE_LOD_GROUP_HPP