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