diff --git a/.gitignore b/.gitignore index 46d5785..030ae65 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ #binaries build/* -release/* #builders *.pro.user #test directory test diff --git a/graph/scene.cpp b/graph/scene.cpp index 5d879d7..9b07340 100644 --- a/graph/scene.cpp +++ b/graph/scene.cpp @@ -1,139 +1,155 @@ #include "scene.h" #include "shape.h" #include "camera.h" -/* include from Qt library */ +/* includes from Qt library */ #include <QGLShaderProgram> +#include <QMatrix4x4> using namespace std; float scene::delta_time = 10e-4; /* Render objects list */ list<Shape*> objects; /* Reference to the camera object */ Camera *_camera = NULL; /* Shader manager */ QGLShaderProgram shaders; /* Initialized flags */ /* After initialization it is not possible to change the values */ bool initialized = false; +/* Screen information */ +int _width = 1024, _height = 800; + /* Implementations */ void scene::initialize() { if (initialized) throw QString("Error: scene already initialized").toStdString(); if (_camera == NULL) throw QString("Error: scene, null camera instance during initialization").toStdString(); // build the shader shaders.link(); // activate the shader shaders.bind(); /* Enable superposition control for graphical objects */ glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); /* Set initialized flag to true */ initialized = true; } void scene::close() { // TODO } -obj_iter scene::obj_beg() +scene::iterator scene::obj_beg() { return objects.begin(); } -obj_iter scene::obj_end() +scene::iterator scene::obj_end() { return objects.end(); } void scene::registerObj(Shape *obj) { objects.push_back(obj); // TODO add to rendering engine } void scene::unregisterObj(Shape *obj) { // TODO remove from rendering engine objects.remove(obj); } void scene::unregisterAll() { // TODO remove from rendering engine objects.clear(); } void scene::addShader(ShaderID id, const QString& file) { switch(id) { case ShaderID::vertex: shaders.addShaderFromSourceFile(QGLShader::Vertex, file); break; case ShaderID::fragment: shaders.addShaderFromSourceFile(QGLShader::Fragment, file); break; default: break; } } void scene::setCamera(Camera *camera) { if (camera == 0) throw QString("Error: scene, null camera instance").toStdString(); _camera = camera; } Camera * scene::camera() { return _camera; } +void scene::resize(int width, int height) +{ + _width = width; + _height = height; + + glViewport(0, 0, width, height); + + QMatrix4x4 matrix; + + // TODO +} + void scene::update(const float *dt) { /* establish delta time to use */ float delta_time = (dt) ? *dt : scene::delta_time; /* Components update and render */ for (auto obj : objects) { /* Updating component */ if (obj->isUpdating()) obj->update(delta_time); /* Rendering component */ if (obj->isRendering()) obj->render(); } /* Update Camera */ /* Rendering flush */ } diff --git a/include/scene.h b/include/scene.h index 0643b76..01b7e52 100644 --- a/include/scene.h +++ b/include/scene.h @@ -1,79 +1,115 @@ #ifndef __SCENE_H__ #define __SCENE_H__ /* * This namespace manages all "low level" * rendering state and functions * * Idea: All graphical components * are contained in a "linked" list such that, * for every frame and for each component * its "update" method is called. * * * */ /* Forward declarations */ class Shape; class Camera; class QString; /* This include is necessary! - * Forward declaration doesn't work for template types + * Forward declaration doesn't work for template containers types */ #include <list> -/* Iterator typedef to loop through all components */ -typedef std::list<Shape*>::iterator obj_iter; /* Graphics scene manager */ namespace scene { /* time unit setting, global variable */ extern float delta_time; + + + + /* + * Initialization functions + */ /* Init function for the symulation scene */ void initialize(); /* Safely close the symulation scene */ void close(); + + + /* + * Iteration functions + */ + + /* Iterator typedef to loop through all components */ + typedef std::list<Shape*>::iterator iterator; + /* Objects iterator */ - obj_iter obj_beg(); + iterator obj_beg(); /* End objects iterator */ - obj_iter obj_end(); + iterator obj_end(); + + + /* + * Shader management + */ /* Shader enum */ enum ShaderID { vertex = 0, fragment }; /* Shader settings */ void addShader(ShaderID id, const QString& file); + /* + * Camera binding functions + */ + /* Set a camera */ void setCamera(Camera *camera); /* Get the camera instance */ Camera * camera(); + + + + /* + * Shape objects registration functions + */ /* Registers a object into the graphics engine (OpenGL) */ void registerObj(Shape*); /* Unregister a object which is in the graphics engine (OpenGL) */ void unregisterObj(Shape*); /* Unregister all object */ void unregisterAll(); + + /* + * Scene update functions + */ + + /* Manage the window resize event */ + void resize(int width, int height); + /* Update the entire scene, called every frame */ void update(const float *dt = 0); } #endif diff --git a/symkit.pro b/symkit.pro index 3ec9d89..c1ce8a8 100644 --- a/symkit.pro +++ b/symkit.pro @@ -1,30 +1,18 @@ win32:TEMPLATE = vclib unix:TEMPLATE = lib QMAKE_CXXFLAGS += -std=c++11 QT += core opengl CONFIG += staticlib release warn_on DESTDIR += lib INCLUDEPATH += "$$PWD/include" -HEADERS += include/vector.h \ - include/svector.h \ - include/particle.h \ - include/matpoint.h \ - include/shape.h \ - include/partsystem.h \ - include/scene.h \ - include/iosymkit.h - -SOURCES += engine/vector.cpp \ - engine/particle.cpp \ - graph/scene.cpp \ - graph/shape.cpp \ - graph/matpoint.cpp \ - graph/partsystem.cpp \ - graph/camera.cpp +HEADERS += $$files(include/*.h, true) + +SOURCES += $$files(engine/*.cpp, true) \ + $$files(graph/*.cpp, true) diff --git a/CMakeLists.txt b/templates/CMakeLists.txt similarity index 100% rename from CMakeLists.txt rename to templates/CMakeLists.txt