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

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