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