This commit is contained in:
Anselme 2016-12-07 18:36:06 +01:00
commit 9abb185ea5
21 changed files with 359 additions and 288 deletions

View File

@ -7,8 +7,8 @@ SET(VERSION_MINOR 1)
set(EXTRA_INCLUDES ${PROJECT_SOURCE_DIR}/src)
# choose source file
file(GLOB LIB_SRC_LIST src/*.cpp src/tools/*.cpp src/scene/*.cpp)
file(GLOB LIB_HEAD_LIST src/*.h src/tools/*.h src/scene/*.h)
file(GLOB LIB_SRC_LIST src/*.cpp src/tools/*.cpp src/scene/*.cpp src/sparrowshell/*.cpp)
file(GLOB LIB_HEAD_LIST src/*.h src/tools/*.h src/scene/*.h src/sparrowshell/*.h)
set(EXEC_SRC_LIST src/test/main.cpp)
#set compilation option

View File

@ -9,7 +9,7 @@
#include <btBulletDynamicsCommon.h>
#include "resourcemanager.h"
#include "scene/scenetree.h"
#include "sparrowshell.h"
#include "sparrowshell/sparrowshell.h"
Engine::Engine() :
m_window(NULL),

View File

@ -11,6 +11,7 @@ void ContainerNode::addChild(SceneNode* node)
{
if(node != nullptr)
{
node->setSceneTree(m_scene);
m_children.push_back(node);
node->m_parent = this;
}

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 <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
#define LIGHTNODE_H
#include "scenenode.h"
#include "graphicalnode.h"
#include "glm/mat4x4.hpp"
#include "scene.h"
class LightNode : public SceneNode
class LightNode : public GraphicalNode
{
Light *m_light;
bool m_visible;
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 setSceneTree(SceneTree *tree);
void toggleVisibility();
virtual Light* getLight() { return m_light; }
};

View File

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

View File

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

View File

@ -1,158 +0,0 @@
#include "sparrowshell.h"
#include "message.h"
#include "input.h"
#include "scene/scenetree.h"
#include "scene/meshnode.h"
#include "scene/textnode.h"
#include "mesh.h"
#include "phongmaterial.h"
#include "tools/utils.h"
#include "tools/font.h"
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
const unsigned int SparrowShell::BUFFER_DISPLAYED_NUMBER = 10;
const unsigned int SparrowShell::SCROLLBAR_PIXEL_WIDTH = 10;
const float SparrowShell::SHELL_DEPTH = 10;
SparrowShell::SparrowShell(sf::Window* window, Input* input):
m_window(window),
m_input(input),
m_position(glm::ivec2(0,0)),
m_buffer(ShellBuffer(BUFFER_MAX_LENGTH))
{
sf::Vector2u size = m_window->getSize();
m_dimension = glm::ivec2(size.x,size.y/2);
Mesh* mesh = new Mesh();
m_buffer.setFontSize(16.f);
mesh->addRectangle2D(m_position,m_dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = glm::vec3(0.1,0.1,0.1);
mat->m_opacity = 0.5;
mesh->setMaterial(mat);
mesh->setDepth(SHELL_DEPTH);
mesh->initGL();
m_background = new MeshNode(mesh);
this->addChild(m_background);
m_scrollbar = SparrowShell::ScrollBar(this);
}
void SparrowShell::out(std::string s)
{
Font *shellfont = RESOURCE_GET(Font,"shellfont");
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer.getFontSize());
tnode->setDepth(SHELL_DEPTH+1);
// m_currentScene->addToIndex(tnode);
m_buffer.push(tnode);
if (m_buffer.size() > BUFFER_DISPLAYED_NUMBER)
m_resizeScrollBar = true;
}
void SparrowShell::scrollUp(){
if (m_index + BUFFER_DISPLAYED_NUMBER < m_buffer.size()){
m_index++;
m_indexMoved = true;
}
}
void SparrowShell::scrollDown(){
if (m_index > 0){
m_index--;
m_indexMoved = true;
}
}
void SparrowShell::toggleShell(){
m_shellEnabled = !m_shellEnabled;
// if (m_shellEnabled){
// for(unsigned int i = 0;i<m_buffer.size();i++)
// m_scene->addToIndex(m_buffer[i]);
// }else{
// for(unsigned int i = 0;i<m_buffer.size();i++)
// m_scene->removeFromIndex(m_buffer[i]);
// }
for(auto child : m_children){
MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
if(meshchild)
meshchild->toggleVisibility();
}
m_buffer.toggleBuffer();
m_background->toggleVisibility();
}
void SparrowShell::update(){
TextNode* tnode;
glm::vec2 text_pos(0);
for(auto action : m_input->getActions()){
if(action == 15){
toggleShell();
}
}
//move position of shellBuffer
// position textnode inside shellBuffer
if(m_shellEnabled){
for(unsigned int i = 0; i<m_buffer.size(); i++){
tnode = (TextNode*)m_buffer[i];
if (i >= m_index && i < m_index + BUFFER_DISPLAYED_NUMBER){
utils::setPosition2D(tnode,text_pos);
text_pos.y += m_buffer.getFontSize();
m_scene->addToIndex(tnode);
}
}
}
m_scrollbar.update();
}
void SparrowShell::ShellBuffer::toggleBuffer(){
for(auto child : m_children){
MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
if(meshchild)
meshchild->toggleVisibility();
}
}
void SparrowShell::ShellBuffer::push(TextNode* s){
if (m_children.size() >= m_max_size){
m_children[m_zero_offset++] = s;
m_zero_offset %= m_max_size;
}else
m_children.push_back(s);
}
SparrowShell::ScrollBar::ScrollBar(SparrowShell* shell):m_shell(shell){
m_position = glm::ivec2(m_shell->m_dimension.x - SparrowShell::SCROLLBAR_PIXEL_WIDTH,0);
m_dimension = glm::ivec2(SparrowShell::SCROLLBAR_PIXEL_WIDTH,m_shell->m_dimension.y);
Mesh* mesh = new Mesh();
mesh->addRectangle2D(glm::vec2(0),m_dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = glm::vec3(0,0,0.5);
mesh->setDepth(SHELL_DEPTH+1);
mesh->setMaterial(mat);
mesh->initGL();
m_mesh = new MeshNode(mesh);
utils::setPosition2D(m_mesh,m_position);
m_shell->addChild(m_mesh);
}
void SparrowShell::ScrollBar::update(){
m_position.y = m_shell->m_position.y;
m_dimension.y = m_shell->m_dimension.y;
float cran = ((float)m_shell->m_dimension.y/(float)m_shell->m_buffer.size());
int indexCursor = m_shell->m_buffer.size()-(m_shell->m_index+BUFFER_DISPLAYED_NUMBER);
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor);
if (m_shell->m_resizeScrollBar){
glm::ivec2 new_dim(m_dimension.x,(int)(cran * BUFFER_DISPLAYED_NUMBER));
utils::resize2D(m_mesh,m_dimension,new_dim);
m_shell->m_resizeScrollBar = false;
}
if (m_shell->m_resizeScrollBar || m_shell->m_indexMoved)
utils::setPosition2D(m_mesh,new_pos);
}

View File

@ -1,81 +0,0 @@
#ifndef SPARROWSHELL_H
#define SPARROWSHELL_H
#include <list>
#include "system.h"
#include "scene/scenetree.h"
#include "glm/glm.hpp"
class Input;
class MeshNode;
class TextNode;
namespace sf {
class Window;
}
class SparrowShell : public ContainerNode
{
private:
class ScrollBar{
SparrowShell* m_shell;
glm::ivec2 m_position;
glm::ivec2 m_dimension;
MeshNode *m_mesh;
public:
ScrollBar(){}
ScrollBar(SparrowShell* shell);
void update();
};
class ShellBuffer : public ContainerNode {
private:
int m_zero_offset = 0;
unsigned int m_max_size;
float m_font_size;
public:
ShellBuffer(int buffer_size):m_max_size(buffer_size){}
SceneNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}
void push(TextNode*);
unsigned int size(){return m_children.size();}
void toggleBuffer();
// if this font_size is scaling down, sizes which are power of 2 render better.
void setFontSize(float font_size){m_font_size = font_size;}
float getFontSize(){return m_font_size;}
};
static const unsigned int BUFFER_MAX_LENGTH;
static const unsigned int BUFFER_DISPLAYED_NUMBER;
static const unsigned int SCROLLBAR_PIXEL_WIDTH;
static const float SHELL_DEPTH;
sf::Window* m_window;
Input* m_input;
glm::ivec2 m_position;
glm::ivec2 m_dimension;
ShellBuffer m_buffer;
unsigned int m_index = 0;
bool m_resizeScrollBar = false;
bool m_indexMoved = false;
bool m_shellEnabled = false;
//textMesh
MeshNode* m_background;
ScrollBar m_scrollbar;
public:
SparrowShell(sf::Window*, Input*);
void update();
// void setScene(SceneTree *scene){m_currentScene = scene;}
void scrollUp();
void scrollDown();
void toggleShell();
void out(std::string);
};
#endif // SPARROWSHELL_H

View File

@ -0,0 +1,19 @@
#include "shellbuffer.h"
#include "scene/meshnode.h"
#include "scene/textnode.h"
void ShellBuffer::toggleBuffer(){
for(auto child : m_children){
MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
if(meshchild)
meshchild->toggleVisibility();
}
}
void ShellBuffer::push(TextNode* s){
if (m_children.size() >= m_max_size){
m_children[m_zero_offset++] = s;
m_zero_offset %= m_max_size;
}else
m_children.push_back(s);
}

View File

@ -0,0 +1,25 @@
#ifndef SHELLBUFFER_H
#define SHELLBUFFER_H
#include "scene/containernode.h"
class TextNode;
class ShellBuffer : public ContainerNode {
private:
int m_zero_offset = 0;
unsigned int m_max_size;
float m_font_size;
public:
ShellBuffer(int buffer_size):m_max_size(buffer_size){}
SceneNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}
void push(TextNode*);
unsigned int size(){return m_children.size();}
void toggleBuffer();
// if this font_size is scaling down, sizes which are power of 2 render better.
void setFontSize(float font_size){m_font_size = font_size;}
float getFontSize(){return m_font_size;}
};
#endif // SHELLBUFFER_H

View File

@ -0,0 +1,46 @@
#include "shellscrollbar.h"
#include "sparrowshell.h"
#include "mesh.h"
#include "phongmaterial.h"
#include "scene/meshnode.h"
#include "tools/utils.h"
ShellScrollBar::ShellScrollBar()
{
}
ShellScrollBar::ShellScrollBar(SparrowShell* shell):m_shell(shell){
m_position = glm::ivec2(m_shell->getDimension().x - SparrowShell::SCROLLBAR_PIXEL_WIDTH,0);
m_dimension = glm::ivec2(SparrowShell::SCROLLBAR_PIXEL_WIDTH,m_shell->getDimension().y);
Mesh* mesh = new Mesh();
mesh->addRectangle2D(glm::vec2(0),m_dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = glm::vec3(0,0,0.5);
mesh->setDepth(SparrowShell::SHELL_DEPTH+1);
mesh->setMaterial(mat);
mesh->initGL();
m_mesh = new MeshNode(mesh);
utils::setPosition2D(m_mesh,m_position);
m_shell->addChild(m_mesh);
}
void ShellScrollBar::update(){
m_position.y = m_shell->getPosition().y;
m_dimension.y = m_shell->getDimension().y;
float cran = ((float)m_shell->getDimension().y/(float)m_shell->getBuffer()->size());
int indexCursor = m_shell->getBuffer()->size()-(m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_NUMBER);
glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor);
if (m_shell->isBufferResized()){
glm::ivec2 new_dim(m_dimension.x,(int)(cran * SparrowShell::BUFFER_DISPLAYED_NUMBER));
utils::resize2D(m_mesh,m_dimension,new_dim);
}
if (m_shell->isBufferResized() || m_shell->indexMoved())
utils::setPosition2D(m_mesh,new_pos);
}

View File

@ -0,0 +1,20 @@
#ifndef SHELLSCROLLBAR_H
#define SHELLSCROLLBAR_H
#include "glm/vec2.hpp"
class MeshNode;
class SparrowShell;
class ShellScrollBar
{
SparrowShell* m_shell;
glm::ivec2 m_position;
glm::ivec2 m_dimension;
MeshNode *m_mesh;
public:
ShellScrollBar();
ShellScrollBar(SparrowShell* shell);
void update();
};
#endif // SHELLSCROLLBAR_H

View File

@ -0,0 +1,99 @@
#include "sparrowshell.h"
//#include "message.h"
#include "input.h"
#include "scene/scenetree.h"
#include "scene/meshnode.h"
#include "scene/textnode.h"
#include "mesh.h"
#include "phongmaterial.h"
#include "tools/utils.h"
#include "tools/font.h"
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
const unsigned int SparrowShell::BUFFER_DISPLAYED_NUMBER = 10;
const unsigned int SparrowShell::SCROLLBAR_PIXEL_WIDTH = 10;
const float SparrowShell::SHELL_DEPTH = 10;
SparrowShell::SparrowShell(sf::Window* window, Input* input):
m_window(window),
m_input(input),
m_position(glm::ivec2(0,0)),
m_buffer(new ShellBuffer(BUFFER_MAX_LENGTH))
{
sf::Vector2u size = m_window->getSize();
m_dimension = glm::ivec2(size.x,size.y/2);
Mesh* mesh = new Mesh();
m_buffer->setFontSize(16.f);
mesh->addRectangle2D(m_position,m_dimension);
PhongMaterial *mat = new PhongMaterial();
mat->diffuse = glm::vec3(0.1,0.1,0.1);
mat->m_opacity = 0.5;
mesh->setMaterial(mat);
mesh->setDepth(SHELL_DEPTH);
mesh->initGL();
m_background = new MeshNode(mesh);
this->addChild(m_background);
m_scrollbar = ShellScrollBar(this);
}
void SparrowShell::out(std::string s)
{
Font *shellfont = RESOURCE_GET(Font,"shellfont");
TextNode* tnode = shellfont->getTextNode(s,glm::vec3(0.7,1,0.3),m_buffer->getFontSize());
tnode->setDepth(SHELL_DEPTH+1);
// m_currentScene->addToIndex(tnode);
m_buffer->push(tnode);
if (m_buffer->size() > SparrowShell::BUFFER_DISPLAYED_NUMBER)
m_resizeBuffer = true;
}
void SparrowShell::scrollUp(){
if (m_index + SparrowShell::BUFFER_DISPLAYED_NUMBER < m_buffer->size()){
m_index++;
m_indexMoved = true;
}
}
void SparrowShell::scrollDown(){
if (m_index > 0){
m_index--;
m_indexMoved = true;
}
}
void SparrowShell::toggleShell(){
m_shellEnabled = !m_shellEnabled;
for(auto child : m_children){
MeshNode* meshchild = dynamic_cast<MeshNode*>(child);
if(meshchild)
meshchild->toggleVisibility();
}
m_buffer->toggleBuffer();
m_background->toggleVisibility();
}
void SparrowShell::update(){
TextNode* tnode;
glm::vec2 text_pos(0);
for(auto action : m_input->getActions()){
if(action == 15){
toggleShell();
}
}
//move position of shellBuffer
// position textnode inside shellBuffer
if(m_shellEnabled){
for(unsigned int i = 0; i<m_buffer->size(); i++){
// tnode = (TextNode*)(m_buffer+i);
// if (i >= m_index && i < m_index + BUFFER_DISPLAYED_NUMBER){
// utils::setPosition2D(tnode,text_pos);
// text_pos.y += m_buffer->getFontSize();
// m_scene->addToIndex(tnode);
// }
}
}
m_scrollbar.update();
}

View File

@ -0,0 +1,68 @@
#ifndef SPARROWSHELL_H
#define SPARROWSHELL_H
#include <list>
#include "system.h"
#include "scene/scenetree.h"
#include "glm/vec2.hpp"
#include "sparrowshell/shellbuffer.h"
#include "sparrowshell/shellscrollbar.h"
class Input;
class MeshNode;
class TextNode;
class ShellBuffer;
namespace sf {
class Window;
}
class SparrowShell : public ContainerNode
{
private:
sf::Window* m_window;
Input* m_input;
glm::ivec2 m_position;
glm::ivec2 m_dimension;
ShellBuffer* m_buffer;
unsigned int m_index = 0;
bool m_resizeBuffer = false;
bool m_indexMoved = false;
bool m_shellEnabled = false;
//textMesh
MeshNode* m_background;
ShellScrollBar m_scrollbar;
public:
static const unsigned int BUFFER_MAX_LENGTH;
static const unsigned int BUFFER_DISPLAYED_NUMBER;
static const unsigned int SCROLLBAR_PIXEL_WIDTH;
static const float SHELL_DEPTH;
SparrowShell(sf::Window*, Input*);
void update();
void scrollUp();
void scrollDown();
void toggleShell();
void out(std::string);
void setSceneTree(SceneTree* tree)
{
ContainerNode::setSceneTree(tree);
// m_buffer->setSceneTree(tree);
}
glm::ivec2 getPosition(){return m_position;}
glm::ivec2 getDimension(){return m_dimension;}
unsigned int getIndex(){return m_index;}
ShellBuffer* getBuffer(){return m_buffer;}
bool isBufferResized(){return m_resizeBuffer;}
bool indexMoved(){return m_indexMoved;}
};
#endif // SPARROWSHELL_H

View File

@ -20,7 +20,7 @@
#include <tools/font.h>
#include <tools/utils.h>
#include <sparrowshell.h>
#include <sparrowshell/sparrowshell.h>
#include <glm/ext.hpp>
@ -209,7 +209,6 @@ int main(){
engine.outputShell(std::to_string(i));
}
Input* input = engine.getInput();
input->setKeysMap(myKeysMap());
@ -249,5 +248,4 @@ int main(){
*/
}