Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 27, 2008, 4:08:51 AM (16 years ago)
Author:
landauf
Message:

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/CameraHandler.cc

    r2006 r2019  
    3333
    3434#include "core/ObjectList.h"
     35#include "core/Core.h"
    3536#include "Camera.h"
    3637#include "GraphicsEngine.h"
     
    3839#include <OgreCamera.h>
    3940
    40 namespace orxonox {
     41namespace orxonox
     42{
     43    CameraHandler::CameraHandler()
     44    {
     45//        GraphicsEngine::getInstance().getViewport()->setCamera(this->cam_);
     46    }
    4147
    42   CameraHandler* CameraHandler::singletonRef = NULL;
     48    CameraHandler& CameraHandler::getInstance()
     49    {
     50        static CameraHandler instance;
     51        return instance;
     52    }
    4353
    44   CameraHandler::CameraHandler()
    45   {
    46     this->cam_ = GraphicsEngine::getInstance().getLevelSceneManager()->createCamera("Cam");
    47     GraphicsEngine::getInstance().getViewport()->setCamera(this->cam_);
    48     this->cam_->setNearClipDistance(1);
    49     //GraphicsEngine::getInstance().getRenderWindow()->addViewport(this->cam_, 2, 0.4, 0.4, 0.2, 0.2);
    50     /*this->activeCamera_ = *ObjectList<Camera>::begin();
    51     this->activeCamera_->cam_ = this->cam_;*/
    52   }
     54    Camera* CameraHandler::getActiveCamera() const
     55    {
     56        if (this->cameraList_.size() > 0)
     57            return this->cameraList_.front();
     58        else
     59            return 0;
     60    }
    5361
    54   void CameraHandler::requestFocus(Camera* requestCam)
    55   {
    56     // notify old camera (if it exists)
    57     if(focusList_.size() > 0)
    58       focusList_.back()->removeFocus();
    59     // add to list
    60     focusList_.push_back(requestCam);
    61     // set focus to new camera and update (if necessary)
    62     if(!requestCam->hasFocus()) {
    63       requestCam->setFocus(this->cam_);
    64       requestCam->update();
     62    void CameraHandler::requestFocus(Camera* camera)
     63    {
     64        if (!Core::showsGraphics())
     65            return;
     66
     67        // notify old camera (if it exists)
     68        if (this->cameraList_.size() > 0)
     69            this->cameraList_.front()->removeFocus();
     70
     71        // add to list
     72        this->cameraList_.push_front(camera);
     73        camera->setFocus(GraphicsEngine::getInstance().getViewport());
    6574    }
    66     // delete dublicates
    67     focusList_.unique();
    68   }
    6975
    70   void CameraHandler::releaseFocus(Camera* cam)
    71   {
    72     // notify the cam of releasing the focus
    73     if(cam->hasFocus())
    74       cam->removeFocus();
    75     // delete camera from list
    76     focusList_.remove(cam);
    77     // set new focus if necessary
    78     if(focusList_.size() > 0 && !(focusList_.back()->hasFocus()))
    79       focusList_.back()->setFocus(this->cam_);
    80   }
    81 /*
    82   void CameraHandler::changeActiveCamera(Camera* setCam)
    83   {
    84     cam_->getParentSceneNode()->detachObject(cam_);
    85     //setCam->attachCamera(cam_);
    86     activeCamera_ = setCam;
    87   }
    88 */
    89 /*  bool isInVector(Camera* cam)
    90   {
    91     for(std::vector<Camera*>::iterator it = cams_.begin(); it != cams_.end(); it++)
     76    void CameraHandler::releaseFocus(Camera* camera)
    9277    {
    93       if (*it == cam) return true;
     78        if (!Core::showsGraphics())
     79            return;
     80
     81        // notify the cam of releasing the focus
     82        if (this->cameraList_.front() == camera)
     83        {
     84            camera->removeFocus();
     85            this->cameraList_.pop_front();
     86
     87            // set new focus if necessary
     88            if (cameraList_.size() > 0)
     89                cameraList_.front()->setFocus(GraphicsEngine::getInstance().getViewport());
     90        }
     91        else
     92        {
     93            this->cameraList_.remove(camera);
     94        }
    9495    }
    95     return false;
    96   }*/
    9796}
Note: See TracChangeset for help on using the changeset viewer.