Page principale | Liste des namespaces | Hiérarchie des classes | Liste par ordre alphabétique | Liste des composants | Liste des fichiers | Membres des namespaces | Composants | Déclarations

ExManagerCamera.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  * ExNihilo 3D Engine
00003  * 
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  *
00018  * Please read AUTHORS file !!!
00019  * 
00020  * $Id: ExManagerCamera.cpp,v 1.8 2002/11/24 11:58:56 data Exp $
00021  *
00022  */
00023 #include "ExManagerCamera.h"
00024 
00025 bool ExManagerCamera::m_flag = false; 
00026 ExManagerCamera* ExManagerCamera::m_instance = NULL; 
00027 
00028 ExManagerCamera* ExManagerCamera::CreateSingleton(void){
00029 Guard(ExManagerCamera* ExManagerCamera::CreateSingleton(void))
00030         if(!m_flag)
00031         {
00032                 m_flag = true; // We are creating the error log now, so set flag to true
00033                 m_instance = new ExManagerCamera; // Create the error log
00034         }else
00035         {
00036                 std::cout<<"Error singleton already created"<<std::endl;
00037         }
00038         return m_instance; 
00039 UnGuard
00040 }
00041 
00042 ExManagerCamera::ExManagerCamera(void)
00043 {
00044         
00045 }
00046 
00047 ExManagerCamera::~ExManagerCamera(void)
00048 {
00049 }
00050 
00051 void ExManagerCamera::Reset(void)
00052 {
00053 Guard(void ExManagerCamera::Reset(void))
00054         ExManagerObject<ExCCamera *>::Reset();
00055         Init();
00056 UnGuard
00057 }
00058 
00059 void ExManagerCamera::Init(void)
00060 {
00061 Guard(void ExManagerCamera::Init(void))
00062         ExManagerObject<ExCCamera *>::Init();
00063         AddCamera("Camera",CAMERA_DEFAULT);
00064         AddCamera("Camera2",CAMERA_DEFAULT);
00065         AddCamera("Camera3",CAMERA_DEFAULT);
00066         AddCamera("CameraChase",CAMERA_CHASE);
00067         AddCamera("CameraFirst",CAMERA_FIRST);
00068         AddCamera("CameraFlight",CAMERA_FLIGHT);
00069         SetCurrentObject("Camera");
00070 UnGuard
00071 }
00072 void ExManagerCamera::AddCamera(std::string CameraName,CameraType Type)
00073 {
00074 Guard(void ExManagerCamera::AddCamera(std::string CameraName,CameraType Type))
00075         ExCCamera *Camera;
00076         switch(Type) 
00077         {
00078         case CAMERA_DEFAULT:
00079                 Camera = new ExCCamera;
00080                 break;
00081         case CAMERA_FREE:
00082                 Camera = new ExCCameraFree;
00083                 break;
00084         case CAMERA_CHASE:
00085                 Camera = new ExCCameraChase;
00086                 ((ExCCameraChase *)Camera)->SetManagerModel(ManagerModel);
00087                 break;
00088         case CAMERA_FIRST:
00089                 Camera= new ExCCameraFirst;
00090                 ((ExCCameraFirst *)Camera)->SetManagerModel(ManagerModel);
00091                 break;
00092         case CAMERA_FLIGHT:
00093                 Camera= new ExCCameraFlight;
00094                 break;
00095         }
00096         Camera->SetName(CameraName);
00097         ExManagerObject<ExCCamera *>::Add(Camera);
00098 UnGuard
00099 }
00100 void ExManagerCamera::Draw(void)
00101 {
00102 Guard(void ExManagerCamera::Draw(void))
00103         glMatrixMode(GL_PROJECTION);
00104         glLoadIdentity();
00105         glViewport(0,0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
00106         gluPerspective(GetCurrentObject()->GetZoom(),
00107                 (1.0f *glutGet(GLUT_WINDOW_WIDTH)/glutGet(GLUT_WINDOW_HEIGHT)),
00108                 GetCurrentObject()->GetClipNear(),
00109                 GetCurrentObject()->GetClipFar());
00110         glMatrixMode(GL_MODELVIEW);
00111         glLoadIdentity();
00112         //Draw camera gizmo
00113         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00114         {
00115                 m_ItMap->second->DrawCameraGizmo();
00116         }
00117         GetCurrentObject()->Draw();     
00118 UnGuard
00119 }
00120 
00121 ExCCamera* ExManagerCamera::GetCurrentObject(void)
00122 {
00123 Guard(ExCCamera* ExManagerCamera::GetCurrentObject(void))
00124         return GetObject(m_CurrentObjectId);
00125 UnGuard
00126 }
00127 
00128 ExCCamera * ExManagerCamera::GetObject(ExNihilo::ExId id)
00129 {
00130 Guard(ExCCamera *ExManagerCamera::GetObject(ExNihilo::ExId id))
00131         for(m_ItMap=m_Map->begin();m_ItMap!=m_Map->end();m_ItMap++)
00132         {
00133                 if(m_ItMap->second->GetId()==id)return m_ItMap->second;
00134         }
00135         return NULL;
00136 UnGuard
00137 }
00138 
00139 ExCAction ExManagerCamera::InputCommand(ExCCommand Command)
00140 {
00141 Guard(ExManagerCamera::InputCommand(ExCCommand Command))
00142         if(GetCurrentObject()==NULL)return NOTHING;
00143         return  NOTHING;
00144 UnGuard
00145 }
00146 
00147 ExCAction ExManagerCamera::InputAction(ExCAction Action)
00148 {
00149 Guard(ExManagerCamera::InputAction(ExCAction Action))
00150         switch(Action.m_Action)
00151         {
00152         case CAMERA_CURRENT_INCREASE_SPEED:
00153                 GetCurrentObject()->m_speed++;
00154                 break;
00155 
00156         case CAMERA_CURRENT_DECREASE_SPEED:
00157                 GetCurrentObject()->m_speed--;
00158                 break;
00159 
00160         case CAMERA_CURRENT_FULL_STOP:
00161                 GetCurrentObject()->m_speed=0;
00162                 break;
00163 
00164         case CAMERA_CURRENT_START_ROTATEX_UP:
00165                 GetCurrentObject()->StartAction(ROTATE_X_UP     );
00166                 break;
00167         
00168         case CAMERA_CURRENT_STOP_ROTATEX_UP:
00169                 GetCurrentObject()->StopAction(ROTATE_X_UP);
00170                 break;
00171         
00172         case CAMERA_CURRENT_ROTATEX_UP:
00173                 GetCurrentObject()->m_Angle.IncX(2);
00174                 break;
00175         
00176         case CAMERA_CURRENT_START_ROTATEX_DOWN:
00177                 GetCurrentObject()->StartAction(ROTATE_X_DOWN);
00178                 break;
00179         
00180         case CAMERA_CURRENT_STOP_ROTATEX_DOWN:
00181                 GetCurrentObject()->StopAction(ROTATE_X_DOWN);
00182                 break;
00183         
00184         case CAMERA_CURRENT_ROTATEX_DOWN:
00185                 GetCurrentObject()->m_Angle.DecX(2);
00186                 break;
00187 
00188         case CAMERA_CURRENT_START_ROTATEZ_UP:
00189                 GetCurrentObject()->StartAction(ROTATE_Z_UP);
00190                 break;
00191         
00192         case CAMERA_CURRENT_STOP_ROTATEZ_UP:
00193                 GetCurrentObject()->StopAction(ROTATE_Z_UP);
00194                 break;
00195         
00196         case CAMERA_CURRENT_ROTATEZ_UP:
00197                 GetCurrentObject()->m_Angle.IncZ(2);
00198                 break;
00199         
00200         case CAMERA_CURRENT_START_ROTATEZ_DOWN:
00201                 GetCurrentObject()->StartAction(ROTATE_Z_DOWN);
00202                 break;
00203         
00204         case CAMERA_CURRENT_STOP_ROTATEZ_DOWN:
00205                 GetCurrentObject()->StopAction(ROTATE_Z_DOWN);
00206                 break;
00207         
00208         case CAMERA_CURRENT_ROTATEZ_DOWN:
00209                 GetCurrentObject()->m_Angle.DecZ(2);
00210                 break;
00211 
00212         case CAMERA_CURRENT_START_ROTATEY_UP:
00213                 GetCurrentObject()->StartAction(ROTATE_Y_UP);
00214                 break;
00215         
00216         case CAMERA_CURRENT_STOP_ROTATEY_UP:
00217                 GetCurrentObject()->StopAction(ROTATE_Y_UP);
00218                 break;
00219         
00220         case CAMERA_CURRENT_ROTATEY_UP:
00221                 GetCurrentObject()->m_Angle.IncY(2);
00222                 break;
00223         
00224         case CAMERA_CURRENT_START_ROTATEY_DOWN:
00225                 GetCurrentObject()->StartAction(ROTATE_Y_DOWN);
00226                 break;
00227         
00228         case CAMERA_CURRENT_STOP_ROTATEY_DOWN:
00229                 GetCurrentObject()->StopAction(ROTATE_Y_DOWN);
00230                 break;
00231         
00232         case CAMERA_CURRENT_ROTATEY_DOWN:
00233                 GetCurrentObject()->m_Angle.DecY(2);
00234                 break;
00235                 
00236         case CAMERA_NEXT_CAM:
00237                 NextObject();
00238                 break;
00239         case CAMERA_PREV_CAM:
00240                 PreviousObject();
00241                 break;
00242 
00243         case CAMERA_CURRENT_INCREASE_ZOOM:
00244                 GetCurrentObject()->ZoomOut();
00245                 break;
00246         case CAMERA_CURRENT_START_INCREASE_ZOOM:
00247                 GetCurrentObject()->StartAction(ZOOM_UP);
00248                 break;
00249         case CAMERA_CURRENT_STOP_INCREASE_ZOOM:
00250                 GetCurrentObject()->StopAction(ZOOM_UP);
00251                 break;
00252 
00253         case CAMERA_CURRENT_DECREASE_ZOOM:
00254                 GetCurrentObject()->ZoomIn();
00255                 break;
00256         case CAMERA_CURRENT_START_DECREASE_ZOOM:
00257                 GetCurrentObject()->StartAction(ZOOM_DOWN);
00258                 break;
00259         case CAMERA_CURRENT_STOP_DECREASE_ZOOM:
00260                 GetCurrentObject()->StopAction(ZOOM_DOWN);
00261                 break;  
00262         case CAMERA_SET_POS_X:
00263                 GetCurrentObject()->m_Position.SetX(atof(Action.m_Param.data()));
00264                 break;
00265         case CAMERA_SET_POS_Y:
00266                 GetCurrentObject()->m_Position.SetY(atof(Action.m_Param.data()));
00267                 break;
00268         case CAMERA_SET_POS_Z:
00269                 GetCurrentObject()->m_Position.SetZ(atof(Action.m_Param.data()));
00270                 break;
00271         case CAMERA_SET_TARGET_POS_X:
00272                 GetCurrentObject()->m_Target.SetX(atof(Action.m_Param.data()));
00273                 break;
00274         case CAMERA_SET_TARGET_POS_Y:
00275                 GetCurrentObject()->m_Target.SetY(atof(Action.m_Param.data()));
00276                 break;
00277         case CAMERA_SET_TARGET_POS_Z:
00278                 GetCurrentObject()->m_Target.SetZ(atof(Action.m_Param.data()));
00279                 break;
00280         case CAMERA_SET_ANGLE_X:
00281                 GetCurrentObject()->m_Angle.SetX(atof(Action.m_Param.data()));
00282                 break;
00283         case CAMERA_SET_ANGLE_Y:
00284                 GetCurrentObject()->m_Angle.SetY(atof(Action.m_Param.data()));
00285                 break;
00286         case CAMERA_SET_ANGLE_Z:
00287                 GetCurrentObject()->m_Angle.SetZ(atof(Action.m_Param.data()));
00288                 break;
00289         case CAMERA_CURRENT_SHOW_INFO:
00290                 GetCurrentObject()->SetShowInfoState(true);
00291                 break;
00292         case CAMERA_CURRENT_HIDE_INFO:
00293                 GetCurrentObject()->SetShowInfoState(false);
00294                 break;
00295         //--------------------------------------------------------------------
00296         //Chase cam action
00297         //--------------------------------------------------------------------
00298         case CAMERA_CURRENT_START_INCREASE_AROUND:
00299                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00300                 {
00301                         GetCurrentObject()->StartAction(ANGLE_AROUND_TARGET_UP);
00302                 }
00303                 break;
00304         case CAMERA_CURRENT_STOP_INCREASE_AROUND:
00305                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00306                 {
00307                         GetCurrentObject()->StopAction(ANGLE_AROUND_TARGET_UP);
00308                 }
00309                 break;
00310         case CAMERA_CURRENT_START_DECREASE_AROUND:
00311                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00312                 {
00313                         GetCurrentObject()->StartAction(ANGLE_AROUND_TARGET_DOWN);
00314                 }
00315                 break;
00316         case CAMERA_CURRENT_STOP_DECREASE_AROUND:
00317                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00318                 {
00319                         GetCurrentObject()->StopAction(ANGLE_AROUND_TARGET_DOWN);
00320                 }
00321                 break;
00322 
00323         case CAMERA_CURRENT_START_INCREASE_DISTANCE:
00324                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00325                 {
00326                         GetCurrentObject()->StartAction(DISTANCE_FROM_TARGET_UP);
00327                 }
00328                 break;
00329         case CAMERA_CURRENT_STOP_INCREASE_DISTANCE:
00330                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00331                 {
00332                         GetCurrentObject()->StopAction(DISTANCE_FROM_TARGET_UP);
00333                 }
00334                 break;
00335         case CAMERA_CURRENT_START_DECREASE_DISTANCE:
00336                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00337                 {
00338                         GetCurrentObject()->StartAction(DISTANCE_FROM_TARGET_DOWN);
00339                 }
00340                 break;
00341         case CAMERA_CURRENT_STOP_DECREASE_DISTANCE:
00342                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00343                 {
00344                         GetCurrentObject()->StopAction(DISTANCE_FROM_TARGET_DOWN);
00345                 }
00346                 break;
00347 
00348         case CAMERA_CURRENT_START_INCREASE_HEIGHT:
00349                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00350                 {
00351                         GetCurrentObject()->StartAction(HEIGHT_FROM_TARGET_UP);
00352                 }
00353                 break;
00354         case CAMERA_CURRENT_STOP_INCREASE_HEIGHT:
00355                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00356                 {
00357                         GetCurrentObject()->StopAction(HEIGHT_FROM_TARGET_UP);
00358                 }
00359                 break;
00360         case CAMERA_CURRENT_START_DECREASE_HEIGHT:
00361                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00362                 {
00363                         GetCurrentObject()->StartAction(HEIGHT_FROM_TARGET_DOWN);
00364                 }
00365                 break;
00366         case CAMERA_CURRENT_STOP_DECREASE_HEIGHT:
00367                 if(strcmp("class ExCCameraChase",GetCurrentObject()->GetType().data())==0)
00368                 {
00369                         GetCurrentObject()->StopAction(HEIGHT_FROM_TARGET_DOWN);
00370                 }
00371                 break;
00372         default:
00373                 *Consol<<"Can not file action in CAMERA_ACTION_MAP"<<std::endl;
00374                 break;
00375         }
00376         return  NOTHING;
00377 UnGuard
00378 }

Généré le Tue Oct 28 12:43:35 2003 pour ExNihilo par doxygen 1.3.4