S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CRainfall Class Reference

#include <Rain.h>

List of all members.

Public Member Functions

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

Static Public Member Functions

static CRainfall * NewL (GLint aParticlesCount, TVector aPosition, GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel)

Public Attributes

GLfloat iWidth
GLfloat iDepth
GLfloat iGroundLevel

Protected Member Functions

 CRainfall ()
void ConstructL (GLint aParticlesCount, TVector aPosition, GLfloat aWidth, GLfloat aDepth, GLfloat aGroundLevel)

Protected Attributes

TInt64 iSeed


Detailed Description

Rainfall particle effect class. Raindrops 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 Rain.h.


Constructor & Destructor Documentation

CRainfall::~CRainfall (   )  [virtual]
 

Destructor. Does nothing in this implementation.

Definition at line 539 of file Rain.cpp.

00540         {
00541         }

CRainfall::CRainfall (   )  [protected]
 

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

Definition at line 485 of file Rain.cpp.

00486         {
00487         }


Member Function Documentation

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

Factory method for creating a new CRain object.

Parameters:
aParticlesCount Number of particles used to create the rain effect.
aPosition Position of the rain particle generator.
aWidth Width of the rain area.
aDepth Height of the rain area.
aGroundLevel Ground level after which particle is reset back to beginning.

Definition at line 499 of file Rain.cpp.

References ConstructL().

00501         {
00502         /* Symbian 2-phase constructor. Calls both the default 
00503            C++ constructor and Symbian ConstructL methods */
00504         CRainfall* self = new (ELeave) CRainfall;
00505         CleanupStack::PushL( self );
00506         self->ConstructL( aParticlesCount, aPosition, aWidth, aDepth, aGroundLevel);
00507         CleanupStack::Pop();
00508 
00509         return self;
00510         }

void CRainfall::ConstructL (  GLint  aParticlesCount,
TVector  aPosition,
GLfloat  aWidth,
GLfloat  aDepth,
GLfloat  aGroundLevel
)  [protected]
 

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

Parameters:
aParticlesCount Number of particles used to create the rain effect.
aPosition Position of the rain particle generator.
aWidth Width of the rain area.
aDepth Height of the rain area.
aGroundLevel Ground level after which particle is reset back to beginning.

Definition at line 522 of file Rain.cpp.

References iDepth, iGroundLevel, iSeed, and iWidth.

00524         {
00525         CParticleEngine::ConstructL(aParticlesCount, aPosition);
00526 
00527         iWidth = aWidth;
00528         iDepth = aDepth;
00529         iGroundLevel = aGroundLevel;
00530 
00531         TTime now;
00532         now.HomeTime();
00533         iSeed = now.Int64();
00534 
00535         ResetEngine();
00536         }

GLfloat CRainfall::Random (   ) 
 

Returns a random float number.

Returns:
Random float number.

Definition at line 611 of file Rain.cpp.

References iSeed.

00612         {
00613         return ((GLfloat)(Math::FRand(iSeed)));
00614         }

void CRainfall::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 548 of file Rain.cpp.

References iDepth, iWidth, and Random().

00549         {
00550 
00551         TParticle & Particle = iParticles[aIndex];
00552 
00553     Particle.iPosition = TVector( iWidth * (Random() - 0.5f), 0, iDepth * (Random() - 0.5f)) + iPosition;
00554     Particle.iVelocity = TVector( 0, (GLfloat)(-(Random()*20.0f+20.0f)), 0);
00555         }

void CRainfall::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 562 of file Rain.cpp.

References iGroundLevel, and ResetParticle().

00563         {
00564     for ( GLint i = 0; i < iParticlesCount; i++ )
00565                 {
00566         iParticles[i].iPosition += (iParticles[i].iVelocity * aElapsedTime);
00567         if ( iParticles[i].iPosition.iY < iGroundLevel )
00568                         {
00569                         ResetParticle(i);
00570                         }
00571                 }
00572         }

void CRainfall::RenderEngine (  TCamera &  aCamera  ) 
 

Implementation of CParticleEngine::RenderEngine(). Renders each particle to the screen as simple lines.

Definition at line 580 of file Rain.cpp.

00581         {
00582     glDisable( GL_TEXTURE_2D );
00583     glEnable(GL_BLEND);
00584 
00585     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00586         glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
00587 
00588         TVector CameraPos = aCamera.GetPosition();
00589 
00590         glVertexPointer( 3, GL_BYTE, 0, rainVertices );
00591     for ( GLint i = 0; i < iParticlesCount; i++ )
00592                 {
00593                 glLoadIdentity();
00594                 glTranslatef(iParticles[i].iPosition.iX-CameraPos.iX,
00595                                  iParticles[i].iPosition.iY-CameraPos.iY,
00596                                          iParticles[i].iPosition.iZ-CameraPos.iZ);
00597     
00598                 glDrawArrays( GL_LINES, 0, 2 );
00599                 }
00600 
00601     glEnable( GL_TEXTURE_2D );
00602     glDisable(GL_BLEND);
00603         }


Member Data Documentation

GLfloat CRainfall::iWidth
 

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

Definition at line 293 of file Rain.h.

GLfloat CRainfall::iDepth
 

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

Definition at line 295 of file Rain.h.

GLfloat CRainfall::iGroundLevel
 

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

Definition at line 297 of file Rain.h.

TInt64 CRainfall::iSeed [protected]
 

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

Definition at line 302 of file Rain.h.


© Nokia 2006

Back to top