1 | /**
|
---|
2 | \file
|
---|
3 | TestCullingApplication.h
|
---|
4 | */
|
---|
5 | #include "CEGUIForwardRefs.h"
|
---|
6 | #include "ExampleApplication.h"
|
---|
7 |
|
---|
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)
|
---|
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 | // Register this so that we get mouse events.
|
---|
28 | mEventProcessor->addMouseListener( this );
|
---|
29 | mEventProcessor->addMouseMotionListener( this );
|
---|
30 | } // MouseQueryListener
|
---|
31 |
|
---|
32 | ~MouseQueryListener( )
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 | bool frameStarted(const FrameEvent &evt)
|
---|
37 | {
|
---|
38 | return ExampleFrameListener::frameStarted( evt );
|
---|
39 | }
|
---|
40 |
|
---|
41 | /* MouseListener callbacks. */
|
---|
42 | virtual void mouseClicked(MouseEvent* e) { }
|
---|
43 | virtual void mouseEntered(MouseEvent* e) { }
|
---|
44 | virtual void mouseExited(MouseEvent* e) { }
|
---|
45 |
|
---|
46 | // This is when the mouse button goes DOWN.
|
---|
47 | virtual void mousePressed(MouseEvent* e);
|
---|
48 |
|
---|
49 | // This is when the mouse button is let UP.
|
---|
50 | virtual void mouseReleased(MouseEvent* e);
|
---|
51 |
|
---|
52 | /* MouseMotionListener callbacks */
|
---|
53 | virtual void mouseMoved (MouseEvent *e);
|
---|
54 |
|
---|
55 | // This is when the mouse is clicked, held and dragged.
|
---|
56 | virtual void mouseDragged (MouseEvent *e);
|
---|
57 |
|
---|
58 | protected:
|
---|
59 | bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down
|
---|
60 | SceneManager *mSceneMgr; // A pointer to the scene manager
|
---|
61 | SceneNode *mCurrentObject; // The newly created object
|
---|
62 | CEGUI::Renderer *mGUIRenderer; // cegui renderer
|
---|
63 | SceneNode* mShipNode;
|
---|
64 | };
|
---|
65 |
|
---|
66 |
|
---|
67 | class TestCullingFrameListener : public ExampleFrameListener
|
---|
68 | {
|
---|
69 | protected:
|
---|
70 | SceneNode* mShipNode;
|
---|
71 |
|
---|
72 | public:
|
---|
73 | TestCullingFrameListener(RenderWindow* win, Camera* cam, SceneNode* shipNode) : ExampleFrameListener(win, cam)
|
---|
74 | {
|
---|
75 | mShipNode = shipNode;
|
---|
76 | };
|
---|
77 |
|
---|
78 | bool frameStarted(const FrameEvent& evt)
|
---|
79 | {
|
---|
80 | Real MoveFactor = 80.0 * evt.timeSinceLastFrame;
|
---|
81 |
|
---|
82 | mInputDevice->capture();
|
---|
83 |
|
---|
84 | if(mInputDevice->isKeyDown(Ogre::KC_UP))
|
---|
85 | mShipNode->translate(0.0, MoveFactor, 0.0);
|
---|
86 |
|
---|
87 | if(mInputDevice->isKeyDown(Ogre::KC_DOWN))
|
---|
88 | mShipNode->translate(0.0, -MoveFactor, 0.0);
|
---|
89 |
|
---|
90 | if(mInputDevice->isKeyDown(Ogre::KC_LEFT))
|
---|
91 | mShipNode->translate(-MoveFactor, 0.0, 0.0);
|
---|
92 |
|
---|
93 | if(mInputDevice->isKeyDown(Ogre::KC_RIGHT))
|
---|
94 | mShipNode->translate(MoveFactor, 0.0, 0.0);
|
---|
95 |
|
---|
96 | if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE))
|
---|
97 | return false;
|
---|
98 |
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 | };
|
---|
102 |
|
---|
103 | class TestCullingApplication : public ExampleApplication
|
---|
104 | {
|
---|
105 | public:
|
---|
106 | /*TestCullingApplication()
|
---|
107 | {
|
---|
108 |
|
---|
109 |
|
---|
110 | }*/
|
---|
111 |
|
---|
112 | protected:
|
---|
113 | void createScene(void);
|
---|
114 |
|
---|
115 | void createFrameListener(void)
|
---|
116 | {
|
---|
117 | mFrameListener= new MouseQueryListener(mWindow, mCamera, mSceneMgr, mGUIRenderer, mShipNode);
|
---|
118 | mFrameListener->showDebugOverlay(true);
|
---|
119 | mRoot->addFrameListener(mFrameListener);
|
---|
120 | }
|
---|
121 |
|
---|
122 | CEGUI::OgreCEGUIRenderer *mGUIRenderer;
|
---|
123 | CEGUI::System *mGUISystem;
|
---|
124 |
|
---|
125 | private:
|
---|
126 | Entity* mShip;
|
---|
127 | SceneNode* mShipNode;
|
---|
128 |
|
---|
129 | /* String mQuakePk3;
|
---|
130 | String mQuakeLevel;
|
---|
131 |
|
---|
132 | // Override resource sources (include Quake3 archives)
|
---|
133 | void setupResources(void)
|
---|
134 | {
|
---|
135 |
|
---|
136 | // Load Quake3 locations from a file
|
---|
137 | ConfigFile cf;
|
---|
138 |
|
---|
139 | cf.load("quake3settings.cfg");
|
---|
140 |
|
---|
141 | mQuakePk3 = cf.getSetting("Pak0Location");
|
---|
142 | mQuakeLevel = cf.getSetting("Map");
|
---|
143 |
|
---|
144 | ExampleApplication::setupResources();
|
---|
145 | ResourceManager::addCommonArchiveEx(mQuakePk3, "Zip");
|
---|
146 |
|
---|
147 | }*/
|
---|
148 | // Override scene manager (use indoor instead of generic)
|
---|
149 | void chooseSceneManager(void)
|
---|
150 | {
|
---|
151 | mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
|
---|
152 | //mSceneMgr = mRoot->getSceneManager(ST_INTERIOR);
|
---|
153 | }
|
---|
154 | /*
|
---|
155 | // Scene creation
|
---|
156 | void createScene(void)
|
---|
157 | {
|
---|
158 |
|
---|
159 | // Load world geometry
|
---|
160 | mSceneMgr->setWorldGeometry(mQuakeLevel);
|
---|
161 |
|
---|
162 | // modify camera for close work
|
---|
163 | mCamera->setNearClipDistance(4);
|
---|
164 | mCamera->setFarClipDistance(4000);
|
---|
165 |
|
---|
166 | // Also change position, and set Quake-type orientation
|
---|
167 | // Get random player start point
|
---|
168 | ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true);
|
---|
169 | mCamera->setPosition(vp.position);
|
---|
170 | mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up
|
---|
171 | mCamera->rotate(vp.orientation);
|
---|
172 | // Don't yaw along variable axis, causes leaning
|
---|
173 | mCamera->setFixedYawAxis(true, Vector3::UNIT_Z);
|
---|
174 | }*/
|
---|
175 |
|
---|
176 | };
|
---|
177 |
|
---|