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

118 lines
3.1 KiB

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