i6engine  1.0
MeshComponent.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_MODULES_COMPONENTS_MESHCOMPONENT_H__
26 #define __I6ENGINE_MODULES_COMPONENTS_MESHCOMPONENT_H__
27 
28 #include <cstdint>
29 #include <functional>
30 #include <queue>
31 #include <vector>
32 
34 #include "i6engine/utils/weakPtr.h"
35 
39 
40 namespace Ogre {
41  class AnimationState;
42  class Entity;
43  class SceneNode;
44 } /* namespace Ogre */
45 
46 namespace i6e {
47 namespace api {
48  class Component;
50 } /* namespace api */
51 namespace modules {
52 
53  class BoundingBoxComponent;
54  class GraphicsManager;
55  class GraphicsNode;
57 
64  class MeshComponent {
65  friend class BoundingBoxComponent;
66  friend class GraphicsNode;
67  friend class MovableTextComponent;
68 
69  private:
73  GraphicsManager * _manager;
74 
78  GraphicsNode * _parent;
79 
83  Ogre::SceneNode * _sceneNode;
84 
88  Ogre::AnimationState * _animationState;
89 
90  double _animationSpeed;
91 
92  uint64_t _lastTime;
93  uint64_t _lastFrameTime;
94 
95  std::vector<int64_t> _movableTextObservers;
96  std::vector<int64_t> _boundingBoxObservers;
97 
98  std::map<GraphicsNode *, std::string> _attachedNodes;
99  struct sortFrameFunctions {
100  bool operator()(const std::pair<uint64_t, std::function<void(void)>> & a, const std::pair<uint64_t, std::function<void(void)>> & b) const {
101  return !(a.first < b.first);
102  }
103  };
104 
105  std::priority_queue<std::pair<uint64_t, std::function<void(void)>>, std::vector<std::pair<uint64_t, std::function<void(void)>>>, sortFrameFunctions> _queueA;
106  std::priority_queue<std::pair<uint64_t, std::function<void(void)>>, std::vector<std::pair<uint64_t, std::function<void(void)>>>, sortFrameFunctions> _queueB;
107 
109  bool _shadowCasting;
110 
114  MeshComponent(GraphicsManager * manager, GraphicsNode * parent, const int64_t goid, const int64_t coid, const std::string & meshName, const bool visible, const Vec3 & position, const Quaternion & rotation, const Vec3 & scale);
115 
119  ~MeshComponent();
120 
121  void updateMeshComponent(const std::string & meshName, const bool visible);
122 
123  void setVisibility(bool visible);
124 
125  void setShadowCasting(bool enabled);
126 
134  void setMaterial(const std::string & materialName);
135 
145  void setCustomParameter(uint32_t num, const Vec4 & value);
146 
150  void playAnimation(const std::string & anim, bool looping, double offsetPercent);
151 
155  void setAnimationSpeed(double animationSpeed) {
156  _animationSpeed = animationSpeed;
157  }
158 
162  void stopAnimation();
163 
168  void addAnimationFrameEvent(uint64_t frameTime, const std::function<void(void)> & func);
169 
170  void Tick();
171 
172  void addMovableTextObserver(int64_t coid) {
173  _movableTextObservers.push_back(coid);
174  }
175 
176  void removeMovableTextObserver(int64_t coid);
177 
178  void addBoundingBoxObserver(int64_t coid) {
179  _boundingBoxObservers.push_back(coid);
180  }
181 
182  void removeBoundingBoxObserver(int64_t coid);
183 
184  Ogre::Entity * getEntity() const;
185 
186  void attachToBone(GraphicsNode * otherNode, const std::string & boneName);
187 
188  void detachFromBone(GraphicsNode * otherNode);
189 
193  MeshComponent(const MeshComponent &) = delete;
194 
198  const MeshComponent & operator=(const MeshComponent &) = delete;
199 
201  };
202 
203 } /* namespace modules */
204 } /* namespace i6e */
205 
206 #endif /* __I6ENGINE_MODULES_COMPONENTS_MESHCOMPONENT_H__ */
207 
Implements 4-dimensional vectors.
Definition: i6eVector4.h:56
Saves all graphics-related data associated with one GameObject.
Definition: GraphicsNode.h:61
Class describing a 3d rotation.
Definition: i6eQuaternion.h:58
Implements 3-dimensional vectors.
Definition: i6eVector.h:48
Handles all light related functionality.
#define ASSERT_THREAD_SAFETY_HEADER
Handles all light related functionality.
Definition: MeshComponent.h:64