Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
light.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIGHT_H_INCLUDED
20 #define LIGHT_H_INCLUDED
21 
22 #include "../generic/managed.h"
23 #include "../generic/identifiable.h"
24 #include "../generic/manual_object.h"
25 #include "../types.h"
26 
27 #include "stage_node.h"
28 
29 namespace smlt {
30 
31 class Light :
32  public TypedDestroyableObject<Light, Stage>,
33  public ContainerNode,
34  public generic::Identifiable<LightID>,
35  public ChainNameable<Light> {
36 
37 public:
38  typedef std::shared_ptr<Light> ptr;
39 
40  Light(Stage* stage);
41 
42  void set_type(LightType type);
43 
44  /*
45  * Direction (ab)uses the light's position.
46  * Setting the direction implicitly sets the light type to directional
47  *
48  * Direction is stored reversed in the position.
49  */
50  Vec3 direction() const {
51  return absolute_position();
52  }
53 
54  void set_direction(float x, float y, float z) {
55  set_direction(Vec3(x, y, z));
56  }
57 
58  void set_range(float range) {
59  range_ = range;
60  bounds_ = AABB(Vec3(), range_);
61  }
62 
63  void set_direction(const Vec3& dir) {
64  set_type(LIGHT_TYPE_DIRECTIONAL);
65  move_to(-dir.x, -dir.y, -dir.z);
66  }
67 
68  void set_diffuse(const smlt::Colour& colour) {
69  diffuse_ = colour;
70  }
71 
72  void set_ambient(const smlt::Colour& colour) {
73  ambient_ = colour;
74  }
75 
76  void set_specular(const smlt::Colour& colour) {
77  specular_ = colour;
78  }
79 
80  LightType type() const { return type_; }
81  const smlt::Colour& ambient() const { return ambient_; }
82  const smlt::Colour& diffuse() const { return diffuse_; }
83  const smlt::Colour& specular() const { return specular_; }
84 
87 
88  void set_attenuation(float range, float constant, float linear, float quadratic);
89  void set_attenuation_from_range(float range);
90 
91  float range() const { return range_; }
92  float constant_attenuation() const { return const_attenuation_; }
93  float linear_attenuation() const { return linear_attenuation_; }
94  float quadratic_attenuation() const { return quadratic_attenuation_; }
95 
96  const AABB& aabb() const override {
97  return bounds_;
98  }
99 
100  void update(float step) override {
101  _S_UNUSED(step);
102  }
103 
104  void clean_up() override {
105  StageNode::clean_up();
106  }
107 
108 private:
109  UniqueIDKey make_key() const override {
110  return make_unique_id_key(id());
111  }
112 
113  LightType type_;
114 
115  smlt::Colour ambient_;
116  smlt::Colour diffuse_;
117  smlt::Colour specular_;
118 
119  AABB bounds_;
120  float range_;
121  float const_attenuation_;
122  float linear_attenuation_;
123  float quadratic_attenuation_;
124 };
125 
126 }
127 #endif
smlt::Vec3
Definition: vec3.h:23
smlt::Stage
Definition: stage.h:80
smlt::Light::set_attenuation
void set_attenuation(float range, float constant, float linear, float quadratic)
Definition: light.cpp:54
smlt
Definition: animation.cpp:25
smlt::Light
Definition: light.h:35
smlt::Light::global_ambient
smlt::Colour global_ambient() const
Definition: light.cpp:44
smlt::generic::Identifiable
Definition: identifiable.h:26
smlt::ContainerNode
Definition: stage_node.h:304
smlt::TypedDestroyableObject
Definition: manual_object.h:34
smlt::ChainNameable
Definition: nameable.h:34
smlt::AABB
Definition: aabb.h:22
smlt::Colour
Definition: colour.h:29
smlt::Light::set_attenuation_from_range
void set_attenuation_from_range(float range)
Light::set_attenuation_from_range.
Definition: light.cpp:69