MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cameramanager.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicscameramanager_cpp
41 #define _graphicscameramanager_cpp
42 
43 #include "Graphics/cameramanager.h"
44 #include "Graphics/scenemanager.h"
45 #include "Graphics/graphicsmanager.h"
46 #include "Graphics/cameraproxy.h"
47 
48 #include "cameracontroller.h"
49 #include "entresol.h"
50 
51 #include <Ogre.h>
52 
53 #include <vector>
54 #include <sstream>
55 
56 namespace Mezzanine
57 {
58  namespace Graphics
59  {
61  SceneMan(NULL)
62  {
63  Graphics::SceneManager* SceneCheck = this->TheEntresol->GetSceneManager();
64  if( SceneCheck )
65  this->SceneMan = SceneCheck;
66  }
67 
69  SceneMan(NULL)
70  {
71  Graphics::SceneManager* SceneCheck = this->TheEntresol->GetSceneManager();
72  if( SceneCheck )
73  this->SceneMan = SceneCheck;
74  /// @todo This class currently doesn't initialize anything from XML, if that changes this constructor needs to be expanded.
75  }
76 
78  {
79  this->Deinitialize();
80  }
81 
82  ///////////////////////////////////////////////////////////////////////////////
83  // Camera Management
84 
86  {
87  StringStream CamName;
88  CamName << "Camera" << this->Cameras.size() + 1;
89  return this->CreateCamera(CamName.str());
90  }
91 
93  {
94  if( !this->Initialized ) {
95  this->Initialize();
96  }
97  CameraProxy* NewCam = new CameraProxy(Name,this);
98  this->Cameras.push_back(NewCam);
99  return NewCam;
100  }
101 
103  {
104  for( CameraIterator CamIt = this->Cameras.begin() ; CamIt != this->Cameras.end() ; ++CamIt )
105  {
106  if( Name == (*CamIt)->GetName() )
107  return *CamIt;
108  }
109  return NULL;
110  }
111 
113  {
114  return this->Cameras[Index];
115  }
116 
118  {
119  return this->Cameras.size();
120  }
121 
123  {
124  CameraProxy* camera = NULL;
125  for( CameraIterator it = this->Cameras.begin() ; it != this->Cameras.end() ; it++ )
126  {
127  camera = (*it);
128  delete camera;
129  }
130  this->Cameras.clear();
131  return;
132  }
133 
134  ///////////////////////////////////////////////////////////////////////////////
135  // Camera Controller Management
136 
138  {
139  CameraControllerIterator CamIt = this->CameraControllers.find(Controlled);
140  if(CamIt == this->CameraControllers.end())
141  {
142  CameraController* Controller = new CameraController(Controlled);
143  this->CameraControllers[Controlled] = Controller;
144  return Controller;
145  }else{
146  return (*CamIt).second;
147  }
148  }
149 
151  {
152  if(this->CameraControllers.empty())
153  return;
154  for( CameraControllerIterator CamIt = this->CameraControllers.begin() ; CamIt != this->CameraControllers.end() ; CamIt++ )
155  {
156  if(ToBeDestroyed == (*CamIt).second)
157  {
158  delete (*CamIt).second;
159  this->CameraControllers.erase(CamIt);
160  return;
161  }
162  }
163  }
164 
166  {
167  if(this->CameraControllers.empty())
168  return;
169  CameraControllerIterator CamIt = this->CameraControllers.find(ControlledCam);
170  if(CamIt != this->CameraControllers.end())
171  {
172  delete (*CamIt).second;
173  this->CameraControllers.erase(CamIt);
174  return;
175  }
176  }
177 
179  {
180  if(this->CameraControllers.empty())
181  return;
182  for( CameraControllerIterator CamIt = this->CameraControllers.begin() ; CamIt != this->CameraControllers.end() ; CamIt++ )
183  {
184  delete (*CamIt).second;
185  }
186  this->CameraControllers.clear();
187  }
188 
189  ///////////////////////////////////////////////////////////////////////////////
190  // Utility
191 
193  {
194  // Do Nothing currently
195  }
196 
198  {
199  if( !this->Initialized )
200  {
201  //WorldManager::Initialize();
202 
203  if( !this->SceneMan )
204  {
205  SceneManager* SceneCheck = this->TheEntresol->GetSceneManager();
206  if( SceneCheck ) {
207  this->SceneMan = SceneCheck;
208  }else{
209  MEZZ_EXCEPTION(Exception::INVALID_STATE_EXCEPTION,"Attempting to initiailze CameraManager when SceneManager has not yet been constructed. The SceneManager is a dependancy of the CameraManager.");
210  }
211  }
212 
213  this->Initialized = true;
214  }
215  }
216 
218  {
219  if( this->Initialized )
220  {
222  this->DestroyAllCameras();
223 
224  this->SceneMan = NULL;
225  this->Initialized = false;
226  }
227  }
228 
230  {
231  return this->SceneMan;
232  }
233 
234  ///////////////////////////////////////////////////////////////////////////////
235  // Type Identifier Methods
236 
238  { return ManagerBase::MT_CameraManager; }
239 
241  { return "DefaultCameraManager"; }
242 
243  ///////////////////////////////////////////////////////////////////////////////
244  // DefaultCameraManagerFactory Methods
245 
247  {
248  }
249 
251  {
252  }
253 
255  {
256  return "DefaultCameraManager";
257  }
258 
260  {
261  return new CameraManager();
262  }
263 
265  {
266  return new CameraManager(XMLNode);
267  }
268 
270  {
271  delete ToBeDestroyed;
272  }
273  }//Graphics
274 }//Mezzanine
275 #endif