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

113 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. #ifndef ANTKEEPER_SCENE_BILLBOARD_HPP
  20. #define ANTKEEPER_SCENE_BILLBOARD_HPP
  21. #include "scene/object.hpp"
  22. #include "geom/aabb.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. class material;
  25. namespace scene {
  26. /// Enumerates billboard types.
  27. enum class billboard_type
  28. {
  29. // No alignment
  30. flat,
  31. // Aligns to face camera
  32. spherical,
  33. // Rotates about an alignment axis to face camera
  34. cylindrical
  35. };
  36. /**
  37. * A 2D unit quad with one material.
  38. */
  39. class billboard: public object<billboard>
  40. {
  41. public:
  42. typedef geom::aabb<float> aabb_type;
  43. billboard();
  44. billboard(const billboard& other);
  45. billboard& operator=(const billboard& other);
  46. void set_material(material* material);
  47. /// Sets the billboard alignment mode.
  48. void set_billboard_type(billboard_type type);
  49. /// Sets the axis around which the billboard will be rotated when the alignment is set to billboard_alignment::cylindrical.
  50. void set_alignment_axis(const float3& axis);
  51. virtual const bounding_volume_type& get_local_bounds() const;
  52. virtual const bounding_volume_type& get_world_bounds() const;
  53. material* get_material() const;
  54. billboard_type get_billboard_type() const;
  55. const float3& get_alignment_axis() const;
  56. virtual void update_tweens();
  57. private:
  58. static const aabb_type local_bounds;
  59. virtual void transformed();
  60. aabb_type world_bounds;
  61. material* material;
  62. billboard_type type;
  63. float3 alignment_axis;
  64. };
  65. inline const typename object_base::bounding_volume_type& billboard::get_local_bounds() const
  66. {
  67. return local_bounds;
  68. }
  69. inline const typename object_base::bounding_volume_type& billboard::get_world_bounds() const
  70. {
  71. return world_bounds;
  72. }
  73. inline material* billboard::get_material() const
  74. {
  75. return material;
  76. }
  77. inline billboard_type billboard::get_billboard_type() const
  78. {
  79. return type;
  80. }
  81. inline const float3& billboard::get_alignment_axis() const
  82. {
  83. return alignment_axis;
  84. }
  85. } // namespace scene
  86. #endif // ANTKEEPER_SCENE_BILLBOARD_HPP