source: trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h @ 27

Revision 27, 5.4 KB checked in by gametools, 19 years ago (diff)
Line 
1/**
2    \file
3        TestCullingApplication.h
4*/
5#include "CEGUIForwardRefs.h"
6#include "ExampleApplication.h"
7#include "OgreOcclusionCullingSceneManager.h"
8
9class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener
10{
11public:
12
13    MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer,
14                                           SceneNode* shipNode)
15        : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShipNode(shipNode),  mShutdownRequested(false)
16    {
17
18                // Setup default variables
19        mCurrentObject = NULL;
20        mLMouseDown = false;
21        mRMouseDown = false;
22        mSceneMgr = sceneManager;
23
24        // Reduce move speed
25        mMoveSpeed = 50;
26        mRotateSpeed *= 2;
27       
28                mAlgorithmType = OcclusionCullingSceneManager::RENDER_COHERENT;
29
30                //mMyOverlay = OverlayManager::getSingleton().getByName("scripts/MyPanel");
31                mMyOverlay = OverlayManager::getSingleton().getByName("Core/MyPanel");
32
33                //mDebugOverlay->hide();
34                //mMyOverlay->show();
35                // Register this so that we get mouse events.
36        mEventProcessor->addMouseListener(this);
37        mEventProcessor->addMouseMotionListener(this);
38                mEventProcessor->addKeyListener(this);
39    } // MouseQueryListener
40
41    ~MouseQueryListener( )
42    {
43    }
44
45        void myShowOverlay(bool show)
46        {
47                if (mDebugOverlay)
48        {
49            if (show)
50            {
51                mDebugOverlay->show();
52            }
53            else
54            {
55                mDebugOverlay->hide();
56            }
57        }
58                if(mMyOverlay)
59                {
60                        mMyOverlay->show();
61                }
62
63        }
64    bool frameStarted(const FrameEvent &evt)
65    {
66        /*    Real MoveFactor = 80.0 * evt.timeSinceLastFrame;
67 
68                mInputDevice->capture();
69 
70                if(mInputDevice->isKeyDown(Ogre::KC_UP))
71                {
72                        mAlgorithmType = (mAlgorithmType + 1) % OcclusionCullingSceneManager::NUM_RENDERMODES;
73                        //mShipNode->translate(0.0, MoveFactor, 0.0);
74                }
75 
76                if(mInputDevice->isKeyDown(Ogre::KC_DOWN))
77                        mShipNode->translate(0.0, -MoveFactor, 0.0);
78 
79                if(mInputDevice->isKeyDown(Ogre::KC_LEFT))
80                        mShipNode->translate(-MoveFactor, 0.0, 0.0);
81 
82                if(mInputDevice->isKeyDown(Ogre::KC_RIGHT))
83                        mShipNode->translate(MoveFactor, 0.0, 0.0);             
84 
85                if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE))
86                        return false;*/
87
88                if(mInputDevice->isKeyDown(Ogre::KC_L))
89                        myShowOverlay(false);
90
91                return ExampleFrameListener::frameStarted(evt);
92    }
93
94    /* MouseListener callbacks. */
95    virtual void mouseClicked(MouseEvent* e) { }
96    virtual void mouseEntered(MouseEvent* e) { }
97    virtual void mouseExited(MouseEvent* e)  { }
98
99    // This is when the mouse button goes DOWN.
100    virtual void mousePressed(MouseEvent* e);
101
102    // This is when the mouse button is let UP.
103    virtual void mouseReleased(MouseEvent* e);
104
105    /* MouseMotionListener callbacks */
106    virtual void mouseMoved (MouseEvent *e);
107   
108    // This is when the mouse is clicked, held and dragged.
109    virtual void mouseDragged (MouseEvent *e);
110
111    void keyPressed(KeyEvent* e)
112    {
113        if(e->getKey() == KC_ESCAPE)
114        {
115            mShutdownRequested = true;
116            e->consume();
117            return;
118        }
119
120        CEGUI::System::getSingleton().injectKeyDown(e->getKey());
121                CEGUI::System::getSingleton().injectChar(e->getKeyChar());
122        e->consume();
123    }
124
125        void keyReleased(KeyEvent* e)
126        {
127                CEGUI::System::getSingleton().injectKeyUp(e->getKey());
128                e->consume();
129        }
130        void keyClicked(KeyEvent* e)
131        {
132                // Do nothing
133                e->consume();
134        }
135
136          bool frameEnded(const FrameEvent& evt)
137    {
138        if (mShutdownRequested)
139            return false;
140        else
141            return ExampleFrameListener::frameEnded(evt);
142    }
143
144        void setAlgorithmType(int type) { mAlgorithmType = type; }
145        int getAlgorithmType() { return mAlgorithmType; }
146
147protected:
148    bool mLMouseDown, mRMouseDown;     // True if the mouse buttons are down
149    SceneManager *mSceneMgr;           // A pointer to the scene manager
150    SceneNode *mCurrentObject;         // The newly created object
151    CEGUI::Renderer *mGUIRenderer;     // cegui renderer
152        SceneNode* mShipNode;
153        bool mShutdownRequested;
154        int mAlgorithmType;
155        Overlay *mMyOverlay;
156};
157
158
159class TestCullingApplication : public ExampleApplication
160{
161public:
162    /*TestCullingApplication()
163    {
164
165    }*/
166
167protected:
168        void createScene(void);
169
170        void createFrameListener(void)
171    {
172                mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mShipNode);
173                mFrameListener->showDebugOverlay(true);
174                mRoot->addFrameListener(mFrameListener);
175    }
176
177        CEGUI::OgreCEGUIRenderer *mGUIRenderer;
178        CEGUI::System *mGUISystem;
179
180private:
181        Entity* mShip;
182        SceneNode* mShipNode;
183
184/*    String mQuakePk3;
185    String mQuakeLevel;
186
187    // Override resource sources (include Quake3 archives)
188    void setupResources(void)
189    {
190
191        // Load Quake3 locations from a file
192        ConfigFile cf;
193
194        cf.load("quake3settings.cfg");
195
196        mQuakePk3 = cf.getSetting("Pak0Location");
197        mQuakeLevel = cf.getSetting("Map");
198
199                ExampleApplication::setupResources();
200        ResourceManager::addCommonArchiveEx(mQuakePk3, "Zip");
201
202    }*/
203    // Override scene manager (use indoor instead of generic)
204    void chooseSceneManager(void)
205    {
206        mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
207    }
208       
209};
210
Note: See TracBrowser for help on using the repository browser.