Antkeeper  0.0.1
rectangle-light.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 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 
21 #include <engine/math/numbers.hpp>
22 
23 namespace scene {
24 
26 {
27  transformed();
28 }
29 
31 {
32  set_scale({size.x(), size.y(), 1.0f});
33 }
34 
35 void rectangle_light::transformed()
36 {
37  const auto& transform = get_transform();
38 
39  // Update corner positions
40  // m_corners[0] = transform * math::fvec3{-0.5f, 0.0f, -0.5f};
41  // m_corners[1] = transform * math::fvec3{ 0.5f, 0.0f, -0.5f};
42  // m_corners[2] = transform * math::fvec3{ 0.5f, 0.0f, 0.5f};
43  // m_corners[3] = transform * math::fvec3{-0.5f, 0.0f, 0.5f};
44  m_corners[0] = transform * math::fvec3{-0.5f, -0.5f, 0.0f};
45  m_corners[1] = transform * math::fvec3{-0.5f, 0.5f, 0.0f};
46  m_corners[2] = transform * math::fvec3{ 0.5f, 0.5f, 0.0f};
47  m_corners[3] = transform * math::fvec3{ 0.5f, -0.5f, 0.0f};
48 
49  // Update area
50  m_area = get_scale().x() * get_scale().y();
51  area_updated();
52 }
53 
54 void rectangle_light::color_updated()
55 {
56  m_colored_luminous_flux = get_color() * m_luminous_flux;
57  m_colored_luminance = get_color() * m_luminance;
58 }
59 
60 void rectangle_light::area_updated() noexcept
61 {
62  // Calculate luminance from luminous flux
63  m_luminance = m_luminous_flux / (m_area * math::pi<float>);
64  m_colored_luminance = get_color() * m_luminance;
65 }
66 
67 void rectangle_light::luminous_flux_updated() noexcept
68 {
69  m_colored_luminous_flux = get_color() * m_luminous_flux;
70 
71  // Calculate luminance from luminous flux
72  m_luminance = m_luminous_flux / (m_area * math::pi<float>);
73  m_colored_luminance = get_color() * m_luminance;
74 }
75 
76 void rectangle_light::luminance_updated() noexcept
77 {
78  m_colored_luminance = get_color() * m_luminance;
79 
80  // Calculate luminous flux from luminance
81  m_luminous_flux = m_luminance * (m_area * math::pi<float>);
82  m_colored_luminous_flux = get_color() * m_luminous_flux;
83 }
84 
85 } // namespace scene
constexpr const math::fvec3 & get_color() const noexcept
Returns the scene-linear RGB color of the light.
Definition: scene/light.hpp:57
void set_scale(const vector_type &scale)
Sets the scale of the object.
Definition: object.hpp:108
constexpr const vector_type & get_scale() const noexcept
Returns the scale of the object.
Definition: object.hpp:145
constexpr const transform_type & get_transform() const noexcept
Returns the transform of the object.
Definition: object.hpp:127
void set_size(const math::fvec2 &size)
Sets the size of the light.
rectangle_light()
Constructs a rectangular area light.
3D scene.
Definition: context.hpp:28
n-dimensional vector.
Definition: vector.hpp:44
constexpr element_type & x() noexcept
Returns a reference to the first element.
Definition: vector.hpp:164
constexpr element_type & y() noexcept
Returns a reference to the second element.
Definition: vector.hpp:180