|
Nokia N97 SDK Example Applications Guide |
#include <Rain.h>
Inheritance diagram for CRain:

Definition at line 41 of file Rain.h.
Public Types |
|
| enum | { ELoadingTextures, ERunning } |
Public Member Functions |
|
| virtual | ~CRain () |
| void | AppInitL (void) |
| void | AppExit (void) |
| void | AppCycle (GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs) |
| void | OnEnterStateL (TInt aState) |
| void | OnStartLoadingTexturesL () |
| void | OnEndLoadingTexturesL () |
| void | DrawPlane () |
| void | DrawTree (GLfloat aX, GLfloat aZ) |
| void | DrawCloud (GLfloat aTimeSecs) |
| CRainfall * | GetRainfall () |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions |
|
| static CRain * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions |
|
| CRain (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Attributes |
|
| CTextureManager * | iTextureManager |
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TTexture | iTreeTexture |
| TTexture | iGrassTexture |
| TTexture | iCloudTexture |
| GLfloat | iCloudTextureCoords [8] |
| GLfloat | iTextureOffset |
| CRainfall * | iRainfall |
| TCamera | iCamera |
| GLfloat | iCloudVertices [12] |
|
|
Application states: ELoadingTextures - indicates that the app. is loading textures. ERunning - indicates that the app. is running. Definition at line 152 of file Rain.h.
|
|
|
Destructor. Does nothing. Definition at line 116 of file Rain.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 300 of file Rain.cpp. References iScreenHeight, and iScreenWidth. Referenced by NewL(). 00301 : CFiniteStateMachine() 00302 { 00303 iScreenWidth = aWidth; 00304 iScreenHeight = aHeight; 00305 00306 }
|
|
||||||||||||
|
Factory method for creating a new CRain object. Definition at line 101 of file Rain.cpp. References CRain(). 00102 { 00103 /* Symbian 2-phase constructor. Calls both the default 00104 C++ constructor and Symbian ConstructL methods */ 00105 CRain* self = new (ELeave) CRain( aWidth, aHeight ); 00106 CleanupStack::PushL( self ); 00107 self->ConstructL(); 00108 CleanupStack::Pop(); 00109 00110 return self; 00111 }
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode and creates the CTextureManager instance and starts loading of required textures. Definition at line 125 of file Rain.cpp. References iCamera, iCloudTexture, iCloudTextureCoords, iGrassTexture, iRainfall, iScreenHeight, iScreenWidth, iTextureManager, iTreeTexture, CRainfall::NewL(), and SetScreenSize(). 00126 { 00127 // Construct a texture manager that uses the application's private 00128 // directory as the location for all textures. 00129 iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenHeight, 00130 FRUSTUM_TOP, FRUSTUM_BOTTOM, FRUSTUM_RIGHT, FRUSTUM_LEFT, FRUSTUM_NEAR, 00131 this ); 00132 00133 // Initialize viewport and projection. 00134 SetScreenSize( iScreenWidth, iScreenHeight ); 00135 00136 /* Set the screen background color. */ 00137 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00138 00139 /* Enable back face culling. */ 00140 glEnable( GL_CULL_FACE ); 00141 glEnable( GL_TEXTURE_2D ); 00142 glEnable( GL_DEPTH_TEST ); 00143 00144 //Enable alpha test for color keying. 00145 glEnable( GL_ALPHA_TEST ); 00146 glAlphaFunc( GL_GREATER, 0.0f ); 00147 00148 /*Disable lighting */ 00149 glDisable( GL_LIGHTING ); 00150 00151 /* Enable vertex arrays. */ 00152 glEnableClientState( GL_VERTEX_ARRAY ); 00153 /* Enable texture arrays. */ 00154 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 00155 00156 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00157 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00158 00159 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); 00160 00161 iCloudTextureCoords[0] = 0; iCloudTextureCoords[1] = 1; 00162 iCloudTextureCoords[2] = 0; iCloudTextureCoords[3] = 0; 00163 iCloudTextureCoords[4] = 1; iCloudTextureCoords[5] = 0; 00164 iCloudTextureCoords[6] = 1; iCloudTextureCoords[7] = 1; 00165 00166 iRainfall = CRainfall::NewL( 1000, TVector(0, 80, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), 120, (FRUSTUM_FAR-FRUSTUM_NEAR), 0); 00167 00168 iCamera.LookAt(TVector(0, 30.0f, 0), TVector(0, 0, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), TVector(0, 1, 0)); 00169 00170 // Defining a color key interval for the tree texture. 00171 TUint8 MinColor[] = { 50, 0, 50}; 00172 TUint8 MaxColor[] = { 200, 0, 200}; 00173 00174 // Pushing the textures into the loading queue. 00175 _LIT(KTreeName, "tree.gif"); 00176 _LIT(KGrassName, "grass.jpg"); 00177 _LIT(KCloudName, "cloud.jpg"); 00178 00179 iTextureManager->RequestToLoad(KTreeName , &iTreeTexture, MinColor, MaxColor ); 00180 iTextureManager->RequestToLoad(KGrassName, &iGrassTexture ); 00181 iTextureManager->RequestToLoad(KCloudName, &iCloudTexture ); 00182 00183 //Start to load the textures. 00184 iTextureManager->DoLoadL(); 00185 }
|
|
|
Called upon application exit. Destroys the CTextureManager instance that was created in AppInitL() method. Definition at line 192 of file Rain.cpp. References iRainfall, and iTextureManager. Referenced by CRainContainer::~CRainContainer(). 00193 { 00194 delete iRainfall; 00195 delete iTextureManager; 00196 }
|
|
||||||||||||||||
|
Renders one frame.
Definition at line 272 of file Rain.cpp. References DrawCloud(), DrawPlane(), DrawTree(), iCamera, iRainfall, CRainfall::RenderEngine(), and CRainfall::UpdateEngine(). Referenced by CRainContainer::DrawCallBack(). 00273 { 00274 glClear( GL_DEPTH_BUFFER_BIT ); 00275 00276 /* Draws the clouds, and the ground plane */ 00277 glDisable( GL_DEPTH_TEST ); 00278 DrawCloud( aDeltaTimeSecs ); 00279 DrawPlane(); 00280 00281 //Draw the trees. 00282 DrawTree( -TREE_STEP_X, -1*TREE_STEP_Z); 00283 DrawTree( +TREE_STEP_X, -1*TREE_STEP_Z); 00284 DrawTree( -TREE_STEP_X, -2*TREE_STEP_Z); 00285 DrawTree( +TREE_STEP_X, -2*TREE_STEP_Z); 00286 00287 glEnable( GL_DEPTH_TEST ); 00288 00289 /*Update and render the particle engine */ 00290 iRainfall->UpdateEngine(aDeltaTimeSecs); 00291 iRainfall->RenderEngine(iCamera); 00292 }
|
|
|
Called when the finite state machine enters a new state. Does nothing in this implementation.
Definition at line 321 of file Rain.cpp.
|
|
|
Called when texture manager starts loading the textures. Sets the current state to "loading textures". Definition at line 330 of file Rain.cpp.
|
|
|
Called when texture manager has completed texture loading. Changes the current state to "running". Definition at line 340 of file Rain.cpp. 00341 { 00342 if ( GetState() == ELoadingTextures ) 00343 { 00344 SetStateL( ERunning ); 00345 } 00346 }
|
|
|
Draws the ground plane. Definition at line 203 of file Rain.cpp. References iCamera, and iGrassTexture. Referenced by AppCycle(). 00204 { 00205 glBindTexture( GL_TEXTURE_2D, iGrassTexture.iID ); 00206 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00207 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00208 00209 glLoadIdentity(); 00210 T3DModel::MakeWorldViewMatrix(iCamera, TVector(0.0f, 0.0f, 0.0f)); 00211 glScalef( 1000, 0, 1000 ); 00212 00213 glVertexPointer( 3, GL_BYTE, 0, planeVertices ); 00214 glTexCoordPointer( 2, GL_BYTE, 0, planeTextureCoords ); 00215 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles ); 00216 }
|
|
||||||||||||
|
Draws a tree at the given location.
Definition at line 245 of file Rain.cpp. References iCamera, and iTreeTexture. Referenced by AppCycle(). 00246 { 00247 glLoadIdentity(); 00248 00249 //Turns the tree so that it always faces the camera. 00250 T3DModel::MakeBillboardWorldViewMatrix(iCamera, TVector(aX, 0.0f, aZ)); 00251 glScalef( 10, 30, 10 ); 00252 00253 glBindTexture( GL_TEXTURE_2D, iTreeTexture.iID ); 00254 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00255 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00256 00257 glVertexPointer( 3, GL_BYTE, 0, treeVertices ); 00258 glTexCoordPointer( 2, GL_BYTE, 0, treeTextureCoords ); 00259 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, treeTriangles ); 00260 00261 }
|
|
|
Draws the clouds.
Definition at line 223 of file Rain.cpp. References iCloudTexture, iCloudTextureCoords, iCloudVertices, and iTextureOffset. Referenced by AppCycle(). 00224 { 00225 iTextureOffset += (GLfloat)(0.01f * aDeltaTimeSecs); 00226 00227 iCloudTextureCoords[0] = iCloudTextureCoords[2]= iTextureOffset; 00228 iCloudTextureCoords[4] = iCloudTextureCoords[6]= iTextureOffset+0.4f; 00229 00230 glLoadIdentity(); 00231 glBindTexture( GL_TEXTURE_2D, iCloudTexture.iID ); 00232 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00233 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00234 00235 glVertexPointer( 3, GL_FLOAT, 0, iCloudVertices ); 00236 glTexCoordPointer( 2, GL_FLOAT, 0, iCloudTextureCoords ); 00237 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, cloudTriangles ); 00238 }
|
|
|
Returns pointer to the particle-engine effect
Definition at line 353 of file Rain.cpp. References iRainfall. 00354 { 00355 return iRainfall; 00356 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size and sets this size to the CTextureManager.
Definition at line 363 of file Rain.cpp. References iCloudVertices, iScreenHeight, iScreenWidth, and iTextureManager. Referenced by AppInitL(), and CRainContainer::SizeChanged(). 00364 { 00365 iScreenWidth = aWidth; 00366 iScreenHeight = aHeight; 00367 00368 // Notify the texture manager of screen size change 00369 iTextureManager->SetScreenSize( aWidth, aHeight ); 00370 00371 // Reinitialize viewport and projection. 00372 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00373 00374 // Recalculate the view frustrum 00375 glMatrixMode( GL_PROJECTION ); 00376 glLoadIdentity(); 00377 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00378 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00379 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00380 FRUSTUM_NEAR, FRUSTUM_FAR ); 00381 glMatrixMode( GL_MODELVIEW ); 00382 00383 // Recalculate cloud vertices based on the aspect ratio 00384 iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio; 00385 iCloudVertices[ 1 ] = 0.f; 00386 iCloudVertices[ 2 ] = -FRUSTUM_NEAR; 00387 00388 iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio; 00389 iCloudVertices[ 4 ] = FRUSTUM_TOP; 00390 iCloudVertices[ 5 ] = -FRUSTUM_NEAR; 00391 00392 iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio; 00393 iCloudVertices[ 7 ] = FRUSTUM_TOP; 00394 iCloudVertices[ 8 ] = -FRUSTUM_NEAR; 00395 00396 iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio; 00397 iCloudVertices[ 10 ] = 0.f; 00398 iCloudVertices[ 11 ] = -FRUSTUM_NEAR; 00399 }
|
|
|
Second phase contructor. Does nothing. Definition at line 313 of file Rain.cpp.
|
|
|
Texture manager that is used to load the used textures. Definition at line 163 of file Rain.h. Referenced by AppExit(), AppInitL(), and SetScreenSize(). |
|
|
Width of the screen Definition at line 165 of file Rain.h. Referenced by AppInitL(), CRain(), and SetScreenSize(). |
|
|
Height of the screen Definition at line 167 of file Rain.h. Referenced by AppInitL(), CRain(), and SetScreenSize(). |
|
|
Tree texture. Definition at line 170 of file Rain.h. Referenced by AppInitL(), and DrawTree(). |
|
|
Ground texture. Definition at line 172 of file Rain.h. Referenced by AppInitL(), and DrawPlane(). |
|
|
Cloud texture. Definition at line 174 of file Rain.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture coordinates. Definition at line 176 of file Rain.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture offset. Definition at line 178 of file Rain.h. Referenced by DrawCloud(). |
|
|
Rainfall particle effect. Definition at line 181 of file Rain.h. Referenced by AppCycle(), AppExit(), AppInitL(), and GetRainfall(). |
|
|
Camera. Definition at line 184 of file Rain.h. Referenced by AppCycle(), AppInitL(), DrawPlane(), and DrawTree(). |
|
|
Vertice coordinates drawing the clouds. Definition at line 187 of file Rain.h. Referenced by DrawCloud(), and SetScreenSize(). |
|
© Nokia 2009 |