Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10712 was 10618, checked in by bknecht, 18 years ago

merged cleanup into trunk (only improvements)

File size: 10.5 KB
RevLine 
[10593]1/*
[10406]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 "cameraman.h"
[10593]17#include "blackscreen.h"
18#include "loading/load_param_xml.h"
[10406]19#include "sound_engine.h"
20#include "script_class.h"
21
22ObjectListDefinition(CameraMan);
23
24CREATE_SCRIPTABLE_CLASS(CameraMan,
[10593]25                        /// Camera management
26                        addMethod("changeTarget", Executor3<CameraMan, lua_State*, const std::string&, const std::string&,const std::string&>(&CameraMan::changeTarget))
27                        ->addMethod("attachCamera", Executor3<CameraMan, lua_State*,const std::string&,const std::string&,const std::string&>(&CameraMan::attachCamera))
28                        ->addMethod("jumpCam", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::jumpCam))
29                        ->addMethod("moveCam", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::moveCam))
30                        ->addMethod("setRelCoor", Executor4<CameraMan, lua_State*,const std::string&,float,float,float>(&CameraMan::setRelCameraCoor))
31                        ->addMethod("setRelCoorSoft", Executor5<CameraMan, lua_State*,const std::string&,float,float,float,float>(&CameraMan::setRelCameraCoorSoft))
32                        ->addMethod("setCam", Executor1<CameraMan, lua_State*, const std::string&>(&CameraMan::setCam))
33                        /// Current Camera
34                        ->addMethod("changeCurrTarget", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::changeCurrTarget))
35                        ->addMethod("attachCurrCamera", Executor2<CameraMan, lua_State*,const std::string&,const std::string&>(&CameraMan::attachCurrCamera))
36                        ->addMethod("jumpCurrCam", Executor3<CameraMan, lua_State*,float,float,float>(&CameraMan::jumpCurrCam))
37                        ->addMethod("moveCurrCam", Executor3<CameraMan, lua_State*,float,float,float>(&CameraMan::moveCurrCam))
38                        /// Fading
[10428]39                        ->addMethod("toggleFade", Executor0<CameraMan, lua_State*>(&CameraMan::togglFade))
[10424]40                        ->addMethod("initFadeBlack", Executor0<CameraMan, lua_State*>(&CameraMan::initFadeBlack))
[10593]41                        /// Polling
[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))
[10596]45                        ->addMethod("getCurrCamName", Executor0ret<CameraMan, lua_State*,const std::string&>(&CameraMan::getCurrCamName))
[10406]46                       );
47
48
[10593]49
50/**
[10596]51 * Constructor of the CameraManager
[10593]52 */
[10406]53CameraMan::CameraMan(const TiXmlElement* root)
54{
55  this->registerObject(this, CameraMan::_objectList);
56
57  this->nearClip = 1.0;
58  this->farClip = 1000.0;
59
60  this->fadeToBlack=new BlackScreen();
61
[10593]62  this->setCam( State::getCamera() );
[10406]63
64  if (root != NULL)
65    this->loadParams(root);
66}
67
[10593]68/**
69 *  Loads the parameters of the CameraManager from the xml file
70 * @param root reference to the xml root element
71 */
[10406]72void CameraMan::loadParams(const TiXmlElement* root)
73{
74  BaseObject::loadParams(root);
[10414]75  LoadParamXML(root, "Cameras", this, CameraMan, createCameras);
76}
77
[10593]78/**
79 *  Creates all the Cameras
80 * @param root reference to the xml root element
81 */
[10414]82void CameraMan::createCameras(const TiXmlElement* camerasTag)
83{
[10411]84    LOAD_PARAM_START_CYCLE(camerasTag, object);
85    {
86      this->createCam(object);
87    }
88    LOAD_PARAM_END_CYCLE(object);
[10406]89}
90
[10593]91/**
92 *  Creates a Camera from a xml node
93 * @param root reference to the xml node
94 */
[10406]95void CameraMan::createCam(const TiXmlElement* root)
96{
[10593]97  Camera* newCam = new Camera(root);
98  newCam->setClipRegion(nearClip, farClip);
[10406]99}
100
[10593]101/**
102 *  Changes the target of a camera. (where the camera looks at)
103 *
104 * @param cameraName the name of the camera whose target is changed
105 * @param className the class of the new target
106 * @param objectName the name of the new target
107 */
108void CameraMan::changeTarget(const std::string& cameraName,const std::string& className, const std::string& objectName)
[10495]109{
[10593]110  BaseObject* object = ObjectListBase::getBaseObject(className, objectName);
111  Camera* camera = Camera::objectList().getObject(cameraName);
[10480]112
[10593]113  if( object != NULL && camera != NULL && object->isA(PNode::staticClassID()))
[10406]114  {
[10593]115    camera->lookAt(dynamic_cast<PNode*>(object));
116    return;
[10406]117  }
118
[10593]119 printf("ERROR CAMERAMANAGER: Couldn't change target for camera %s to: %s %s \n", cameraName.c_str(), className.c_str(),objectName.c_str() );
[10406]120
121}
122
[10593]123/**
124 *  Attaches a camera to a new pnode. (the camera follows the pnode)
125 *
126 * @param cameraName the name of the camera
127 * @param className the class of the new parent node
128 * @param objectName the name of the new parent node
129 */
130void CameraMan::attachCamera(const std::string& cameraName, const std::string& className, const std::string& targetEntity)
131{
132  BaseObject* object = ObjectListBase::getBaseObject(className, targetEntity);
133  Camera* camera = Camera::objectList().getObject(cameraName);
[10406]134
[10593]135  if( object != NULL && camera != NULL && object->isA(PNode::staticClassID()) )
[10406]136  {
[10593]137    camera->target->atach(dynamic_cast<PNode*>(object));
138    camera->setViewMode(Camera::ViewNormal);
[10480]139    return;
[10406]140  }
141
[10593]142  printf("ERROR CAMERAMANAGER: Couldn't attach camera %s to: %s %s \n", cameraName.c_str(), className.c_str(),targetEntity.c_str() );
[10406]143
144}
145
146
[10593]147/**
148 *  Sets a camera to a new position
149 *
150 * @param cameraName the name of the camera
151 * @param x the new x coordinate
152 * @param y the new y coordinate
153 * @param z the new z coordinate
154 */
155void CameraMan::jumpCam(const std::string& cameraName, float x, float y, float z)
[10406]156{
[10593]157  Camera* camera = Camera::objectList().getObject(cameraName);
158  if( camera != NULL )
[10463]159  {
[10593]160    camera->target->jump( x, y, z );
[10463]161  }
[10406]162}
163
[10593]164/**
165 *  Moves a camera slowly to a new position
166 *
167 * @param cameraName the name of the camera
168 * @param x the new x coordinate
169 * @param y the new y coordinate
170 * @param z the new z coordinate
171 */
172void CameraMan::moveCam(const std::string& cameraName, float x, float y, float z)
[10406]173{
[10593]174  Camera* camera = Camera::objectList().getObject(cameraName);
175  if( camera != NULL )
[10408]176  {
[10593]177    camera->target->trans( x, y, z );
[10408]178  }
[10406]179}
180
[10593]181/**
182 *  Sets the coordinate of a camera relative to its target.
183 *
184 * @param cameraName the name of the camera
185 * @param x the new x coordinate
186 * @param y the new y coordinate
187 * @param z the new z coordinate
188 */
189void CameraMan::setRelCameraCoor(const std::string& cameraName, float x, float y, float z)
[10416]190{
[10593]191  Camera* camera = Camera::objectList().getObject(cameraName);
192  camera->setRelCoor(x,y,z);
193  camera->target->setRelCoor(0,0,0);
[10480]194}
[10416]195
[10593]196/**
197 *  Sets the coordinate of a camera relative to its target. (softly)
198 *
199 * @param cameraName the name of the camera
200 * @param x the new x coordinate
201 * @param y the new y coordinate
202 * @param z the new z coordinate
203 */
204void CameraMan::setRelCameraCoorSoft(const std::string& cameraName, float x, float y, float z, float bias)
[10480]205{
[10593]206  Camera* newCam = Camera::objectList().getObject(cameraName);
207  newCam->setRelCoor(x,y,z);
208  newCam->target->setRelCoorSoft(0,0,0);
[10416]209}
210
[10593]211/**
212 *  Sets a new camera as the current one.
213 *
214 * @param cameraName the name of the new camera
215 */
216void CameraMan::setCam(const std::string& cameraName)
[10480]217{
[10593]218  Camera* camera = Camera::objectList().getObject(cameraName);
[10416]219
[10593]220  if(camera != NULL)
221  {
222    this->setCam(camera);
223    return;
224  }
225  printf("ERROR CAMERAMANAGER: Couldn't set camera : %s \n", cameraName.c_str());
[10413]226}
[10406]227
[10593]228/**
229 *  Sets a new camera as the current one.
230 *
231 * @param camera a pointer to the new camera
232 */
233void CameraMan::setCam(Camera* newCamera)
[10406]234{
[10593]235  if( newCamera == NULL)
[10480]236  {
[10593]237    PRINTF(0)("trying to add a zero camera! uiuiui!\n");
238    return;
[10480]239  }
[10593]240 
241  State::setCamera(newCamera, newCamera->getTarget());
242  OrxSound::SoundEngine::getInstance()->setListener(newCamera);
[10406]243
[10593]244  this->fadeToBlack->setRelCoor(0., 0., 0.);
245  this->fadeToBlack->setParent(newCamera);
[10480]246
[10406]247}
248
[10593]249/**
250 *  Sets the clipregion of all the cameras
251 *
252 * @param nearClip the new near clip
253 * @param nearClip the new far clip
254 */
255void CameraMan::setClipRegion(float nearClip, float farClip)
[10406]256{
[10593]257  this->nearClip=nearClip;
258  this->farClip=farClip;
[10480]259
[10593]260  for (ObjectList<Camera>::const_iterator it = Camera::objectList().begin();
261       it != Camera::objectList().end();
262       ++it)
[10480]263  {
[10593]264     (*it)->setClipRegion(this->nearClip, this->farClip);
[10480]265  }
[10406]266}
267
[10593]268/**
269 *  Changes the target of the current camera. (where the camera looks at)
270 *
271 * @param className the class of the new target
272 * @param objectName the name of the new target
273 */
274void CameraMan::changeCurrTarget(const std::string& className, const std::string& objectName)
[10406]275{
[10593]276  this->changeTarget( (State::getCamera())->getName() , className, objectName);
[10406]277}
278
[10593]279/**
280 *  Attaches the current camera to a new pnode. (the camera follows the pnode)
281 *
282 * @param className the class of the new parent node
283 * @param objectName the name of the new parent node
284 */
285void CameraMan::attachCurrCamera(const std::string& className, const std::string& targetEntity)
[10483]286{
[10593]287  this->attachCamera( (State::getCamera())->getName(), className,  targetEntity);
[10483]288}
289
[10593]290/**
291 *  Sets the current camera to a new position
292 *
293 * @param x the new x coordinate
294 * @param y the new y coordinate
295 * @param z the new z coordinate
296 */
297void CameraMan::jumpCurrCam(float x, float y, float z)
[10424]298{
[10593]299  this->jumpCam((State::getCamera())->getName(), x, y, z);
[10424]300}
[10406]301
[10593]302/**
303 *  Moves the current camera slowly to a new position
304 *
305 * @param x the new x coordinate
306 * @param y the new y coordinate
307 * @param z the new z coordinate
308 */
309void CameraMan::moveCurrCam(float x, float y, float z)
[10406]310{
[10593]311  this->moveCam( (State::getCamera())->getName(), x, y, z);
[10406]312}
313
[10593]314/**
315 *  Toggles the fadestate (from in to out and via versa)
316 */
317void CameraMan::togglFade()
[10406]318{
[10593]319 if( this->fadeToBlack)
320    fadeToBlack->toggleFade();
[10406]321}
322
[10593]323/**
324 *  Sets the fadestate immediately to black (fade out)
325 */
326void CameraMan::initFadeBlack()
[10482]327{
[10593]328  if( this->fadeToBlack)
329    fadeToBlack->initFadeBlack();
[10482]330}
Note: See TracBrowser for help on using the repository browser.