Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7966 for code


Ignore:
Timestamp:
Feb 26, 2011, 5:00:17 PM (14 years ago)
Author:
landauf
Message:

some changes related to camera switching:

  • added ViewportEventListener (currently only listens to camera changes in a viewport)
  • Shader now correctly updates its visibility if the camera changes the scene
  • (the same lines of code also fix the weird Ogre behavior which was originally fixed in CameraManager)
  • GraphicsManager also updates the GUIManager's camera
  • if all cameras are destroyed, CameraManager now officially switches to NULL camera
Location:
code/branches/usability/src
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/usability/src/libraries/core/CMakeLists.txt

    r7284 r7966  
    3535  OrxonoxClass.cc
    3636  Resource.cc
    37   WindowEventListener.cc
    3837
    3938  # hierarchy
     
    4948  Template.cc
    5049  XMLPort.cc
     50
     51COMPILATION_BEGIN ListenerCompilation.cc
     52  ViewportEventListener.cc
     53  WindowEventListener.cc
    5154  XMLNameListener.cc
     55COMPILATION_END
    5256
    5357COMPILATION_BEGIN FilesystemCompilation.cc
  • code/branches/usability/src/libraries/core/CorePrereqs.h

    r7849 r7966  
    182182    class Thread;
    183183    class ThreadPool;
     184    class ViewportEventListener;
    184185    template <class T>
    185186    class WeakPtr;
  • code/branches/usability/src/libraries/core/GraphicsManager.cc

    r7874 r7966  
    5757#include "Game.h"
    5858#include "GameMode.h"
     59#include "GUIManager.h"
    5960#include "Loader.h"
    6061#include "MemoryArchive.h"
    6162#include "PathConfig.h"
     63#include "ViewportEventListener.h"
    6264#include "WindowEventListener.h"
    6365#include "XMLFile.h"
     
    381383    void GraphicsManager::setCamera(Ogre::Camera* camera)
    382384    {
     385        Ogre::Camera* oldCamera = this->viewport_->getCamera();
     386
    383387        this->viewport_->setCamera(camera);
     388        GUIManager::getInstance().setCamera(camera);
     389
     390        for (ObjectList<ViewportEventListener>::iterator it = ObjectList<ViewportEventListener>::begin(); it != ObjectList<ViewportEventListener>::end(); ++it)
     391            it->cameraChanged(this->viewport_, oldCamera);
    384392    }
    385393
  • code/branches/usability/src/libraries/tools/Shader.cc

    r6417 r7966  
    5656        this->bVisible_ = true;
    5757        this->bLoadCompositor_ = GameMode::showsGraphics();
    58         this->bViewportInitialized_ = false;
     58        this->bViewportInitialized_ = true;
    5959
    6060        if (this->bLoadCompositor_ && Ogre::Root::getSingletonPtr())
     
    8989    {
    9090        this->scenemanager_ = scenemanager;
    91         this->bViewportInitialized_ = false;
    92     }
    93 
     91//        this->bViewportInitialized_ = false;
     92    }
     93
     94    void Shader::cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera)
     95    {
     96        if (!this->scenemanager_ || (viewport != this->scenemanager_->getCurrentViewport() && this->scenemanager_->getCurrentViewport() != NULL))
     97            return;
     98
     99        // update compositor in viewport (shader should only be active if the current camera is in the same scene as the shader)
     100
     101        // Note:
     102        // The shader needs also to be switched off and on after changing the camera in the
     103        // same scene to avoid weird behaviour with active compositors while switching the
     104        // camera (like freezing the image)
     105        //
     106        // Last known Ogre version needing this workaround:
     107        // 1.4.8
     108        // 1.7.2
     109
     110
     111        if (oldCamera && this->scenemanager_ == oldCamera->getSceneManager())
     112            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, false);
     113
     114        if (viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager())
     115            Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->isVisible());
     116    }
     117/*
    94118    void Shader::tick(float dt)
    95119    {
     
    102126        }
    103127    }
    104 
     128*/
    105129    void Shader::changedCompositor()
    106130    {
     
    119143                if (!this->compositorInstance_)
    120144                    COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositor_ << "\"." << std::endl;
    121                 Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible());
     145                //Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible());
    122146            }
    123147            this->oldcompositor_ = this->compositor_;
  • code/branches/usability/src/libraries/tools/Shader.h

    r5781 r7966  
    3737
    3838#include "util/OgreForwardRefs.h"
    39 #include "tools/interfaces/Tickable.h"
     39#include "core/ViewportEventListener.h"
    4040
    4141namespace orxonox
    4242{
    43     class _ToolsExport Shader : public Tickable
     43    class _ToolsExport Shader : public ViewportEventListener
    4444    {
    4545        typedef std::pair<bool, void*>                  ParameterPointer;
     
    5252            Shader(Ogre::SceneManager* scenemanager = 0);
    5353            virtual ~Shader();
    54 
    55             virtual void tick(float dt);
    5654
    5755            inline void setVisible(bool bVisible)
     
    8381                { return this->scenemanager_; }
    8482
     83            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
     84
    8585            void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
    8686            void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
  • code/branches/usability/src/orxonox/CameraManager.cc

    r7879 r7966  
    2929#include "CameraManager.h"
    3030
     31#include <cassert>
     32
    3133#include <OgreSceneManager.h>
    3234#include <OgreViewport.h>
    3335#include <OgreCompositorManager.h>
    3436
    35 #include "util/StringUtils.h"
    3637#include "util/ScopedSingletonManager.h"
    3738#include "core/GameMode.h"
    3839#include "core/GraphicsManager.h"
    39 #include "core/GUIManager.h"
    4040#include "core/ObjectList.h"
    4141#include "tools/Shader.h"
    4242#include "graphics/Camera.h"
    43 #include "Scene.h"
    4443
    4544namespace orxonox
     
    4847
    4948    CameraManager::CameraManager()
    50         : viewport_(GraphicsManager::getInstance().getViewport())
    5149    {
    5250        assert(GameMode::showsGraphics());
     
    5553    CameraManager::~CameraManager()
    5654    {
    57         GUIManager::getInstance().setCamera(0);
    5855    }
    5956
     
    9592            if (!this->cameraList_.empty())
    9693                this->cameraList_.front()->setFocus();
     94            else
     95                this->useCamera(NULL);
    9796        }
    9897        else
     
    102101    void CameraManager::useCamera(Ogre::Camera* camera)
    103102    {
    104         // This workaround is needed to avoid weird behaviour with active compositors while
    105         // switching the camera (like freezing the image)
    106         //
    107         // Last known Ogre version needing this workaround:
    108         // 1.4.8
    109         // 1.7.2
    110 
    111         // deactivate all compositors
    112         {
    113             Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
    114             while (iterator.hasMoreElements())
    115                 Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
    116         }
    117 
    118         this->viewport_->setCamera(camera);
    119         GUIManager::getInstance().setCamera(camera);
    120 
    121         // reactivate all visible compositors
    122         {
    123             for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
    124                 it->updateVisibility();
    125         }
     103        GraphicsManager::getInstance().setCamera(camera);
    126104    }
    127105}
  • code/branches/usability/src/orxonox/CameraManager.h

    r6746 r7966  
    3838#include "OrxonoxPrereqs.h"
    3939
    40 #include <cassert>
    4140#include <list>
    4241#include "util/OgreForwardRefs.h"
    4342#include "util/Singleton.h"
    4443#include "core/OrxonoxClass.h"
    45 #include "core/SmartPtr.h"
    4644
    4745namespace orxonox
     
    6563
    6664            std::list<Camera*>    cameraList_;
    67             Ogre::Viewport*       viewport_;
    6865
    6966            static CameraManager* singletonPtr_s;
  • code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc

    r7876 r7966  
    9696    {
    9797        // show main menu
     98        GraphicsManager::getInstance().setCamera(this->camera_);
    9899        GUIManager::getInstance().showGUI("MainMenu", true);
    99         GUIManager::getInstance().setCamera(this->camera_);
    100100        GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
    101         GraphicsManager::getInstance().setCamera(this->camera_);
    102101
    103102        InputManager::getInstance().enterState("MainMenuHackery");
     
    129128        InputManager::getInstance().leaveState("MainMenuHackery");
    130129
    131         GUIManager::getInstance().setCamera(0);
     130        GraphicsManager::getInstance().setCamera(0);
    132131        GUIManager::getInstance().setBackgroundImage("");
    133132        GUIManager::hideGUI("MainMenu");
    134         GraphicsManager::getInstance().setCamera(0);
    135133
    136134        ModifyConsoleCommand(__CC_startStandalone_name).deactivate();
  • code/branches/usability/src/orxonox/graphics/Camera.cc

    r7163 r7966  
    8282        if (this->isInitialized())
    8383        {
    84             if (GUIManager::getInstance().getCamera() == this->camera_)
    85                 GUIManager::getInstance().setCamera(NULL);
    8684            this->releaseFocus();
    8785
Note: See TracChangeset for help on using the changeset viewer.