Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
light.h
Go to the documentation of this file.
1 #ifndef LIGHT_H
2 #define LIGHT_H
3 #include <easylogging++.h>
4 #include <glm/glm.hpp>
5 #include <glm/ext.hpp>
6 #include <iostream>
7 #include "component.h"
8 //= SCRIPTABLE
9 //= SCRIPTABLE BASES Component
10 
11 namespace Graphics {
15  class Light : public Component {
16  public:
17  //= SCRIPTABLE ENUM
21  enum Type : unsigned int { POINT, SPOT };
22  private:
23  Type type;
24  glm::vec3 color;
25  float intensity;
26  float linear_attenuation;
27  float quadratic_attenuation;
28  int quantized_bands;
29  float cone_angle;
30  glm::vec3 cone_direction;
31  public:
32  virtual void onStart() override;
33  virtual bool onUpdate(const double delta) override;
34  virtual void onDestroy() override;
35 
36  //= BEGIN SCRIPTABLE
37 
43  Light(const Light::Type& type = Type::POINT);
47  ~Light();
53  void setColor(const glm::vec3 color) noexcept;
59  glm::vec3 getColor() const noexcept;
65  void setIntensity(const float intensity) noexcept;
71  float getIntensity() const noexcept;
77  void setLinearAttenuation(const float linear) noexcept;
83  float getLinearAttenuation() const noexcept;
89  void setQuadraticAttenuation(const float quadratic) noexcept;
95  float getQuadraticAttenuation() const noexcept;
96 
102  bool castsQuantizedBands() const noexcept;
108  void setNumberOfQuantizedBands(const int bands) noexcept;
114  int getNumberOfQuantizedBands() const noexcept;
115 
121  void setConeAngle(const float angle) noexcept;
127  float getConeAngle() const noexcept;
133  void setConeDirection(const glm::vec3 direction) noexcept;
139  glm::vec3 getConeDirection() const noexcept;
140 
146  Light::Type getType() const noexcept;
147 
155  float influenceOnComponent(const Component& component) const;
156  virtual std::string className() const noexcept override;
157  //= END SCRIPTABLE
158 
159  virtual unsigned long long getValueForSorting() const noexcept override;
160 
161  virtual void log(el::base::type::ostream_t& os) const override;
162 
163  static inline const Light::Type stringToType(const std::string& str) {
164  if(str == "Spot" || str == "spot" || str == "SPOT")
165  return Light::Type::SPOT;
166  else if(str == "Point" || str == "point" || str == "POINT")
167  return Light::Type::POINT;
168  else
169  return Light::Type::POINT;
170  }
171 
172  static inline const std::string typeToString(const Light::Type& type) {
173  if(type == Light::Type::SPOT)
174  return std::string("Spot");
175  else if(type == Light::Type::POINT)
176  return std::string("Point");
177  else
178  return std::string("N/A");
179  }
180 
181  };
182 }
183 
184 #endif
void setNumberOfQuantizedBands(const int bands) noexcept
Sets the number of quantized bands.
Definition: light.cpp:65
bool castsQuantizedBands() const noexcept
Function to see if lights cast quantized bands or are smooth.
Definition: light.cpp:61
float getIntensity() const noexcept
Gets the intensity.
Definition: light.cpp:41
void setColor(const glm::vec3 color) noexcept
Sets the color.
Definition: light.cpp:29
~Light()
Destroys the object.
Definition: light.cpp:13
void setIntensity(const float intensity) noexcept
Sets the intensity.
Definition: light.cpp:37
void setLinearAttenuation(const float linear) noexcept
Sets the linear attenuation.
Definition: light.cpp:45
float getConeAngle() const noexcept
Gets the cone angle.
Definition: light.cpp:77
Base Class for all components.
Definition: component.h:20
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: light.cpp:17
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: light.cpp:104
virtual unsigned long long getValueForSorting() const noexceptoverride
Gets the value for sorting.
Definition: light.cpp:100
Light::Type getType() const noexcept
Gets the type.
Definition: light.cpp:89
glm::vec3 getConeDirection() const noexcept
Gets the cone direction.
Definition: light.cpp:85
Definition: light.h:21
void setConeDirection(const glm::vec3 direction) noexcept
Sets the cone direction.
Definition: light.cpp:81
float getLinearAttenuation() const noexcept
Gets the linear attenuation.
Definition: light.cpp:49
void setQuadraticAttenuation(const float quadratic) noexcept
Sets the quadratic attenuation.
Definition: light.cpp:53
float getQuadraticAttenuation() const noexcept
Gets the quadratic attenuation.
Definition: light.cpp:57
void setConeAngle(const float angle) noexcept
Sets the cone angle.
Definition: light.cpp:73
glm::vec3 getColor() const noexcept
Gets the color.
Definition: light.cpp:33
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: light.cpp:21
Light(const Light::Type &type=Type::POINT)
Light constructor.
Definition: light.cpp:7
float influenceOnComponent(const Component &component) const
Calculates a light's influence on a given component.
Definition: light.cpp:93
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: light.cpp:25
int getNumberOfQuantizedBands() const noexcept
Gets the number of quantized bands.
Definition: light.cpp:69
Definition: light.h:21
Class for light.
Definition: light.h:15
virtual void log(el::base::type::ostream_t &os) const override
Definition: light.cpp:108
static const std::string typeToString(const Light::Type &type)
Definition: light.h:172
Type
Light type enum.
Definition: light.h:21
static const Light::Type stringToType(const std::string &str)
Definition: light.h:163