basic shell background
This commit is contained in:
parent
128bbc2cf2
commit
d6eeddf812
@ -30,6 +30,7 @@ public:
|
||||
void stop();
|
||||
|
||||
Input* getInput() {return m_input;}
|
||||
sf::Window* getWindow(){return m_window;}
|
||||
SparrowRenderer* getRenderer() {return m_renderer;}
|
||||
btDiscreteDynamicsWorld* getPhysics() {return m_world;}
|
||||
|
||||
|
10
src/main.cpp
10
src/main.cpp
@ -12,6 +12,8 @@
|
||||
#include "tools/pathfinder.h"
|
||||
#include "tools/loader.h"
|
||||
|
||||
#include "sparrowshell.h"
|
||||
|
||||
int main(){
|
||||
Engine engine;
|
||||
|
||||
@ -20,8 +22,9 @@ int main(){
|
||||
engine.createWindow("test");
|
||||
SceneTree scene;
|
||||
|
||||
// creating a 2D mesh
|
||||
/* // creating a 2D mesh
|
||||
Mesh* mesh = new Mesh();
|
||||
mesh->addRectangle2D(50,50,100,100);
|
||||
// first triangle
|
||||
mesh->addVertex(glm::vec2(50, 50), glm::vec2(0, 0)); // 2D position and then texture coordinates
|
||||
mesh->addVertex(glm::vec2(50, 150), glm::vec2(0, 1));
|
||||
@ -33,6 +36,7 @@ int main(){
|
||||
// in the case you don't want to worry about if you defined the triangles in the right order,
|
||||
// you can call this : mesh->setIsDoubleSided(true);
|
||||
|
||||
|
||||
// creating the material
|
||||
PhongMaterial *mat = new PhongMaterial();
|
||||
// setting an arbitrary color to the square : (orange)
|
||||
@ -49,6 +53,10 @@ int main(){
|
||||
// creating the scene node
|
||||
MeshNode *node = new MeshNode(mesh);
|
||||
scene.addObject(scene.getRootObject(), node);
|
||||
*/
|
||||
|
||||
SparrowShell *shell = new SparrowShell(engine.getWindow(),engine.getInput());
|
||||
scene.addObject(scene.getRootObject(),shell);
|
||||
|
||||
// the pipeline needs to updates his shaders because the scene changed
|
||||
// this should be handled somewhere else in the future
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <guipipeline.h>
|
||||
#include <algorithm>
|
||||
// Scene
|
||||
#include <iostream>
|
||||
|
||||
SceneTree::SceneTree() :
|
||||
Scene(),
|
||||
@ -41,6 +42,11 @@ void SceneTree::update()
|
||||
void SceneTree::addObject(ContainerNode *parent, SceneNode *node)
|
||||
{
|
||||
parent->addChild(node);
|
||||
addToIndex(node);
|
||||
node->addedToSceneTree(this);
|
||||
}
|
||||
|
||||
void SceneTree::addToIndex(SceneNode* node){
|
||||
Light *light = node->getLight();
|
||||
GeometryNode *geometrynode = node->getGeometryNode();
|
||||
//TODO : Check for doublon in m_lights et m_geometries => not necessary if correctly removed ?
|
||||
@ -50,6 +56,10 @@ void SceneTree::addObject(ContainerNode *parent, SceneNode *node)
|
||||
|
||||
void SceneTree::removeObject(ContainerNode* parent,SceneNode *node){
|
||||
parent->removeChild(node);
|
||||
removeFromIndex(node);
|
||||
}
|
||||
|
||||
void SceneTree::removeFromIndex(SceneNode *node){
|
||||
auto it_l = std::find(m_lights.begin(),m_lights.end(),node->getLight());
|
||||
if (it_l != m_lights.end()){
|
||||
std::iter_swap(it_l,m_lights.end()-1);
|
||||
@ -62,7 +72,6 @@ void SceneTree::removeObject(ContainerNode* parent,SceneNode *node){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Container Node
|
||||
|
||||
void ContainerNode::update()
|
||||
@ -95,3 +104,11 @@ void ContainerNode::removeChild(SceneNode* node)
|
||||
}
|
||||
}
|
||||
|
||||
void ContainerNode::addedToSceneTree(SceneTree *tree)
|
||||
{
|
||||
for(auto child : m_children)
|
||||
{
|
||||
tree->addToIndex(child);
|
||||
child->addedToSceneTree(tree);
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <trackballcamera.h>
|
||||
|
||||
class SimplePipeline;
|
||||
class SceneTree;
|
||||
|
||||
/**
|
||||
* @brief The SceneNode class represents a class of the game
|
||||
@ -21,6 +22,7 @@ public:
|
||||
virtual void update() = 0;
|
||||
virtual Light* getLight() {return nullptr;}
|
||||
virtual GeometryNode* getGeometryNode() {return nullptr;}
|
||||
virtual void addedToSceneTree(SceneTree* tree){}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -40,6 +42,13 @@ public:
|
||||
* @brief removeChild removes the first iteration of node of the children list
|
||||
*/
|
||||
void removeChild(SceneNode* node);
|
||||
/**
|
||||
* @brief addedToSceneTree is called when this node is added to a SceneTree
|
||||
*
|
||||
* @param tree
|
||||
*/
|
||||
void addedToSceneTree(SceneTree *tree);
|
||||
|
||||
protected:
|
||||
std::vector<SceneNode*> m_children;
|
||||
};
|
||||
@ -88,7 +97,9 @@ public:
|
||||
|
||||
ContainerNode* getRootObject(){return &m_root;}
|
||||
void addObject(ContainerNode *parent, SceneNode *node);
|
||||
void addToIndex(SceneNode* node);
|
||||
void removeObject(ContainerNode* parent,SceneNode *node);
|
||||
void removeFromIndex(SceneNode *node);
|
||||
private:
|
||||
ContainerNode m_root;
|
||||
std::vector<Light*> m_lights;
|
||||
|
@ -2,6 +2,9 @@
|
||||
|
||||
#include "message.h"
|
||||
#include "input.h"
|
||||
#include "scenetree.h"
|
||||
#include "mesh.h"
|
||||
#include "phongmaterial.h"
|
||||
|
||||
const unsigned int SparrowShell::BUFFER_MAX_LENGTH = 50;
|
||||
const unsigned int SparrowShell::BUFFER_DISPLAYED_NUMBER = 10;
|
||||
@ -9,7 +12,15 @@ const unsigned int SparrowShell::SCROLLBAR_PIXEL_WIDTH = 2;
|
||||
|
||||
SparrowShell::SparrowShell(sf::Window* window, Input* input): m_window(window),m_input(input),m_position(glm::ivec2(0,0)),m_scrollbar(this)
|
||||
{
|
||||
//m_dimension = glm::ivec2();//
|
||||
sf::Vector2u size = m_window->getSize();
|
||||
m_dimension = glm::ivec2(size.x,size.y/2);
|
||||
Mesh* mesh = new Mesh();
|
||||
mesh->addRectangle2D(m_position,m_dimension);
|
||||
PhongMaterial *mat = new PhongMaterial();
|
||||
mat->diffuse = glm::vec3(0,0.5,0.5);
|
||||
mesh->setMaterial(mat);
|
||||
mesh->initGL();
|
||||
this->addChild(new MeshNode(mesh));
|
||||
}
|
||||
|
||||
void SparrowShell::out(std::string s)
|
||||
@ -33,6 +44,12 @@ void SparrowShell::update()
|
||||
m_scrollbar.update();
|
||||
}
|
||||
|
||||
//GeometryNode* SparrowShell::getGeometryNode()
|
||||
//{
|
||||
// return geometry;
|
||||
//}
|
||||
|
||||
|
||||
SparrowShell::ScrollBar::ScrollBar(SparrowShell* shell):m_shell(shell){
|
||||
m_position = glm::ivec2(m_shell->m_dimension.x - SCROLLBAR_PIXEL_WIDTH,0);
|
||||
m_dimension = glm::ivec2(SCROLLBAR_PIXEL_WIDTH,m_shell->m_dimension.y);
|
||||
|
@ -13,9 +13,13 @@ namespace sf {
|
||||
class Window;
|
||||
}
|
||||
|
||||
class SparrowShell : public SceneNode
|
||||
class SparrowShell : public ContainerNode
|
||||
{
|
||||
private:
|
||||
class BackGround : public MeshNode {
|
||||
|
||||
};
|
||||
|
||||
class ScrollBar{
|
||||
SparrowShell* m_shell;
|
||||
glm::ivec2 m_position;
|
||||
@ -47,6 +51,7 @@ public:
|
||||
SparrowShell(sf::Window*, Input*);
|
||||
|
||||
void update();
|
||||
|
||||
void scrollUp();
|
||||
void scrollDown();
|
||||
void out(std::string);
|
||||
|
Loading…
x
Reference in New Issue
Block a user