[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" |
---|
[10192] | 24 | |
---|
[10343] | 25 | ObjectListDefinition(CameraMan); |
---|
[10192] | 26 | |
---|
[10272] | 27 | |
---|
[10388] | 28 | CREATE_SCRIPTABLE_CLASS(CameraMan, |
---|
| 29 | addMethod("changeCurrTarget", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::changeCurrTarget)) |
---|
[10394] | 30 | ->addMethod("changeTarget", Executor3<CameraMan, lua_State*, const std::string&, const std::string&,const std::string&>(&CameraMan::changeTarget)) |
---|
[10393] | 31 | ->addMethod("setCam", Executor1<CameraMan, lua_State*, const std::string&>(&CameraMan::setCam)) |
---|
[10388] | 32 | ->addMethod("togglFade", Executor0<CameraMan, lua_State*>(&CameraMan::togglFade)) |
---|
[10390] | 33 | ->addMethod("getCurrCameraCoorX", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorX)) |
---|
| 34 | ->addMethod("getCurrCameraCoorY", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorY)) |
---|
| 35 | ->addMethod("getCurrCameraCoorZ", Executor0ret<CameraMan, lua_State*,float>(&CameraMan::getCurrCameraCoorZ)) |
---|
[10388] | 36 | ); |
---|
| 37 | |
---|
| 38 | |
---|
[10390] | 39 | CameraMan::CameraMan(const TiXmlElement* root) |
---|
[10192] | 40 | { |
---|
[10343] | 41 | this->registerObject(this, CameraMan::_objectList); |
---|
[10272] | 42 | |
---|
| 43 | this->nearClip = 1.0; |
---|
| 44 | this->farClip = 1000.0; |
---|
| 45 | |
---|
[10197] | 46 | currentCam=State::getCamera(); |
---|
[10206] | 47 | this->cameras.push_back(currentCam); |
---|
[10400] | 48 | |
---|
[10238] | 49 | State::setCamera(currentCam, currentCam->getTarget()); |
---|
[10342] | 50 | this->fadeToBlack=new BlackScreen(); |
---|
[10400] | 51 | this->fadeToBlack->setParent(this->currentCam); |
---|
| 52 | this->fadeToBlack->setRelCoor(3., 0., 0.); |
---|
[10390] | 53 | |
---|
| 54 | if (root != NULL) |
---|
| 55 | this->loadParams(root); |
---|
[10192] | 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
[10390] | 59 | void CameraMan::loadParams(const TiXmlElement* root) |
---|
[10192] | 60 | { |
---|
[10390] | 61 | BaseObject::loadParams(root); |
---|
| 62 | |
---|
| 63 | LOAD_PARAM_START_CYCLE(root, object); |
---|
| 64 | { |
---|
[10393] | 65 | this->createCam(object); |
---|
[10390] | 66 | } |
---|
| 67 | LOAD_PARAM_END_CYCLE(object); |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | void CameraMan::createCam(const TiXmlElement* root) |
---|
| 73 | { |
---|
[10393] | 74 | //Camera* newCamera=new Camera(root); |
---|
[10390] | 75 | this->cameras.push_back(new Camera(root)); |
---|
[10254] | 76 | cameras[cameras.size()-1]->target->detach(); |
---|
[10272] | 77 | cameras[cameras.size()-1]->setClipRegion(nearClip, farClip); |
---|
[10259] | 78 | |
---|
[10192] | 79 | } |
---|
| 80 | |
---|
[10343] | 81 | void CameraMan::setCam(int cameraNo) |
---|
[10192] | 82 | { |
---|
[10206] | 83 | if (cameraNo<cameras.size()) |
---|
[10197] | 84 | { |
---|
[10193] | 85 | currentCam=cameras[cameraNo]; |
---|
[10198] | 86 | State::setCamera(currentCam, currentCam->getTarget()); |
---|
[10259] | 87 | OrxSound::SoundEngine::getInstance()->setListener(currentCam); |
---|
[10348] | 88 | |
---|
[10343] | 89 | this->fadeToBlack->setParent(this->currentCam); |
---|
| 90 | this->fadeToBlack->setRelCoor(3., 0., 0.); |
---|
[10197] | 91 | } |
---|
[10195] | 92 | |
---|
[10192] | 93 | } |
---|
| 94 | |
---|
[10393] | 95 | void CameraMan::setCam(const std::string& camName) |
---|
| 96 | { |
---|
| 97 | BaseObject* object = ObjectListBase::getBaseObject("Camera", camName); |
---|
| 98 | |
---|
| 99 | if(object != NULL) |
---|
| 100 | { |
---|
[10396] | 101 | |
---|
[10393] | 102 | currentCam = dynamic_cast<Camera*>(object) ; |
---|
| 103 | |
---|
| 104 | if( ! this->cameraIsInVector(currentCam) ) |
---|
| 105 | this->cameras.push_back(currentCam); |
---|
| 106 | |
---|
| 107 | State::setCamera(currentCam, currentCam->getTarget()); |
---|
| 108 | OrxSound::SoundEngine::getInstance()->setListener(currentCam); |
---|
| 109 | this->fadeToBlack->setParent(this->currentCam); |
---|
| 110 | this->fadeToBlack->setRelCoor(3., 0., 0.); |
---|
[10398] | 111 | return; |
---|
| 112 | } |
---|
| 113 | printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", camName.c_str()); |
---|
[10393] | 114 | |
---|
| 115 | } |
---|
[10204] | 116 | |
---|
[10343] | 117 | void CameraMan::moveCurrCam(int x, int y, int z) |
---|
[10204] | 118 | { |
---|
| 119 | currentCam->target->trans(x,y,z); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
[10343] | 123 | void CameraMan::moveCam(int x, int y, int z, int camNo) |
---|
[10204] | 124 | { |
---|
| 125 | cameras[camNo]->target->trans(x,y,z); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
[10388] | 129 | void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName) |
---|
[10204] | 130 | { |
---|
[10338] | 131 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 132 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
| 133 | cameras[camNo]->lookAt(dynamic_cast<PNode*>(object)); |
---|
[10204] | 134 | } |
---|
| 135 | |
---|
| 136 | |
---|
[10394] | 137 | void CameraMan::changeTarget(const std::string& camName,const std::string& className, const std::string& objectName) |
---|
| 138 | { |
---|
| 139 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 140 | BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName); |
---|
[10400] | 141 | if( object != NULL && newCam != NULL && object->isA(PNode::staticClassID())) |
---|
[10394] | 142 | dynamic_cast<Camera*>(newCam)->lookAt(dynamic_cast<PNode*>(object)); |
---|
| 143 | } |
---|
| 144 | |
---|
[10388] | 145 | void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName) |
---|
[10204] | 146 | { |
---|
[10338] | 147 | BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
| 148 | if( object != NULL && object->isA(PNode::staticClassID())) |
---|
| 149 | currentCam->lookAt(dynamic_cast<PNode*>(object)); |
---|
[10236] | 150 | } |
---|
| 151 | |
---|
[10343] | 152 | void CameraMan::atachCurrTarget(PNode* target) |
---|
[10236] | 153 | { |
---|
[10205] | 154 | currentCam->target->atach(target); |
---|
[10204] | 155 | } |
---|
| 156 | |
---|
[10343] | 157 | void CameraMan::jumpCam(int x, int y, int z, int camNo) |
---|
[10204] | 158 | { |
---|
[10206] | 159 | cameras[camNo]->target->jump(x, y, z); |
---|
[10204] | 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
[10272] | 163 | |
---|
[10343] | 164 | void CameraMan::setClipRegion(float nearCli, float farCli) |
---|
[10272] | 165 | { |
---|
| 166 | this->nearClip=nearCli; |
---|
| 167 | this->farClip=farCli; |
---|
| 168 | |
---|
| 169 | for(int i = 0; i < this->cameras.size(); i++) |
---|
| 170 | cameras[i]->setClipRegion(nearCli, farCli); |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | |
---|
[10343] | 174 | void CameraMan::jumpCurrCam(int x, int y, int z) |
---|
[10204] | 175 | { |
---|
[10206] | 176 | currentCam->target->jump(x, y, z); |
---|
[10204] | 177 | } |
---|
| 178 | |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | |
---|
[10343] | 182 | void CameraMan::togglFade() |
---|
[10330] | 183 | { |
---|
| 184 | if( this->fadeToBlack) |
---|
| 185 | fadeToBlack->toggleFade(); |
---|
| 186 | } |
---|
[10204] | 187 | |
---|
| 188 | |
---|
| 189 | |
---|
[10393] | 190 | bool CameraMan::cameraIsInVector(Camera* camera) |
---|
| 191 | { |
---|
| 192 | |
---|
| 193 | for(std::vector<Camera*>::const_iterator it = cameras.begin(); it != cameras.end(); it++ ) |
---|
| 194 | { |
---|
| 195 | if( (*it) == camera) |
---|
| 196 | { |
---|
| 197 | return true; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | return false; |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
[10330] | 206 | //how to get a class fkt pointer |
---|
[10204] | 207 | |
---|
[10330] | 208 | //BaseObject* object = ObjectListBase::getBaseObject(className, objectName); |
---|
[10204] | 209 | |
---|
| 210 | |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | |
---|
| 220 | |
---|
[10330] | 221 | |
---|
| 222 | |
---|