Nokia N97 SDK
Example Applications Guide

CFireFly Class Reference

#include <Firefly.h>

List of all members.


Detailed Description

Class that represents the firefly that is light source for the bumpmapping.

Definition at line 25 of file Firefly.h.


Public Member Functions

virtual  ~CFireFly ()
void  DoMovement (GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs)
void  Draw ()

Static Public Member Functions

static CFireFly *  NewL (GLfloat aLeft, GLfloat aRight, GLfloat aBottom, GLfloat aTop, GLfloat aMinZCoord, GLfloat aMaxZCoord, CTextureManager *aTexManager)

Public Attributes

TVector  iPosition

Protected Member Functions

  CFireFly (GLfloat aLeft, GLfloat aRight, GLfloat aBottom, GLfloat aTop, GLfloat aMinZCoord, GLfloat aMaxZCoord)
void  ConstructL (CTextureManager *aTexManager)

Private Attributes

TVector  iTarget
TVector  iSpeed
TTexture  iGlowTexture
GLfloat  iLeft
GLfloat  iRight
GLfloat  iBottom
GLfloat  iTop
GLfloat  iMinZ
GLfloat  iMaxZ
TInt64  iSeed


Constructor & Destructor Documentation

CFireFly::~CFireFly (   )  [virtual]
 

Destructor. Destroys the position, target and speed vectors.

Definition at line 111 of file Firefly.cpp.

00112         {
00113         }

CFireFly::CFireFly (  GLfloat  aLeft,
GLfloat  aRight,
GLfloat  aBottom,
GLfloat  aTop,
GLfloat  aMinZCoord,
GLfloat  aMaxZCoord
)  [protected]
 

Standard constructor that must never Leave. Stores the given parameters to class attributes.

Parameters:
aLeft  Left boundary of the rectangular area where this firefly should move in.
aRight  Right boundary of the rectangular area where this firefly should move in.
aBottom  Bottom boundary of the rectangular area where this firefly should move in.
aTop  Top boundary of the rectangular area where this firefly should move in.
aMinZCoord  Minimum Z-coordinate for the firefly.
aMaxZCoord  Maximum Z-coordinate for the firefly.

Definition at line 80 of file Firefly.cpp.

References iBottom, iLeft, iMaxZ, iMinZ, iPosition, iRight, iTarget, and iTop.

Referenced by NewL().

00081         {
00082         iLeft        = aLeft;
00083         iRight       = aRight;
00084         iBottom      = aBottom;
00085         iTop         = aTop;
00086         iMinZ        = aMinZCoord;
00087         iMaxZ        = aMaxZCoord;
00088         iPosition.iZ = aMinZCoord;
00089         iTarget.iZ   = aMinZCoord;
00090         }


Member Function Documentation

CFireFly * CFireFly::NewL (  GLfloat  aLeft,
GLfloat  aRight,
GLfloat  aBottom,
GLfloat  aTop,
GLfloat  aMinZCoord,
GLfloat  aMaxZCoord,
CTextureManager *  aTexManager
)  [static]
 

Factory method for creating a new FireFly object. Calls the hidden constructors.

Parameters:
aLeft  Left boundary of the rectangular area where this firefly should move in.
aRight  Right boundary of the rectangular area where this firefly should move in.
aBottom  Bottom boundary of the rectangular area where this firefly should move in.
aTop  Top boundary of the rectangular area where this firefly should move in.
aMinZCoord  Minimum Z-coordinate for the firefly.
aMaxZCoord  Maximum Z-coordinate for the firefly.
aTexManager  Texture manager that is used to load the required textures for the firefly.

Definition at line 61 of file Firefly.cpp.

References CFireFly().

Referenced by CBumpMap::AppInitL().

00063         {
00064     // Symbian 2-phase constructor. Calls both the default
00065     // C++ constructor and Symbian ConstructL methods
00066     CFireFly* self = new (ELeave) CFireFly( aLeft, aRight, aBottom, aTop, aMinZCoord, aMaxZCoord );
00067 
00068     CleanupStack::PushL( self );
00069     self->ConstructL( aTexManager );
00070     CleanupStack::Pop();
00071 
00072         return self;
00073         }

void CFireFly::ConstructL (  CTextureManager *  aTexManager  )  [protected]
 

Second phase constructor that can call methods that may leave.

Parameters:
aTexManager  Texture manager that is used to load the required textures for the firefly.

Definition at line 97 of file Firefly.cpp.

