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