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