Nokia N97 SDK
Example Applications Guide

CRainfall Class Reference

#include <Rain.h>

Inheritance diagram for CRainfall:

List of all members.

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 196 of file Rain.h.


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


Constructor & Destructor Documentation

CRainfall::~CRainfall (   )  [virtual]
 

Destructor. Does nothing in this implementation.

Definition at line 460 of file Rain.cpp.

00461         {
00462         }

CRainfall::CRainfall (   )  [protected]
 

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

Definition at line 406 of file Rain.cpp.

00407         {
00408         }


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 420 of file Rain.cpp.

References ConstructL().

Referenced by CRain::AppInitL().

00422         {
00423         /* Symbian 2-phase constructor. Calls both the default
00424            C++ constructor and Symbian ConstructL methods */
00425         CRainfall* self = new (ELeave) CRainfall;
00426         CleanupStack::PushL( self );
00427         self->ConstructL( aParticlesCount, aPosition, aWidth, aDepth, aGroundLevel);
00428         CleanupStack::Pop();
00429 
00430         return self;
00431         }

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 443 of file Rain.cpp.

References iDepth, iGroundLevel, iSeed, and iWidth.

Referenced by NewL().

00445         {
00446         CParticleEngine::ConstructL(aParticlesCount, aPosition);
00447 
00448         iWidth = aWidth;
00449         iDepth = aDepth;
00450         iGroundLevel = aGroundLevel;
00451 
00452         TTime now;
00453         now.HomeTime();
00454         iSeed = now.Int64();
00455 
00456         ResetEngine();
00457         }

GLfloat CRainfall::Random (   ) 
 

Returns a random float number.

Returns:
Random float number.

Definition at line 531 of file Rain.cpp.

References iSeed.

Referenced by ResetParticle().

00532         {
00533         return ((GLfloat)(Math::FRand(iSeed)));
00534         }

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 469 of file Rain.cpp.

References iDepth, iSeed, iWidth, and Random().

Referenced by UpdateEngine().

00470         {
00471 
00472         TParticle & Particle = iParticles[aIndex];
00473 
00474     Particle.iPosition = TVector( iWidth * (Random() - 0.5f), 0, iDepth * (Random() - 0.5f)) + iPosition;
00475     Particle.iVelocity = TVector( 0, randrange( -40.f, -20.f, iSeed ), 0);
00476         }

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 483 of file Rain.cpp.

References iGroundLevel, and ResetParticle().

Referenced by CRain::AppCycle().

00484         {
00485     for ( GLint i = 0; i < iParticlesCount; i++ )
00486                 {
00487         iParticles[i].iPosition += (iParticles[i].iVelocity * aDeltaTimeSecs);
00488         if ( iParticles[i].iPosition.iY < iGroundLevel )
00489                         {
00490                         ResetParticle(i);
00491                         }
00492                 }
00493         }

void CRainfall::RenderEngine (  TCamera &  aCamera  ) 
 

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

Definition at line 501 of file Rain.cpp.

Referenced by CRain::AppCycle().

00502         {
00503     glDisable( GL_TEXTURE_2D );
00504     glEnable(GL_BLEND);
00505     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00506         glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
00507 
00508         TVector CameraPos = aCamera.GetPosition();
00509 
00510         glVertexPointer( 3, GL_BYTE, 0, rainVertices );
00511     for ( GLint i = 0; i < iParticlesCount; i++ )
00512                 {
00513                 glLoadIdentity();
00514                 glTranslatef( iParticles[i].iPosition.iX - CameraPos.iX,
00515                                   iParticles[i].iPosition.iY - CameraPos.iY,
00516                                           iParticles[i].iPosition.iZ - CameraPos.iZ );
00517 
00518                 glDrawArrays( GL_LINES, 0, 2 );
00519                 }
00520 
00521     glEnable( GL_TEXTURE_2D );
00522     glDisable(GL_BLEND);
00523         }


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 268 of file Rain.h.

Referenced by ConstructL(), and ResetParticle().

GLfloat CRainfall::iDepth
 

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

Definition at line 270 of file Rain.h.

Referenced by ConstructL(), and ResetParticle().

GLfloat CRainfall::iGroundLevel
 

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

Definition at line 272 of file Rain.h.

Referenced by ConstructL(), and UpdateEngine().

TInt64 CRainfall::iSeed [protected]
 

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

Definition at line 277 of file Rain.h.

Referenced by ConstructL(), Random(), and ResetParticle().


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

© Nokia 2009

Back to top