S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CSnowfall Class Reference

#include <Snow.h>

List of all members.

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


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 221 of file Snow.h.


Constructor & Destructor Documentation

CSnowfall::~CSnowfall (   )  [virtual]
 

Destructor. Does nothing in this implementation.

Definition at line 565 of file Snow.cpp.

00566         {
00567         }

CSnowfall::CSnowfall (   )  [protected]
 

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

Definition at line 503 of file Snow.cpp.

00504         {
00505         };


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 519 of file Snow.cpp.

References ConstructL().

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         }

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 543 of file Snow.cpp.

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

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         }

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 574 of file Snow.cpp.

References iDepth, iSeed, and iWidth.

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         }

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 592 of file Snow.cpp.

References iGroundLevel, and ResetParticle().

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         }

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 609 of file Snow.cpp.

References iTexture.

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         }


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 289 of file Snow.h.

GLfloat CSnowfall::iDepth
 

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

Definition at line 291 of file Snow.h.

GLfloat CSnowfall::iGroundLevel
 

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

Definition at line 293 of file Snow.h.

TInt64 CSnowfall::iSeed [protected]
 

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

Definition at line 299 of file Snow.h.

TTexture CSnowfall::iTexture [protected]
 

Snowflake texture.

Definition at line 301 of file Snow.h.


© Nokia 2006

Back to top