Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/cameraman.cc @ 10546

Last change on this file since 10546 was 10498, checked in by bknecht, 18 years ago

use pauseCamera in scripts to pause the track of the camera. this works also with pause on NPCs and spaceships with tracks

File size: 11.6 KB
Line 
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
28ObjectListDefinition(CameraMan);
29
30SHELL_COMMAND(camerainfo, CameraMan, cameraInfo);
31
32
33CREATE_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                        ->addMethod("jumpCurrCam", Executor3<CameraMan, lua_State*,float,float,float>(&CameraMan::jumpCurrCam))
46                        ->addMethod("jumpCam", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::jumpCam))
47                        //->addMethod("setViewMode", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::setViewMode))
48                        ->addMethod("setRelCoor", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::setRelCameraCoor))
49                        ->addMethod("setRelCoorSoft", Executor5<CameraMan, lua_State*,const std::string&,float,float,float,float>(&CameraMan::setRelCameraCoorSoft))
50                        ->addMethod("pauseCamera", Executor2<CameraMan, lua_State*, const std::string&, bool>(&CameraMan::pauseCamera))
51                       );
52
53
54CameraMan::CameraMan(const TiXmlElement* root)
55{
56  this->registerObject(this, CameraMan::_objectList);
57
58  this->nearClip = 1.0;
59  this->farClip = 1000.0;
60
61  this->fadeToBlack=new BlackScreen();
62
63  this->setCam( State::getCamera());
64
65  if (root != NULL)
66    this->loadParams(root);
67}
68
69
70void CameraMan::loadParams(const TiXmlElement* root)
71{
72  BaseObject::loadParams(root);
73  LoadParamXML(root, "Cameras", this, CameraMan, createCameras);
74}
75
76
77void CameraMan::createCameras(const TiXmlElement* camerasTag)
78{
79
80    LOAD_PARAM_START_CYCLE(camerasTag, object);
81    {
82      this->createCam(object);
83    }
84    LOAD_PARAM_END_CYCLE(object);
85
86}
87
88
89void CameraMan::createCam(const TiXmlElement* root)
90{
91  this->cameras.push_back(new Camera(root));
92  cameras[cameras.size()-1]->setClipRegion(nearClip, farClip);
93}
94
95/*void CameraMan::setViewMode(const std::string& cameraName, const std::string& viewMode)
96{
97     BaseObject* newCam = ObjectListBase::getBaseObject("Camera", cameraName);
98     
99     if (!strcmp(viewMode, "ViewNormal"))
100     {
101         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewNormal);
102     }
103     else if (!strcmp(viewMode, "ViewTop"))
104     {
105         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewTop);
106     }
107     else if (!strcmp(viewMode, "ViewBehind"))
108     {
109         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewBehind);
110     }
111     else if (!strcmp(viewMode, "ViewFront"))
112     {
113         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewFront);
114     }
115     else if (!strcmp(viewMode, "ViewLeft"))
116     {
117         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewLeft);
118     }
119     else if (!strcmp(viewMode, "ViewRight"))
120     {
121         dynamic_cast<Camera*>(newCam)->setViewMode(Camera::ViewRight);
122     }
123}*/
124
125void CameraMan::setRelCameraCoor(const std::string& camName, float x, float y, float z)
126{
127     BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName);
128     dynamic_cast<Camera*>(newCam)->setRelCoor(x,y,z);
129     dynamic_cast<Camera*>(newCam)->target->setRelCoor(0,0,0);
130}
131
132void CameraMan::setRelCameraCoorSoft(const std::string& camName, float x, float y, float z, float bias)
133{
134     BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName);
135     dynamic_cast<Camera*>(newCam)->setRelCoorSoft(x,y,z,bias);
136     dynamic_cast<Camera*>(newCam)->target->setRelCoorSoft(0,0,0,bias);
137}
138
139void CameraMan::pauseCamera(const std::string& camName, bool stop)
140{
141     BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName);
142     dynamic_cast<Camera*>(newCam)->pauseTrack(stop);
143}
144
145void CameraMan::setCam(unsigned int cameraNo)
146{
147  if (cameraNo<cameras.size())
148  {
149    this->setCam( cameras[cameraNo]);
150  }
151}
152
153void CameraMan::setCam(const std::string& camName)
154{
155  BaseObject* object = ObjectListBase::getBaseObject("Camera", camName);
156
157  if(object != NULL)
158  {
159    this->setCam(dynamic_cast<Camera*>(object));
160    return;
161  }
162  printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", camName.c_str());
163}
164
165
166void CameraMan::setCam(Camera* camera)
167{
168  if( camera == NULL)
169  {
170    PRINTF(0)("trying to add a zero camera! uiuiui!\n");
171    return;
172  }
173 
174  this->currentCam = camera;
175
176  State::setCamera(currentCam, currentCam->getTarget());
177  OrxSound::SoundEngine::getInstance()->setListener(currentCam);
178
179  // check if it is already added
180  if( ! this->cameraIsInVector(currentCam) )
181    this->cameras.push_back(currentCam);
182
183  this->fadeToBlack->setRelCoor(0., 0., 0.);
184  this->fadeToBlack->setParent(this->currentCam);
185}
186
187
188void CameraMan::moveCurrCam(int x, int y, int z)
189{
190  currentCam->target->trans(x,y,z);
191}
192
193
194void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName)
195{
196  BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
197  if( object != NULL && object->isA(PNode::staticClassID()))
198  {
199    currentCam->lookAt(dynamic_cast<PNode*>(object));
200    State::setCamera(this->currentCam,  dynamic_cast<CameraTarget*>(object));
201  }
202}
203
204
205void CameraMan::atachCurrCameraToWorldEntity(const std::string& className, const std::string& targetEntity)
206{
207  BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity);
208
209  if(object != NULL && object->isA(PNode::staticClassID()))
210  {
211   this->atachTarget(this->currentCam, dynamic_cast<PNode*>(object));
212   return;
213  }
214
215printf("ERROR CAMERAMANAGER: Couldn't set camera to: %s %s \n", className.c_str(),targetEntity.c_str() );
216}
217
218
219
220void CameraMan::detachCurrCamera()
221{
222  currentCam->target->detach();
223}
224
225
226
227void CameraMan::jumpCurrCam(float x, float y, float z)
228{
229  currentCam->target->jump(x, y, z);
230}
231
232void CameraMan::togglFade()
233{
234  if( this->fadeToBlack)
235    fadeToBlack->toggleFade();
236}
237
238
239void CameraMan::initFadeBlack()
240{
241  if( this->fadeToBlack)
242    fadeToBlack->initFadeBlack();
243}
244
245
246void CameraMan::moveCam(int x, int y, int z, int camNo)
247{
248  cameras[camNo]->target->trans(x,y,z);
249}
250
251
252void CameraMan::changeTarget(int camNo,const std::string& className, const std::string& objectName)
253{
254  BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
255  if( object != NULL && object->isA(PNode::staticClassID()))
256  {
257    cameras[camNo]->lookAt(dynamic_cast<PNode*>(object));
258  }
259}
260
261
262void CameraMan::changeTarget(const std::string& camName,const std::string& className, const std::string& objectName)
263{
264  BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
265  BaseObject* newCam = ObjectListBase::getBaseObject("Camera", camName);
266  if( object != NULL && newCam != NULL && object->isA(PNode::staticClassID()))
267  {
268    dynamic_cast<Camera*>(newCam)->lookAt(dynamic_cast<PNode*>(object));
269    State::setCamera( dynamic_cast<Camera*>(newCam),  dynamic_cast<CameraTarget*>(object));
270  }
271}
272
273
274void CameraMan::atachCameraToWorldEntity(const std::string& cameraName, const std::string& className, const std::string& targetEntity)
275{
276  BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity);
277  BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName);
278
279  if( object != NULL && targetCam != NULL && object->isA(PNode::staticClassID()) )
280  {
281    this->atachTarget(dynamic_cast<Camera*>(targetCam), dynamic_cast<PNode*>( object ));
282    return;
283  }
284
285  printf("ERROR CAMERAMANAGER: Couldn't set camera %s to: %s %s \n", cameraName.c_str(), className.c_str(),targetEntity.c_str() );
286}
287
288
289
290void CameraMan::jumpCam(int x, int y, int z, int camNo)
291{
292  cameras[camNo]->target->jump(x, y, z);
293}
294
295
296void CameraMan::jumpCam(const std::string& cameraName, float x, float y, float z)
297{
298  BaseObject* targetCam = ObjectListBase::getBaseObject("Camera", cameraName);
299  if( targetCam != NULL )
300  {
301    dynamic_cast<Camera*>(targetCam)->target->jump( x, y, z );
302  }
303
304}
305
306
307void CameraMan::setClipRegion(float nearCli, float farCli)
308{
309  this->nearClip=nearCli;
310  this->farClip=farCli;
311
312  for(unsigned int i = 0; i < this->cameras.size(); i++)
313    cameras[i]->setClipRegion(nearCli, farCli);
314}
315
316
317
318bool CameraMan::cameraIsInVector(Camera* camera)
319{
320
321  for(std::vector<Camera*>::const_iterator it = cameras.begin(); it != cameras.end(); it++ )
322  {
323    if( (*it) == camera)
324    {
325      return true;
326    }
327  }
328  return false;
329
330
331}
332
333
334void CameraMan::cameraInfo()
335{
336  bool sameCam = (this->currentCam == State::getCamera());
337
338
339  PRINT(0)("==== CameraMan::cameraInfo ===\n");
340  PRINT(0)("=  Camera Name: %s\n", this->currentCam->getName().c_str());
341  PRINT(0)("=  Tests:\n");
342  PRINT(0)("==  State::Cam == this::Cam  %i\n", sameCam);
343  PRINT(0)("==  Parenting Informations:\n");
344  this->currentCam->debugNode(10);
345  PRINT(0)("==============================\n");
346}
347
348
349float CameraMan::getCurrCameraCoorX()
350{ return this->currentCam->getAbsCoorX(); }
351
352float CameraMan::getCurrCameraCoorY()
353{ return this->currentCam->getAbsCoorY(); }
354
355float CameraMan::getCurrCameraCoorZ()
356{ return this->currentCam->getAbsCoorZ(); }
357
358
359
360void CameraMan::atachTarget(Camera* cam ,PNode* target)
361{
362  cam->target->atach(target);
363  cam->setViewMode(Camera::ViewNormal);
364  State::setCamera( cam,  dynamic_cast<CameraTarget*>(target));
365
366}
367
368//how to get a class fkt pointer
369
370//BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
371
372
373
374
375
376
377
378
379
380
381
382
383
384
Note: See TracBrowser for help on using the repository browser.