Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10464 was 10463, checked in by patrick, 18 years ago

camera stuff

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