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