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

139 lines
3.0 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_LIGHT_HPP
  20. #define ANTKEEPER_SCENE_LIGHT_HPP
  21. #include "scene/object.hpp"
  22. #include "geom/sphere.hpp"
  23. #include "utility/fundamental-types.hpp"
  24. namespace scene {
  25. /// Light object type enumerations.
  26. enum class light_type
  27. {
  28. /// Denotes an ambient light.
  29. ambient,
  30. /// Denotes a directional light.
  31. directional,
  32. /// Denotes a point light.
  33. point,
  34. /// Denotes a spot light.
  35. spot
  36. };
  37. /**
  38. * Abstract base class for light objects.
  39. */
  40. class light: public object<light>
  41. {
  42. public:
  43. typedef geom::sphere<float> sphere_type;
  44. /// Creates a light.
  45. light();
  46. /// Returns an enumeration denoting the light object type.
  47. virtual light_type get_light_type() const = 0;
  48. /**
  49. * Sets the color of the light.
  50. *
  51. * @param color Scene-linear light color.
  52. */
  53. void set_color(const float3& color);
  54. /**
  55. * Sets the intensity of the light.
  56. *
  57. * @param intensity Light intensity.
  58. */
  59. void set_intensity(float intensity);
  60. /// Returns the bounding volume of the light.
  61. virtual const bounding_volume_type& get_bounds() const;
  62. /// Returns the light color.
  63. const float3& get_color() const;
  64. /// Returns the light intensity.
  65. float get_intensity() const;
  66. /// Returns the intensity-scaled light color.
  67. const float3& get_scaled_color() const;
  68. const tween<float3>& get_color_tween() const;
  69. const tween<float>& get_intensity_tween() const;
  70. const tween<float3>& get_scaled_color_tween() const;
  71. /// @copydoc object_base::update_tweens();
  72. virtual void update_tweens();
  73. private:
  74. virtual void transformed();
  75. tween<float3> color;
  76. tween<float> intensity;
  77. tween<float3> scaled_color;
  78. sphere_type bounds;
  79. };
  80. inline const typename object_base::bounding_volume_type& light::get_bounds() const
  81. {
  82. return bounds;
  83. }
  84. inline const float3& light::get_color() const
  85. {
  86. return color[1];
  87. }
  88. inline float light::get_intensity() const
  89. {
  90. return intensity[1];
  91. }
  92. inline const float3& light::get_scaled_color() const
  93. {
  94. return scaled_color[1];
  95. }
  96. inline const tween<float3>& light::get_color_tween() const
  97. {
  98. return color;
  99. }
  100. inline const tween<float>& light::get_intensity_tween() const
  101. {
  102. return intensity;
  103. }
  104. inline const tween<float3>& light::get_scaled_color_tween() const
  105. {
  106. return scaled_color;
  107. }
  108. } // namespace scene
  109. #endif // ANTKEEPER_SCENE_LIGHT_HPP