Nokia N97 SDK
Example Applications Guide

FloatingDuck.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : FloatingDuck.h
00004  *  Part of     : OpenGLEx / FloatingDuck
00005  *
00006  *  Copyright (c) 2005-2006 Nokia Corporation.
00007  *  This material, including documentation and any related
00008  *  computer programs, is protected by copyright controlled by
00009  *  Nokia Corporation.
00010  * ==============================================================================
00011  */
00012 
00013 #ifndef __FLOATINGDUCKH__
00014 #define __FLOATINGDUCKH__
00015 
00016 //  INCLUDES
00017 
00018 #include <e32base.h> // for CBase definition
00019 #include <GLES\gl.h> // OpenGL ES header file
00020 #include "utils3d.h" // OpenGL ES Example Utilities
00021 #include "glutils.h" // Misc GLU and GLUT methods
00022 #include "duck.h"    // Duck model
00023 
00024 /**
00025  * Class that does the actual OpenGL ES rendering.
00026  * Subclass of CFiniteStateMachine because the application
00027  * needs to handle loading textures and running states.
00028  */
00029 class CFloatingDuck
00030         : public CFiniteStateMachine, public MTextureLoadingListener
00031         {
00032         public: // Constructors and destructor
00033 
00034         /**
00035          * Factory method for creating a new CFloatingDuck object.
00036                  * Calls the hidden constructors.
00037          */
00038                 static CFloatingDuck* NewL( GLuint aWidth, GLuint aHeight );
00039 
00040         /**
00041          * Destructor. Does nothing.
00042          */
00043                 virtual ~CFloatingDuck();
00044 
00045         protected: // Hidden constructors
00046 
00047         /**
00048          * Standard constructor that must never Leave.
00049          * Stores the given screen width and height.
00050          * @param aWidth Width of the screen.
00051          * @param aHeight Height of the screen.
00052          */
00053                 CFloatingDuck( GLuint aWidth, GLuint aHeight );
00054 
00055         /**
00056          * Second phase constructor that can call methods that may leave. Does nothing.
00057          */
00058                 void ConstructL( void );
00059 
00060 
00061         public: // New methods
00062 
00063         /**
00064          * Initializes OpenGL ES, sets the vertex and color
00065          * arrays and pointers. Also selects the shading mode and
00066          * creates the CTextureManager instance and starts loading
00067          * of required textures.
00068          */
00069                 void AppInitL( void );
00070 
00071         /**
00072          * Called upon application exit. Destroys the CTextureManager
00073          * instance that was created in AppInitL() method.
00074          */
00075                 void AppExit( void );
00076 
00077         /**
00078          * Renders one frame.
00079          * @param aFrame Number of the frame to be rendered.
00080                  * @param aTimeSecs Seconds elapsed since the application started running.
00081                  * @param aDeltaTimeSecs Seconds elapsed since last call to AppCycle().
00082          */
00083                 void AppCycle( GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs );
00084 
00085         /**
00086          * Called when the finite state machine enters a new state.
00087          * Does nothing in this implementation.
00088          * @param aState State that is about to be entered.
00089          */
00090                 void OnEnterStateL( TInt aState);
00091 
00092         /**
00093          * Called when texture manager starts loading the textures.
00094          * Sets the current state to "loading textures".
00095          */
00096                 void OnStartLoadingTexturesL();
00097 
00098         /**
00099          * Called when texture manager has completed texture loading.
00100          * Changes the current state to "running".
00101          */
00102                 void OnEndLoadingTexturesL();
00103 
00104         /**
00105          * Notifies that the screen size has dynamically changed during execution of
00106          * this program. Resets the viewport to this new size and sets this size
00107          * to the CTextureManager.
00108          * @param aWidth New width of the screen.
00109          * @param aHeight New height of the screen.
00110          */
00111         void SetScreenSize( GLuint aWidth, GLuint aHeight );
00112 
00113     private: // Internal methods
00114 
00115         /**
00116          * Draws the duck and uses the clip plane to clip it to water surface.
00117          * @param aFrame Number of the frame to be rendered.
00118                  * @param aTimeSecs Seconds elapsed since the application started running.
00119                  * @param yScale Scale of the duck in y-axis.
00120          */
00121         void DrawDuck( GLuint aFrame, GLfloat aTimeSecs, GLfloat yScale );
00122 
00123         /**
00124          * Draws the semitransparent water surface.
00125          * @param aFrame Number of the frame to be rendered.
00126                  * @param aTimeSecs Seconds elapsed since the application started running.
00127          */
00128         void DrawWater( GLuint aFrame, GLfloat aTimeSecs );
00129 
00130         /**
00131          * Draws the semitransparent water surface ripples.
00132          * @param aFrame Number of the frame to be rendered.
00133                  * @param aTimeSecs Seconds elapsed since the application started running.
00134          */
00135         void DrawRipples( GLuint aFrame, GLfloat aTimeSecs );
00136 
00137         public: // Data
00138         /**
00139          * Application states:
00140          * ELoadingTextures - indicates that the app. is loading textures.
00141          * ERunning - indicates that the app. is running.
00142          */
00143                 enum
00144                 {
00145                 ELoadingTextures,
00146                 ERunning
00147                 };
00148 
00149         private: // Data
00150 
00151         /** Width of the screen */
00152         GLuint iScreenWidth;
00153         /** Height of the screen */
00154         GLuint iScreenHeight;
00155         /** Camera. */
00156                 TCamera iCamera;
00157                 /** Up and down y-axis offset for the duck. */
00158                 GLfloat iDuckOffset;
00159 
00160                 /** Buffer object id that referes to the duck vertex data. */
00161                 GLuint iVertexDataBufferId;
00162                 /** Buffer object id that referes to the duck normal data. */
00163                 GLuint iNormalDataBufferId;
00164                 /** Buffer object id that referes to the duck indices data. */
00165                 GLuint iIndexDataBufferId;
00166         /** Ripple vertex data */
00167         GLfloat* iRippleVertices;
00168         /** Ripple index data */
00169         GLushort* iRippleIndices;
00170         };
00171 
00172 #endif
00173 
00174 // End of File
00175 

© Nokia 2009

Back to top