| 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: | 
|---|
| 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 |  | 
|---|
| 24 | ObjectListDefinition(CameraMan); | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | CREATE_SCRIPTABLE_CLASS(CameraMan, | 
|---|
| 28 |                         addMethod("changeCurrTarget", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::changeCurrTarget)) | 
|---|
| 29 |                         ->addMethod("changeTarget", Executor3<CameraMan, lua_State*, int, const std::string&,const std::string&>(&CameraMan::changeTarget)) | 
|---|
| 30 |                         ->addMethod("togglFade", Executor0<CameraMan, lua_State*>(&CameraMan::togglFade)) | 
|---|
| 31 |                        ); | 
|---|
| 32 |  | 
|---|
| 33 |  | 
|---|
| 34 | CameraMan::CameraMan() | 
|---|
| 35 | { | 
|---|
| 36 |   this->registerObject(this, CameraMan::_objectList); | 
|---|
| 37 |  | 
|---|
| 38 |   this->nearClip = 1.0; | 
|---|
| 39 |   this->farClip = 1000.0; | 
|---|
| 40 |  | 
|---|
| 41 |   currentCam=State::getCamera(); | 
|---|
| 42 |   this->cameras.push_back(currentCam); | 
|---|
| 43 |   State::setCamera(currentCam, currentCam->getTarget()); | 
|---|
| 44 |   this->fadeToBlack=new BlackScreen(); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | void CameraMan::createCam() | 
|---|
| 49 | { | 
|---|
| 50 |  // Camera* newCamera=new Camera(); | 
|---|
| 51 |   this->cameras.push_back(new Camera()); | 
|---|
| 52 |   cameras[cameras.size()-1]->target->detach(); | 
|---|
| 53 |   cameras[cameras.size()-1]->setClipRegion(nearClip, farClip); | 
|---|
| 54 |  | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | void CameraMan::setCam(int cameraNo) | 
|---|
| 58 | { | 
|---|
| 59 |   if (cameraNo<cameras.size()) | 
|---|
| 60 |   { | 
|---|
| 61 |   currentCam=cameras[cameraNo]; | 
|---|
| 62 |   State::setCamera(currentCam, currentCam->getTarget()); | 
|---|
| 63 |   OrxSound::SoundEngine::getInstance()->setListener(currentCam); | 
|---|
| 64 |  | 
|---|
| 65 |   this->fadeToBlack->setParent(this->currentCam); | 
|---|
| 66 |   this->fadeToBlack->setRelCoor(3., 0., 0.); | 
|---|
| 67 |   } | 
|---|
| 68 |  | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 | void CameraMan::moveCurrCam(int x, int y, int z) | 
|---|
| 74 | { | 
|---|
| 75 | currentCam->target->trans(x,y,z); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | void CameraMan::moveCam(int x, int y, int z, int camNo) | 
|---|
| 80 | { | 
|---|
| 81 | cameras[camNo]->target->trans(x,y,z); | 
|---|
| 82 | } | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName) | 
|---|
| 86 | { | 
|---|
| 87 |   BaseObject* object = ObjectListBase::getBaseObject(className, objectName); | 
|---|
| 88 |   if( object != NULL && object->isA(PNode::staticClassID())) | 
|---|
| 89 |     cameras[camNo]->lookAt(dynamic_cast<PNode*>(object)); | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName) | 
|---|
| 94 | { | 
|---|
| 95 |   BaseObject* object = ObjectListBase::getBaseObject(className, objectName); | 
|---|
| 96 |   if( object != NULL && object->isA(PNode::staticClassID())) | 
|---|
| 97 |     currentCam->lookAt(dynamic_cast<PNode*>(object)); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | void CameraMan::atachCurrTarget(PNode* target) | 
|---|
| 101 | { | 
|---|
| 102 |   currentCam->target->atach(target); | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | void CameraMan::jumpCam(int x, int y, int z, int camNo) | 
|---|
| 106 | { | 
|---|
| 107 |   cameras[camNo]->target->jump(x, y, z); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | void CameraMan::setClipRegion(float nearCli, float farCli) | 
|---|
| 113 | { | 
|---|
| 114 |   this->nearClip=nearCli; | 
|---|
| 115 |   this->farClip=farCli; | 
|---|
| 116 |  | 
|---|
| 117 |   for(int i = 0; i < this->cameras.size(); i++) | 
|---|
| 118 |     cameras[i]->setClipRegion(nearCli, farCli); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 |  | 
|---|
| 122 | void CameraMan::jumpCurrCam(int x, int y, int z) | 
|---|
| 123 | { | 
|---|
| 124 |   currentCam->target->jump(x, y, z); | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 |  | 
|---|
| 130 | void CameraMan::togglFade() | 
|---|
| 131 | { | 
|---|
| 132 |   if( this->fadeToBlack) | 
|---|
| 133 |     fadeToBlack->toggleFade(); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | //how to get a class fkt pointer | 
|---|
| 139 |  | 
|---|
| 140 | //BaseObject* object = ObjectListBase::getBaseObject(className, objectName); | 
|---|
| 141 |  | 
|---|
| 142 |  | 
|---|
| 143 |  | 
|---|
| 144 |  | 
|---|
| 145 |  | 
|---|
| 146 |  | 
|---|
| 147 |  | 
|---|
| 148 |  | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|
| 152 |  | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|