00001 00012 /*************************************************************************** 00013 * Copyright (C) 2007 by Jan Koci * 00014 * honza.koci@email.cz * 00015 * http://kengine.sourceforge.net/tutorial/ 00016 * * 00017 * This program is free software; you can redistribute it and/or modify * 00018 * it under the terms of the GNU General Public License as published by * 00019 * the Free Software Foundation; either version 2 of the License, or * 00020 * (at your option) any later version. * 00021 * * 00022 * This program is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00025 * GNU General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU General Public License * 00028 * along with this program; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00031 ***************************************************************************/ 00032 00033 #include "K3dCameraBuild.h" 00034 00035 K3dCameraBuild::K3dCameraBuild(K3dGameData *_pGameData) 00036 { 00037 m_pGameData = _pGameData; 00038 } 00039 00040 K3dCameraBuild::~K3dCameraBuild(void) 00041 { 00042 DeleteCameras(); 00043 } 00044 00046 void K3dCameraBuild::LoadCameras() 00047 { 00048 cout << "void K3dCameraBuild::LoadCameras()" << endl; 00049 K3dString strFc = "void K3dCameraBuild::LoadCameras() -- "; 00050 K3dString strOut; 00051 00052 // Get lua from global data 00053 K3dLua *pLua = m_pGameData->GetLua(); 00054 00055 // Get number of caemeras 00056 pLua->LuaGetGlobal(K_STR_NUM_CAMERAS); 00057 if (!pLua->LuaIsNumber(-1)) 00058 { 00059 strOut = strFc + K_STR_NUM_CAMERAS; 00060 strOut += " is not a valid number"; 00061 pLua->LuaError(strOut.GetString().c_str()); 00062 return; 00063 } 00064 int iNumCameras = (int) pLua->LuaToNumber(-1); 00065 for(int i=0; i<iNumCameras; i++) 00066 { 00067 00068 K3dCameraObj *pCamera = new K3dCameraObj(m_pGameData); 00069 m_pGameData->GetCameraObjSP().Add(pCamera); 00070 00071 K3dString kString(K_STR_CAMERA); 00072 // Add number behind string 00073 kString.AddNumber(i); 00074 00075 pLua->LuaGetGlobal(kString.GetString().c_str()); 00076 if (!pLua->LuaIsTable(-1)) 00077 { 00078 strOut = strFc + kString; 00079 strOut += " is not a valid camera table"; 00080 pLua->LuaError(strOut.GetString().c_str()); 00081 } 00082 00083 // Load camera name 00084 pCamera->GetName() = pLua->LuaGetFieldString(K_STR_NAME); 00085 // Load camera positions 00086 pCamera->GetCameraPos()[0] = (float)pLua->LuaGetFieldNumber(K_STR_POS_X); 00087 pCamera->GetCameraPos()[1] = (float)pLua->LuaGetFieldNumber(K_STR_POS_Y); 00088 pCamera->GetCameraPos()[2] = (float)pLua->LuaGetFieldNumber(K_STR_POS_Z); 00089 // Load camera rotation 00090 pCamera->GetCameraRot()[0] = (float)pLua->LuaGetFieldNumber(K_STR_ROT_X); 00091 pCamera->GetCameraRot()[1] = (float)pLua->LuaGetFieldNumber(K_STR_ROT_Y); 00092 pCamera->GetCameraRot()[2] = (float)pLua->LuaGetFieldNumber(K_STR_ROT_Z); 00093 // Load mouse move 00094 pCamera->GetIsMouseMove() = pLua->LuaGetFieldBool(K_STR_MOUSEMOVE); 00095 // Load camera view 00096 if(pLua->LuaGetFieldBool(K_STR_DESCENT)) 00097 { 00098 pCamera->GetCameraView() = K_CAM_DESCENT; 00099 } 00100 if(pLua->LuaGetFieldBool(K_STR_FIRST_PERSON)) 00101 { 00102 pCamera->GetCameraView() = K_CAM_FIRST_PERSON; 00103 } 00104 if(pLua->LuaGetFieldBool(K_STR_SPECTATE)) 00105 { 00106 pCamera->GetCameraView() = K_CAM_SPECTATE; 00107 } 00108 // Load camera speed 00109 pCamera->GetCameraSpeed() = (float)pLua->LuaGetFieldNumber(K_STR_SPEED); 00110 } 00111 // Load active camera index 00112 pLua->LuaGetGlobal(K_STR_ACTIVECAMERA_ID); 00113 if (!pLua->LuaIsNumber(-1)) 00114 { 00115 strOut = strFc + K_STR_ACTIVECAMERA_ID; 00116 strOut += " is not a valid number"; 00117 pLua->LuaError(strOut.GetString().c_str()); 00118 } 00119 m_pGameData->GetActiveCamId() = (int) pLua->LuaToNumber(-1); 00120 00121 } 00122 00124 void K3dCameraBuild::DeleteCameras() 00125 { 00126 std::cout << "void K3dCameraBuild::DeleteCameras()" << endl; 00127 while(m_pGameData->GetCameraObjSP().GetNum()) 00128 { 00129 K3dCameraObj *p = m_pGameData->GetCameraObjSP().Get(0); 00130 p = m_pGameData->GetCameraObjSP().Delete(p); 00131 } 00132 }