Nokia N97 SDK
Example Applications Guide

CSnowfall Class Reference

#include <Snow.h>

Inheritance diagram for CSnowfall:

List of all members.

Detailed Description

Snowfall particle effect class. Snowflakes are released from within the rectangle (iPosition.iX-iWidth/2, iPosition.iY, iPosition.iX-iWidth/2) (iPosition.iX+iWidth/2, iPosition.iY, iPosition.iX+iWidth/2). Once particle's y coordinate is below (smaller than) iGroundLevel, it is reset.

Definition at line 193 of file Snow.h.


Public Member Functions

virtual  ~CSnowfall ()
void  ResetParticle (GLint aIndex)
void  UpdateEngine (GLfloat aElapsedTime)
void  RenderEngine (TCamera &aCamera)

Static Public Member Functions

static CSnowfall *  NewL (GLint aParticlesCount, TVector aPosition, GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel, CTextureManager *aTextureManager)

Public Attributes

GLfloat  iWidth
GLfloat  iDepth
GLfloat  iGroundLevel

Protected Member Functions

  CSnowfall ()
void  ConstructL (GLint aParticlesCount, TVector aPosition, GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel, CTextureManager *aTextureManager)

Protected Attributes

TInt64  iSeed
TTexture  iTexture


Constructor & Destructor Documentation

CSnowfall::~CSnowfall (   )  [virtual]
 

Destructor. Does nothing in this implementation.

Definition at line 515 of file Snow.cpp.

00516         {
00517         }

CSnowfall::CSnowfall (   )  [protected]
 

Standard constructor that must never Leave. Does nothing in this implementation.

Definition at line 453 of file Snow.cpp.

00454         {
00455         };


Member Function Documentation

CSnowfall * CSnowfall::NewL (  GLint  aParticlesCount,
TVector  aPosition,
GLfloat  aWidth,
GLfloat  aDepth,
GLfloat  aGroundLevel,
CTextureManager *  aTextureManager
)  [static]
 

Factory method for creating a new CSnowfall object.

Parameters:
aParticlesCount  Number of particles used to create the snow effect.
aPosition  Position of the snow particle generator.
aWidth  Width of the snow area.
aDepth  Height of the snow area.
aGroundLevel  Ground level after which particle is reset back to beginning.
aTextureManager  Texture manager that is used to load the snow texture.

Definition at line 469 of file Snow.cpp.

References ConstructL().

Referenced by CSnow::AppInitL().

00472         {
00473     /* Symbian 2-phase constructor. Calls both the default
00474        C++ constructor and Symbian ConstructL methods */
00475     CSnowfall* self = new (ELeave) CSnowfall;
00476     CleanupStack::PushL( self );
00477     self->ConstructL( aParticlesCount, aPosition, aWidth, aDepth, aGroundLevel, aTextureManager);
00478     CleanupStack::Pop();
00479 
00480     return self;
00481         }

void CSnowfall::ConstructL (  GLint  aParticlesCount,
TVector  aPosition,
GLfloat  aWidth,
GLfloat  aDepth,
GLfloat  aGroundLevel,
CTextureManager *  aTextureManager
)  [protected]
 

Second phase contructor. Constructs the snow effect using the given parameters.

Parameters:
aParticlesCount  Number of particles used to create the snow effect.
aPosition  Position of the snow particle generator.
aWidth  Width of the snow area.
aDepth  Height of the snow area.
aGroundLevel  Ground level after which particle is reset back to beginning.
aTextureManager  Texture manager that is used to load the snow texture.

Definition at line 493 of file Snow.cpp.

References iDepth, iGroundLevel, iSeed, iTexture, and iWidth.

Referenced by NewL().

00496         {
00497     CParticleEngine::ConstructL(aParticlesCount, aPosition);
00498 
00499     iWidth = aWidth;
00500     iDepth = aDepth;
00501     iGroundLevel = aGroundLevel;
00502 
00503     TTime now;
00504     now.HomeTime();
00505     iSeed = now.Int64();
00506 
00507     ResetEngine();
00508 
00509         _LIT(KSnowName, "snow.jpg");
00510     aTextureManager->RequestToLoad(KSnowName, &iTexture );
00511         }

