|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : Rain.h 00004 * Part of : OpenGLEx / Rain 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 __RAINH__ 00017 #define __RAINH__ 00018 00019 // INCLUDES 00020 00021 #include <e32base.h> // for CBase definition 00022 #include <GLES\gl.h> // OpenGL ES header file 00023 #include "utils.h" 00024 00025 // MACROS 00026 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 // FORWARD DECLARATIONS 00035 00036 class CRainfall; 00037 00038 /** 00039 * Class that does the actual OpenGL ES rendering. 00040 * Subclass of CFiniteStateMachine because the application 00041 * needs to handle loading textures and running states. 00042 */ 00043 class CRain 00044 : public CFiniteStateMachine, public MTextureLoadingListener 00045 { 00046 public: // Constructors and destructor 00047 00048 /** 00049 * Factory method for creating a new CRain object. 00050 */ 00051 static CRain* NewL( TUint aWidth, TUint aHeight ); 00052 00053 /** 00054 * Destructor. Does nothing. 00055 */ 00056 virtual ~CRain(); 00057 00058 public: 00059 /** 00060 * Initializes OpenGL ES, sets the vertex and color 00061 * arrays and pointers. Also selects the shading mode and 00062 * creates the CTextureManager instance and starts loading 00063 * of required textures. 00064 */ 00065 void AppInitL( void ); 00066 00067 /** 00068 * Called upon application exit. Destroys the CTextureManager 00069 * instance that was created in AppInitL() method. 00070 */ 00071 void AppExit( void ); 00072 00073 /** 00074 * Renders one frame. 00075 * @param aFrame Number of the frame to be rendered. 00076 */ 00077 void AppCycle( TInt aFrame ); 00078 00079 /** 00080 * Called when the finite state machine enters a new state. 00081 * Does nothing in this implementation. 00082 * @param aState State that is about to be entered. 00083 */ 00084 void OnEnterStateL( TInt aState); 00085 00086 /** 00087 * Called when texture manager starts loading the textures. 00088 * Sets the current state to "loading textures". 00089 */ 00090 void OnStartLoadingTexturesL(); 00091 00092 /** 00093 * Called when texture manager has completed texture loading. 00094 * Changes the current state to "running". 00095 */ 00096 void OnEndLoadingTexturesL(); 00097 00098 /** 00099 * Draws the ground plane. 00100 */ 00101 void DrawPlane(); 00102 00103 /** 00104 * Draws a tree at the given location. 00105 * @param aX X-coordinate for the tree. 00106 * @param aZ Z-coordinate for the tree. 00107 */ 00108 void DrawTree(GLfloat aX, GLfloat aZ); 00109 00110 /** 00111 * Draws the clouds. 00112 */ 00113 void DrawCloud(); 00114 00115 /** 00116 * Returns pointer to the particle-engine effect 00117 * @return Effect 00118 */ 00119 CRainfall* GetRainfall(); 00120 00121 /** 00122 * Returns the current system time. 00123 * @return System time. 00124 */ 00125 TTime GetTimeTick(); 00126 00127 /** 00128 * Returns elapsed time (in sec.) between the current and the previous frame 00129 * @return Elapsed time (in sec.) between the current and the previous frame 00130 */ 00131 GLfloat GetElapsedTime(); 00132 00133 /** 00134 * Returns current frames-per-second count. 00135 * @return Current frames per second. 00136 */ 00137 GLfloat GetFPSCount(); 00138 00139 /** 00140 * Notifies that the screen size has dynamically changed during execution of 00141 * this program. Resets the viewport to this new size and sets this size 00142 * to the CTextureManager. 00143 * @param aWidth New width of the screen. 00144 * @param aHeight New height of the screen. 00145 */ 00146 void SetScreenSize( TUint aWidth, TUint aHeight ); 00147 00148 protected: 00149 00150 /** 00151 * Standard constructor that must never Leave. 00152 * Stores the given screen width and height. 00153 * @param aWidth Width of the screen. 00154 * @param aHeight Height of the screen. 00155 */ 00156 CRain( TUint aWidth, TUint aHeight ); 00157 00158 /** 00159 * Second phase contructor. Does nothing. 00160 */ 00161 void ConstructL( void ); 00162 00163 public: // Data 00164 /** 00165 * Application states: 00166 * ELoadingTextures - indicates that the app. is loading textures. 00167 * ERunning - indicates that the app. is running. 00168 */ 00169 enum 00170 { 00171 ELoadingTextures, 00172 ERunning 00173 }; 00174 00175 00176 00177 private: // Data 00178 00179 /** Texture manager that is used to load the used textures. */ 00180 CTextureManager * iTextureManager; 00181 /** Width of the screen */ 00182 TUint iScreenWidth; 00183 /** Height of the screen */ 00184 TUint iScreenHeight; 00185 00186 /** Tree texture. */ 00187 TTexture iTreeTexture; 00188 /** Ground texture. */ 00189 TTexture iGrassTexture; 00190 /** Cloud texture. */ 00191 TTexture iCloudTexture; 00192 /** Cloud texture coordinates. */ 00193 GLfloat iCloudTextureCoords[8]; 00194 /** Cloud texture offset. */ 00195 GLfloat iTextureOffset; 00196 00197 /** Rainfall particle effect. */ 00198 CRainfall * iRainfall; 00199 00200 /** Camera. */ 00201 TCamera iCamera; 00202 /** Reference time. */ 00203 TTime iT0; 00204 /** Reference time + time delta. */ 00205 TTime iT1; 00206 /** Elapsed time = iT1 - iT0 */ 00207 GLfloat iElapsedTime; 00208 /** Current frames per second. */ 00209 GLfloat iFPSCount; 00210 00211 /** Vertice coordinates drawing the clouds. */ 00212 GLfloat iCloudVertices[12]; 00213 }; 00214 00215 /** 00216 * Rainfall particle effect class. Raindrops are released from within the rectangle 00217 * (iPosition.iX-iWidth / 2, iPosition.iY, iPosition.iX-iWidth / 2) 00218 * (iPosition.iX+iWidth / 2, iPosition.iY, iPosition.iX+iWidth / 2). 00219 * Once particle's y coordinate is below (smaller than) iGroundLevel, it is reset. 00220 */ 00221 class CRainfall: public CParticleEngine 00222 { 00223 public: 00224 /** 00225 * Factory method for creating a new CRain object. 00226 * @param aParticlesCount Number of particles used to create the rain effect. 00227 * @param aPosition Position of the rain particle generator. 00228 * @param aWidth Width of the rain area. 00229 * @param aDepth Height of the rain area. 00230 * @param aGroundLevel Ground level after which particle is reset back to beginning. 00231 */ 00232 static CRainfall* NewL(GLint aParticlesCount, TVector aPosition, 00233 GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel); 00234 /** Destructor. Does nothing in this implementation. */ 00235 virtual ~CRainfall(); 00236 00237 protected: 00238 00239 /** 00240 * Standard constructor that must never Leave. 00241 * Does nothing in this implementation. 00242 */ 00243 CRainfall(); 00244 00245 /** 00246 * Second phase contructor. Constructs the rain effect using the given parameters. 00247 * @param aParticlesCount Number of particles used to create the rain effect. 00248 * @param aPosition Position of the rain particle generator. 00249 * @param aWidth Width of the rain area. 00250 * @param aDepth Height of the rain area. 00251 * @param aGroundLevel Ground level after which particle is reset back to beginning. 00252 */ 00253 void ConstructL(GLint aParticlesCount, TVector aPosition, 00254 GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel); 00255 00256 00257 public: // New functions 00258 00259 /** 00260 * Returns a random float number. 00261 * @return Random float number. 00262 */ 00263 GLfloat Random(); 00264 00265 public: // Functions from base classes 00266 00267 /** 00268 * Implementation of CParticleEngine::ResetParticle() method 00269 * Resets the given particle to the rain "start plane" and gives it random location inside 00270 * the rain area (defined when creating this effect) and random downwards speed. 00271 * @param aIndex Particle to be reset. 00272 */ 00273 void ResetParticle(GLint aIndex); 00274 00275 /** 00276 * Implementation of CParticleEngine::UpdateEngine() method. 00277 * Moves all the particles according to their current velocity vector and resets all particles 00278 * that have fallen beneath the ground level back to the beginning plain. 00279 * @param aElapsedTime Elapsed time since last frame. Used when calculating how much 00280 * each particle has moved. 00281 */ 00282 void UpdateEngine(GLfloat aElapsedTime); 00283 00284 /** 00285 * Implementation of CParticleEngine::RenderEngine(). 00286 * Renders each particle to the screen as simple lines. 00287 */ 00288 void RenderEngine(TCamera &aCamera); 00289 00290 public: // Data 00291 00292 /** Width of the particle source area. This defines the width of the area where the rain falls. */ 00293 GLfloat iWidth; 00294 /** Depth of the particle source area. This defines the depth of the area where the rain falls. */ 00295 GLfloat iDepth; 00296 /** Ground level that defines the plane after which the particles are reset back to the source plain. */ 00297 GLfloat iGroundLevel; 00298 00299 protected: // Data 00300 00301 /** Seed for the random generator (the time when ConstructL was called). */ 00302 TInt64 iSeed; 00303 }; 00304 00305 #endif 00306 00307 // End of File 00308
|
© Nokia 2006 |