ComputerGraphik TU WIEN
sceneObject.hpp
Go to the documentation of this file.
1 #ifndef SCENEOBJECT_HPP
2 #define SCENEOBJECT_HPP
3 
4 #include <map>
5 #include <memory>
6 #include <vector>
7 #include <GL/glew.h>
8 #include <glm/vec3.hpp>
9 #include <glm/mat4x4.hpp>
10 
11 class Scene;
12 class Model;
13 class Shader;
14 
16 
30 class SceneObject : public std::enable_shared_from_this<SceneObject> {
31 public:
32  typedef std::vector<std::pair<double, glm::mat4> > Animation;
33 
34  SceneObject(std::shared_ptr<SceneObject>& effectParent, const glm::mat4& modelMatrix = glm::mat4(1));
35  SceneObject(const std::string& name, Scene* scene = 0, Model* model = 0, const glm::mat4& modelMatrix = glm::mat4(1));
36  virtual ~SceneObject();
37 
38  Model* getModel() const { return model; }
39  Shader* getShader() const { return shader; }
40  glm::mat4 getModelMatrix() const { return modelMatrix; }
41  glm::mat4 getGlobalModelMatrix() const;
42  std::string getName() const { return name; }
43  std::shared_ptr<SceneObject> getParent() const { return parent.lock(); }
44 
45  void setAnimationTime(double time);
46  bool setAnimation(const Animation& anim);
47 
48  bool delChild(size_t idx);
49  bool getChild(size_t idx, std::shared_ptr<SceneObject>& child) const;
50  bool addChild(std::shared_ptr<SceneObject>& child);
51 
52  bool remEffect(const std::string& name);
53  SceneObject* getEffect(const std::string& name) const;
54  bool addEffect(const std::string& name, std::unique_ptr<SceneObject>& effect);
55 
56  //TODO use sentinels but one more sentinel would be needed besides post pre and draw
57  bool doNotRender() { return norender; }
58  bool getIsVolSun() { return isVolSun; }
59 
60  virtual void reset();
61  virtual void draw() const;
62  virtual bool animate(double time);
63  virtual void update(double deltaT);
64  virtual void setShader(Shader* val);
65 
66 protected:
67  GLuint vao;
71  glm::mat4 modelMatrix;
72 
73  std::string name;
74  std::weak_ptr<SceneObject> parent;
75  std::vector<std::shared_ptr<SceneObject> > childs;
76  std::map<std::string, std::unique_ptr<SceneObject> > effectChilds;
77 
78  size_t animIDX;
79  Animation animation;
80 
81  bool norender; //also last in init list, TODO: see above
82  bool isVolSun; //TODO same thing as above
83 };
84 
85 inline glm::mat4 SceneObject::getGlobalModelMatrix() const {
86  glm::mat4 M = modelMatrix;
87  std::shared_ptr<SceneObject> node = getParent();
88  while(node) {
89  M = node->getModelMatrix() * M;
90  node = node->getParent();
91  }
92  return M;
93 }
94 
95 #endif //SCENEOBJECT_HPP
GLuint vao
Definition: sceneObject.hpp:67
SceneObject(std::shared_ptr< SceneObject > &effectParent, const glm::mat4 &modelMatrix=glm::mat4(1))
Definition: sceneObject.cpp:15
bool addChild(std::shared_ptr< SceneObject > &child)
Definition: sceneObject.cpp:193
virtual void update(double deltaT)
Definition: sceneObject.cpp:113
virtual void setShader(Shader *val)
Definition: sceneObject.cpp:128
Encapsulates a graphical object model in the GPU.
Definition: model.hpp:14
void setAnimationTime(double time)
Definition: sceneObject.cpp:211
glm::mat4 getModelMatrix() const
Definition: sceneObject.hpp:40
SceneObject * getEffect(const std::string &name) const
Definition: sceneObject.cpp:227
Model * model
Definition: sceneObject.hpp:69
std::vector< std::pair< double, glm::mat4 > > Animation
Definition: sceneObject.hpp:32
bool getIsVolSun()
Definition: sceneObject.hpp:58
std::map< std::string, std::unique_ptr< SceneObject > > effectChilds
Definition: sceneObject.hpp:76
size_t animIDX
Definition: sceneObject.hpp:78
Model * getModel() const
Definition: sceneObject.hpp:38
virtual ~SceneObject()
Definition: sceneObject.cpp:41
std::weak_ptr< SceneObject > parent
Definition: sceneObject.hpp:74
bool doNotRender()
Definition: sceneObject.hpp:57
virtual void reset()
Definition: sceneObject.cpp:108
Shader * getShader() const
Definition: sceneObject.hpp:39
virtual bool animate(double time)
Definition: sceneObject.cpp:118
std::string getName() const
Definition: sceneObject.hpp:42
bool addEffect(const std::string &name, std::unique_ptr< SceneObject > &effect)
Definition: sceneObject.cpp:235
Encapsulates the Rendering Engine, holds a complete scene and it's assets.
Definition: scene.hpp:71
Scene * scene
Definition: sceneObject.hpp:68
bool getChild(size_t idx, std::shared_ptr< SceneObject > &child) const
Definition: sceneObject.cpp:168
std::shared_ptr< SceneObject > getParent() const
Definition: sceneObject.hpp:43
std::string name
Definition: sceneObject.hpp:73
glm::mat4 modelMatrix
Definition: sceneObject.hpp:71
Encapsulates a shader program.
Definition: shader.hpp:9
bool norender
Definition: sceneObject.hpp:81
bool delChild(size_t idx)
Definition: sceneObject.cpp:179
bool remEffect(const std::string &name)
Definition: sceneObject.cpp:218
Animation animation
Definition: sceneObject.hpp:79
The base class of the objects which are rendered.
Definition: sceneObject.hpp:30
virtual void draw() const
Definition: sceneObject.cpp:46
Shader * shader
Definition: sceneObject.hpp:70
bool setAnimation(const Animation &anim)
Definition: sceneObject.cpp:203
glm::mat4 getGlobalModelMatrix() const
Definition: sceneObject.hpp:85
std::vector< std::shared_ptr< SceneObject > > childs
Definition: sceneObject.hpp:75
bool isVolSun
Definition: sceneObject.hpp:82