i6engine  1.0
AnimatedLuminousAppearanceComponent.h
Go to the documentation of this file.
1 /*
2  * i6engine
3  * Copyright (2016) Daniel Bonrath, Michael Baer, All rights reserved.
4  *
5  * This file is part of i6engine; i6engine is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __I6ENGINE_API_ANIMATEDLUMINOUSAPPEARANCECOMPONENT_H_
26 #define __I6ENGINE_API_ANIMATEDLUMINOUSAPPEARANCECOMPONENT_H_
27 
30 
31 namespace i6e {
32 namespace api {
33 
48  public:
52  AnimatedLuminousAppearanceComponent(const int64_t id, const attributeMap & params);
53 
55 
59  attributeMap synchronize() const override;
60 
61  std::string getTemplateName() const override {
62  return "AnimatedLuminousAppearance";
63  }
64 
65  virtual std::vector<componentOptions> getComponentOptions() override;
66 
67  protected:
68  virtual void Tick() override;
69 
73  template<typename T>
74  T interpolate(uint64_t duration, const std::map<double, T> & values) const {
75  uint64_t cT = api::EngineController::GetSingleton().getCurrentTime();
76  double timePoint = (((cT - _startTime) % duration) + 1) / double(duration);
77  for (auto it = values.begin(); it != values.end(); it++) {
78  if (it->first <= timePoint) {
79  double currentTimePoint = it->first;
80  T currentValue = it->second;
81  it++;
82  double timeDiff = 0.0;
83  double timePercent = 0.0;
84  if (it == values.end()) {
85  timeDiff = 1.0 - currentTimePoint;
86  it = values.begin();
87  timeDiff += it->first;
88  timePercent = (timePoint + 1.0 - currentTimePoint) / timeDiff;
89  } else {
90  timeDiff = it->first - currentTimePoint;
91  timePercent = (timePoint - currentTimePoint) / timeDiff;
92  }
93  T newValue = currentValue * (1.0 - timePercent) + (it->second) * timePercent;
94  return newValue;
95  }
96  }
97  ISIXE_THROW_FAILURE("AnimatedLuminousAppearanceComponent", "interpolation didn't work.");
98  return T();
99  }
100 
101  private:
102  uint64_t _startTime;
103  uint64_t _diffuseDuration;
104  std::map<double, Vec3> _diffuseColours;
105  uint64_t _specularDuration;
106  std::map<double, Vec3> _specularColours;
107  uint64_t _attenuationDuration;
108  std::map<double, Vec4> _attenuations;
109 
110  void Init() override;
111  void Finalize() override;
112  };
113 
114 } /* namespace api */
115 } /* namespace i6e */
116 
117 #endif /* __I6ENGINE_API_ANIMATEDLUMINOUSAPPEARANCECOMPONENT_H_ */
118 
Tells the engine that this GameObject is emitting light. For creating a LuminousAppearanceComponent, these keys are possible: Name Required Type Description Public lightType yes int one of the LightTypes yes diffuseColor yes Vec3 diffuse colour of the light yes specularColor yes Vec3 specular colour of the light yes attenuation yes Vec4 attenuation of the light, W = range (range in world units), X = constant (1.0 never attenuate, 0.0 complete attenuation), Y = linear (linear attenuation depending on distance), Z = quadratic factor yes pos no Vec3 relative position to SceneNode yes direction *) Vec3 direction of the light shaft, *) required if lightType is DIRECTIONAL or SPOT yes spotLightRangeInner *) double range of the inner cone of a spot light in degree, *) required if lightType is SPOT yes spotLightRangeOuter *) double range of the outer cone of a spot light in degree, *) required if lightType is SPOT yes
T interpolate(uint64_t duration, const std::map< double, T > &values) const
used to interpolate between two following values depending on current time
#define ISIXE_MODULES_API
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
static T & GetSingleton()
Returns a reference to the Singleton class.
Definition: Singleton.h:56
#define ISIXE_THROW_FAILURE(module, message)
Definition: Exceptions.h:39
std::string getTemplateName() const override
returns the name this template was registered with
interpolates light colours and attenuation (e.g. range) For creating a AnimatedLuminousAppearanceComp...