1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | You may use this sample code for anything you like, it is not covered by the |
---|
11 | LGPL like the rest of the engine. |
---|
12 | ----------------------------------------------------------------------------- |
---|
13 | */ |
---|
14 | |
---|
15 | #ifndef _OceanDemo_H_ |
---|
16 | #define _OceanDemo_H_ |
---|
17 | |
---|
18 | #include "CEGUI/CEGUI.h" |
---|
19 | #include "OgreCEGUIRenderer.h" |
---|
20 | |
---|
21 | #include "OgreConfigFile.h" |
---|
22 | #include "OgreStringConverter.h" |
---|
23 | #include "OgreException.h" |
---|
24 | #include "OgreFrameListener.h" |
---|
25 | |
---|
26 | #include "MaterialControls.h" |
---|
27 | #include <OIS/OIS.h> |
---|
28 | |
---|
29 | //--------------------------------------------------------------------------- |
---|
30 | enum MovementType |
---|
31 | { |
---|
32 | mv_CAMERA, mv_MODEL, mv_LIGHT |
---|
33 | }; |
---|
34 | |
---|
35 | //--------------------------------------------------------------------------- |
---|
36 | class OceanDemo; |
---|
37 | |
---|
38 | class OceanDemo_FrameListener : public Ogre::FrameListener, public OIS::KeyListener, OIS::MouseListener |
---|
39 | { |
---|
40 | #define MINSPEED .150f |
---|
41 | #define MOVESPEED 30 |
---|
42 | #define MAXSPEED 1.800f |
---|
43 | |
---|
44 | |
---|
45 | protected: |
---|
46 | OceanDemo* mMain; |
---|
47 | |
---|
48 | Ogre::Vector3 mTranslateVector; |
---|
49 | bool mStatsOn; |
---|
50 | unsigned int mNumScreenShots; |
---|
51 | bool mWriteToFile; |
---|
52 | float mMoveScale; |
---|
53 | float mRotScale; |
---|
54 | float mSpeed; |
---|
55 | float mAvgFrameTime; |
---|
56 | int mSceneDetailIndex; |
---|
57 | Ogre::Real mMoveSpeed; |
---|
58 | Ogre::Real mRotateSpeed; |
---|
59 | float mSkipCount; |
---|
60 | float mUpdateFreq; |
---|
61 | CEGUI::Point mLastMousePosition; |
---|
62 | bool mLastMousePositionSet; |
---|
63 | bool mSpinModel; |
---|
64 | bool mSpinLight; |
---|
65 | |
---|
66 | OIS::Mouse *mMouse; |
---|
67 | OIS::Keyboard *mKeyboard; |
---|
68 | OIS::InputManager* mInputManager; |
---|
69 | |
---|
70 | // just to stop toggles flipping too fast |
---|
71 | Ogre::Real mTimeUntilNextToggle ; |
---|
72 | float mRotX, mRotY; |
---|
73 | Ogre::TextureFilterOptions mFiltering; |
---|
74 | int mAniso; |
---|
75 | bool mQuit; |
---|
76 | bool mLMBDown; |
---|
77 | bool mRMBDown; |
---|
78 | bool mProcessMovement; |
---|
79 | bool mUpdateMovement; |
---|
80 | bool mMoveFwd; |
---|
81 | bool mMoveBck; |
---|
82 | bool mMoveLeft; |
---|
83 | bool mMoveRight; |
---|
84 | |
---|
85 | CEGUI::Renderer* mGuiRenderer; |
---|
86 | CEGUI::Window* mGuiAvg; |
---|
87 | CEGUI::Window* mGuiCurr; |
---|
88 | CEGUI::Window* mGuiBest; |
---|
89 | CEGUI::Window* mGuiWorst; |
---|
90 | CEGUI::Window* mGuiTris; |
---|
91 | CEGUI::Window* mGuiDbg; |
---|
92 | CEGUI::Window* mRoot; |
---|
93 | |
---|
94 | std::string mDebugText; |
---|
95 | |
---|
96 | CEGUI::MouseButton convertOISButtonToCegui(int ois_button_id); |
---|
97 | void CheckMovementKeys( CEGUI::Key::Scan keycode, bool state ); |
---|
98 | void updateStats(void); |
---|
99 | |
---|
100 | |
---|
101 | public: |
---|
102 | OceanDemo_FrameListener(OceanDemo* main); |
---|
103 | virtual ~OceanDemo_FrameListener(); |
---|
104 | |
---|
105 | |
---|
106 | virtual bool mouseMoved ( const OIS::MouseEvent &arg ); |
---|
107 | virtual bool mousePressed ( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); |
---|
108 | virtual bool mouseReleased ( const OIS::MouseEvent &arg, OIS::MouseButtonID id ); |
---|
109 | |
---|
110 | virtual bool keyPressed ( const OIS::KeyEvent &arg ); |
---|
111 | virtual bool keyReleased ( const OIS::KeyEvent &arg ); |
---|
112 | |
---|
113 | bool frameStarted(const Ogre::FrameEvent& evt); |
---|
114 | bool handleMouseMove(const CEGUI::EventArgs& e); |
---|
115 | bool handleMouseButtonUp(const CEGUI::EventArgs& e); |
---|
116 | bool handleMouseButtonDown(const CEGUI::EventArgs& e); |
---|
117 | bool handleMouseWheelEvent(const CEGUI::EventArgs& e); |
---|
118 | bool handleKeyDownEvent(const CEGUI::EventArgs& e); |
---|
119 | bool handleKeyUpEvent(const CEGUI::EventArgs& e); |
---|
120 | bool handelModelSpinChange(const CEGUI::EventArgs& e); |
---|
121 | bool handelLightSpinChange(const CEGUI::EventArgs& e); |
---|
122 | }; |
---|
123 | |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | //--------------------------------------------------------------------------- |
---|
128 | class OceanDemo |
---|
129 | { |
---|
130 | protected: |
---|
131 | Ogre::Root* mRoot; |
---|
132 | Ogre::Camera* mCamera; |
---|
133 | Ogre::SceneManager* mSceneMgr; |
---|
134 | // the scene node of the entity |
---|
135 | Ogre::SceneNode* mMainNode; |
---|
136 | |
---|
137 | OceanDemo_FrameListener* mFrameListener; |
---|
138 | Ogre::RenderWindow* mWindow; |
---|
139 | CEGUI::OgreCEGUIRenderer* mGUIRenderer; |
---|
140 | CEGUI::System* mGUISystem; |
---|
141 | Ogre::Entity* mCurrentEntity; |
---|
142 | Ogre::Entity* mOceanSurfaceEnt; |
---|
143 | |
---|
144 | size_t mCurrentMaterial; |
---|
145 | Ogre::MaterialPtr mActiveMaterial; |
---|
146 | Ogre::Pass* mActivePass; |
---|
147 | Ogre::GpuProgramPtr mActiveFragmentProgram; |
---|
148 | Ogre::GpuProgramPtr mActiveVertexProgram; |
---|
149 | Ogre::GpuProgramParametersSharedPtr mActiveFragmentParameters; |
---|
150 | Ogre::GpuProgramParametersSharedPtr mActiveVertexParameters; |
---|
151 | |
---|
152 | typedef std::vector< ShaderControlGUIWidget > ShaderControlContainer; |
---|
153 | typedef ShaderControlContainer::iterator ShaderControlIterator; |
---|
154 | |
---|
155 | ShaderControlContainer mShaderControlContainer; |
---|
156 | MaterialControlsContainer mMaterialControlsContainer; |
---|
157 | CEGUI::Scrollbar* mVertScroll; |
---|
158 | MovementType mMouseMovement; |
---|
159 | |
---|
160 | |
---|
161 | // These internal methods package up the stages in the startup process |
---|
162 | /** Sets up the application - returns false if the user chooses to abandon configuration. */ |
---|
163 | bool setup(void); |
---|
164 | |
---|
165 | /** Configures the application - returns false if the user chooses to abandon configuration. */ |
---|
166 | bool configure(void); |
---|
167 | void chooseSceneManager(void); |
---|
168 | void createCamera(void); |
---|
169 | void createViewports(void); |
---|
170 | |
---|
171 | /// Method which will define the source of resources (other than current folder) |
---|
172 | void setupResources(void); |
---|
173 | void loadResources(void); |
---|
174 | bool setupGUI(void); |
---|
175 | void createScene(void); |
---|
176 | void createFrameListener(void); |
---|
177 | |
---|
178 | void initComboBoxes(void); |
---|
179 | void initDemoEventWiring(void); |
---|
180 | void configureShaderControls(void); |
---|
181 | |
---|
182 | void doErrorBox(const char* text); |
---|
183 | |
---|
184 | bool handleQuit(const CEGUI::EventArgs& e); |
---|
185 | bool handleShaderControl(const CEGUI::EventArgs& e); |
---|
186 | bool handleModelComboChanged(const CEGUI::EventArgs& e); |
---|
187 | bool handleShaderComboChanged(const CEGUI::EventArgs& e); |
---|
188 | bool handleScrollControlsWindow(const CEGUI::EventArgs& e); |
---|
189 | bool handleMovementTypeChange(const CEGUI::EventArgs& e); |
---|
190 | |
---|
191 | bool handleErrorBox(const CEGUI::EventArgs& e); |
---|
192 | void setShaderControlVal(const float val, const size_t index); |
---|
193 | |
---|
194 | public: |
---|
195 | OceanDemo() : mRoot(0), mFrameListener(0), mGUIRenderer(NULL), mGUISystem(0), |
---|
196 | mCurrentEntity(0), mCurrentMaterial(0), mActivePass(0), mMouseMovement(mv_CAMERA) |
---|
197 | { |
---|
198 | } |
---|
199 | |
---|
200 | ~OceanDemo(); |
---|
201 | |
---|
202 | void go(void); |
---|
203 | Ogre::Camera* getCamera(void) const { return mCamera; } |
---|
204 | Ogre::SceneManager* getSceneManager(void) const { return mSceneMgr; } |
---|
205 | Ogre::RenderWindow* getRenderWindow(void) const { return mWindow; } |
---|
206 | MovementType getMouseMovement(void) const { return mMouseMovement; } |
---|
207 | Ogre::SceneNode* getMainNode(void) const { return mMainNode; } |
---|
208 | |
---|
209 | }; |
---|
210 | |
---|
211 | |
---|
212 | #endif // end _OceanDemo_H_ |
---|