S60 3rd Edition SDK for Symbian OS
Example Applications Guide

Snow.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : Snow.cpp
00004 *  Part of     : OpenGLEx / Snow
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 // INCLUDE FILES
00017 
00018 #include "snow.h"
00019 #include <aknnotewrappers.h> 
00020 #include <e32math.h>
00021 
00022 // MACROS
00023 
00024 // CONSTANTS
00025 
00026 /** Vertice coordinates for the ground plane. */
00027 static const GLbyte planeVertices[4 * 3] =
00028         {
00029     +1,0,-1,
00030     +1,0,+1,
00031     -1,0,+1,
00032     -1,0,-1
00033         };
00034 
00035 /** Texture coordinates for ground plane. */
00036 static const GLbyte planeTextureCoords[4 * 2] =
00037         {
00038       0, 10,
00039       0,  0,
00040      10,  0,
00041      10, 10
00042         };
00043  
00044 
00045 /** Indices for drawing the triangles of the ground plane. */
00046 static const GLubyte planeTriangles[2 * 3] =
00047         {
00048     0,2,1,
00049     0,3,2
00050         };
00051 
00052 
00053 /** Vertice coordinates for tree. */
00054 static const GLbyte treeVertices[4 * 3] =
00055         {
00056     +1, 0,0,
00057     +1,+1,0,
00058     -1,+1,0,
00059     -1, 0,0
00060         };
00061 
00062 /** Texture coordinates for tree. */
00063 static const GLbyte treeTextureCoords[4 * 2] =
00064         {
00065     0, 1,
00066     0, 0,
00067     1, 0,
00068     1, 1
00069         };
00070 
00071 /** Indices for drawing the tree. */
00072 static const GLubyte treeTriangles[2 * 3] =
00073         {
00074     0,1,2,
00075     0,2,3
00076         };
00077 
00078 /** Indices for drawing the clouds. */
00079 static const GLubyte cloudTriangles [] =
00080         {
00081     0,1,2,
00082     0,2,3
00083         };
00084 
00085 /** Vertice coordinates for snow. */
00086 static const GLbyte snowVertices[4 * 3] =
00087         {
00088     +2, 0,0,
00089     +2,+2,0,
00090     -2,+2,0,
00091     -2, 0,0
00092         };
00093 
00094 /** Texture coordinates for snow. */
00095 static const GLbyte snowTextureCoords[4 * 2] =
00096         {
00097     0, 1,
00098     0, 0,
00099     1, 0,
00100     1, 1
00101         };
00102 
00103 /* Indices for drawing the snow. */
00104 static const GLubyte snowTriangles[2 * 3] =
00105         {
00106     0,1,2,
00107     0,2,3
00108         };
00109 
00110 
00111 // LOCAL CONSTANTS AND MACROS
00112 
00113 // ============================= MEMBER FUNCTIONS ===============================
00114 
00115 // -----------------------------------------------------------------------------
00116 // CSnow::NewL
00117 // Symbian 2-phase constructor. Can leave.
00118 // -----------------------------------------------------------------------------
00119 //
00120 CSnow* CSnow::NewL( TUint aWidth, TUint aHeight )
00121         {
00122     /* Symbian 2-phase constructor. Calls both the default 
00123        C++ constructor and Symbian ConstructL methods */
00124     CSnow* self = new (ELeave) CSnow( aWidth, aHeight );
00125     CleanupStack::PushL( self );
00126     self->ConstructL();
00127     CleanupStack::Pop();
00128 
00129     return self;
00130         }
00131 
00132 // Destructor. 
00133 CSnow::~CSnow()
00134         {
00135         }
00136 
00137 // -----------------------------------------------------------------------------
00138 // CSnow::GetElapsedTime
00139 // Gets the elapsed time.
00140 // Returns:             The elapsed time
00141 // -----------------------------------------------------------------------------
00142 //
00143 GLfloat CSnow::GetElapsedTime() 
00144         { 
00145         return iElapsedTime; 
00146         }
00147 
00148 // -----------------------------------------------------------------------------
00149 // CSnow::GetFPSCount
00150 // Gets the frames per second.
00151 // Returns:             Frames per second
00152 // -----------------------------------------------------------------------------
00153 //
00154 GLfloat CSnow::GetFPSCount()
00155         { 
00156         return iFPSCount; 
00157         }
00158 
00159 // -----------------------------------------------------------------------------
00160 // CSnow::GetSnowfall
00161 // Gets the particle engine.
00162 // Returns:             The owned particle engine pointer
00163 // -----------------------------------------------------------------------------
00164 //
00165 CSnowfall* CSnow::GetSnowfall()
00166         { 
00167         return iSnowfall;
00168         }
00169 
00170 // -----------------------------------------------------------------------------
00171 // CSnow::AppInit
00172 // Application initialization code.
00173 // -----------------------------------------------------------------------------
00174 //
00175 void CSnow::AppInitL( void )
00176         {
00177     /* Set the screen background color. */
00178     glClearColor( 0.f, 0.f, 0.f, 1.f );
00179 
00180     /* Enable back face culling. */
00181     glEnable( GL_CULL_FACE  );
00182     glEnable( GL_TEXTURE_2D );
00183     glEnable( GL_DEPTH_TEST );
00184 
00185     //Enable alpha test for color keying.
00186     glEnable( GL_ALPHA_TEST );
00187     glAlphaFunc( GL_GREATER, 0.0f );
00188 
00189     /*Disable lighting */
00190     glDisable( GL_LIGHTING );
00191 
00192     /* Initialize viewport and projection. */
00193     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00194     glMatrixMode( GL_PROJECTION );
00195 
00196     // Calculate the view frustrum
00197     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00198     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00199                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00200                 FRUSTUM_NEAR, FRUSTUM_FAR );
00201 
00202     // Calculate cloud vertices based on the aspect ratio
00203     iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio;
00204     iCloudVertices[ 1 ] = 0.f;
00205     iCloudVertices[ 2 ] = -FRUSTUM_NEAR;
00206 
00207     iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio;
00208     iCloudVertices[ 4 ] = FRUSTUM_TOP;
00209     iCloudVertices[ 5 ] = -FRUSTUM_NEAR;
00210 
00211     iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio;
00212     iCloudVertices[ 7 ] = FRUSTUM_TOP;
00213     iCloudVertices[ 8 ] = -FRUSTUM_NEAR;
00214 
00215     iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio;
00216     iCloudVertices[ 10 ] = 0.f;
00217     iCloudVertices[ 11 ] = -FRUSTUM_NEAR;
00218 
00219     glMatrixMode( GL_MODELVIEW );
00220 
00221     /* Enable vertex arrays. */
00222     glEnableClientState( GL_VERTEX_ARRAY );
00223     /* Enable texture arrays. */
00224     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00225 
00226     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00227     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00228 
00229 
00230     iCloudTextureCoords[0] = 0; iCloudTextureCoords[1] = 1; 
00231     iCloudTextureCoords[2] = 0; iCloudTextureCoords[3] = 0; 
00232     iCloudTextureCoords[4] = 1; iCloudTextureCoords[5] = 0; 
00233     iCloudTextureCoords[6] = 1; iCloudTextureCoords[7] = 1; 
00234 
00235     iCamera.LookAt(TVector(0, 30.0f, 0), TVector(0, 0, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), TVector(0, 1, 0));
00236  
00237     // Construct a texture manager that uses the application's private
00238         // directory as the source location for all textures.
00239     iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenWidth,
00240                                               FRUSTUM_TOP, FRUSTUM_BOTTOM, FRUSTUM_RIGHT, FRUSTUM_LEFT, FRUSTUM_NEAR,                               
00241                                               this );
00242     iSnowfall = CSnowfall::NewL(600, TVector(0, 80, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), 120, (FRUSTUM_FAR-FRUSTUM_NEAR), 0, iTextureManager);
00243 
00244     // Defining a color key interval for the tree texture.
00245     TUint8 MinColor[] = { 50, 0, 50 };
00246     TUint8 MaxColor[] = { 255, 75, 255 };
00247     
00248     // Pushing the textures into the loading queue.
00249         _LIT(KSnowyTreeName, "snowy_tree.gif");
00250         _LIT(KSnowyGroundName, "snowy_ground.jpg");
00251         _LIT(KCloudName, "cloud.jpg");
00252     iTextureManager->RequestToLoad(KSnowyTreeName, &iTreeTexture, MinColor, MaxColor );
00253     iTextureManager->RequestToLoad(KSnowyGroundName, &iGroundTexture );
00254     iTextureManager->RequestToLoad(KCloudName, &iCloudTexture );
00255 
00256     //Start to load the textures.
00257     iTextureManager->DoLoadL();
00258         }
00259 
00260 // -----------------------------------------------------------------------------
00261 // CSnow::AppExit
00262 // Application cleanup code.
00263 // -----------------------------------------------------------------------------
00264 //
00265 void CSnow::AppExit( void )
00266         {
00267     delete iSnowfall;
00268     delete iTextureManager;
00269         }
00270 
00271 // -----------------------------------------------------------------------------
00272 // CSnow::DrawPlane
00273 // Draws the ground plane.
00274 // -----------------------------------------------------------------------------
00275 //
00276 void CSnow::DrawPlane()
00277         {
00278     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE );
00279 
00280     glBindTexture(  GL_TEXTURE_2D, iGroundTexture.iID );
00281     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00282     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00283 
00284     glLoadIdentity();
00285     T3DModel::MakeWorldViewMatrix(iCamera, TVector(0.0f, 0.0f, 0.0f));
00286     glScalef( 1000, 0, 1000 );
00287 
00288 
00289     glVertexPointer( 3, GL_BYTE, 0, planeVertices );
00290     glTexCoordPointer( 2, GL_BYTE, 0, planeTextureCoords );
00291     glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles );
00292 
00293     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00294     glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00295 
00296     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00297         }
00298 
00299 // -----------------------------------------------------------------------------
00300 // CSnow::DrawCloud
00301 // Draws the clouds.
00302 // -----------------------------------------------------------------------------
00303 //
00304 void CSnow::DrawCloud()
00305         {
00306     iTextureOffset += (GLfloat)(0.01*iElapsedTime);
00307 
00308     iCloudTextureCoords[0] = iCloudTextureCoords[2] = iTextureOffset;
00309     iCloudTextureCoords[4] = iCloudTextureCoords[6] = iTextureOffset + 0.4f;
00310 
00311     glDisable( GL_DEPTH_TEST );
00312 
00313     glLoadIdentity();
00314 
00315     glBindTexture(  GL_TEXTURE_2D, iCloudTexture.iID );
00316 
00317     glVertexPointer( 3, GL_FLOAT, 0, iCloudVertices );
00318     glTexCoordPointer( 2, GL_FLOAT, 0, iCloudTextureCoords );
00319     glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, cloudTriangles );
00320 
00321     glEnable( GL_DEPTH_TEST );
00322         }
00323 
00324 // -----------------------------------------------------------------------------
00325 // CSnow::DrawTree
00326 // Draws a tree.
00327 // -----------------------------------------------------------------------------
00328 //
00329 void CSnow::DrawTree( GLfloat aX, GLfloat aZ)
00330         {
00331     glLoadIdentity();
00332 
00333     //Turns the tree so that it always faces the camera.
00334     T3DModel::MakeBillboardWorldViewMatrix(iCamera, TVector(aX, 0.0f, aZ));
00335     glScalef( 10, 30, 10 );
00336 
00337     glBindTexture(  GL_TEXTURE_2D, iTreeTexture.iID );
00338     
00339     glVertexPointer( 3, GL_BYTE, 0, treeVertices );
00340     glTexCoordPointer( 2, GL_BYTE, 0, treeTextureCoords );
00341     glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, treeTriangles );
00342         }
00343 
00344 // -----------------------------------------------------------------------------
00345 // CSnow::AppCycle
00346 // Draws and animates the objects.
00347 // -----------------------------------------------------------------------------
00348 //
00349 void CSnow::AppCycle( TInt /*aFrame*/ )
00350         {
00351     glClear( GL_DEPTH_BUFFER_BIT );
00352 
00353     iT0 = iT1;
00354     do 
00355                 {
00356         iT1 = GetTimeTick();
00357         //Compute the elapsed time (in sec.) between the current and the previous frame.
00358         iElapsedTime = I64LOW( iT1.MicroSecondsFrom( iT0 ).Int64() * ( 1 / 1000000.0f ) );
00359                 } while ( iElapsedTime == 0 );                   
00360     
00361         iFPSCount = 1 / (iElapsedTime);        //Compute the frame rate.
00362 
00363     /* Draws the clouds, and the ground plane */
00364     glDisable( GL_DEPTH_TEST );
00365     DrawCloud();
00366     DrawPlane();
00367 
00368     const TReal32 treeStepX = 30.0f;
00369     const TReal32 treeStepZ = 100.0f;
00370 
00371     //Draw the trees.
00372     DrawTree( -treeStepX, -1*treeStepZ);
00373     DrawTree( +treeStepX, -1*treeStepZ);
00374     DrawTree( -treeStepX, -2*treeStepZ);
00375     DrawTree( +treeStepX, -2*treeStepZ);
00376 
00377     glEnable( GL_DEPTH_TEST );
00378 
00379     /*Update and render the particle engine */
00380     iSnowfall->UpdateEngine(iElapsedTime);
00381     iSnowfall->RenderEngine(iCamera);
00382         }
00383 
00384 // ----------------------------------------------------------------------
00385 // CSnow::CSnow
00386 // C++ default constructor can NOT contain any code, that
00387 // might leave.
00388 // ----------------------------------------------------------------------
00389 //
00390 CSnow::CSnow( TUint aWidth, TUint aHeight )
00391         : CFiniteStateMachine()
00392         {
00393     iScreenWidth  = aWidth;
00394     iScreenHeight = aHeight;
00395 
00396         }
00397 
00398 // ----------------------------------------------------------------------
00399 // CSnow::ConstructL
00400 // Symbian 2nd phase constructor can leave.
00401 // ----------------------------------------------------------------------
00402 //
00403 void CSnow::ConstructL( void )
00404         {
00405         }
00406 
00407 // ---------------------------------------------------------
00408 // CSnow::OnEnterState( TInt aState )
00409 // Called by TFiniteStateMachine when the f.s.m enters a new state
00410 // ---------------------------------------------------------
00411 void CSnow::OnEnterStateL( TInt aState )
00412         {
00413     if ( aState == ERunning )
00414                 {
00415         iT1 = GetTimeTick();
00416                 }
00417         }
00418 
00419 // -------------------------------------------------------------------------------------------------------
00420 // CSnow::OnStartLoadingTextures()
00421 // Called for a MTextureLoadingListener by the texture manager when texture loading operation starts 
00422 // -------------------------------------------------------------------------------------------------------
00423 
00424 void CSnow::OnStartLoadingTexturesL()
00425         {
00426     SetStateL( ELoadingTextures );
00427         }
00428 
00429 // ------------------------------------------------------------------------------------------------------------
00430 // CSnow::OnEndLoadingTextures()
00431 // Called for a MTextureLoadingListener by the texture manager when texture loading operation is completed
00432 // ------------------------------------------------------------------------------------------------------------
00433 void CSnow::OnEndLoadingTexturesL()
00434         {
00435         if ( GetState() == ELoadingTextures )
00436                 {
00437         SetStateL( ERunning );
00438                 }
00439         }
00440 
00441 // ----------------------------------------------------------------------
00442 // CSnow::GetTimeTick
00443 // Get the current time
00444 // Returns:     The current time.
00445 // ----------------------------------------------------------------------
00446 //
00447 TTime CSnow::GetTimeTick()
00448 {
00449    TTime time;
00450    time.UniversalTime();
00451    
00452    return time;
00453 }
00454 
00455 // -----------------------------------------------------------------------------
00456 // CSnow::SetScreenSize
00457 // Reacts to the dynamic screen size change during execution of this program.
00458 // -----------------------------------------------------------------------------
00459 //
00460 void CSnow::SetScreenSize( TUint aWidth, TUint aHeight )
00461     {
00462     iScreenWidth  = aWidth;
00463     iScreenHeight = aHeight;
00464     
00465     // Notify the texture manager of screen size change
00466     iTextureManager->SetScreenSize( aWidth, aHeight );
00467 
00468     // Reinitialize viewport and projection.
00469     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00470 
00471     // Recalculate the view frustrum
00472     glMatrixMode( GL_PROJECTION );
00473     glLoadIdentity();
00474     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00475     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00476                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00477                 FRUSTUM_NEAR, FRUSTUM_FAR );
00478     glMatrixMode( GL_MODELVIEW );
00479 
00480     // Recalculate cloud vertices based on the aspect ratio
00481     iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio;
00482     iCloudVertices[ 1 ] = 0.f;
00483     iCloudVertices[ 2 ] = -FRUSTUM_NEAR;
00484 
00485     iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio;
00486     iCloudVertices[ 4 ] = FRUSTUM_TOP;
00487     iCloudVertices[ 5 ] = -FRUSTUM_NEAR;
00488 
00489     iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio;
00490     iCloudVertices[ 7 ] = FRUSTUM_TOP;
00491     iCloudVertices[ 8 ] = -FRUSTUM_NEAR;
00492 
00493     iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio;
00494     iCloudVertices[ 10 ] = 0.f;
00495     iCloudVertices[ 11 ] = -FRUSTUM_NEAR;
00496     }
00497 
00498 // ----------------------------------------------------------------------
00499 // CSnowfall::CSnowfall
00500 // C++ default constructor can NOT contain any code, that
00501 // ----------------------------------------------------------------------
00502 //
00503 CSnowfall::CSnowfall() 
00504         {
00505         };
00506 
00507 
00508 // ----------------------------------------------------------------------
00509 // CSnowfall::NewL
00510 // 2nd Two-phased constructor.
00511 // Creates and initializes a CSnowfall object:
00512 //   snowflakes are released from within
00513 //   the rectangle (aPosition.iX-aWidth/2, aPosition.iY, aPosition.iX-aWidth/2)
00514 //                 (aPosition.iX+aWidth/2, aPosition.iY, aPosition.iX+aWidth/2).
00515 //   Once their height is < iGroundLevel, they are reset.// Returns:    The current time.
00516 // ----------------------------------------------------------------------
00517 //
00518 
00519 CSnowfall* CSnowfall::NewL(GLint aParticlesCount, TVector aPosition,
00520                            GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel,
00521                            CTextureManager * aTextureManager)
00522         {
00523     /* Symbian 2-phase constructor. Calls both the default 
00524        C++ constructor and Symbian ConstructL methods */
00525     CSnowfall* self = new (ELeave) CSnowfall;
00526     CleanupStack::PushL( self );
00527     self->ConstructL( aParticlesCount, aPosition, aWidth, aDepth, aGroundLevel, aTextureManager);
00528     CleanupStack::Pop();
00529 
00530     return self;
00531         }
00532 
00533 // ----------------------------------------------------------------------
00534 // CSnowfall::ConstructL
00535 // 2nd phase constructor
00536 // Initializes a CSnowfall object:
00537 //   snowflakes are released from within
00538 //   the rectangle (aPosition.iX-aWidth/2, aPosition.iY, aPosition.iX-aWidth/2)
00539 //                 (aPosition.iX+aWidth/2, aPosition.iY, aPosition.iX+aWidth/2).
00540 //   Once their height is < iGroundLevel, they are reset.
00541 // ----------------------------------------------------------------------
00542 //
00543 void CSnowfall::ConstructL(GLint aParticlesCount, TVector aPosition,
00544                            GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel,
00545                            CTextureManager * aTextureManager)
00546         {
00547     CParticleEngine::ConstructL(aParticlesCount, aPosition);
00548 
00549     iWidth = aWidth;
00550     iDepth = aDepth;
00551     iGroundLevel = aGroundLevel;
00552 
00553     TTime now;
00554     now.HomeTime();
00555     iSeed = now.Int64();
00556 
00557     ResetEngine();
00558 
00559         _LIT(KSnowName, "snow.jpg");
00560     aTextureManager->RequestToLoad(KSnowName, &iTexture );
00561         }
00562 
00563 // Destructor. 
00564 
00565 CSnowfall::~CSnowfall()
00566         {
00567         }
00568 
00569 // ----------------------------------------------------------------------
00570 // CSnowfall::ResetParticle
00571 // Implementation of CParticleEngine::ResetParticle(GLint)
00572 // ----------------------------------------------------------------------
00573 //
00574 void CSnowfall::ResetParticle(GLint aIndex)
00575         {
00576     TParticle& Particle = iParticles[aIndex];
00577 
00578     Particle.iPosition = TVector( iWidth * ((float)(Math::FRand(iSeed)) - 0.5f),
00579                 0, 
00580                 iDepth * ((float)(Math::FRand(iSeed)) - 0.5f)) + iPosition;
00581 
00582     Particle.iVelocity = TVector( (float)(Math::FRand(iSeed)) * 4.0f - 2.0f, 
00583                 -((float)(Math::FRand(iSeed)) * 20.0f + 20.0f), 
00584                 (float)(Math::FRand(iSeed)) * 4.0f - 2.0f);
00585         }
00586 
00587 // ----------------------------------------------------------------------
00588 // CSnowfall::UpdateEngine
00589 // Implementation of CParticleEngine::UpdateEngine(GLfloat aElapsedTime)
00590 // ----------------------------------------------------------------------
00591 //
00592 void CSnowfall::UpdateEngine(GLfloat aElapsedTime)
00593         {
00594     for ( GLint i = 0; i < iParticlesCount; i++ )
00595                 {
00596         iParticles[i].iPosition += (iParticles[i].iVelocity * aElapsedTime);
00597         if ( iParticles[i].iPosition.iY < iGroundLevel )
00598                         {
00599             ResetParticle(i);
00600                         }
00601                 }
00602         }
00603 
00604 // ----------------------------------------------------------------------
00605 // CSnowfall::RenderEngine
00606 // Implementation of CParticleEngine::RenderEngine(TCamera &)
00607 // ----------------------------------------------------------------------
00608 //
00609 void CSnowfall::RenderEngine(TCamera& aCamera)
00610         {
00611     glEnable(GL_BLEND);
00612     glBlendFunc(GL_ONE, GL_ONE);
00613 
00614     TVector CameraPos = aCamera.GetPosition();
00615 
00616     glBindTexture(  GL_TEXTURE_2D, iTexture.iID );
00617     glVertexPointer( 3, GL_BYTE, 0, snowVertices );
00618     glTexCoordPointer( 2, GL_BYTE, 0, snowTextureCoords );
00619 
00620     for ( GLint i = 0; i < iParticlesCount; i++ )
00621                 {
00622         glLoadIdentity();
00623         glTranslatef(iParticles[i].iPosition.iX-CameraPos.iX,
00624                      iParticles[i].iPosition.iY-CameraPos.iY,
00625                      iParticles[i].iPosition.iZ-CameraPos.iZ);
00626 
00627         glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, snowTriangles );
00628                 }
00629 
00630     glDisable(GL_BLEND);
00631         }
00632 
00633 

© Nokia 2006

Back to top