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

Definition at line 40 of file Snow.h.
Public Types |
|
| enum | { ELoadingTextures, ERunning } |
Public Member Functions |
|
| virtual | ~CSnow () |
| 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 aDeltaTimeSecs) |
| CSnowfall * | GetSnowfall () |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions |
|
| static CSnow * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions |
|
| CSnow (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Attributes |
|
| CTextureManager * | iTextureManager |
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TTexture | iTreeTexture |
| TTexture | iGroundTexture |
| TTexture | iCloudTexture |
| GLfloat | iCloudTextureCoords [8] |
| GLfloat | iTextureOffset |
| CSnowfall * | iSnowfall |
| 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 153 of file Snow.h.
|
|
|
Destructor. Does nothing. Definition at line 130 of file Snow.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 358 of file Snow.cpp. References iScreenHeight, and iScreenWidth. Referenced by NewL(). 00359 : CFiniteStateMachine() 00360 { 00361 iScreenWidth = aWidth; 00362 iScreenHeight = aHeight; 00363 00364 }
|
|
||||||||||||
|
Factory method for creating a new CRain object. Definition at line 117 of file Snow.cpp. References CSnow(). 00118 { 00119 /* Symbian 2-phase constructor. Calls both the default 00120 C++ constructor and Symbian ConstructL methods */ 00121 CSnow* self = new (ELeave) CSnow( aWidth, aHeight ); 00122 CleanupStack::PushL( self ); 00123 self->ConstructL(); 00124 CleanupStack::Pop(); 00125 00126 return self; 00127 }
|
|
|
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 150 of file Snow.cpp. References iCamera, iCloudTexture, iCloudTextureCoords, iCloudVertices, iGroundTexture, iScreenHeight, iScreenWidth, iSnowfall, iTextureManager, iTreeTexture, CSnowfall::NewL(), and SetScreenSize(). 00151 { 00152 // Construct a texture manager that uses the application's private 00153 // directory as the source location for all textures. 00154 iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenHeight, 00155 FRUSTUM_TOP, FRUSTUM_BOTTOM, FRUSTUM_RIGHT, FRUSTUM_LEFT, FRUSTUM_NEAR, 00156 this ); 00157 00158 // Initialize viewport and projection. 00159 SetScreenSize( iScreenWidth, iScreenHeight ); 00160 00161 /* Set the screen background color. */ 00162 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00163 00164 /* Enable back face culling. */ 00165 glEnable( GL_CULL_FACE ); 00166 glEnable( GL_TEXTURE_2D ); 00167 glEnable( GL_DEPTH_TEST ); 00168 00169 //Enable alpha test for color keying. 00170 glEnable( GL_ALPHA_TEST ); 00171 glAlphaFunc( GL_GREATER, 0.0f ); 00172 00173 /*Disable lighting */ 00174 glDisable( GL_LIGHTING ); 00175 00176 // Calculate cloud vertices based on the aspect ratio 00177 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00178 iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio; 00179 iCloudVertices[ 1 ] = 0.f; 00180 iCloudVertices[ 2 ] = -FRUSTUM_NEAR; 00181 00182 iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio; 00183 iCloudVertices[ 4 ] = FRUSTUM_TOP; 00184 iCloudVertices[ 5 ] = -FRUSTUM_NEAR; 00185 00186 iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio; 00187 iCloudVertices[ 7 ] = FRUSTUM_TOP; 00188 iCloudVertices[ 8 ] = -FRUSTUM_NEAR; 00189 00190 iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio; 00191 iCloudVertices[ 10 ] = 0.f; 00192 iCloudVertices[ 11 ] = -FRUSTUM_NEAR; 00193 00194 glMatrixMode( GL_MODELVIEW ); 00195 00196 /* Enable vertex arrays. */ 00197 glEnableClientState( GL_VERTEX_ARRAY ); 00198 /* Enable texture arrays. */ 00199 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 00200 00201 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00202 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00203 00204 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); 00205 00206 iCloudTextureCoords[0] = 0; iCloudTextureCoords[1] = 1; 00207 iCloudTextureCoords[2] = 0; iCloudTextureCoords[3] = 0; 00208 iCloudTextureCoords[4] = 1; iCloudTextureCoords[5] = 0; 00209 iCloudTextureCoords[6] = 1; iCloudTextureCoords[7] = 1; 00210 00211 iCamera.LookAt( TVector( 0, 30.0f, 0 ), 00212 TVector(0, 0, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), 00213 TVector(0, 1, 0)); 00214 00215 iSnowfall = CSnowfall::NewL( 00216 700, // Number of particles 00217 TVector( 0, 80, -( FRUSTUM_FAR + FRUSTUM_NEAR ) / 2 ), // Center position 00218 120.f, // Area width 00219 ( FRUSTUM_FAR - FRUSTUM_NEAR ), // Area height 00220 0, // Ground level 00221 iTextureManager ); // Texture manager 00222 00223 // Defining a color key interval for the tree texture. 00224 TUint8 MinColor[] = { 50, 0, 50 }; 00225 TUint8 MaxColor[] = { 255, 75, 255 }; 00226 00227 // Pushing the textures into the loading queue. 00228 _LIT(KSnowyTreeName, "snowy_tree.gif"); 00229 _LIT(KSnowyGroundName, "snowy_ground.jpg"); 00230 _LIT(KCloudName, "cloud.jpg"); 00231 iTextureManager->RequestToLoad(KSnowyTreeName, &iTreeTexture, MinColor, MaxColor ); 00232 iTextureManager->RequestToLoad(KSnowyGroundName, &iGroundTexture ); 00233 iTextureManager->RequestToLoad(KCloudName, &iCloudTexture ); 00234 00235 //Start to load the textures. 00236 iTextureManager->DoLoadL(); 00237 }
|
|
|
Called upon application exit. Destroys the CTextureManager instance that was created in AppInitL() method. Definition at line 244 of file Snow.cpp. References iSnowfall, and iTextureManager. Referenced by CSnowContainer::~CSnowContainer(). 00245 { 00246 delete iSnowfall; 00247 delete iTextureManager; 00248 }
|
|
||||||||||||||||
|
Renders one frame.
Definition at line 327 of file Snow.cpp. References DrawCloud(), DrawPlane(), DrawTree(), iCamera, iSnowfall, CSnowfall::RenderEngine(), and CSnowfall::UpdateEngine(). Referenced by CSnowContainer::DrawCallBack(). 00328 { 00329 glClear( GL_DEPTH_BUFFER_BIT ); 00330 00331 /* Draws the clouds, and the ground plane */ 00332 glDisable( GL_DEPTH_TEST ); 00333 DrawCloud( aDeltaTimeSecs ); 00334 DrawPlane(); 00335 00336 const TReal32 treeStepX = 30.0f; 00337 const TReal32 treeStepZ = 100.0f; 00338 00339 //Draw the trees. 00340 DrawTree( -treeStepX, -1*treeStepZ); 00341 DrawTree( +treeStepX, -1*treeStepZ); 00342 DrawTree( -treeStepX, -2*treeStepZ); 00343 DrawTree( +treeStepX, -2*treeStepZ); 00344 00345 glEnable( GL_DEPTH_TEST ); 00346 00347 /*Update and render the particle engine */ 00348 iSnowfall->UpdateEngine( aDeltaTimeSecs ); 00349 iSnowfall->RenderEngine( iCamera ); 00350 }
|
|
|
Called when the finite state machine enters a new state. Does nothing in this implementation.
Definition at line 379 of file Snow.cpp.
|
|
|
Called when texture manager starts loading the textures. Sets the current state to "loading textures". Definition at line 388 of file Snow.cpp.
|
|
|
Called when texture manager has completed texture loading. Changes the current state to "running". Definition at line 397 of file Snow.cpp. 00398 { 00399 if ( GetState() == ELoadingTextures ) 00400 { 00401 SetStateL( ERunning ); 00402 } 00403 }
|
|
|
Draws the ground plane Definition at line 255 of file Snow.cpp. References iCamera, and iGroundTexture. Referenced by AppCycle(). 00256 { 00257 glBindTexture( GL_TEXTURE_2D, iGroundTexture.iID ); 00258 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00259 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00260 00261 glLoadIdentity(); 00262 T3DModel::MakeWorldViewMatrix(iCamera, TVector(0.0f, 0.0f, 0.0f)); 00263 glScalef( 1000, 0, 1000 ); 00264 00265 00266 glVertexPointer( 3, GL_BYTE, 0, planeVertices ); 00267 glTexCoordPointer( 2, GL_BYTE, 0, planeTextureCoords ); 00268 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles ); 00269 }
|
|
||||||||||||
|
Draws a tree at the given location.
Definition at line 302 of file Snow.cpp. References iCamera, and iTreeTexture. Referenced by AppCycle(). 00303 { 00304 glLoadIdentity(); 00305 00306 //Turns the tree so that it always faces the camera. 00307 T3DModel::MakeBillboardWorldViewMatrix(iCamera, TVector(aX, 0.0f, aZ)); 00308 glScalef( 10, 30, 10 ); 00309 00310 glBindTexture( GL_TEXTURE_2D, iTreeTexture.iID ); 00311 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00312 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00313 00314 glVertexPointer( 3, GL_BYTE, 0, treeVertices ); 00315 glTexCoordPointer( 2, GL_BYTE, 0, treeTextureCoords ); 00316 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, treeTriangles ); 00317 }
|
|
|
Draws the clouds.
Definition at line 276 of file Snow.cpp. References iCloudTexture, iCloudTextureCoords, iCloudVertices, and iTextureOffset. Referenced by AppCycle(). 00277 { 00278 iTextureOffset += (GLfloat)(0.01f*aDeltaTimeSecs); 00279 00280 iCloudTextureCoords[0] = iCloudTextureCoords[2] = iTextureOffset; 00281 iCloudTextureCoords[4] = iCloudTextureCoords[6] = iTextureOffset + 0.4f; 00282 00283 glDisable( GL_DEPTH_TEST ); 00284 00285 glLoadIdentity(); 00286 00287 glBindTexture( GL_TEXTURE_2D, iCloudTexture.iID ); 00288 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00289 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00290 glVertexPointer( 3, GL_FLOAT, 0, iCloudVertices ); 00291 glTexCoordPointer( 2, GL_FLOAT, 0, iCloudTextureCoords ); 00292 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, cloudTriangles ); 00293 00294 glEnable( GL_DEPTH_TEST ); 00295 }
|
|
|
Returns pointer to the particle-engine effect
Definition at line 140 of file Snow.cpp. References iSnowfall. 00141 { 00142 return iSnowfall; 00143 }
|
|
||||||||||||
|
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 410 of file Snow.cpp. References iCloudVertices, iScreenHeight, iScreenWidth, and iTextureManager. Referenced by AppInitL(), and CSnowContainer::SizeChanged(). 00411 { 00412 iScreenWidth = aWidth; 00413 iScreenHeight = aHeight; 00414 00415 // Notify the texture manager of screen size change 00416 iTextureManager->SetScreenSize( aWidth, aHeight ); 00417 00418 // Reinitialize viewport and projection. 00419 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00420 00421 // Recalculate the view frustrum 00422 glMatrixMode( GL_PROJECTION ); 00423 glLoadIdentity(); 00424 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00425 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00426 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00427 FRUSTUM_NEAR, FRUSTUM_FAR ); 00428 glMatrixMode( GL_MODELVIEW ); 00429 00430 // Recalculate cloud vertices based on the aspect ratio 00431 iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio; 00432 iCloudVertices[ 1 ] = 0.f; 00433 iCloudVertices[ 2 ] = -FRUSTUM_NEAR; 00434 00435 iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio; 00436 iCloudVertices[ 4 ] = FRUSTUM_TOP; 00437 iCloudVertices[ 5 ] = -FRUSTUM_NEAR; 00438 00439 iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio; 00440 iCloudVertices[ 7 ] = FRUSTUM_TOP; 00441 iCloudVertices[ 8 ] = -FRUSTUM_NEAR; 00442 00443 iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio; 00444 iCloudVertices[ 10 ] = 0.f; 00445 iCloudVertices[ 11 ] = -FRUSTUM_NEAR; 00446 }
|
|
|
Second phase contructor. Does nothing. Definition at line 371 of file Snow.cpp.
|
|
|
Texture manager that is used to load the used textures. Definition at line 162 of file Snow.h. Referenced by AppExit(), AppInitL(), and SetScreenSize(). |
|
|
Width of the screen Definition at line 164 of file Snow.h. Referenced by AppInitL(), CSnow(), and SetScreenSize(). |
|
|
Height of the screen Definition at line 166 of file Snow.h. Referenced by AppInitL(), CSnow(), and SetScreenSize(). |
|
|
Tree texture. Definition at line 169 of file Snow.h. Referenced by AppInitL(), and DrawTree(). |
|
|
Ground texture. Definition at line 171 of file Snow.h. Referenced by AppInitL(), and DrawPlane(). |
|
|
Cloud texture. Definition at line 173 of file Snow.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture coordinates. Definition at line 175 of file Snow.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture offset. Definition at line 177 of file Snow.h. Referenced by DrawCloud(). |
|
|
Snowfall particle effect. Definition at line 180 of file Snow.h. Referenced by AppCycle(), AppExit(), AppInitL(), and GetSnowfall(). |
|
|
Camera. Definition at line 182 of file Snow.h. Referenced by AppCycle(), AppInitL(), DrawPlane(), and DrawTree(). |
|
|
Vertice coordinates drawing the clouds. Definition at line 184 of file Snow.h. Referenced by AppInitL(), DrawCloud(), and SetScreenSize(). |
|
© Nokia 2009 |