Loading [MathJax]/extensions/TeX/AMSsymbols.js
Radium Engine  1.5.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
LightData.hpp
1 #pragma once
2 
3 #include <Core/Asset/AssetData.hpp>
4 #include <Core/RaCore.hpp>
5 #include <Core/Utils/Color.hpp>
6 #include <Core/Utils/Log.hpp>
7 
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 namespace Ra {
13 namespace Core {
14 namespace Asset {
15 
25 class RA_CORE_API LightData : public AssetData
26 {
27 
28  public:
29  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
30 
34  enum LightType {
35  UNKNOWN = 1 << 0,
36  POINT_LIGHT = 1 << 1,
37  SPOT_LIGHT = 1 << 2,
38  DIRECTIONAL_LIGHT = 1 << 3,
39  AREA_LIGHT = 1 << 4
40  };
41 
47  Scalar constant;
48  Scalar linear;
49  Scalar quadratic;
50  explicit LightAttenuation( Scalar c = 1, Scalar l = 0, Scalar q = 0 ) :
51  constant( c ), linear( l ), quadratic( q ) {}
52  };
53  // TODO : allow to define other attenuation function such
54  // \max\left(0,1-\frac{\left|x\right|^2}{r^2}\right)^2
55 
60  explicit LightData( const std::string& name = "", const LightType& type = UNKNOWN );
61 
68  LightData( const LightData& data );
69 
71  ~LightData();
72 
78  inline void setName( const std::string& name );
79 
84  inline const Eigen::Matrix<Scalar, 4, 4>& getFrame() const;
85 
90  inline void setFrame( const Eigen::Matrix<Scalar, 4, 4>& frame );
91 
100  inline void setLight( const Core::Utils::Color& color,
101  const Eigen::Matrix<Scalar, 3, 1>& direction );
102 
110  inline void setLight( const Core::Utils::Color& color,
111  const Eigen::Matrix<Scalar, 3, 1>& position,
112  LightAttenuation attenuation );
113 
122  inline void setLight( const Core::Utils::Color& color,
123  const Eigen::Matrix<Scalar, 3, 1>& position,
124  const Eigen::Matrix<Scalar, 3, 1>& direction,
125  Scalar inAngle,
126  Scalar outAngle,
127  LightAttenuation attenuation );
128 
137  inline void setLight( const Core::Utils::Color& color,
138  const Eigen::Matrix<Scalar, 3, 1>& cog,
139  const Eigen::Matrix<Scalar, 3, 3>& spatialCov,
140  const Eigen::Matrix<Scalar, 3, 3>& normalCov,
141  LightAttenuation attenuation );
142 
146  inline LightType getType() const;
147 
151  inline bool isPointLight() const;
152 
156  inline bool isSpotLight() const;
157 
161  inline bool isDirectionalLight() const;
162 
166  inline bool isAreaLight() const;
167 
171  inline void displayInfo() const;
172 
173  protected:
175 
176  Eigen::Matrix<Scalar, 4, 4> m_frame;
177  LightType m_type;
178 
179  // This part is public so that systems handling lights could access to the data.
180  // TODO : make these protected with getters ? Define independant types ?
181  public:
182  Core::Utils::Color m_color;
183 
184  struct DirLight {
185  Eigen::Matrix<Scalar, 3, 1> direction;
186  };
187  struct PointLight {
188  Eigen::Matrix<Scalar, 3, 1> position;
189  LightAttenuation attenuation;
190  };
191  struct SpotLight {
192  Eigen::Matrix<Scalar, 3, 1> position;
193  Eigen::Matrix<Scalar, 3, 1> direction;
194  Scalar innerAngle;
195  Scalar outerAngle;
196  LightAttenuation attenuation;
197  };
198  struct AreaLight {
199  // TODO : this representation is usefull but might be improved
200  Eigen::Matrix<Scalar, 3, 1> position;
201  Eigen::Matrix<Scalar, 3, 3> spatialCovariance;
202  Eigen::Matrix<Scalar, 3, 3> normalCovariance;
203  LightAttenuation attenuation;
204  };
205 
206  union {
207  DirLight m_dirlight;
208  PointLight m_pointlight;
209  SpotLight m_spotlight;
210  AreaLight m_arealight;
211  };
212 };
213 
217 
219 inline void LightData::setName( const std::string& name ) {
220  m_name = name;
221 }
222 
225  return m_type;
226 }
227 
229 inline const Eigen::Matrix<Scalar, 4, 4>& LightData::getFrame() const {
230  return m_frame;
231 }
232 
233 inline void LightData::setFrame( const Eigen::Matrix<Scalar, 4, 4>& frame ) {
234  m_frame = frame;
235 }
236 
238 inline void LightData::setLight( const Core::Utils::Color& color,
239  const Eigen::Matrix<Scalar, 3, 1>& direction ) {
240  m_type = DIRECTIONAL_LIGHT;
241  m_color = color;
242  m_dirlight.direction = direction;
243 }
244 
246 inline void LightData::setLight( const Core::Utils::Color& color,
247  const Eigen::Matrix<Scalar, 3, 1>& position,
248  LightAttenuation attenuation ) {
249  m_type = POINT_LIGHT;
250  m_color = color;
251  m_pointlight.position = position;
252  m_pointlight.attenuation = attenuation;
253 }
254 
256 inline void LightData::setLight( const Core::Utils::Color& color,
257  const Eigen::Matrix<Scalar, 3, 1>& position,
258  const Eigen::Matrix<Scalar, 3, 1>& direction,
259  Scalar inAngle,
260  Scalar outAngle,
261  LightAttenuation attenuation ) {
262  m_type = SPOT_LIGHT;
263  m_color = color;
264  m_spotlight.position = position;
265  m_spotlight.direction = direction;
266  m_spotlight.innerAngle = inAngle;
267  m_spotlight.outerAngle = outAngle;
268  m_spotlight.attenuation = attenuation;
269 }
270 
272 inline void LightData::setLight( const Core::Utils::Color& color,
273  const Eigen::Matrix<Scalar, 3, 1>& cog,
274  const Eigen::Matrix<Scalar, 3, 3>& spatialCov,
275  const Eigen::Matrix<Scalar, 3, 3>& normalCov,
276  LightAttenuation attenuation ) {
277  m_type = AREA_LIGHT;
278  m_color = color;
279  m_arealight.position = cog;
280  m_arealight.spatialCovariance = spatialCov;
281  m_arealight.normalCovariance = normalCov;
282  m_arealight.attenuation = attenuation;
283 }
284 
286 inline bool LightData::isPointLight() const {
287  return ( m_type == POINT_LIGHT );
288 }
289 
290 inline bool LightData::isSpotLight() const {
291  return ( m_type == SPOT_LIGHT );
292 }
293 
294 inline bool LightData::isDirectionalLight() const {
295  return ( m_type == DIRECTIONAL_LIGHT );
296 }
297 
298 inline bool LightData::isAreaLight() const {
299  return ( m_type == AREA_LIGHT );
300 }
301 
303 inline void LightData::displayInfo() const {
304  using namespace Core::Utils; // log
305  std::string type;
306  switch ( m_type ) {
307  case POINT_LIGHT:
308  type = "POINT LIGHT";
309  break;
310  case SPOT_LIGHT:
311  type = "SPOT LIGHT";
312  break;
313  case DIRECTIONAL_LIGHT:
314  type = "DIRECTIONAL LIGHT";
315  break;
316  case AREA_LIGHT:
317  type = "AREA LIGHT";
318  break;
319  case UNKNOWN:
320  default:
321  type = "UNKNOWN";
322  break;
323  }
324  LOG( logINFO ) << "======== LIGHT INFO ========";
325  LOG( logINFO ) << " Name : " << m_name;
326  LOG( logINFO ) << " Type : " << type;
327 }
328 
329 } // namespace Asset
330 } // namespace Core
331 } // namespace Ra
void setLight(const Core::Utils::Color &color, const Eigen::Matrix< Scalar, 3, 1 > &direction)
construct a directional light
Definition: LightData.hpp:238
void displayInfo() const
DEBUG.
Definition: LightData.hpp:303
bool isPointLight() const
QUERY.
Definition: LightData.hpp:286
void setName(const std::string &name)
LIGHT DATA ///.
Definition: LightData.hpp:219
Eigen::Matrix< Scalar, 4, 4 > m_frame
VARIABLE.
Definition: LightData.hpp:176
const Eigen::Matrix< Scalar, 4, 4 > & getFrame() const
FRAME.
Definition: LightData.hpp:229
bool isDirectionalLight() const
Definition: LightData.hpp:294
LightType getType() const
TYPE.
Definition: LightData.hpp:224
void setFrame(const Eigen::Matrix< Scalar, 4, 4 > &frame)
Definition: LightData.hpp:233
Definition: Cage.cpp:3