source: OGRE/trunk/ogrenew/Samples/OceanDemo/include/OceanDemo.h @ 692

Revision 692, 6.6 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 The OGRE Team
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL 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 "OgreEventQueue.h"
23#include "OgreKeyEvent.h"
24#include "OgreEventListeners.h"
25#include "OgreStringConverter.h"
26#include "OgreException.h"
27#include "OgreFrameListener.h"
28
29#include "MaterialControls.h"
30
31//---------------------------------------------------------------------------
32enum MovementType
33{
34        mv_CAMERA, mv_MODEL, mv_LIGHT
35};
36
37//---------------------------------------------------------------------------
38class OceanDemo;
39
40class OceanDemo_FrameListener : public Ogre::FrameListener, public Ogre::KeyListener, Ogre::MouseMotionListener, Ogre::MouseListener
41{
42#define MINSPEED .150f
43#define MOVESPEED 30
44#define MAXSPEED 1.800f
45
46
47protected:
48    Ogre::EventProcessor* mEventProcessor;
49    Ogre::InputReader* mInputDevice;
50        OceanDemo* mMain;
51
52    Ogre::Vector3 mTranslateVector;
53    bool mStatsOn;
54        unsigned int mNumScreenShots;
55        bool mWriteToFile;
56    float mMoveScale;
57    float mRotScale;
58        float mSpeed;
59        float mAvgFrameTime;
60        int mSceneDetailIndex;
61    Ogre::Real mMoveSpeed;
62    Ogre::Real mRotateSpeed;
63        float mSkipCount;
64        float mUpdateFreq;
65        CEGUI::Point mLastMousePosition;
66        bool mLastMousePositionSet;
67        bool mSpinModel;
68        bool mSpinLight;
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        CEGUI::MouseButton convertOgreButtonToCegui(int ogre_button_id);
95        void CheckMovementKeys( CEGUI::Key::Scan keycode, bool state );
96        void updateStats(void);
97
98
99public:
100        OceanDemo_FrameListener(OceanDemo* main);
101        virtual ~OceanDemo_FrameListener();
102
103
104        virtual void mouseMoved (Ogre::MouseEvent *e);
105        virtual void mouseDragged (Ogre::MouseEvent *e);
106        virtual void keyPressed (Ogre::KeyEvent *e);
107        virtual void keyReleased (Ogre::KeyEvent *e);
108        virtual void mousePressed (Ogre::MouseEvent *e);
109        virtual void mouseReleased (Ogre::MouseEvent *e);
110
111        // do-nothing events
112        virtual void keyClicked (Ogre::KeyEvent *e) {}
113        virtual void mouseClicked (Ogre::MouseEvent *e) {}
114        virtual void mouseEntered (Ogre::MouseEvent *e) {}
115        virtual void mouseExited (Ogre::MouseEvent *e) {}
116
117
118        bool frameStarted(const Ogre::FrameEvent& evt);
119        bool handleMouseMove(const CEGUI::EventArgs& e);
120        bool handleMouseButtonUp(const CEGUI::EventArgs& e);
121        bool handleMouseButtonDown(const CEGUI::EventArgs& e);
122        bool handleMouseWheelEvent(const CEGUI::EventArgs& e);
123        bool handleKeyDownEvent(const CEGUI::EventArgs& e);
124        bool handleKeyUpEvent(const CEGUI::EventArgs& e);
125        bool handelModelSpinChange(const CEGUI::EventArgs& e);
126        bool handelLightSpinChange(const CEGUI::EventArgs& e);
127};
128
129
130
131
132//---------------------------------------------------------------------------
133class OceanDemo
134{
135protected:
136    Ogre::Root*                   mRoot;
137    Ogre::Camera*                 mCamera;
138    Ogre::SceneManager*   mSceneMgr;
139        // the scene node of the entity
140        Ogre::SceneNode*          mMainNode;
141
142    OceanDemo_FrameListener* mFrameListener;
143    Ogre::RenderWindow*   mWindow;
144    CEGUI::OgreCEGUIRenderer*    mGUIRenderer;
145    CEGUI::System*        mGUISystem;
146        Ogre::Entity*             mCurrentEntity;
147    Ogre::Entity*         mOceanSurfaceEnt;
148
149        size_t                            mCurrentMaterial;
150        Ogre::MaterialPtr         mActiveMaterial;
151        Ogre::Pass*                       mActivePass;
152        Ogre::GpuProgramPtr       mActiveFragmentProgram;
153        Ogre::GpuProgramPtr       mActiveVertexProgram;
154        Ogre::GpuProgramParametersSharedPtr mActiveFragmentParameters;
155        Ogre::GpuProgramParametersSharedPtr mActiveVertexParameters;
156
157        typedef std::vector< ShaderControlGUIWidget > ShaderControlContainer;
158        typedef ShaderControlContainer::iterator ShaderControlIterator;
159
160        ShaderControlContainer    mShaderControlContainer;
161    MaterialControlsContainer mMaterialControlsContainer;
162        CEGUI::Scrollbar*         mVertScroll;
163        MovementType              mMouseMovement;
164
165
166    // These internal methods package up the stages in the startup process
167    /** Sets up the application - returns false if the user chooses to abandon configuration. */
168    bool setup(void);
169
170        /** Configures the application - returns false if the user chooses to abandon configuration. */
171    bool configure(void);
172    void chooseSceneManager(void);
173    void createCamera(void);
174    void createViewports(void);
175
176    /// Method which will define the source of resources (other than current folder)
177    void setupResources(void);
178        void loadResources(void);
179        void createScene(void);
180        void createFrameListener(void);
181
182        void initComboBoxes(void);
183        void initDemoEventWiring(void);
184        void configureShaderControls(void);
185
186        void doErrorBox(const char* text);
187
188        bool handleQuit(const CEGUI::EventArgs& e);
189        bool handleShaderControl(const CEGUI::EventArgs& e);
190        bool handleModelComboChanged(const CEGUI::EventArgs& e);
191        bool handleShaderComboChanged(const CEGUI::EventArgs& e);
192        bool handleScrollControlsWindow(const CEGUI::EventArgs& e);
193        bool handleMovementTypeChange(const CEGUI::EventArgs& e);
194
195        bool handleErrorBox(const CEGUI::EventArgs& e);
196        void setShaderControlVal(const float val, const size_t index);
197
198public:
199        OceanDemo() : mFrameListener(0), mRoot(0), mGUIRenderer(NULL), mGUISystem(0),
200        mCurrentEntity(0), mCurrentMaterial(0), mMouseMovement(mv_CAMERA)
201    {
202    }
203
204    ~OceanDemo();
205
206    void go(void);
207        Ogre::Camera* getCamera(void) const { return mCamera; }
208        Ogre::SceneManager* getSceneManager(void) const { return mSceneMgr; }
209        Ogre::RenderWindow* getRenderWindow(void) const { return mWindow; }
210        MovementType getMouseMovement(void) const { return mMouseMovement; }
211        Ogre::SceneNode* getMainNode(void) const { return mMainNode; }
212
213};
214
215
216#endif  // end _OceanDemo_H_
Note: See TracBrowser for help on using the repository browser.