S60 3rd Edition SDK for Symbian OS
Example Applications Guide

Billboard.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : Billboard.h
00004 *  Part of     : OpenGLEx / Billboard
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 __BILLBOARH__
00017 #define __BILLBOARH__
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 // MACROS
00025 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00026 #define FRUSTUM_RIGHT   1.f     //right vertical clipping plane
00027 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00028 #define FRUSTUM_TOP     1.f     //top horizontal clipping plane
00029 #define FRUSTUM_NEAR    3.f     //near depth clipping plane
00030 #define FRUSTUM_FAR  1000.f     //far depth clipping plane
00031 
00032 // CLASS DECLARATION
00033 
00034 /**
00035  * Class that does the actual OpenGL ES rendering.
00036  * Subclass of CFiniteStateMachine because the application
00037  * needs to handle loading textures and running states.
00038  */
00039 class CBillboard : public CFiniteStateMachine, public MTextureLoadingListener
00040         {
00041         public:   // Constructors and destructor
00042   
00043         /**
00044          * Factory method for creating a new CBillboard object.
00045          */
00046                 static CBillboard* NewL( TUint aWidth, TUint aHeight);
00047 
00048         /**
00049          * Destructor. Does nothing.
00050          */
00051                 virtual ~CBillboard();
00052 
00053         public: // New functions
00054 
00055         /**
00056          * Initializes OpenGL ES, sets the vertex and color
00057          * arrays and pointers. Also selects the shading mode and
00058          * creates the CTextureManager instance and starts loading
00059          * of required textures.
00060          */
00061                 void AppInitL( void );
00062 
00063         /**
00064          * Called upon application exit. Destroys the CTextureManager
00065          * instance that was created in AppInitL() method.
00066          */
00067                 void AppExit( void );
00068 
00069         /**
00070          * Renders one frame.
00071          * @param aFrame Number of the frame to be rendered.
00072          */
00073                 void AppCycle( TInt aFrame);
00074 
00075                 /**
00076                  * Draws the ground plane.
00077                  * @param aFrame Current frame number.
00078                  */
00079                 void DrawPlane( TInt aFrame  );
00080 
00081                 /**
00082                  * Draws a tree.
00083                  * @param aFrame Current frame number.
00084                  * @param aI Counter.
00085                  * @param aJ Counter.
00086                  */
00087                 void DrawTree( TInt aFrame, TInt aI, TInt aJ );
00088 
00089                 /**
00090                  * Draws clouds.
00091                  * @param aFrame Current frame number
00092                  */
00093                 void DrawCloud( TInt aFrame);
00094 
00095         /**
00096          * Called when the finite state machine enters a new state.
00097          * Does nothing in this implementation.
00098          * @param aState State that is about to be entered.
00099          */
00100                 void OnEnterStateL( TInt aState );
00101 
00102         /**
00103          * Called when texture manager starts loading the textures.
00104          * Sets the current state to "loading textures".
00105          */
00106                 void OnStartLoadingTexturesL();
00107 
00108         /**
00109          * Called when texture manager has completed texture loading.
00110          * Changes the current state to "running".
00111          */
00112                 void OnEndLoadingTexturesL();
00113 
00114                 /**
00115                  * Returns the system time using TTime.
00116                  * @return Current system time.
00117                  */
00118                 TTime GetTimeTick(); 
00119 
00120                 /**
00121                  * Returns the elapsed time between the current and the previous frame.
00122                  * @return Elapsed time between the current and the previous frame in seconds.
00123                  */
00124                 GLfixed GetElapsedTime();
00125 
00126                 /**
00127                  * Returns the current frame rate in frames per second.
00128                  * @return Current f.p.s.
00129                  */
00130                 GLfixed GetFPSCount();
00131     
00132                 /**
00133                  * Move the camera from/to the origin.
00134                  * @param aDirection Direction to move the camera.
00135                  * @param aTime Time interval that is used as the basis for calculating the movement.
00136                  */
00137                 void MoveCamera(GLint aDirection, GLfixed aTime = 0);
00138 
00139                 /**
00140                  * Turn the camera in azimuth.
00141                  * @param aDirection Direction to turn the camera.
00142                  * @param aTime Time interval that is used as the basis for calculating the movement.
00143                  */
00144                 void TurnCamera(GLint aDirection, GLfixed aTime = 0);
00145                 
00146                 /**
00147                  * Notifies that the screen size has dynamically changed during execution of
00148                  * this program. Resets the viewport to this new size and sets this size
00149                  * to the CTextureManager.
00150          * @param aWidth New width of the screen.
00151          * @param aHeight New height of the screen.
00152                  */
00153                 void SetScreenSize( TUint aWidth, TUint aHeight );
00154 
00155 
00156         protected:
00157         
00158         /**
00159          * Standard constructor that must never Leave.
00160          * Stores the given screen width and height.
00161          * @param aWidth Width of the screen.
00162          * @param aHeight Height of the screen.
00163          */
00164                 CBillboard( TUint aWidth, TUint aHeight);
00165         
00166         /**
00167          * Second phase contructor. Does nothing.
00168          */
00169                 void ConstructL( void );
00170     
00171         public:  // Data
00172 
00173         /**
00174          * Application states:
00175          * ELoadingTextures - indicates that the app. is loading textures.
00176          * ERunning - indicates that the app. is running.
00177          */
00178                 enum 
00179                         {
00180                         ELoadingTextures, 
00181                         ERunning
00182                         };
00183                 
00184         /** Animation direction and speed for moving the camera. */
00185                 GLbyte iDirection;
00186 
00187         private:  // Data
00188         
00189         /** Width of the screen */
00190         TUint iScreenWidth;
00191         /** Height of the screen */
00192         TUint iScreenHeight;
00193 
00194         /** Texture manager that is used to load the used textures. */
00195                 CTextureManager * iTextureManager;
00196 
00197                 /** Tree texture. */
00198                 TTexture iTreeTexture;
00199                 /** Grass texture. */
00200                 TTexture iGrassTexture;
00201                 /** Cloud texture. */
00202                 TTexture iCloudTexture;
00203                 /** Cloud texture coordinates. */
00204                 GLshort iCloudTextureCoords[8];
00205                 /** Cloud texture offset. Used to animate the clouds in the sky. */
00206                 GLshort iTextureOffset;
00207 
00208                 /** Camera. */
00209                 TCamerax iCamera;
00210                 /** Camera azimuth. */
00211                 GLfixed iAzimuth;
00212                 /** Camera distance. */
00213                 GLfixed iDistance;
00214 
00215                 /** Time begin. */
00216                 TTime iT0;
00217                 /** Time end. */
00218                 TTime iT1;
00219                 /** Time delta = elapsed time */
00220                 GLfixed iElapsedTime;
00221                 /** Counter for frames per second. */
00222                 GLfixed iFPSCount;
00223 
00224         /** Vertice coordinates drawing the clouds. */
00225         GLfloat iCloudVertices[12];
00226 
00227                 /** Lookup-table for sin, cos, tan. */
00228                 CLookUpTable * iLookUpTable;
00229 };
00230 
00231 
00232 #endif      // __BILLBOARH_
00233 
00234 // End of File
00235 

© Nokia 2006

Back to top