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