Add scene
This commit is contained in:
parent
83aa421c04
commit
4e97825c1a
22
src/main.cpp
22
src/main.cpp
|
@ -1,6 +1,6 @@
|
||||||
#include "gl.hpp"
|
#include "gl.hpp"
|
||||||
#include "program.hpp"
|
#include "program.hpp"
|
||||||
#include "object.hpp"
|
#include "scene.hpp"
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -23,6 +23,8 @@ static GLuint texture_uniform;
|
||||||
|
|
||||||
static bool keys[GLFW_KEY_LAST];
|
static bool keys[GLFW_KEY_LAST];
|
||||||
|
|
||||||
|
static Scene scene;
|
||||||
|
|
||||||
static Camera camera;
|
static Camera camera;
|
||||||
static Camera camera1;
|
static Camera camera1;
|
||||||
static Camera camera2;
|
static Camera camera2;
|
||||||
|
@ -100,6 +102,8 @@ int main()
|
||||||
bunny1 = new Object(*bunny);
|
bunny1 = new Object(*bunny);
|
||||||
bunny1->position.x = 2.0;
|
bunny1->position.x = 2.0;
|
||||||
|
|
||||||
|
scene << suzanne1 << teapot1 << bunny1;
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glClearColor(1, 1, 1, 0);
|
glClearColor(1, 1, 1, 0);
|
||||||
|
@ -145,24 +149,16 @@ void iterate()
|
||||||
const glm::mat4 mvp3 = camera3.transformation();
|
const glm::mat4 mvp3 = camera3.transformation();
|
||||||
|
|
||||||
glViewport(0, 0, 640 / 2, 480 / 2);
|
glViewport(0, 0, 640 / 2, 480 / 2);
|
||||||
suzanne1->draw(mvp);
|
scene.draw(mvp);
|
||||||
teapot1->draw(mvp);
|
|
||||||
bunny1->draw(mvp);
|
|
||||||
|
|
||||||
glViewport(640 / 2, 0, 640 / 2, 480 / 2);
|
glViewport(640 / 2, 0, 640 / 2, 480 / 2);
|
||||||
suzanne1->draw(mvp1);
|
scene.draw(mvp1);
|
||||||
teapot1->draw(mvp1);
|
|
||||||
bunny1->draw(mvp1);
|
|
||||||
|
|
||||||
glViewport(640 / 2, 480 / 2, 640 / 2, 480 / 2);
|
glViewport(640 / 2, 480 / 2, 640 / 2, 480 / 2);
|
||||||
suzanne1->draw(mvp2);
|
scene.draw(mvp2);
|
||||||
teapot1->draw(mvp2);
|
|
||||||
bunny1->draw(mvp2);
|
|
||||||
|
|
||||||
glViewport(0, 480 / 2, 640 / 2, 480 / 2);
|
glViewport(0, 480 / 2, 640 / 2, 480 / 2);
|
||||||
suzanne1->draw(mvp3);
|
scene.draw(mvp3);
|
||||||
teapot1->draw(mvp3);
|
|
||||||
bunny1->draw(mvp3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWCALL void on_key(int key, int action)
|
GLFWCALL void on_key(int key, int action)
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef _SCENE_HPP_
|
||||||
|
#define _SCENE_HPP_
|
||||||
|
|
||||||
|
#include "object.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
|
class Scene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline Scene &operator <<(Object *object);
|
||||||
|
|
||||||
|
inline void draw(const glm::mat4 &mvp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Object*> _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_
|
Reference in New Issue