60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
#ifndef SCENE_H
|
|
#define SCENE_H
|
|
|
|
#include <glm/mat4x4.hpp>
|
|
#include "camera.h"
|
|
#include <vector>
|
|
#include "light.h"
|
|
#include "phongentity.h"
|
|
|
|
// Scene interface :
|
|
|
|
template <class T>
|
|
class SceneIterator
|
|
{
|
|
public:
|
|
virtual SceneIterator& operator++() = 0;
|
|
virtual T& operator*() = 0;
|
|
virtual bool isValid() = 0;
|
|
void next() {if(isValid()) operator++();}
|
|
T& getItem() {return operator*();}
|
|
};
|
|
|
|
class Scene
|
|
{
|
|
public:
|
|
virtual SceneIterator<Light*>* getLights() = 0;
|
|
virtual SceneIterator<PhongEntity*>* getGeometry() = 0;
|
|
};
|
|
|
|
// Some basic implementations :
|
|
|
|
template <class T>
|
|
class ArraySceneIterator : public SceneIterator<T>
|
|
{
|
|
std::vector<T> &vec;
|
|
int id;
|
|
public:
|
|
ArraySceneIterator(std::vector<T> &myVec, int myId=0) : vec(myVec), id(myId) {}
|
|
virtual SceneIterator<T>& operator++() {++id; return *this;}
|
|
virtual T& operator*() {return vec[id];}
|
|
virtual bool isValid() {return id < vec.size();}
|
|
};
|
|
|
|
class ArrayScene : public Scene
|
|
{
|
|
std::vector<Light*> lights;
|
|
std::vector<PhongEntity*> entities;
|
|
public:
|
|
void clearLights() {lights.clear();}
|
|
void clearEntities() {entities.clear();}
|
|
void clearScene() {clearLights(); clearEntities();}
|
|
void addEntity(PhongEntity* myEntity) {entities.push_back(myEntity);}
|
|
void addLight(Light* myLight) {lights.push_back(myLight);}
|
|
|
|
virtual SceneIterator<Light*>* getLights() {return new ArraySceneIterator<Light*>(lights);}
|
|
virtual SceneIterator<PhongEntity*>* getGeometry() {return new ArraySceneIterator<PhongEntity*>(entities);}
|
|
};
|
|
|
|
#endif // SCENE_H
|