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