From 4e97825c1a4f2b695ab6f38b4acc5c6751ce73b7 Mon Sep 17 00:00:00 2001 From: Meoweg Date: Tue, 10 Nov 2015 17:28:49 +0000 Subject: [PATCH] Add scene --- src/main.cpp | 22 +++++++++------------- src/scene.hpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 13 deletions(-) create mode 100644 src/scene.hpp diff --git a/src/main.cpp b/src/main.cpp index 2250a23..76e8c24 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include "gl.hpp" #include "program.hpp" -#include "object.hpp" +#include "scene.hpp" #include "camera.hpp" #include @@ -23,6 +23,8 @@ static GLuint texture_uniform; static bool keys[GLFW_KEY_LAST]; +static Scene scene; + static Camera camera; static Camera camera1; static Camera camera2; @@ -100,6 +102,8 @@ int main() bunny1 = new Object(*bunny); bunny1->position.x = 2.0; + scene << suzanne1 << teapot1 << bunny1; + glEnable(GL_DEPTH_TEST); glClearColor(1, 1, 1, 0); @@ -145,24 +149,16 @@ void iterate() const glm::mat4 mvp3 = camera3.transformation(); glViewport(0, 0, 640 / 2, 480 / 2); - suzanne1->draw(mvp); - teapot1->draw(mvp); - bunny1->draw(mvp); + scene.draw(mvp); glViewport(640 / 2, 0, 640 / 2, 480 / 2); - suzanne1->draw(mvp1); - teapot1->draw(mvp1); - bunny1->draw(mvp1); + scene.draw(mvp1); glViewport(640 / 2, 480 / 2, 640 / 2, 480 / 2); - suzanne1->draw(mvp2); - teapot1->draw(mvp2); - bunny1->draw(mvp2); + scene.draw(mvp2); glViewport(0, 480 / 2, 640 / 2, 480 / 2); - suzanne1->draw(mvp3); - teapot1->draw(mvp3); - bunny1->draw(mvp3); + scene.draw(mvp3); } GLFWCALL void on_key(int key, int action) diff --git a/src/scene.hpp b/src/scene.hpp new file mode 100644 index 0000000..ada35d3 --- /dev/null +++ b/src/scene.hpp @@ -0,0 +1,34 @@ +#ifndef _SCENE_HPP_ +#define _SCENE_HPP_ + +#include "object.hpp" + +#include + +#include + +class Scene +{ +public: + inline Scene &operator <<(Object *object); + + inline void draw(const glm::mat4 &mvp); + +private: + std::vector _objects; +}; + +Scene &Scene::operator <<(Object *object) +{ + _objects.push_back(object); + + return *this; +} + +void Scene::draw(const glm::mat4 &mvp) +{ + for (auto object : _objects) + object->draw(mvp); +} + +#endif // _SCENE_HPP_