00001 #ifndef SCENE_H_INCLUDED
00002 #define SCENE_H_INCLUDED
00003
00004 #include <vector>
00005 #include <map>
00006 #include "includeGL.h"
00007 #include <CGLA/Mat4x4f.h>
00008
00009 #include "Transform.h"
00010 #include "GameObject.h"
00011
00012 class MeshRenderer;
00013 class Renderable;
00014 class GameObject;
00015 class Transform;
00016 class Material;
00017 class Light;
00018 class Camera;
00019
00020 using namespace CGLA;
00021
00022 class Scene{
00023 public: static GLuint shadowMap;
00024 const static int shadowMapSize = 1024;
00025 static Mat4x4f projShadowMatrix;
00026 protected:
00027
00028 std::vector<Transform*> transforms;
00029 std::vector<Light*> lights;
00030 std::vector<Camera*> cameras;
00031
00032
00033 std::map<Material*, vector<Renderable*> > matSortedBatches;
00034 std::vector<Renderable*> shadowCasters;
00035
00036 Transform* sceneRoot;
00037 Camera* mainCamera;
00038
00039 void traverseSceneGraph();
00040 void make_proj_shadow_texture(Light* light);
00041
00042 public:
00043 Scene();
00044 void clear();
00045
00046 void render();
00047
00048 void setRoot(Transform* root);
00049 Transform* getRoot();
00050
00051 void addGameObject(GameObject * object);
00052 void removeGameObject(GameObject* object);
00053
00054 void addLight(Light* light);
00055 void addMeshRenderer(MeshRenderer* renderer);
00056 void applyLightsStates()const;
00057 void addCamera(Camera * camera);
00058
00059 void setMainCamera(Camera* camera);
00060 void updateRenderQueue();
00061
00062
00063 void Scene::printNode(Transform * trans, int level){
00064 string tab;
00065 for(int i = 0; i < level ; i++){
00066 tab += " ";
00067 }
00068 if(!trans){
00069 std::cout<<"NULL Transform!!"<<std::endl;
00070 return;
00071 }
00072
00073 std::cout<<tab + trans->getGameObject()->getName()<<std::endl;
00074
00075 Transform::ChildrenIterator childIt = trans->getChildrenIteratorBegin();
00076 for(; childIt != trans->getChildrenIteratorEnd(); ++childIt){
00077 printNode(*childIt,level+1);
00078 }
00079 }
00080 void Scene::printSceneInfo(Scene* scene){
00081 std::cout<<"*********Objects in scene***********"<<std::endl;
00082 printNode(scene->getRoot(),0);
00083 std::cout<<"************************************"<<std::endl;
00084 }
00085 };
00086
00087
00088 #endif // SCENE_H_INCLUDED