void CSnowfall::ResetParticle (  GLint  aIndex  ) 
 

Implementation of CParticleEngine::ResetParticle() method Resets the given particle to the rain "start plane" and gives it random location inside the rain area (defined when creating this effect) and random downwards speed.

Parameters:
aIndex  Particle to be reset.

Definition at line 524 of file Snow.cpp.

References iDepth, iSeed, and iWidth.

Referenced by UpdateEngine().

00525         {
00526     TParticle& Particle = iParticles[aIndex];
00527 
00528     Particle.iPosition = TVector(
00529         randrange( -iWidth / 0.5f, iWidth / 0.5f, iSeed ),
00530                 0,
00531                 randrange( -iDepth / 0.5f, iDepth / 0.5f, iSeed ) ) + iPosition;
00532 
00533     Particle.iVelocity = TVector(
00534         randrange( -0.2f,   0.2f, iSeed ),
00535         randrange( -20.f, -10.f, iSeed ),
00536         randrange( -0.2f,   0.2f, iSeed ) );
00537         }

void CSnowfall::UpdateEngine (  GLfloat  aElapsedTime  ) 
 

Implementation of CParticleEngine::UpdateEngine() method. Moves all the particles according to their current velocity vector and resets all particles that have fallen beneath the ground level back to the beginning plain.

Parameters:
aElapsedTime  Elapsed time since last frame. Used when calculating how much each particle has moved.

Definition at line 544 of file Snow.cpp.

References iGroundLevel, and ResetParticle().

Referenced by CSnow::AppCycle().

00545         {
00546     for ( GLint i = 0; i < iParticlesCount; i++ )
00547                 {
00548         iParticles[i].iPosition += (iParticles[i].iVelocity * aDeltaTimeSecs);
00549         if ( iParticles[i].iPosition.iY < iGroundLevel )
00550                         {
00551             ResetParticle(i);
00552                         }
00553                 }
00554         }

void CSnowfall::RenderEngine (  TCamera &  aCamera  ) 
 

Implementation of CParticleEngine::RenderEngine(). Renders each particle to the screen as texture mapped polygon that uses the iTexture as texture.

Definition at line 561 of file Snow.cpp.

References iTexture.

Referenced by CSnow::AppCycle().

00562         {
00563     glEnable(GL_BLEND);
00564     glBlendFunc(GL_ONE, GL_ONE);
00565 
00566     TVector CameraPos = aCamera.GetPosition();
00567 
00568     glBindTexture(  GL_TEXTURE_2D, iTexture.iID );
00569     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00570     glVertexPointer( 3, GL_BYTE, 0, snowVertices );
00571     glTexCoordPointer( 2, GL_BYTE, 0, snowTextureCoords );
00572 
00573     for ( GLint i = 0; i < iParticlesCount; i++ )
00574                 {
00575         glLoadIdentity();
00576         glTranslatef(iParticles[i].iPosition.iX-CameraPos.iX,
00577                      iParticles[i].iPosition.iY-CameraPos.iY,
00578                      iParticles[i].iPosition.iZ-CameraPos.iZ);
00579 
00580         glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, snowTriangles );
00581                 }
00582 
00583     glDisable(GL_BLEND);
00584         }


Member Data Documentation

GLfloat CSnowfall::iWidth
 

Width of the particle source area. This defines the width of the area where the snow falls.

Definition at line 261 of file Snow.h.

Referenced by ConstructL(), and ResetParticle().

GLfloat CSnowfall::iDepth
 

Depth of the particle source area. This defines the depth of the area where the snow falls.

Definition at line 263 of file Snow.h.

Referenced by ConstructL(), and ResetParticle().

GLfloat CSnowfall::iGroundLevel
 

Ground level that defines the plane after which the particles are reset back to the source plain.

Definition at line 265 of file Snow.h.

Referenced by ConstructL(), and UpdateEngine().

TInt64 CSnowfall::iSeed [protected]
 

Seed for the random generator (the time when ConstructL was called).

Definition at line 271 of file Snow.h.

Referenced by ConstructL(), and ResetParticle().

TTexture CSnowfall::iTexture [protected]
 

Snowflake texture.

Definition at line 273 of file Snow.h.

Referenced by ConstructL(), and RenderEngine().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top