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

89 lines
2.7 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. #include "vegetation.hpp"
  20. #include "entity/components/model.hpp"
  21. #include "entity/components/transform.hpp"
  22. #include "scene/model-instance.hpp"
  23. #include "scene/lod-group.hpp"
  24. #include "scene/collection.hpp"
  25. #include "render/material.hpp"
  26. #include "geom/aabb.hpp"
  27. #include "utility/fundamental-types.hpp"
  28. #include <cmath>
  29. namespace entity {
  30. namespace system {
  31. vegetation::vegetation(entity::registry& registry):
  32. updatable(registry),
  33. terrain_patch_size(1.0f),
  34. vegetation_patch_size(1.0f),
  35. vegetation_patch_columns(1),
  36. vegetation_patch_rows(1),
  37. vegetation_density(1.0f),
  38. vegetation_model(nullptr)
  39. {
  40. registry.on_construct<component::terrain>().connect<&vegetation::on_terrain_construct>(this);
  41. registry.on_destroy<component::terrain>().connect<&vegetation::on_terrain_destroy>(this);
  42. }
  43. vegetation::~vegetation()
  44. {}
  45. void vegetation::update(double t, double dt)
  46. {}
  47. void vegetation::set_terrain_patch_size(float size)
  48. {
  49. terrain_patch_size = size;
  50. vegetation_patch_size = terrain_patch_size / static_cast<float>(vegetation_patch_columns);
  51. }
  52. void vegetation::set_vegetation_patch_resolution(int subdivisions)
  53. {
  54. // Determine number of vegetation patch columns and rows per terrain patch
  55. vegetation_patch_columns = static_cast<int>(std::pow(2, subdivisions));
  56. vegetation_patch_rows = vegetation_patch_columns;
  57. vegetation_patch_size = terrain_patch_size / static_cast<float>(vegetation_patch_columns);
  58. }
  59. void vegetation::set_vegetation_density(float density)
  60. {
  61. vegetation_density = density;
  62. }
  63. void vegetation::set_vegetation_model(::model* model)
  64. {
  65. vegetation_model = model;
  66. }
  67. void vegetation::set_scene(scene::collection* collection)
  68. {
  69. this->scene_collection = collection;
  70. }
  71. void vegetation::on_terrain_construct(entity::registry& registry, entity::id entity_id, component::terrain& component)
  72. {}
  73. void vegetation::on_terrain_destroy(entity::registry& registry, entity::id entity_id)
  74. {}
  75. } // namespace system
  76. } // namespace entity