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 m_VecCamera.clear(); 00056 m_VecCameraFree.clear(); 00057 m_VecCameraChase.clear(); 00058 Init(); 00059 UnGuard 00060 } 00061 00062 void ExManagerCamera::Init(void) 00063 { 00064 Guard(void ExManagerCamera::Init(void)) 00065 ExManagerObject<ExCCamera *>::Init(); 00066 00067 00068 00069 ExCCamera Camera; 00070 Camera.SetName("Camera"); 00071 ExManagerCamera::Add(Camera); 00072 ExManagerCamera::Add(Camera); 00073 00074 00075 /* 00076 ExCCameraChase CameraChase; 00077 Camera.SetName("CameraChase"); 00078 ExManagerCamera::Add(CameraChase); 00079 ExManagerCamera::Add(CameraChase);*/ 00080 SetCurrentObject("Camera"); 00081 UnGuard 00082 } 00083 00084 void ExManagerCamera::Draw(void) 00085 { 00086 Guard(void ExManagerCamera::Draw(void)) 00087 glMatrixMode(GL_PROJECTION); 00088 glLoadIdentity(); 00089 glViewport(0,0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT)); 00090 gluPerspective(GetCurrentObject()->GetZoom(), 00091 (1.0f *glutGet(GLUT_WINDOW_WIDTH)/glutGet(GLUT_WINDOW_HEIGHT)), 00092 GetCurrentObject()->GetClipNear(), 00093 GetCurrentObject()->GetClipFar()); 00094 glMatrixMode(GL_MODELVIEW); 00095 glLoadIdentity(); 00096 GetCurrentObject()->Draw(); 00097 UnGuard 00098 } 00099 00100 bool ExManagerCamera::Add(ExCCamera Camera) 00101 { 00102 Guard(bool ExManagerCamera::Add(ExCCamera Camera)) 00103 m_VecCamera.push_back(Camera); 00104 return ExManagerObject<ExCCamera *>::Add(&m_VecCamera.at(m_VecCamera.size()-1)); 00105 UnGuard 00106 } 00107 00108 bool ExManagerCamera::Add(ExCCameraFree Camera) 00109 { 00110 Guard(bool ExManagerCamera::Add(ExCCameraFree Camera)) 00111 m_VecCameraFree.push_back(Camera); 00112 return ExManagerObject<ExCCamera *>::Add(&m_VecCameraFree.at(m_VecCameraFree.size()-1)); 00113 UnGuard 00114 } 00115 00116 bool ExManagerCamera::Add(ExCCameraChase Camera) 00117 { 00118 Guard(bool ExManagerCamera::Add(ExCCameraChase Camera)) 00119 Camera.SetManagerModel(ManagerModel); 00120 m_VecCameraChase.push_back(Camera); 00121 return ExManagerObject<ExCCamera *>::Add(&m_VecCameraChase.at(m_VecCameraChase.size()-1)); 00122 UnGuard 00123 } 00124 00125 ExCCamera* ExManagerCamera::GetCurrentObject(void) 00126 { 00127 Guard(ExCCamera* ExManagerCamera::GetCurrentObject(void)) 00128 return GetObject(m_CurrentObjectId); 00129 UnGuard 00130 } 00131 00132 ExCCamera * ExManagerCamera::GetObject(ExNihilo::ExId id) 00133 { 00134 Guard(ExCCamera *ExManagerCamera::GetObject(ExNihilo::ExId id)) 00135 unsigned int i; 00136 for(i =0;i<m_VecCamera.size();++i) 00137 { 00138 if(m_VecCamera.at(i).GetId()==id)return &m_VecCamera.at(i); 00139 } 00140 for(i =0;i<m_VecCameraFree.size();++i) 00141 { 00142 if(m_VecCameraFree.at(i).GetId()==id)return &m_VecCameraFree.at(i); 00143 } 00144 for(i =0;i<m_VecCameraChase.size();++i) 00145 { 00146 if(m_VecCameraChase.at(i).GetId()==id)return &m_VecCameraChase.at(i); 00147 } 00148 return NULL; 00149 UnGuard 00150 } 00151 00152 ExCAction ExManagerCamera::InputCommand(ExCCommand Command) 00153 { 00154 Guard(ExManagerCamera::InputCommand(ExCCommand Command)) 00155 if(GetCurrentObject()==NULL)return NOTHING; 00156 return NOTHING; 00157 UnGuard 00158 } 00159 00160 ExCAction ExManagerCamera::InputAction(ExCAction Action) 00161 { 00162 Guard(ExManagerCamera::InputAction(ExCAction Action)) 00163 switch(Action.m_Action) 00164 { 00165 case CAMERA_CURRENT_INCREASE_SPEED: 00166 GetCurrentObject()->m_speed++; 00167 break; 00168 00169 case CAMERA_CURRENT_DECREASE_SPEED: 00170 GetCurrentObject()->m_speed--; 00171 break; 00172 00173 case CAMERA_CURRENT_FULL_STOP: 00174 GetCurrentObject()->m_speed=0; 00175 break; 00176 00177 case CAMERA_CURRENT_START_ROTATEX_UP: 00178 GetCurrentObject()->StartAction(ROTATE_X_UP ); 00179 break; 00180 00181 case CAMERA_CURRENT_STOP_ROTATEX_UP: 00182 GetCurrentObject()->StopAction(ROTATE_X_UP); 00183 break; 00184 00185 case CAMERA_CURRENT_ROTATEX_UP: 00186 GetCurrentObject()->m_AngleX++; 00187 GetCurrentObject()->m_AngleX++; 00188 break; 00189 00190 case CAMERA_CURRENT_START_ROTATEX_DOWN: 00191 GetCurrentObject()->StartAction(ROTATE_X_DOWN); 00192 break; 00193 00194 case CAMERA_CURRENT_STOP_ROTATEX_DOWN: 00195 GetCurrentObject()->StopAction(ROTATE_X_DOWN); 00196 break; 00197 00198 case CAMERA_CURRENT_ROTATEX_DOWN: 00199 GetCurrentObject()->m_AngleX--; 00200 GetCurrentObject()->m_AngleX--; 00201 break; 00202 00203 case CAMERA_CURRENT_START_ROTATEZ_UP: 00204 GetCurrentObject()->StartAction(ROTATE_Z_UP); 00205 break; 00206 00207 case CAMERA_CURRENT_STOP_ROTATEZ_UP: 00208 GetCurrentObject()->StopAction(ROTATE_Z_UP); 00209 break; 00210 00211 case CAMERA_CURRENT_ROTATEZ_UP: 00212 GetCurrentObject()->m_AngleZ++; 00213 GetCurrentObject()->m_AngleZ++; 00214 break; 00215 00216 case CAMERA_CURRENT_START_ROTATEZ_DOWN: 00217 GetCurrentObject()->StartAction(ROTATE_Z_DOWN); 00218 break; 00219 00220 case CAMERA_CURRENT_STOP_ROTATEZ_DOWN: 00221 GetCurrentObject()->StopAction(ROTATE_Z_DOWN); 00222 break; 00223 00224 case CAMERA_CURRENT_ROTATEZ_DOWN: 00225 GetCurrentObject()->m_AngleZ--; 00226 GetCurrentObject()->m_AngleZ--; 00227 break; 00228 00229 case CAMERA_CURRENT_START_ROTATEY_UP: 00230 GetCurrentObject()->StartAction(ROTATE_Y_UP); 00231 break; 00232 00233 case CAMERA_CURRENT_STOP_ROTATEY_UP: 00234 GetCurrentObject()->StopAction(ROTATE_Y_UP); 00235 break; 00236 00237 case CAMERA_CURRENT_ROTATEY_UP: 00238 GetCurrentObject()->m_AngleY++; 00239 GetCurrentObject()->m_AngleY++; 00240 break; 00241 00242 case CAMERA_CURRENT_START_ROTATEY_DOWN: 00243 GetCurrentObject()->StartAction(ROTATE_Y_DOWN); 00244 break; 00245 00246 case CAMERA_CURRENT_STOP_ROTATEY_DOWN: 00247 GetCurrentObject()->StopAction(ROTATE_Y_DOWN); 00248 break; 00249 00250 case CAMERA_CURRENT_ROTATEY_DOWN: 00251 GetCurrentObject()->m_AngleY--; 00252 GetCurrentObject()->m_AngleY--; 00253 break; 00254 00255 case CAMERA_NEXT_CAM: 00256 NextObject(); 00257 break; 00258 case CAMERA_PREV_CAM: 00259 PreviousObject(); 00260 break; 00261 00262 case CAMERA_CURRENT_INCREASE_ZOOM: 00263 GetCurrentObject()->ZoomOut(); 00264 break; 00265 case CAMERA_CURRENT_START_INCREASE_ZOOM: 00266 GetCurrentObject()->StartAction(ZOOM_UP); 00267 break; 00268 case CAMERA_CURRENT_STOP_INCREASE_ZOOM: 00269 GetCurrentObject()->StopAction(ZOOM_UP); 00270 break; 00271 00272 case CAMERA_CURRENT_DECREASE_ZOOM: 00273 GetCurrentObject()->ZoomIn(); 00274 break; 00275 case CAMERA_CURRENT_START_DECREASE_ZOOM: 00276 GetCurrentObject()->StartAction(ZOOM_DOWN); 00277 break; 00278 case CAMERA_CURRENT_STOP_DECREASE_ZOOM: 00279 GetCurrentObject()->StopAction(ZOOM_DOWN); 00280 break; 00281 case CAMERA_SET_POS_X: 00282 GetCurrentObject()->m_Position.SetX(atof(Action.m_Param.data())); 00283 break; 00284 case CAMERA_SET_POS_Y: 00285 GetCurrentObject()->m_Position.SetY(atof(Action.m_Param.data())); 00286 break; 00287 case CAMERA_SET_POS_Z: 00288 GetCurrentObject()->m_Position.SetZ(atof(Action.m_Param.data())); 00289 break; 00290 case CAMERA_SET_TARGET_POS_X: 00291 GetCurrentObject()->m_Target.SetX(atof(Action.m_Param.data())); 00292 break; 00293 case CAMERA_SET_TARGET_POS_Y: 00294 GetCurrentObject()->m_Target.SetY(atof(Action.m_Param.data())); 00295 break; 00296 case CAMERA_SET_TARGET_POS_Z: 00297 GetCurrentObject()->m_Target.SetZ(atof(Action.m_Param.data())); 00298 break; 00299 case CAMERA_SET_ANGLE_X: 00300 GetCurrentObject()->m_AngleX=atof(Action.m_Param.data()); 00301 break; 00302 case CAMERA_SET_ANGLE_Y: 00303 GetCurrentObject()->m_AngleY=atof(Action.m_Param.data()); 00304 break; 00305 case CAMERA_SET_ANGLE_Z: 00306 GetCurrentObject()->m_AngleZ=atof(Action.m_Param.data()); 00307 break; 00308 default: 00309 *Consol<<"Can not file action in CAMERA_ACTION_MAP"<<std::endl; 00310 break; 00311 } 00312 return NOTHING; 00313 UnGuard 00314 }