Nokia N97 SDK
Example Applications Guide

Billboard.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : Billboard.h
00004  *  Part of     : OpenGLEx / Billboard
00005  *
00006  *  Copyright (c) 2004-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 __BILLBOARH__
00014 #define __BILLBOARH__
00015 
00016 // INCLUDES
00017 #include <e32base.h> // for CBase definition
00018 #include <GLES\gl.h> // OpenGL ES header file
00019 #include "Utils3d.h"
00020 #include "Billboardinput.h"
00021 
00022 // MACROS
00023 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00024 #define FRUSTUM_RIGHT   1.f     //right vertical clipping plane
00025 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00026 #define FRUSTUM_TOP     1.f     //top horizontal clipping plane
00027 #define FRUSTUM_NEAR    3.f     //near depth clipping plane
00028 #define FRUSTUM_FAR  1000.f     //far depth clipping plane
00029 
00030 // CLASS DECLARATION
00031 
00032 /**
00033  * Class that does the actual OpenGL ES rendering.
00034  * Subclass of CFiniteStateMachine because the application
00035  * needs to handle loading textures and running states.
00036  */
00037 class CBillboard : public CFiniteStateMachine, public MTextureLoadingListener
00038         {
00039         public:   // Constructors and destructor
00040 
00041         /**
00042          * Factory method for creating a new CBillboard object.
00043          * @param aWidth Width of the screen.
00044          * @param aHeight Height of the screen.
00045          * @param iInputHandler Input handler that maps keycodes to inputs and stores the current state for each key.
00046          */
00047                 static CBillboard* NewL( TUint aWidth, TUint aHeight, CBillboardInput* aInputHandler );
00048 
00049         /**
00050          * Destructor. Does nothing.
00051          */
00052                 virtual ~CBillboard();
00053 
00054         public: // New functions
00055 
00056         /**
00057          * Initializes OpenGL ES, sets the vertex and color
00058          * arrays and pointers. Also selects the shading mode and
00059          * creates the CTextureManager instance and starts loading
00060          * of required textures.
00061          */
00062                 void AppInitL( void );
00063 
00064         /**
00065          * Called upon application exit. Destroys the CTextureManager
00066          * instance that was created in AppInitL() method.
00067          */
00068                 void AppExit( void );
00069 
00070         /**
00071          * Renders one frame.
00072          * @param aFrame Number of the frame to be rendered.
00073          * @param aTimeSecs Seconds elapsed since the application started running.
00074          * @param aDeltaTimeSecs Seconds elapsed since last call to AppCycle().
00075          */
00076         void AppCycle( GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs );
00077 
00078                 /**
00079                  * Draws the ground plane. The plane is always drawn at fixed location.
00080                  */
00081                 void DrawPlane();
00082 
00083                 /**
00084                  * Draws a tree. The tree is always drawn at a fixed location based on the
00085                  * row and column, but the orientation of the tree depends on the current
00086                  * camera angle. Trees are always rotated so that they face the camera.
00087                  * @param aRow Tree row counter.
00088                  * @param aCol Tree column counter.
00089                  */
00090                 void DrawTree( TInt aRow, TInt aCol );
00091 
00092                 /**
00093                  * Draws and animates the clouds based on the time that has elapsed since
00094                  * last frame.
00095                  * @param aTimeSecs Total number of seconds elapsed.
00096                  */
00097                 void DrawCloud( GLfloat aTimeSecs );
00098 
00099         /**
00100          * Called when the finite state machine enters a new state.
00101          * Does nothing in this implementation.
00102          * @param aState State that is about to be entered.
00103          */
00104                 void OnEnterStateL( TInt aState );
00105 
00106         /**
00107          * Called when texture manager starts loading the textures.
00108          * Sets the current state to "loading textures".
00109          */
00110                 void OnStartLoadingTexturesL();
00111 
00112         /**
00113          * Called when texture manager has completed texture loading.
00114          * Changes the current state to "running".
00115          */
00116                 void OnEndLoadingTexturesL();
00117 
00118                 /**
00119                  * Turn the camera in azimuth based on the joystick movement or if the automatic
00120                  * rotation is on based on the current iCamRotation value.
00121                  * @param aDeltaTimeSecs Time interval that is used as the basis for calculating the movement.
00122                  */
00123                 void TurnCamera( GLfixed aDeltaTimeSecs );
00124 
00125                 /**
00126                  * Move the camera forwards or backwards based on joystick movement and the delta time.
00127                  * @param aDeltaTimeSecs Time interval that is used as the basis for calculating the movement.
00128                  */
00129                 void MoveCamera( GLfixed aDeltaTimeSecs );
00130 
00131                 /**
00132                  * Notifies that the screen size has dynamically changed during execution of
00133                  * this program. Resets the viewport to this new size and sets this size
00134                  * to the CTextureManager.
00135          * @param aWidth New width of the screen.
00136          * @param aHeight New height of the screen.
00137                  */
00138                 void SetScreenSize( TUint aWidth, TUint aHeight );
00139 
00140         protected:
00141 
00142         /**
00143          * Standard constructor that must never Leave.
00144          * Stores the given screen width and height.
00145          * @param aWidth Width of the screen.
00146          * @param aHeight Height of the screen.
00147          * @param iInputHandler Input handler that maps keycodes to inputs and stores the current state for each key.
00148          */
00149                 CBillboard( TUint aWidth, TUint aHeight, CBillboardInput* aInputHandler );
00150 
00151         /**
00152          * Second phase contructor. Does nothing.
00153          */
00154                 void ConstructL( void );
00155 
00156         public:  // Data
00157 
00158         /**
00159          * Application states:
00160          * ELoadingTextures - indicates that the app. is loading textures.
00161          * ERunning - indicates that the app. is running.
00162          */
00163                 enum
00164                         {
00165                         ELoadingTextures,
00166                         ERunning
00167                         };
00168 
00169 
00170         private:  // Data
00171 
00172         /** Width of the screen */
00173         TUint iScreenWidth;
00174         /** Height of the screen */
00175         TUint iScreenHeight;
00176 
00177         /** Texture manager that is used to load the used textures. */
00178                 CTextureManager * iTextureManager;
00179 
00180                 /** Tree texture. */
00181                 TTexture iTreeTexture;
00182                 /** Grass texture. */
00183                 TTexture iGrassTexture;
00184                 /** Cloud texture. */
00185                 TTexture iCloudTexture;
00186                 /** Cloud texture coordinates. */
00187                 GLfixed iCloudTextureCoords[8];
00188                 /** Cloud texture offset. Used to animate the clouds in the sky. */
00189                 GLfixed iTextureOffset;
00190 
00191         /**
00192          * Input handler that maps keycodes to inputs and stores the current state
00193          * for each key. Owned by the C#Name#Container.
00194          */
00195         CBillboardInput* iInputHandler;
00196         /**
00197          * Indicates whether the camera should be automatically rotated around the
00198          * scene or if the camera is controlled by the joystick's left/right movements.
00199          */
00200         TBool iIsAutorotateOn;
00201                 /** Camera. */
00202                 TCamerax iCamera;
00203                 /** Camera azimuth. */
00204                 GLfixed iAzimuth;
00205                 /** Camera distance. */
00206                 GLfixed iDistance;
00207 
00208         /** Vertice coordinates drawing the clouds. */
00209         GLfloat iCloudVertices[12];
00210 
00211                 /** Lookup-table for sin, cos, tan. */
00212                 CLookUpTable * iLookUpTable;
00213 };
00214 
00215 
00216 #endif      // __BILLBOARH_
00217 
00218 // End of File
00219 

© Nokia 2009

Back to top