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

147 lines
3.3 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 local-space bounding volume of the light.
  61. virtual const bounding_volume_type& get_local_bounds() const;
  62. /// Returns the world-space bounding volume of the light.
  63. virtual const bounding_volume_type& get_world_bounds() const;
  64. /// Returns the light color.
  65. const float3& get_color() const;
  66. /// Returns the light intensity.
  67. float get_intensity() const;
  68. /// Returns the intensity-scaled light color.
  69. const float3& get_scaled_color() const;
  70. const tween<float3>& get_color_tween() const;
  71. const tween<float>& get_intensity_tween() const;
  72. const tween<float3>& get_scaled_color_tween() const;
  73. /// @copydoc object_base::update_tweens();
  74. virtual void update_tweens();
  75. private:
  76. virtual void transformed();
  77. tween<float3> color;
  78. tween<float> intensity;
  79. tween<float3> scaled_color;
  80. sphere_type local_bounds;
  81. sphere_type world_bounds;
  82. };
  83. inline const typename object_base::bounding_volume_type& light::get_local_bounds() const
  84. {
  85. return local_bounds;
  86. }
  87. inline const typename object_base::bounding_volume_type& light::get_world_bounds() const
  88. {
  89. return world_bounds;
  90. }
  91. inline const float3& light::get_color() const
  92. {
  93. return color[1];
  94. }
  95. inline float light::get_intensity() const
  96. {
  97. return intensity[1];
  98. }
  99. inline const float3& light::get_scaled_color() const
  100. {
  101. return scaled_color[1];
  102. }
  103. inline const tween<float3>& light::get_color_tween() const
  104. {
  105. return color;
  106. }
  107. inline const tween<float>& light::get_intensity_tween() const
  108. {
  109. return intensity;
  110. }
  111. inline const tween<float3>& light::get_scaled_color_tween() const
  112. {
  113. return scaled_color;
  114. }
  115. } // namespace scene
  116. #endif // ANTKEEPER_SCENE_LIGHT_HPP