[10473] | 1 | /* |
---|
[10406] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Filip Gospodinov |
---|
| 13 | co-programmer: Silvan Nellen |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | #include "shell_command.h" |
---|
| 17 | #include "cameraman.h" |
---|
| 18 | #include "game_world_data.h" |
---|
| 19 | #include "state.h" |
---|
| 20 | #include "sound_engine.h" |
---|
| 21 | #include <string> |
---|
| 22 | #include "script_class.h" |
---|
| 23 | #include "loading/load_param_xml.h" |
---|
| 24 | #include "blackscreen.h" |
---|
| 25 | #include "p_node.h" |
---|
| 26 | #include "camera.h" |
---|
| 27 | |
---|
| 28 | ObjectListDefinition(CameraMan); |
---|
| 29 | |
---|
| 30 | SHELL_COMMAND(camerainfo, CameraMan, cameraInfo); |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | CREATE_SCRIPTABLE_CLASS(CameraMan, |
---|
| 34 | addMethod("changeCurrTarget", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::changeCurrTarget)) |
---|
| 35 | ->addMethod("atachCurrCameraToWorldEntity", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::atachCurrCameraToWorldEntity)) |
---|
| 36 | ->addMethod("changeTarget", Executor3<CameraMan, lua_State*, const std::string&, const std::string&,const std::string&>(&CameraMan::changeTarget)) |
---|
[10416] | 37 | ->addMethod("atachCameraToWorldEntity", Executor3<CameraMan, lua_State*,const std::string&,const std::string&,const std::string&>(&CameraMan::atachCameraToWorldEntity)) |
---|
[10413] | 38 | ->addMethod("detachCurrCamera", Executor0<CameraMan, lua_State*>(&CameraMan::detachCurrCamera)) |
---|
[10406] | 39 | ->addMethod("setCam", Executor1<CameraMan, lua_State*, const std::string&>(&CameraMan::setCam)) |
---|
[10428] | 40 | ->addMethod("toggleFade", Executor0<CameraMan, lua_State*>(&CameraMan::togglFade)) |
---|
[10424] | 41 | ->addMethod("initFadeBlack", Executor0<CameraMan, lua_State*>(&CameraMan::initFadeBlack)) |
---|
[10406] | 42 | ->addMethod("getCurrCameraCoorX", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorX)) |
---|
| 43 | ->addMethod("getCurrCameraCoorY", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorY)) |
---|
| 44 | ->addMethod("getCurrCameraCoorZ", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorZ)) |
---|
[10441] | 45 | ->addMethod("jumpCurrCam", Executor3<CameraMan, lua_State*,float,float,float>(&CameraMan::jumpCurrCam)) |
---|
[10483] | 46 | ->addMethod("jumpCam", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::jumpCam)) |
---|
[10495] | 47 | //->addMethod("setViewMode", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::setViewMode)) |
---|
| 48 | ->addMethod("setRelCoor", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::setRelCameraCoor)) |
---|
[10497] | 49 | ->addMethod("setRelCoorSoft", Executor5<CameraMan, lua_State*,const std::string&,float,float,float,float>(&CameraMan::setRelCameraCoorSoft)) |
---|
[10498] | 50 | ->addMethod("pauseCamera", Executor2<CameraMan, lua_State*, const std::string&, bool>(&CameraMan::pauseCamera)) |
---|
[10406] | 51 | ); |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | CameraMan::CameraMan(const TiXmlElement* root) |
---|
| 55 | { |
---|
| 56 | this->registerObject(this, CameraMan::_objectList); |
---|
| 57 | |
---|
| 58 | this->nearClip = 1.0; |
---|
| 59 | this->farClip = 1000.0; |
---|
| 60 | |
---|
| 61 | this->fadeToBlack=new BlackScreen(); |
---|
| 62 | |
---|
| 63 | this->setCam( State::getCamera()); |
---|
| 64 | |
---|
| 65 | if (root != NULL) |
---|
| 66 | this->loadParams(root); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | void CameraMan::loadParams(const TiXmlElement* root) |
---|
| 71 | { |
---|
| 72 | BaseObject::loadParams(root); |
---|
[10414] | 73 | LoadParamXML(root, "Cameras", this, CameraMan, createCameras); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | void CameraMan::createCameras(const TiXmlElement* camerasTag) |
---|
| 78 | { |
---|
| 79 | |
---|
[10411] | 80 | LOAD_PARAM_START_CYCLE(camerasTag, object); |
---|
| 81 | { |
---|
| 82 | this->createCam(object); |
---|
| 83 | } |
---|
| 84 | LOAD_PARAM_END_CYCLE(object); |
---|
[10406] | 85 | |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | void CameraMan::createCam(const TiXmlElement* root) |
---|
| 90 | { |
---|
| 91 | this->cameras.push_back(new Camera(root)); |
---|
| 92 | cameras[cameras.size()-1]->setClipRegion(nearClip, farClip); |
---|
| 93 | } |
---|
| 94 | |
---|
[10495] | 95 | /*void CameraMan::setViewMode(const std::string& cameraName, const std::string& viewMode) |
---|
| 96 | { |
---|
| 97 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", cameraName); |
---|
[10497] | 98 | |
---|
| 99 | if (!strcmp(viewMode, "ViewNormal")) |
---|
[10495] | 100 | { |
---|
[10497] | 101 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewNormal); |
---|
[10495] | 102 | } |
---|
[10497] | 103 | else if (!strcmp(viewMode, "ViewTop")) |
---|
| 104 | { |
---|
| 105 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewTop); |
---|
| 106 | } |
---|
| 107 | else if (!strcmp(viewMode, "ViewBehind")) |
---|
| 108 | { |
---|
| 109 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewBehind); |
---|
| 110 | } |
---|
| 111 | else if (!strcmp(viewMode, "ViewFront")) |
---|
| 112 | { |
---|
| 113 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewFront); |
---|
| 114 | } |
---|
| 115 | else if (!strcmp(viewMode, "ViewLeft")) |
---|
| 116 | { |
---|
| 117 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewLeft); |
---|
| 118 | } |
---|
| 119 | else if (!strcmp(viewMode, "ViewRight")) |
---|
| 120 | { |
---|
| 121 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewRight); |
---|
| 122 | } |
---|
[10495] | 123 | }*/ |
---|
[10480] | 124 | |
---|
[10495] | 125 | void CameraMan::setRelCameraCoor(const std::string& camName, float x, float y, float z) |
---|
| 126 | { |
---|
| 127 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 128 | dynamic_cast<Camera*>(newCam)->setRelCoor(x,y,z); |
---|
| 129 | dynamic_cast<Camera*>(newCam)->target->setRelCoor(0,0,0); |
---|
| 130 | } |
---|
[10480] | 131 | |
---|
[10497] | 132 | void CameraMan::setRelCameraCoorSoft(const std::string& camName, float x, float y, float z, float bias) |
---|
| 133 | { |
---|
| 134 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 135 | dynamic_cast<Camera*>(newCam)->setRelCoorSoft(x,y,z,bias); |
---|
| 136 | dynamic_cast<Camera*>(newCam)->target->setRelCoorSoft(0,0,0,bias); |
---|
| 137 | } |
---|
[10480] | 138 | |
---|
[10498] | 139 | void CameraMan::pauseCamera(const std::string& camName, bool stop) |
---|
| 140 | { |
---|
| 141 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 142 | dynamic_cast<Camera*>(newCam)->pauseTrack(stop); |
---|
| 143 | } |
---|
| 144 | |
---|
[10480] | 145 | void CameraMan::setCam(unsigned int cameraNo) |
---|
[10406] | 146 | { |
---|
| 147 | if (cameraNo<cameras.size()) |
---|
| 148 | { |
---|
| 149 | this->setCam( cameras[cameraNo]); |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | void CameraMan::setCam(const std::string& camName) |
---|
| 154 | { |
---|
| 155 | BaseObject* object = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 156 | |
---|
| 157 | if(object != NULL) |
---|
| 158 | { |
---|
[10480] | 159 | this->setCam(dynamic_cast<Camera*>(object)); |
---|
[10406] | 160 | return; |
---|
| 161 | } |
---|
| 162 | printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", camName.c_str()); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | void CameraMan::setCam(Camera* camera) |
---|
| 167 | { |
---|
| 168 | if( camera == NULL) |
---|
| 169 | { |
---|
| 170 | PRINTF(0)("trying to add a zero camera! uiuiui!\n"); |
---|
[10480] | 171 | return; |
---|
[10406] | 172 | } |
---|
[10480] | 173 | |
---|
[10406] | 174 | this->currentCam = camera; |
---|
| 175 | |
---|
| 176 | State::setCamera(currentCam, currentCam->getTarget()); |
---|
| 177 | OrxSound::SoundEngine::getInstance()->setListener(currentCam); |
---|
| 178 | |
---|
| 179 | // check if it is already added |
---|
| 180 | if( ! this->cameraIsInVector(currentCam) ) |
---|
| 181 | this->cameras.push_back(currentCam); |
---|
| 182 | |
---|
| 183 | this->fadeToBlack->setRelCoor(0., 0., 0.); |
---|
| 184 | this->fadeToBlack->setParent(this->currentCam); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | void CameraMan::moveCurrCam(int x, int y, int z) |
---|
| 189 | { |
---|
| 190 | currentCam->target->trans(x,y,z); |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName) |
---|
| 195 | { |
---|
| 196 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 197 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
[10463] | 198 | { |
---|
[10406] | 199 | currentCam->lookAt(dynamic_cast<PNode*>(object)); |
---|
[10463] | 200 | State::setCamera(this->currentCam, dynamic_cast<CameraTarget*>(object)); |
---|
| 201 | } |
---|
[10406] | 202 | } |
---|
| 203 | |
---|
[10463] | 204 | |
---|
[10406] | 205 | void CameraMan::atachCurrCameraToWorldEntity(const std::string& className, const std::string& targetEntity) |
---|
| 206 | { |
---|
| 207 | BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity); |
---|
[10408] | 208 | |
---|
[10480] | 209 | if(object != NULL && object->isA(PNode::staticClassID())) |
---|
[10408] | 210 | { |
---|
[10482] | 211 | this->atachTarget(this->currentCam, dynamic_cast<PNode*>(object)); |
---|
[10408] | 212 | return; |
---|
| 213 | } |
---|
| 214 | |
---|
[10416] | 215 | printf("ERROR CAMERAMANAGER: Couldn't set camera to: %s %s \n", className.c_str(),targetEntity.c_str() ); |
---|
[10406] | 216 | } |
---|
| 217 | |
---|
[10416] | 218 | |
---|
[10480] | 219 | |
---|
| 220 | void CameraMan::detachCurrCamera() |
---|
[10416] | 221 | { |
---|
[10480] | 222 | currentCam->target->detach(); |
---|
| 223 | } |
---|
[10416] | 224 | |
---|
| 225 | |
---|
[10480] | 226 | |
---|
| 227 | void CameraMan::jumpCurrCam(float x, float y, float z) |
---|
| 228 | { |
---|
| 229 | currentCam->target->jump(x, y, z); |
---|
[10416] | 230 | } |
---|
| 231 | |
---|
[10480] | 232 | void CameraMan::togglFade() |
---|
| 233 | { |
---|
| 234 | if( this->fadeToBlack) |
---|
| 235 | fadeToBlack->toggleFade(); |
---|
| 236 | } |
---|
[10416] | 237 | |
---|
[10497] | 238 | |
---|
[10480] | 239 | void CameraMan::initFadeBlack() |
---|
[10413] | 240 | { |
---|
[10480] | 241 | if( this->fadeToBlack) |
---|
| 242 | fadeToBlack->initFadeBlack(); |
---|
[10413] | 243 | } |
---|
[10406] | 244 | |
---|
[10480] | 245 | |
---|
| 246 | void CameraMan::moveCam(int x, int y, int z, int camNo) |
---|
[10406] | 247 | { |
---|
[10480] | 248 | cameras[camNo]->target->trans(x,y,z); |
---|
[10406] | 249 | } |
---|
| 250 | |
---|
| 251 | |
---|
[10480] | 252 | void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName) |
---|
| 253 | { |
---|
| 254 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 255 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
| 256 | { |
---|
| 257 | cameras[camNo]->lookAt(dynamic_cast<PNode*>(object)); |
---|
| 258 | } |
---|
| 259 | } |
---|
[10406] | 260 | |
---|
[10480] | 261 | |
---|
| 262 | void CameraMan::changeTarget(const std::string& camName,const std::string& className, const std::string& objectName) |
---|
[10406] | 263 | { |
---|
[10480] | 264 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 265 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 266 | if( object != NULL && newCam != NULL && object->isA(PNode::staticClassID())) |
---|
| 267 | { |
---|
| 268 | dynamic_cast<Camera*>(newCam)->lookAt(dynamic_cast<PNode*>(object)); |
---|
| 269 | State::setCamera( dynamic_cast<Camera*>(newCam), dynamic_cast<CameraTarget*>(object)); |
---|
| 270 | } |
---|
[10406] | 271 | } |
---|
| 272 | |
---|
| 273 | |
---|
[10480] | 274 | void CameraMan::atachCameraToWorldEntity(const std::string& cameraName, const std::string& className, const std::string& targetEntity) |
---|
[10406] | 275 | { |
---|
[10480] | 276 | BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity); |
---|
| 277 | BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName); |
---|
| 278 | |
---|
| 279 | if( object != NULL && targetCam != NULL && object->isA(PNode::staticClassID()) ) |
---|
| 280 | { |
---|
[10482] | 281 | this->atachTarget(dynamic_cast<Camera*>(targetCam), dynamic_cast<PNode*>( object )); |
---|
[10480] | 282 | return; |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | printf("ERROR CAMERAMANAGER: Couldn't set camera %s to: %s %s \n", cameraName.c_str(), className.c_str(),targetEntity.c_str() ); |
---|
[10406] | 286 | } |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | |
---|
[10480] | 290 | void CameraMan::jumpCam(int x, int y, int z, int camNo) |
---|
[10406] | 291 | { |
---|
[10480] | 292 | cameras[camNo]->target->jump(x, y, z); |
---|
[10406] | 293 | } |
---|
| 294 | |
---|
[10480] | 295 | |
---|
[10483] | 296 | void CameraMan::jumpCam(const std::string& cameraName, float x, float y, float z) |
---|
| 297 | { |
---|
| 298 | BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName); |
---|
| 299 | if( targetCam != NULL ) |
---|
| 300 | { |
---|
| 301 | dynamic_cast<Camera*>(targetCam)->target->jump( x, y, z ); |
---|
| 302 | } |
---|
[10480] | 303 | |
---|
[10483] | 304 | } |
---|
| 305 | |
---|
| 306 | |
---|
[10480] | 307 | void CameraMan::setClipRegion(float nearCli, float farCli) |
---|
[10424] | 308 | { |
---|
[10480] | 309 | this->nearClip=nearCli; |
---|
| 310 | this->farClip=farCli; |
---|
| 311 | |
---|
| 312 | for(unsigned int i = 0; i < this->cameras.size(); i++) |
---|
| 313 | cameras[i]->setClipRegion(nearCli, farCli); |
---|
[10424] | 314 | } |
---|
[10406] | 315 | |
---|
| 316 | |
---|
[10480] | 317 | |
---|
[10406] | 318 | bool CameraMan::cameraIsInVector(Camera* camera) |
---|
| 319 | { |
---|
| 320 | |
---|
| 321 | for(std::vector<Camera*>::const_iterator it = cameras.begin(); it != cameras.end(); it++ ) |
---|
| 322 | { |
---|
| 323 | if( (*it) == camera) |
---|
| 324 | { |
---|
| 325 | return true; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | return false; |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | void CameraMan::cameraInfo() |
---|
| 335 | { |
---|
| 336 | bool sameCam = (this->currentCam == State::getCamera()); |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | PRINT(0)("==== CameraMan::cameraInfo ===\n"); |
---|
| 340 | PRINT(0)("= Camera Name: %s\n", this->currentCam->getName().c_str()); |
---|
| 341 | PRINT(0)("= Tests:\n"); |
---|
| 342 | PRINT(0)("== State::Cam == this::Cam %i\n", sameCam); |
---|
| 343 | PRINT(0)("== Parenting Informations:\n"); |
---|
| 344 | this->currentCam->debugNode(10); |
---|
| 345 | PRINT(0)("==============================\n"); |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | float CameraMan::getCurrCameraCoorX() |
---|
| 350 | { return this->currentCam->getAbsCoorX(); } |
---|
| 351 | |
---|
| 352 | float CameraMan::getCurrCameraCoorY() |
---|
| 353 | { return this->currentCam->getAbsCoorY(); } |
---|
| 354 | |
---|
| 355 | float CameraMan::getCurrCameraCoorZ() |
---|
| 356 | { return this->currentCam->getAbsCoorZ(); } |
---|
| 357 | |
---|
| 358 | |
---|
| 359 | |
---|
[10482] | 360 | void CameraMan::atachTarget(Camera* cam ,PNode* target) |
---|
| 361 | { |
---|
| 362 | cam->target->atach(target); |
---|
| 363 | cam->setViewMode(Camera::ViewNormal); |
---|
| 364 | State::setCamera( cam, dynamic_cast<CameraTarget*>(target)); |
---|
| 365 | |
---|
| 366 | } |
---|
| 367 | |
---|
[10406] | 368 | //how to get a class fkt pointer |
---|
| 369 | |
---|
| 370 | //BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 371 | |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | |
---|
| 382 | |
---|
| 383 | |
---|
| 384 | |
---|