References iGlowTexture, and iSeed.

00098         {
00099         TTime now;
00100         iSeed = now.Int64();
00101 
00102     // Add required textures to the texture manager's loading queue
00103         _LIT( KFireFlyGlowName, "firefly.jpg" );
00104     aTexManager->RequestToLoad( KFireFlyGlowName, &iGlowTexture, false );
00105         }

void CFireFly::DoMovement (  GLuint  aFrame,
GLfloat  aTimeSecs,
GLfloat  aDeltaTimeSecs
) 
 

Calculates the movement of the firefly.

Parameters:
aFrame  Number of the frame to be rendered.
aTimeSecs  Seconds elapsed since the application started running.
aDeltaTimeSecs  Seconds elapsed since last call to AppCycle().

Definition at line 119 of file Firefly.cpp.

References iPosition, iSpeed, and iTarget.

Referenced by CBumpMap::AppCycle().

00120         {
00121     // Speed in x and y directions is based on the distance to the target
00122     iSpeed.iX = ( iTarget.iX - iPosition.iX ) / 40.f;
00123     iSpeed.iY = ( iTarget.iY - iPosition.iY ) / 40.f;
00124     iSpeed.iZ = ( iTarget.iZ - iPosition.iZ ) / 40.f;
00125 
00126     // Make sure the minimum speed is 0.4 in every direction
00127     if( iSpeed.iX != 0.f )
00128         {
00129         iSpeed.iX = iSpeed.iX > 0.f ? Max( iSpeed.iX, 0.4f ) : Min( iSpeed.iX, -0.4f );
00130 
00131         }
00132     if( iSpeed.iY != 0.f )
00133         {
00134         iSpeed.iY = iSpeed.iY > 0.f ? Max( iSpeed.iY, 0.4f ) : Min( iSpeed.iY, -0.4f );
00135         }
00136     if( iSpeed.iZ != 0.f )
00137         {
00138         iSpeed.iZ = iSpeed.iZ > 0.f ? Max( iSpeed.iZ, 0.4f ) : Min( iSpeed.iZ, -0.4f );
00139         }
00140 
00141 
00142     iPosition += ( iSpeed * ( aDeltaTimeSecs * 40.f ) );
00143 
00144     // Check that we don't overshoot the target
00145     if ( ( iSpeed.iX < 0 &&  iPosition.iX < iTarget.iX ) || ( iSpeed.iX > 0 &&  iPosition.iX > iTarget.iX ) )
00146         {
00147         iPosition.iX = iTarget.iX;
00148         iSpeed.iX    = 0.0f;
00149         }
00150 
00151     if ( ( iSpeed.iY < 0 &&  iPosition.iY < iTarget.iY ) || ( iSpeed.iY > 0 &&  iPosition.iY > iTarget.iY ) )
00152         {
00153         iPosition.iY = iTarget.iY;
00154         iSpeed.iY    = 0.0f;
00155         }
00156 
00157     if ( ( iSpeed.iZ < 0 &&  iPosition.iZ < iTarget.iZ ) || ( iSpeed.iZ > 0 &&  iPosition.iZ > iTarget.iZ ) )
00158         {
00159         iPosition.iZ = iTarget.iZ;
00160         iSpeed.iZ    = 0.0f;
00161         }
00162 
00163     // Check if the fly has reached it's current target,
00164     // if it has generate a new target
00165     if( iPosition.iX == iTarget.iX && iPosition.iY == iTarget.iY && iPosition.iZ == iTarget.iZ )
00166                 {
00167                 iTarget.iX = randrange( iLeft, iRight, iSeed );
00168                 iTarget.iY = randrange( iBottom, iTop, iSeed );
00169                 iTarget.iZ = randrange( iMinZ, iMaxZ, iSeed );
00170                 }
00171         }

void CFireFly::Draw (   ) 
 

Draws the firefly at it's current position.

Definition at line 178 of file Firefly.cpp.

References iGlowTexture, iMaxZ, iMinZ, and iPosition.

Referenced by CBumpMap::AppCycle().

