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

99 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_DIRECTIONAL_LIGHT_HPP
  20. #define ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP
  21. #include "scene/light.hpp"
  22. #include "gl/texture-2d.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. namespace scene {
  25. /**
  26. * Light source with parallel rays and constant intensity.
  27. */
  28. class directional_light: public light
  29. {
  30. public:
  31. /// Creates a directional light.
  32. directional_light();
  33. /**
  34. * Sets the light texture, also known as a gobo, cucoloris, or cookie.
  35. *
  36. * @param texture Light texture.
  37. */
  38. void set_light_texture(const gl::texture_2d* texture);
  39. void set_light_texture_opacity(float opacity);
  40. void set_light_texture_translation(const float2& translation);
  41. void set_light_texture_rotation(float rotation);
  42. void set_light_texture_scale(const float2& scale);
  43. /// Returns light_type::directional.
  44. virtual light_type get_light_type() const;
  45. /// Returns the normalized direction vector of the light.
  46. const float3& get_direction() const;
  47. /// Returns the light texture for this light, or `nullptr` if no light texture is set.
  48. const gl::texture_2d* get_light_texture() const;
  49. const tween<float3>& get_direction_tween() const;
  50. /// @copydoc object_base::update_tweens();
  51. virtual void update_tweens();
  52. private:
  53. virtual void transformed();
  54. tween<float3> direction;
  55. const gl::texture_2d* light_texture;
  56. tween<float> light_texture_opacity;
  57. tween<float2> light_texture_translation;
  58. tween<float> light_texture_rotation;
  59. tween<float2> light_texture_scale;
  60. };
  61. inline light_type directional_light::get_light_type() const
  62. {
  63. return light_type::directional;
  64. }
  65. inline const float3& directional_light::get_direction() const
  66. {
  67. return direction[1];
  68. }
  69. inline const tween<float3>& directional_light::get_direction_tween() const
  70. {
  71. return direction;
  72. }
  73. inline const gl::texture_2d* directional_light::get_light_texture() const
  74. {
  75. return light_texture;
  76. }
  77. } // namespace scene
  78. #endif // ANTKEEPER_SCENE_DIRECTIONAL_LIGHT_HPP