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

131 lines
3.4 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_local_bounds() const;
  73. virtual const bounding_volume_type& get_world_bounds() const;
  74. /// Returns the number of detail levels in the group.
  75. std::size_t get_level_count() const;
  76. /**
  77. * Returns a list containing all objects in the LOD group with the specified detail level.
  78. *
  79. * @param level Level of detail.
  80. * @return List of all objects in the group with the specified detail level.
  81. */
  82. const std::list<object_base*>& get_objects(std::size_t level) const;
  83. private:
  84. void update_bounds();
  85. virtual void transformed();
  86. aabb_type local_bounds;
  87. aabb_type world_bounds;
  88. std::vector<std::list<object_base*>> levels;
  89. };
  90. inline const typename object_base::bounding_volume_type& lod_group::get_local_bounds() const
  91. {
  92. return local_bounds;
  93. }
  94. inline const typename object_base::bounding_volume_type& lod_group::get_world_bounds() const
  95. {
  96. return world_bounds;
  97. }
  98. inline std::size_t lod_group::get_level_count() const
  99. {
  100. return levels.size();
  101. }
  102. inline const std::list<object_base*>& lod_group::get_objects(std::size_t level) const
  103. {
  104. return levels[level];
  105. }
  106. } // namespace scene
  107. #endif // ANTKEEPER_SCENE_LOD_GROUP_HPP