[10206] | 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 |
---|
[10394] | 13 | co-programmer: Silvan Nellen |
---|
[10206] | 14 | */ |
---|
| 15 | |
---|
[10192] | 16 | #include "shell_command.h" |
---|
| 17 | #include "cameraman.h" |
---|
[10238] | 18 | #include "game_world_data.h" |
---|
[10195] | 19 | #include "state.h" |
---|
[10259] | 20 | #include "sound_engine.h" |
---|
[10338] | 21 | #include <string> |
---|
[10388] | 22 | #include "script_class.h" |
---|
[10390] | 23 | #include "loading/load_param_xml.h" |
---|
[10404] | 24 | #include "blackscreen.h" |
---|
| 25 | #include "p_node.h" |
---|
| 26 | #include "camera.h" |
---|
[10192] | 27 | |
---|
[10343] | 28 | ObjectListDefinition(CameraMan); |
---|
[10192] | 29 | |
---|
[10404] | 30 | SHELL_COMMAND(camerainfo, CameraMan, cameraInfo); |
---|
[10272] | 31 | |
---|
[10404] | 32 | |
---|
[10388] | 33 | CREATE_SCRIPTABLE_CLASS(CameraMan, |
---|
| 34 | addMethod("changeCurrTarget", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::changeCurrTarget)) |
---|
[10394] | 35 | ->addMethod("changeTarget", Executor3<CameraMan, lua_State*, const std::string&, const std::string&,const std::string&>(&CameraMan::changeTarget)) |
---|
[10403] | 36 | ->addMethod("setCam", Executor1<CameraMan, lua_State*, const std::string&>(&CameraMan::setCam)) |
---|
[10388] | 37 | ->addMethod("togglFade", Executor0<CameraMan, lua_State*>(&CameraMan::togglFade)) |
---|
[10390] | 38 | ->addMethod("getCurrCameraCoorX", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorX)) |
---|
| 39 | ->addMethod("getCurrCameraCoorY", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorY)) |
---|
| 40 | ->addMethod("getCurrCameraCoorZ", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorZ)) |
---|
[10388] | 41 | ); |
---|
| 42 | |
---|
| 43 | |
---|
[10390] | 44 | CameraMan::CameraMan(const TiXmlElement* root) |
---|
[10192] | 45 | { |
---|
[10343] | 46 | this->registerObject(this, CameraMan::_objectList); |
---|
[10272] | 47 | |
---|
| 48 | this->nearClip = 1.0; |
---|
| 49 | this->farClip = 1000.0; |
---|
| 50 | |
---|
[10403] | 51 | this->fadeToBlack=new BlackScreen(); |
---|
[10400] | 52 | |
---|
[10403] | 53 | this->setCam( State::getCamera()); |
---|
| 54 | |
---|
[10390] | 55 | if (root != NULL) |
---|
| 56 | this->loadParams(root); |
---|
[10192] | 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
[10390] | 60 | void CameraMan::loadParams(const TiXmlElement* root) |
---|
[10192] | 61 | { |
---|
[10390] | 62 | BaseObject::loadParams(root); |
---|
[10403] | 63 | |
---|
[10390] | 64 | LOAD_PARAM_START_CYCLE(root, object); |
---|
| 65 | { |
---|
[10393] | 66 | this->createCam(object); |
---|
[10390] | 67 | } |
---|
| 68 | LOAD_PARAM_END_CYCLE(object); |
---|
| 69 | |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | void CameraMan::createCam(const TiXmlElement* root) |
---|
| 74 | { |
---|
[10393] | 75 | //Camera* newCamera=new Camera(root); |
---|
[10390] | 76 | this->cameras.push_back(new Camera(root)); |
---|
[10254] | 77 | cameras[cameras.size()-1]->target->detach(); |
---|
[10272] | 78 | cameras[cameras.size()-1]->setClipRegion(nearClip, farClip); |
---|
[10259] | 79 | |
---|
[10192] | 80 | } |
---|
| 81 | |
---|
[10343] | 82 | void CameraMan::setCam(int cameraNo) |
---|
[10192] | 83 | { |
---|
[10206] | 84 | if (cameraNo<cameras.size()) |
---|
[10197] | 85 | { |
---|
[10403] | 86 | this->setCam( cameras[cameraNo]); |
---|
[10197] | 87 | } |
---|
[10192] | 88 | } |
---|
| 89 | |
---|
[10393] | 90 | void CameraMan::setCam(const std::string& camName) |
---|
| 91 | { |
---|
| 92 | BaseObject* object = ObjectListBase::getBaseObject("Camera", camName); |
---|
[10403] | 93 | |
---|
[10393] | 94 | if(object != NULL) |
---|
| 95 | { |
---|
[10403] | 96 | Camera* currentCam = dynamic_cast<Camera*>(object) ; |
---|
| 97 | |
---|
| 98 | this->setCam(currentCam); |
---|
[10398] | 99 | return; |
---|
| 100 | } |
---|
| 101 | printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", camName.c_str()); |
---|
[10393] | 102 | } |
---|
[10204] | 103 | |
---|
[10403] | 104 | |
---|
| 105 | void CameraMan::setCam(Camera* camera) |
---|
| 106 | { |
---|
| 107 | if( camera == NULL) |
---|
| 108 | { |
---|
| 109 | PRINTF(0)("trying to add a zero camera! uiuiui!\n"); |
---|
| 110 | } |
---|
| 111 | this->currentCam = camera; |
---|
| 112 | |
---|
| 113 | State::setCamera(currentCam, currentCam->getTarget()); |
---|
| 114 | OrxSound::SoundEngine::getInstance()->setListener(currentCam); |
---|
| 115 | |
---|
| 116 | // check if it is already added |
---|
| 117 | if( ! this->cameraIsInVector(currentCam) ) |
---|
| 118 | this->cameras.push_back(currentCam); |
---|
| 119 | |
---|
| 120 | this->fadeToBlack->setRelCoor(0., 0., 0.); |
---|
| 121 | this->fadeToBlack->setParent(this->currentCam); |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
[10343] | 125 | void CameraMan::moveCurrCam(int x, int y, int z) |
---|
[10204] | 126 | { |
---|
[10403] | 127 | currentCam->target->trans(x,y,z); |
---|
[10204] | 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
[10343] | 131 | void CameraMan::moveCam(int x, int y, int z, int camNo) |
---|
[10204] | 132 | { |
---|
[10403] | 133 | cameras[camNo]->target->trans(x,y,z); |
---|
[10204] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
[10388] | 137 | void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName) |
---|
[10204] | 138 | { |
---|
[10338] | 139 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 140 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
| 141 | cameras[camNo]->lookAt(dynamic_cast<PNode*>(object)); |
---|
[10204] | 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
[10394] | 145 | void CameraMan::changeTarget(const std::string& camName,const std::string& className, const std::string& objectName) |
---|
| 146 | { |
---|
| 147 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 148 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
[10400] | 149 | if( object != NULL && newCam != NULL && object->isA(PNode::staticClassID())) |
---|
[10394] | 150 | dynamic_cast<Camera*>(newCam)->lookAt(dynamic_cast<PNode*>(object)); |
---|
| 151 | } |
---|
| 152 | |
---|
[10388] | 153 | void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName) |
---|
[10204] | 154 | { |
---|
[10338] | 155 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 156 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
| 157 | currentCam->lookAt(dynamic_cast<PNode*>(object)); |
---|
[10236] | 158 | } |
---|
| 159 | |
---|
[10343] | 160 | void CameraMan::atachCurrTarget(PNode* target) |
---|
[10236] | 161 | { |
---|
[10205] | 162 | currentCam->target->atach(target); |
---|
[10204] | 163 | } |
---|
| 164 | |
---|
[10343] | 165 | void CameraMan::jumpCam(int x, int y, int z, int camNo) |
---|
[10204] | 166 | { |
---|
[10206] | 167 | cameras[camNo]->target->jump(x, y, z); |
---|
[10204] | 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
[10272] | 171 | |
---|
[10343] | 172 | void CameraMan::setClipRegion(float nearCli, float farCli) |
---|
[10272] | 173 | { |
---|
| 174 | this->nearClip=nearCli; |
---|
| 175 | this->farClip=farCli; |
---|
| 176 | |
---|
| 177 | for(int i = 0; i < this->cameras.size(); i++) |
---|
| 178 | cameras[i]->setClipRegion(nearCli, farCli); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
[10343] | 182 | void CameraMan::jumpCurrCam(int x, int y, int z) |
---|
[10204] | 183 | { |
---|
[10206] | 184 | currentCam->target->jump(x, y, z); |
---|
[10204] | 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|
[10343] | 190 | void CameraMan::togglFade() |
---|
[10330] | 191 | { |
---|
| 192 | if( this->fadeToBlack) |
---|
| 193 | fadeToBlack->toggleFade(); |
---|
| 194 | } |
---|
[10204] | 195 | |
---|
| 196 | |
---|
| 197 | |
---|
[10393] | 198 | bool CameraMan::cameraIsInVector(Camera* camera) |
---|
| 199 | { |
---|
| 200 | |
---|
| 201 | for(std::vector<Camera*>::const_iterator it = cameras.begin(); it != cameras.end(); it++ ) |
---|
| 202 | { |
---|
| 203 | if( (*it) == camera) |
---|
| 204 | { |
---|
| 205 | return true; |
---|
| 206 | } |
---|
| 207 | } |
---|
| 208 | return false; |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|
[10404] | 214 | void CameraMan::cameraInfo() |
---|
| 215 | { |
---|
| 216 | bool sameCam = (this->currentCam == State::getCamera()); |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | PRINT(0)("==== CameraMan::cameraInfo ===\n"); |
---|
| 220 | PRINT(0)("= Camera Name: %s\n", this->currentCam->getName().c_str()); |
---|
| 221 | PRINT(0)("= Tests:\n"); |
---|
| 222 | PRINT(0)("== State::Cam == this::Cam %i\n", sameCam); |
---|
| 223 | PRINT(0)("== Parenting Informations:\n"); |
---|
| 224 | this->currentCam->debugNode(10); |
---|
| 225 | PRINT(0)("==============================\n"); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | float CameraMan::getCurrCameraCoorX() |
---|
| 230 | { return this->currentCam->getAbsCoorX(); } |
---|
| 231 | |
---|
| 232 | float CameraMan::getCurrCameraCoorY() |
---|
| 233 | { return this->currentCam->getAbsCoorY(); } |
---|
| 234 | |
---|
| 235 | float CameraMan::getCurrCameraCoorZ() |
---|
| 236 | { return this->currentCam->getAbsCoorZ(); } |
---|
| 237 | |
---|
| 238 | |
---|
| 239 | |
---|
[10330] | 240 | //how to get a class fkt pointer |
---|
[10204] | 241 | |
---|
[10330] | 242 | //BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
[10204] | 243 | |
---|
| 244 | |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | |
---|
[10330] | 255 | |
---|
| 256 | |
---|