| [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)) |
|---|
| [10406] | 49 | ); |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | CameraMan::CameraMan(const TiXmlElement* root) |
|---|
| 53 | { |
|---|
| 54 | this->registerObject(this, CameraMan::_objectList); |
|---|
| 55 | |
|---|
| 56 | this->nearClip = 1.0; |
|---|
| 57 | this->farClip = 1000.0; |
|---|
| 58 | |
|---|
| 59 | this->fadeToBlack=new BlackScreen(); |
|---|
| 60 | |
|---|
| 61 | this->setCam( State::getCamera()); |
|---|
| 62 | |
|---|
| 63 | if (root != NULL) |
|---|
| 64 | this->loadParams(root); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | void CameraMan::loadParams(const TiXmlElement* root) |
|---|
| 69 | { |
|---|
| 70 | BaseObject::loadParams(root); |
|---|
| [10414] | 71 | LoadParamXML(root, "Cameras", this, CameraMan, createCameras); |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | void CameraMan::createCameras(const TiXmlElement* camerasTag) |
|---|
| 76 | { |
|---|
| 77 | |
|---|
| [10411] | 78 | LOAD_PARAM_START_CYCLE(camerasTag, object); |
|---|
| 79 | { |
|---|
| 80 | this->createCam(object); |
|---|
| 81 | } |
|---|
| 82 | LOAD_PARAM_END_CYCLE(object); |
|---|
| [10406] | 83 | |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | void CameraMan::createCam(const TiXmlElement* root) |
|---|
| 88 | { |
|---|
| 89 | this->cameras.push_back(new Camera(root)); |
|---|
| 90 | cameras[cameras.size()-1]->setClipRegion(nearClip, farClip); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| [10495] | 93 | /*void CameraMan::setViewMode(const std::string& cameraName, const std::string& viewMode) |
|---|
| 94 | { |
|---|
| 95 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", cameraName); |
|---|
| 96 | switch (viewMode) |
|---|
| 97 | { |
|---|
| 98 | default: |
|---|
| 99 | case "ViewNormal": |
|---|
| 100 | { |
|---|
| 101 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewNormal); |
|---|
| 102 | break; |
|---|
| 103 | } |
|---|
| 104 | case "ViewTop": |
|---|
| 105 | { |
|---|
| 106 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewTop); |
|---|
| 107 | break; |
|---|
| 108 | } |
|---|
| 109 | case "ViewBehind": |
|---|
| 110 | { |
|---|
| 111 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewBehind); |
|---|
| 112 | break; |
|---|
| 113 | } |
|---|
| 114 | case "ViewFront": |
|---|
| 115 | { |
|---|
| 116 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewFront); |
|---|
| 117 | break; |
|---|
| 118 | } |
|---|
| 119 | case "ViewLeft": |
|---|
| 120 | { |
|---|
| 121 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewLeft); |
|---|
| 122 | break; |
|---|
| 123 | } |
|---|
| 124 | case "ViewRight": |
|---|
| 125 | { |
|---|
| 126 | dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewRight); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | }*/ |
|---|
| [10480] | 130 | |
|---|
| [10495] | 131 | void CameraMan::setRelCameraCoor(const std::string& camName, float x, float y, float z) |
|---|
| 132 | { |
|---|
| 133 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
|---|
| 134 | dynamic_cast<Camera*>(newCam)->setRelCoor(x,y,z); |
|---|
| 135 | dynamic_cast<Camera*>(newCam)->target->setRelCoor(0,0,0); |
|---|
| 136 | } |
|---|
| [10480] | 137 | |
|---|
| 138 | |
|---|
| 139 | void CameraMan::setCam(unsigned int cameraNo) |
|---|
| [10406] | 140 | { |
|---|
| 141 | if (cameraNo<cameras.size()) |
|---|
| 142 | { |
|---|
| 143 | this->setCam( cameras[cameraNo]); |
|---|
| 144 | } |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | void CameraMan::setCam(const std::string& camName) |
|---|
| 148 | { |
|---|
| 149 | BaseObject* object = ObjectListBase::getBaseObject("Camera", camName); |
|---|
| 150 | |
|---|
| 151 | if(object != NULL) |
|---|
| 152 | { |
|---|
| [10480] | 153 | this->setCam(dynamic_cast<Camera*>(object)); |
|---|
| [10406] | 154 | return; |
|---|
| 155 | } |
|---|
| 156 | printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", camName.c_str()); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | void CameraMan::setCam(Camera* camera) |
|---|
| 161 | { |
|---|
| 162 | if( camera == NULL) |
|---|
| 163 | { |
|---|
| 164 | PRINTF(0)("trying to add a zero camera! uiuiui!\n"); |
|---|
| [10480] | 165 | return; |
|---|
| [10406] | 166 | } |
|---|
| [10480] | 167 | |
|---|
| [10406] | 168 | this->currentCam = camera; |
|---|
| 169 | |
|---|
| 170 | State::setCamera(currentCam, currentCam->getTarget()); |
|---|
| 171 | OrxSound::SoundEngine::getInstance()->setListener(currentCam); |
|---|
| 172 | |
|---|
| 173 | // check if it is already added |
|---|
| 174 | if( ! this->cameraIsInVector(currentCam) ) |
|---|
| 175 | this->cameras.push_back(currentCam); |
|---|
| 176 | |
|---|
| 177 | this->fadeToBlack->setRelCoor(0., 0., 0.); |
|---|
| 178 | this->fadeToBlack->setParent(this->currentCam); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | void CameraMan::moveCurrCam(int x, int y, int z) |
|---|
| 183 | { |
|---|
| 184 | currentCam->target->trans(x,y,z); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName) |
|---|
| 189 | { |
|---|
| 190 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
|---|
| 191 | if( object != NULL && object->isA(PNode::staticClassID())) |
|---|
| [10463] | 192 | { |
|---|
| [10406] | 193 | currentCam->lookAt(dynamic_cast<PNode*>(object)); |
|---|
| [10463] | 194 | State::setCamera(this->currentCam, dynamic_cast<CameraTarget*>(object)); |
|---|
| 195 | } |
|---|
| [10406] | 196 | } |
|---|
| 197 | |
|---|
| [10463] | 198 | |
|---|
| [10406] | 199 | void CameraMan::atachCurrCameraToWorldEntity(const std::string& className, const std::string& targetEntity) |
|---|
| 200 | { |
|---|
| 201 | BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity); |
|---|
| [10408] | 202 | |
|---|
| [10480] | 203 | if(object != NULL && object->isA(PNode::staticClassID())) |
|---|
| [10408] | 204 | { |
|---|
| [10482] | 205 | this->atachTarget(this->currentCam, dynamic_cast<PNode*>(object)); |
|---|
| [10408] | 206 | return; |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| [10416] | 209 | printf("ERROR CAMERAMANAGER: Couldn't set camera to: %s %s \n", className.c_str(),targetEntity.c_str() ); |
|---|
| [10406] | 210 | } |
|---|
| 211 | |
|---|
| [10416] | 212 | |
|---|
| [10480] | 213 | |
|---|
| 214 | void CameraMan::detachCurrCamera() |
|---|
| [10416] | 215 | { |
|---|
| [10480] | 216 | currentCam->target->detach(); |
|---|
| 217 | } |
|---|
| [10416] | 218 | |
|---|
| 219 | |
|---|
| [10480] | 220 | |
|---|
| 221 | void CameraMan::jumpCurrCam(float x, float y, float z) |
|---|
| 222 | { |
|---|
| 223 | currentCam->target->jump(x, y, z); |
|---|
| [10416] | 224 | } |
|---|
| 225 | |
|---|
| [10480] | 226 | void CameraMan::togglFade() |
|---|
| 227 | { |
|---|
| 228 | if( this->fadeToBlack) |
|---|
| 229 | fadeToBlack->toggleFade(); |
|---|
| 230 | } |
|---|
| [10416] | 231 | |
|---|
| [10480] | 232 | void CameraMan::initFadeBlack() |
|---|
| [10413] | 233 | { |
|---|
| [10480] | 234 | if( this->fadeToBlack) |
|---|
| 235 | fadeToBlack->initFadeBlack(); |
|---|
| [10413] | 236 | } |
|---|
| [10406] | 237 | |
|---|
| [10480] | 238 | |
|---|
| 239 | void CameraMan::moveCam(int x, int y, int z, int camNo) |
|---|
| [10406] | 240 | { |
|---|
| [10480] | 241 | cameras[camNo]->target->trans(x,y,z); |
|---|
| [10406] | 242 | } |
|---|
| 243 | |
|---|
| 244 | |
|---|
| [10480] | 245 | void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName) |
|---|
| 246 | { |
|---|
| 247 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
|---|
| 248 | if( object != NULL && object->isA(PNode::staticClassID())) |
|---|
| 249 | { |
|---|
| 250 | cameras[camNo]->lookAt(dynamic_cast<PNode*>(object)); |
|---|
| 251 | } |
|---|
| 252 | } |
|---|
| [10406] | 253 | |
|---|
| [10480] | 254 | |
|---|
| 255 | void CameraMan::changeTarget(const std::string& camName,const std::string& className, const std::string& objectName) |
|---|
| [10406] | 256 | { |
|---|
| [10480] | 257 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
|---|
| 258 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
|---|
| 259 | if( object != NULL && newCam != NULL && object->isA(PNode::staticClassID())) |
|---|
| 260 | { |
|---|
| 261 | dynamic_cast<Camera*>(newCam)->lookAt(dynamic_cast<PNode*>(object)); |
|---|
| 262 | State::setCamera( dynamic_cast<Camera*>(newCam), dynamic_cast<CameraTarget*>(object)); |
|---|
| 263 | } |
|---|
| [10406] | 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| [10480] | 267 | void CameraMan::atachCameraToWorldEntity(const std::string& cameraName, const std::string& className, const std::string& targetEntity) |
|---|
| [10406] | 268 | { |
|---|
| [10480] | 269 | BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity); |
|---|
| 270 | BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName); |
|---|
| 271 | |
|---|
| 272 | if( object != NULL && targetCam != NULL && object->isA(PNode::staticClassID()) ) |
|---|
| 273 | { |
|---|
| [10482] | 274 | this->atachTarget(dynamic_cast<Camera*>(targetCam), dynamic_cast<PNode*>( object )); |
|---|
| [10480] | 275 | return; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | printf("ERROR CAMERAMANAGER: Couldn't set camera %s to: %s %s \n", cameraName.c_str(), className.c_str(),targetEntity.c_str() ); |
|---|
| [10406] | 279 | } |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| [10480] | 283 | void CameraMan::jumpCam(int x, int y, int z, int camNo) |
|---|
| [10406] | 284 | { |
|---|
| [10480] | 285 | cameras[camNo]->target->jump(x, y, z); |
|---|
| [10406] | 286 | } |
|---|
| 287 | |
|---|
| [10480] | 288 | |
|---|
| [10483] | 289 | void CameraMan::jumpCam(const std::string& cameraName, float x, float y, float z) |
|---|
| 290 | { |
|---|
| 291 | BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName); |
|---|
| 292 | if( targetCam != NULL ) |
|---|
| 293 | { |
|---|
| 294 | dynamic_cast<Camera*>(targetCam)->target->jump( x, y, z ); |
|---|
| 295 | } |
|---|
| [10480] | 296 | |
|---|
| [10483] | 297 | } |
|---|
| 298 | |
|---|
| 299 | |
|---|
| [10480] | 300 | void CameraMan::setClipRegion(float nearCli, float farCli) |
|---|
| [10424] | 301 | { |
|---|
| [10480] | 302 | this->nearClip=nearCli; |
|---|
| 303 | this->farClip=farCli; |
|---|
| 304 | |
|---|
| 305 | for(unsigned int i = 0; i < this->cameras.size(); i++) |
|---|
| 306 | cameras[i]->setClipRegion(nearCli, farCli); |
|---|
| [10424] | 307 | } |
|---|
| [10406] | 308 | |
|---|
| 309 | |
|---|
| [10480] | 310 | |
|---|
| [10406] | 311 | bool CameraMan::cameraIsInVector(Camera* camera) |
|---|
| 312 | { |
|---|
| 313 | |
|---|
| 314 | for(std::vector<Camera*>::const_iterator it = cameras.begin(); it != cameras.end(); it++ ) |
|---|
| 315 | { |
|---|
| 316 | if( (*it) == camera) |
|---|
| 317 | { |
|---|
| 318 | return true; |
|---|
| 319 | } |
|---|
| 320 | } |
|---|
| 321 | return false; |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | void CameraMan::cameraInfo() |
|---|
| 328 | { |
|---|
| 329 | bool sameCam = (this->currentCam == State::getCamera()); |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | PRINT(0)("==== CameraMan::cameraInfo ===\n"); |
|---|
| 333 | PRINT(0)("= Camera Name: %s\n", this->currentCam->getName().c_str()); |
|---|
| 334 | PRINT(0)("= Tests:\n"); |
|---|
| 335 | PRINT(0)("== State::Cam == this::Cam %i\n", sameCam); |
|---|
| 336 | PRINT(0)("== Parenting Informations:\n"); |
|---|
| 337 | this->currentCam->debugNode(10); |
|---|
| 338 | PRINT(0)("==============================\n"); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | float CameraMan::getCurrCameraCoorX() |
|---|
| 343 | { return this->currentCam->getAbsCoorX(); } |
|---|
| 344 | |
|---|
| 345 | float CameraMan::getCurrCameraCoorY() |
|---|
| 346 | { return this->currentCam->getAbsCoorY(); } |
|---|
| 347 | |
|---|
| 348 | float CameraMan::getCurrCameraCoorZ() |
|---|
| 349 | { return this->currentCam->getAbsCoorZ(); } |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | |
|---|
| [10482] | 353 | void CameraMan::atachTarget(Camera* cam ,PNode* target) |
|---|
| 354 | { |
|---|
| 355 | cam->target->atach(target); |
|---|
| 356 | cam->setViewMode(Camera::ViewNormal); |
|---|
| 357 | State::setCamera( cam, dynamic_cast<CameraTarget*>(target)); |
|---|
| 358 | |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| [10406] | 361 | //how to get a class fkt pointer |
|---|
| 362 | |
|---|
| 363 | //BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | |
|---|