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

107 lines
2.5 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_bounds() const;
  52. material* get_material() const;
  53. billboard_type get_billboard_type() const;
  54. const float3& get_alignment_axis() const;
  55. virtual void update_tweens();
  56. private:
  57. static const aabb_type untransformed_bounds;
  58. virtual void transformed();
  59. aabb_type bounds;
  60. material* material;
  61. billboard_type type;
  62. float3 alignment_axis;
  63. };
  64. inline const typename object_base::bounding_volume_type& billboard::get_bounds() const
  65. {
  66. return bounds;
  67. }
  68. inline material* billboard::get_material() const
  69. {
  70. return material;
  71. }
  72. inline billboard_type billboard::get_billboard_type() const
  73. {
  74. return type;
  75. }
  76. inline const float3& billboard::get_alignment_axis() const
  77. {
  78. return alignment_axis;
  79. }
  80. } // namespace scene
  81. #endif // ANTKEEPER_SCENE_BILLBOARD_HPP