S60 3rd Edition SDK for Symbian OS
Example Applications Guide

lensflare.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : LensFlare.h
00004 *  Part of     : OpenGLEx / LensFlare
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 #ifndef __LENSFLAREH__
00017 #define __LENSFLAREH__
00018 
00019 // INCLUDES
00020 #include <e32base.h> // for CBase definition
00021 #include <GLES\gl.h> // OpenGL ES header file
00022 #include "utils.h"
00023 
00024 // CONSTANTS
00025 
00026 // MACROS
00027 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00028 #define FRUSTUM_RIGHT  +1.f     //right vertical clipping plane
00029 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00030 #define FRUSTUM_TOP    +1.f     //top horizontal clipping plane
00031 #define FRUSTUM_NEAR   +3.f     //near depth clipping plane
00032 #define FRUSTUM_FAR    +1000.f  //far depth clipping plane
00033 
00034 // DATA TYPES
00035 
00036 // FUNCTION PROTOTYPES
00037 
00038 // FORWARD DECLARATIONS
00039 
00040 // CLASS DECLARATION
00041 
00042 /**
00043  * Class that does the actual OpenGL ES rendering.
00044  * Subclass of CFiniteStateMachine because the application
00045  * needs to handle loading textures and running states.
00046  */
00047 class CLensflare : public CFiniteStateMachine, public MTextureLoadingListener
00048         {
00049         public:
00050 
00051         /**
00052          * Factory method for creating a new CLensflare object.
00053          */
00054                 static CLensflare* NewL( TUint aWidth, TUint aHeight);
00055 
00056         /**
00057          * Destructor. Does nothing.
00058          */
00059                 virtual ~CLensflare();
00060 
00061         public: // New functions
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          */
00081                 void AppCycle( TInt aFrame );
00082 
00083         /**
00084          * Called when the finite state machine enters a new state.
00085          * Gets the current time that is then used as the starting time.
00086          * @param aState State that is about to be entered.
00087          */
00088                 void OnEnterStateL( TInt aState );
00089 
00090         /**
00091          * Called when texture manager starts loading the textures.
00092          * Sets the current state to "loading textures".
00093          */
00094                 void OnStartLoadingTexturesL();
00095 
00096         /**
00097          * Called when texture manager has completed texture loading.
00098          * Changes the current state to "running".
00099          */
00100                 void OnEndLoadingTexturesL();
00101 
00102                 /**
00103                  * Draw the 'NokiaGL' text.
00104                  * @param aReflection Flag that specifies if we are drawing the reflected text or not.
00105                  */
00106                 void DrawText(TBool aReflection);
00107 
00108                 /**
00109                  * Draw the ground plane.
00110                  */
00111                 void DrawPlane();
00112 
00113 
00114                 /**
00115                  * Returns the current system time.
00116                  * @return Current system time
00117                  */
00118                 TTime GetTimeTick(); 
00119 
00120                 /**
00121                  * Returns the ellapsed time (in seconds) between the current and the previous frame.
00122                  * @return iElapsedTime Elapsed time between frames in seconds.
00123                  */
00124                 GLfloat GetElapsedTime();
00125 
00126                 /**
00127                  * Returns the current frames per second rate.
00128                  * @return iFPSCount Current frame rate.
00129                  */
00130                 GLfloat GetFPSCount();
00131 
00132                 /**
00133                  * Move the camera from/to the origin.
00134                  * @param aDirection Direction to move camera.
00135                  * @param aTime Time.
00136                  */
00137                 void MoveCamera(GLint aDirection, GLfloat aTime = 0);
00138 
00139                 /**
00140                  * Turn the camera in azimuth.
00141                  * @param aDirection Direction to turn camera
00142                  * @param aTime Time
00143                  */
00144                 void TurnCameraAzimuth(GLint aDirection, GLfloat aTime = 0);
00145 
00146                 /**
00147                  * Change the camera elevation.
00148                  * @param aDirection Direction to turn camera
00149                  * @param aTime Time.
00150                  */
00151                 void TurnCameraElevation(GLint aDirection, GLfloat aTime = 0);
00152 
00153         /**
00154          * Notifies that the screen size has dynamically changed during execution of
00155          * this program. Resets the viewport to this new size and sets this size
00156          * to the CTextureManager.
00157          * @param aWidth New width of the screen.
00158          * @param aHeight New height of the screen.
00159          */
00160         void SetScreenSize( TUint aWidth, TUint aHeight );
00161 
00162         protected:
00163 
00164         /**
00165          * Standard constructor that must never Leave.
00166          * Stores the given screen width and height.
00167          * @param aWidth Width of the screen.
00168          * @param aHeight Height of the screen.
00169          */
00170                 CLensflare( TUint aWidth, TUint aHeight );
00171 
00172         /**
00173          * Second phase contructor. Does nothing.
00174          */
00175                 void ConstructL( void );
00176 
00177         public: // Data
00178 
00179         /**
00180          * Application states:
00181          * ELoadingTextures - indicates that the app. is loading textures.
00182          * ERunning - indicates that the app. is running.
00183          */
00184                 enum 
00185                         {
00186                         ELoadingTextures, 
00187                         ERunning
00188                         };
00189     
00190 
00191                 /** Camera movement direction. */
00192                 GLbyte iDirection;
00193 
00194         private: // Data
00195 
00196         /** Texture manager that is used to load the used textures. */
00197                 CTextureManager * iTextureManager;
00198         /** Width of the screen */
00199         TUint iScreenWidth;
00200         /** Height of the screen */
00201         TUint iScreenHeight;
00202 
00203                 /** Lens-flare effect. */
00204                 CLensFlareEffect * iLensFlareEffect;
00205 
00206                 /** Trigonometric functions lookup-table. */
00207                 CLookUpTable * iLookUpTable;
00208 
00209                 /** Camera. */
00210                 TCamera iCamera;
00211                 
00212                 /** Delta time measurement start. */
00213                 TTime iT0;
00214                 /** Delta time measurement end. */
00215                 TTime iT1;
00216                 /** Elapsed time == delta. */
00217                 GLfloat iElapsedTime;
00218                 /** Rendered frames per second. */
00219                 GLfloat iFPSCount;
00220                 /** Azimuth angle for camera. */
00221                 GLfloat iAzimuth;
00222                 /** Elevation angle for camera. */
00223                 GLfloat iElevation;
00224                 /** Camera distance. */
00225                 GLfloat iDistance;
00226                 /** Angle of the lensflare effect. */
00227                 GLfloat iLensAngle;
00228                 /** Lens radius. */
00229                 GLfloat iLensRadius;
00230 
00231         };
00232 
00233 #endif
00234 
00235 // End of File

© Nokia 2006

Back to top