added implementation of graphicalnode

This commit is contained in:
Lendemor 2016-12-07 18:35:19 +01:00
parent f718c4b670
commit e4dcab14d9
9 changed files with 77 additions and 44 deletions

View File

@ -0,0 +1,6 @@
#include "graphicalcontainernode.h"
GraphicalContainerNode::GraphicalContainerNode()
{
}

View File

@ -0,0 +1,16 @@
#ifndef GRAPHICALCONTAINERNODE_H
#define GRAPHICALCONTAINERNODE_H
#include "graphicalnode.h"
#include "glm/mat4x4.hpp"
#include <vector>
class GraphicalContainerNode : public GraphicalNode
{
protected:
std::vector<GraphicalNode*> m_children;
public:
GraphicalContainerNode();
};
#endif // GRAPHICALCONTAINERNODE_H

View File

@ -0,0 +1,22 @@
#include "graphicalnode.h"
#include "scenetree.h"
GraphicalNode::GraphicalNode()
{
}
void GraphicalNode::setSceneTree(SceneTree *tree){
SceneNode::setSceneTree(tree);
if (tree)
tree->addToIndex(this);
}
void GraphicalNode::toggleVisibility(){
m_visible = !m_visible;
if(m_visible){
m_scene->addToIndex(this);
}else{
m_scene->removeFromIndex(this);
}
}

25
src/scene/graphicalnode.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef GRAPHICALNODE_H
#define GRAPHICALNODE_H
#include "scenenode.h"
#include "glm/mat4x4.hpp"
class SceneTree;
class GraphicalNode : public SceneNode
{
private:
glm::mat4 m_transform;
protected:
bool m_visible;
public:
GraphicalNode();
void toggleVisibility();
void setSceneTree(SceneTree* tree);
void setTransform(const glm::mat4 &transform) { m_transform = transform; }
const glm::mat4& getTransform() { return m_transform; }
};
#endif // GRAPHICALNODE_H

View File

@ -2,16 +2,3 @@
#include "scenetree.h" #include "scenetree.h"
#include <light.h> #include <light.h>
void LightNode::setSceneTree(SceneTree *tree){
SceneNode::setSceneTree(tree);
tree->addToIndex(this);
}
void LightNode::toggleVisibility(){
m_visible = !m_visible;
if(m_visible){
m_scene->addToIndex(this);
}else{
m_scene->removeFromIndex(this);
}
}

View File

@ -1,26 +1,21 @@
#ifndef LIGHTNODE_H #ifndef LIGHTNODE_H
#define LIGHTNODE_H #define LIGHTNODE_H
#include "scenenode.h" #include "graphicalnode.h"
#include "glm/mat4x4.hpp" #include "glm/mat4x4.hpp"
#include "scene.h" #include "scene.h"
class LightNode : public SceneNode class LightNode : public GraphicalNode
{ {
Light *m_light; Light *m_light;
bool m_visible;
public: public:
LightNode(Light* light) : m_light(light), m_visible(true) {} LightNode(Light* light) : m_light(light) {GraphicalNode::m_visible = true;}
virtual void update() virtual void update()
{ {
} }
virtual void setSceneTree(SceneTree *tree);
void toggleVisibility();
virtual Light* getLight() { return m_light; } virtual Light* getLight() { return m_light; }
}; };

View File

@ -5,18 +5,3 @@
void MeshNode::setDepth(float depth){ void MeshNode::setDepth(float depth){
m_geometry.mesh->setDepth(depth); m_geometry.mesh->setDepth(depth);
} }
void MeshNode::setSceneTree(SceneTree *tree){
SceneNode::setSceneTree(tree);
if (tree)
tree->addToIndex(this);
}
void MeshNode::toggleVisibility(){
m_visible = !m_visible;
if(m_visible){
m_scene->addToIndex(this);
}else{
m_scene->removeFromIndex(this);
}
}

View File

@ -1,7 +1,7 @@
#ifndef MESHNODE_H #ifndef MESHNODE_H
#define MESHNODE_H #define MESHNODE_H
#include "scenenode.h" #include "graphicalnode.h"
#include "glm/mat4x4.hpp" #include "glm/mat4x4.hpp"
#include "scene.h" #include "scene.h"
@ -9,16 +9,16 @@
* @brief The MeshNode class holds a mesh * @brief The MeshNode class holds a mesh
*/ */
class MeshNode : public SceneNode class MeshNode : public GraphicalNode
{ {
GeometryNode m_geometry; GeometryNode m_geometry;
bool m_visible;
public: public:
// temp // temp
glm::mat4 m_movement; glm::mat4 m_movement;
glm::mat4 m_acceleration; glm::mat4 m_acceleration;
MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()), m_visible(true) {} MeshNode(Mesh* mesh) : m_geometry(mesh, glm::mat4()) {GraphicalNode::m_visible = true;}
virtual void update() virtual void update()
{ {
@ -26,14 +26,10 @@ public:
m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix; m_geometry.modelMatrix = m_movement * m_geometry.modelMatrix;
} }
virtual void setSceneTree(SceneTree *tree);
void setTransform(const glm::mat4 &transform) { m_geometry.modelMatrix = transform; } void setTransform(const glm::mat4 &transform) { m_geometry.modelMatrix = transform; }
const glm::mat4& getTransform() { return m_geometry.modelMatrix; } const glm::mat4& getTransform() { return m_geometry.modelMatrix; }
void setDepth(float depth); void setDepth(float depth);
void toggleVisibility();
virtual GeometryNode* getGeometryNode() { return &m_geometry; } virtual GeometryNode* getGeometryNode() { return &m_geometry; }
}; };

View File

@ -15,6 +15,7 @@ SceneTree::SceneTree() :
DeferredPipeline *pipeline = new DeferredPipeline(); DeferredPipeline *pipeline = new DeferredPipeline();
m_pipeline = pipeline; m_pipeline = pipeline;
pipeline->setRenderTarget(FrameBuffer::screen); pipeline->setRenderTarget(FrameBuffer::screen);
m_root.setSceneTree(this);
} }
SceneTree::~SceneTree() SceneTree::~SceneTree()