00179         {
00180     // Colour and normal arrays are not needed to draw the firefly
00181     glDisableClientState( GL_COLOR_ARRAY  );
00182     glDisableClientState( GL_NORMAL_ARRAY );
00183 
00184     // Vertex and texture coordinate arrays are needed
00185     glEnableClientState( GL_VERTEX_ARRAY );
00186     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00187 
00188         glPushMatrix();
00189 
00190     // Translate all drawing to the current location of the firefly
00191     glTranslatef( iPosition.iX, iPosition.iY, iPosition.iZ );
00192 
00193     // To enhance the illusion of the fly flying towards and away from the viewer
00194     // we scale the size based on the distance of the fly from the viewer.
00195     GLfloat scale = ( iPosition.iZ - iMinZ ) / ( iMaxZ - iMinZ );
00196     scale += 0.2f;
00197     glScalef( scale, scale, scale );
00198 
00199     // Setup colour and normal to be used when drawing the firefly
00200     glColor4f(  0.f, 0.93f, 0.87f, 1.f );
00201     glNormal3f( 0.f, 0.f, 1.f );
00202 
00203     // Use texture unit 0 to render the glow
00204     glClientActiveTexture(GL_TEXTURE0);
00205     glActiveTexture( GL_TEXTURE0 );
00206     glEnable( GL_TEXTURE_2D );
00207 
00208     // Set blending function translucency and enable blending
00209     glBindTexture( GL_TEXTURE_2D,  iGlowTexture.iID );
00210     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00211     glEnable( GL_BLEND );
00212     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_COLOR );
00213 
00214     // First draw the "halo" for the firefly
00215     glVertexPointer(   3, GL_FLOAT, 0, KGlowVerticeData );
00216     glTexCoordPointer( 2, GL_FLOAT, 0, KGlowTexCoordsData );
00217     glDrawElements(   GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, KGlowIndices );
00218 
00219     // Disable texturing and blending before drawing the firefly itself
00220     glBlendFunc( GL_SRC_ALPHA,GL_ONE );
00221     glDisable( GL_TEXTURE_2D );
00222     glDisableClientState( GL_TEXTURE_COORD_ARRAY );
00223 
00224     // Draw the firefly as a dot
00225     glColor4f( 1.f, 1.f, 1.f, 1.f );
00226     glVertexPointer( 3, GL_FLOAT, 0, KFlyVerticeData );
00227     glDrawArrays( GL_LINES, 0, 4 );
00228 
00229         glPopMatrix();
00230 
00231     // Restore states and translation
00232     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00233     glEnableClientState( GL_COLOR_ARRAY );
00234         }


Member Data Documentation

TVector CFireFly::iPosition
 

Current position of the firefly. Modified in doMovement() method and also read by the CBumpMap class.

Definition at line 86 of file Firefly.h.

Referenced by CFireFly(), DoMovement(), Draw(), and CBumpMap::DrawBumpmappedRect().

TVector CFireFly::iTarget [private]
 

Current target position of the firefly.

Definition at line 91 of file Firefly.h.

Referenced by CFireFly(), and DoMovement().

TVector CFireFly::iSpeed [private]
 

Current speed vector of the firefly. Used in doMovement() method to move the firefly.

Definition at line 93 of file Firefly.h.

Referenced by DoMovement().

TTexture CFireFly::iGlowTexture [private]
 

Texture that is used to draw the "glow" around the firefly.

Definition at line 95 of file Firefly.h.

Referenced by ConstructL(), and Draw().

GLfloat CFireFly::iLeft [private]
 

Left boundary of the rectangular area where this firefly moves in.

Definition at line 98 of file Firefly.h.

Referenced by CFireFly().

GLfloat CFireFly::iRight [private]
 

Right boundary of the rectangular area where this firefly moves in.

Definition at line 100 of file Firefly.h.

Referenced by CFireFly().

GLfloat CFireFly::iBottom [private]
 

Bottom boundary of the rectangular area where this firefly moves in.

Definition at line 102 of file Firefly.h.

Referenced by CFireFly().

GLfloat CFireFly::iTop [private]
 

Top boundary of the rectangular area where this firefly moves in.

Definition at line 104 of file Firefly.h.

Referenced by CFireFly().

GLfloat CFireFly::iMinZ [private]
 

Minimum Z-coordinate of the firefly.

Definition at line 106 of file Firefly.h.

Referenced by CFireFly(), and Draw().

GLfloat CFireFly::iMaxZ [private]
 

Maximum Z-coordinate of the firefly.

Definition at line 108 of file Firefly.h.

Referenced by CFireFly(), and Draw().

TInt64 CFireFly::iSeed [private]
 

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

Definition at line 110 of file Firefly.h.

Referenced by ConstructL().


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

© Nokia 2009

Back to top