i6engine  1.0
MoverInterpolateComponent.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_MOVERINTERPOLATECOMPONENT_H__
26 #define __I6ENGINE_API_MOVERINTERPOLATECOMPONENT_H__
27 
30 
32 
33 namespace i6e {
34 namespace api {
35 
50  public:
51  enum class Mode : uint16_t {
52  TWOSTATE_TOGGLE, // ! loops forward through all keyframes and afterwards backwards. This is repeated endlessly.
53  TWOSTATE_OPENTIME, // ! same as TWOSTATE_TOGGLE but waits opentime before returning
54  NSTATE_LOOP, // ! loops through all keyframes (moving from last to first keyframe is interpolated just like all other segments)
55  ONCE // ! moves from start to end and stops there
56  };
57 
58  enum class Way : uint16_t {
59  LINEAR, // ! linear interpolation
60  BEZIER // ! approximation using bezier-curves
61  };
62 
63  MoverInterpolateComponent(const int64_t id, const attributeMap & params);
65 
69  void addKeyFrame(const Vec3 & position, const Quaternion & rotation);
70 
75  void removeKeyFrame(const uint32_t id);
76 
87  inline keyFrame getKeyframe(const uint32_t nth) const {
88  return _keyFrames[nth];
89  }
90 
95  inline void setMode(const Mode m) { _mode = m; }
96  inline void setOpenTime(const uint64_t opentime) {
97  _openTime = opentime;
98  }
99  inline void setWay(const Way w) { _way = w; }
100 
101  inline Way getWay() const { return _way; }
102 
103  void start(Vec3 & startPos) override;
104 
108  attributeMap synchronize() const override;
109 
110  std::string getTemplateName() const override {
111  return "MoverInterpolate";
112  }
113 
114  void reset() override;
115 
116  std::vector<componentOptions> getComponentOptions() override;
117 
118  private:
123  std::vector<keyFrame> _keyFrames;
124 
128  Mode _mode;
129 
134  uint64_t _openTime;
135 
139  Way _way;
140 
144  double _totalDistance;
145 
149  double _currentDist;
150 
154  size_t _currentFrame;
155 
159  bool _direction;
160 
164  boost::mutex _lock;
165 
166  void News(const GameMessage::Ptr & msg) override;
167 
168  void getNewPosition(const uint64_t t, Vec3 & newPos, Quaternion & newRot) override;
169 
173  void loadParams(const attributeMap & params) override;
174 
176 
177  const MoverInterpolateComponent & operator=(const MoverInterpolateComponent &) = delete;
178  };
179 
180 } /* namespace api */
181 } /* namespace i6e */
182 
183 #endif /* __I6ENGINE_API_MOVERLINEARCOMPONENT_H__ */
184 
This component let's the Object move through the world automatically on fixed paths Use addKeyFrame()...
keyFrame getKeyframe(const uint32_t nth) const
gets the nth keyFrame param[in] nth which keyFrame should be returned nth can be an arbitary number...
Class describing a 3d rotation.
Definition: i6eQuaternion.h:58
#define ISIXE_MODULES_API
boost::shared_ptr< Message > Ptr
Definition: Message.h:66
std::map< std::string, std::string > attributeMap
Definition: attributeMap.h:42
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
std::pair< Vec3, Quaternion > keyFrame
moving an object interpolating in some way For creating a MoverInterpolateComponent, these keys are possible: Name Required Type Description Public way yes short How are the frames interpolated, one of enum entries of Way yes mode yes short In which order the frames will be processed yes direction yes bool Direction of this mover, true is forward, false is backward yes openTime *) uint64_t time mover stays at end position before moving backwards, *) required when mode is TWOSTATE_OPENTIME yes keyframes yes int number of keyframes to follow yes keyframe__pos *) vector position of i-th keyframe, *) required for all keyframes yes keyframe__rot *) quaternion rotation of i-th keyframe, *) required for all keyframes yes
void setOpenTime(const uint64_t opentime)
std::string getTemplateName() const override
returns the name this template was registered with