Nokia N97 SDK
Example Applications Guide

CEnvMapping Class Reference

#include <EnvMapping.h>

Inheritance diagram for CEnvMapping:

List of all members.

Detailed Description

Class that does the actual OpenGL ES rendering. Subclass of CFiniteStateMachine because the application needs to handle loading textures and running states.

Definition at line 49 of file EnvMapping.h.


Public Types

enum   { ELoadingTextures, ERunning }

Public Member Functions

virtual  ~CEnvMapping ()
void  AppInitL (void)
void  AppExit (void)
void  AppCycle (TInt aFrame)
void  OnEnterStateL (TInt aState)
void  OnStartLoadingTexturesL ()
void  OnEndLoadingTexturesL ()
void  InitializeArraysL (void)
void  CalculateTextureCoordinatesL (void)
void  RotateObjectLeft (void)
void  RotateObjectRight (void)
void  DrawDuck (TInt aFrame)
void  DrawHead (TInt aFrame)
void  DuckModel (void)
void  HeadModel (void)
void  SetScreenSize (TUint aWidth, TUint aHeight)

Static Public Member Functions

static CEnvMapping *  NewL (TUint aWidth, TUint aHeight)

Protected Member Functions

  CEnvMapping (TUint aWidth, TUint aHeight)
void  ConstructL (void)

Private Attributes

CTextureManager *  iTextureManager
TTexture  iEnvMapTexture
TUint  iScreenWidth
TUint  iScreenHeight
GLshort  iNumFaces
GLshort  iNumVertices
TBool  iRotateObjectLeftEnabled
TBool  iRotateObjectRightEnabled
GLint  iObjectRotAngle
GLint  iObjectModel
GLshort  iDuckTexCoords [duckVertices *3]
GLshort  iHeadTexCoords [headVertices *3]
GLfloat *  iFaceNormals
GLubyte *  iNormalCounter


Member Enumeration Documentation

anonymous enum
 

Application states: ELoadingTextures - indicates that the app. is loading textures. ERunning - indicates that the app. is running.

Definition at line 178 of file EnvMapping.h.

00179                         {
00180                         ELoadingTextures,
00181                         ERunning
00182                         };


Constructor & Destructor Documentation

CEnvMapping::~CEnvMapping (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 80 of file EnvMapping.cpp.

References iFaceNormals, and iNormalCounter.

00081 {
00082     delete iFaceNormals;
00083     delete iNormalCounter;
00084 }

CEnvMapping::CEnvMapping (  TUint  aWidth,
TUint  aHeight
)  [protected]
 

Standard constructor that must never Leave. Stores the given screen width and height.

Parameters:
aWidth  Width of the screen.
aHeight  Height of the screen.

Definition at line 27 of file EnvMapping.cpp.

References iFaceNormals, iNormalCounter, iScreenHeight, and iScreenWidth.

Referenced by NewL().

00027                                                      : CFiniteStateMachine()
00028 {
00029     iFaceNormals   = 0; // Initialize member variables
00030     iNormalCounter = 0;
00031 
00032     iScreenWidth  = aWidth;
00033     iScreenHeight = aHeight;
00034 }


Member Function Documentation

CEnvMapping * CEnvMapping::NewL (  TUint  aWidth,
TUint  aHeight
)  [static]
 

Factory method for creating a new CSimpleCube object.

Definition at line 56 of file EnvMapping.cpp.

References CEnvMapping().

00057 {
00058     /* Symbian 2-phase constructor. Calls both the default
00059        C++ constructor and Symbian ConstructL methods */
00060     CEnvMapping* self = new (ELeave) CEnvMapping( aWidth, aHeight );
00061     CleanupStack::PushL( self );
00062     self->ConstructL();
00063     CleanupStack::Pop();
00064 
00065     return self;
00066 }

void CEnvMapping::AppInitL (  void   ) 
 

Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode and creates the CTextureManager instance and starts loading of required textures.

Definition at line 94 of file EnvMapping.cpp.

References iDuckTexCoords, iEnvMapTexture, iObjectRotAngle, iRotateObjectLeftEnabled, iRotateObjectRightEnabled, iScreenHeight, iScreenWidth, iTextureManager, and SetScreenSize().

00095 {
00096     // Construct a texture manager that uses the application's private
00097     // directory as the location for all textures.
00098     iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenHeight,
00099                                                   FRUSTUM_TOP, FRUSTUM_BOTTOM, FRUSTUM_RIGHT, FRUSTUM_LEFT, FRUSTUM_NEAR,
00100                                                   this );
00101 
00102     // Initialize viewport and projection.
00103     SetScreenSize( iScreenWidth, iScreenHeight );
00104 
00105     /* Set the screen background color. */
00106     glClearColor( 0.f, 0.f, 0.f, 1.f );
00107 
00108     /* Enable back face culling. */
00109     glEnable( GL_DEPTH_TEST );
00110     glEnable( GL_CULL_FACE  );
00111     glEnable( GL_TEXTURE_2D );
00112 
00113     /* Enable vertex arrays. */
00114     glEnableClientState( GL_VERTEX_ARRAY );
00115     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00116 
00117     /* Set array pointers. */
00118     glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck );
00119     glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords );
00120 
00121     /* Set the initial shading mode */
00122     glShadeModel( GL_FLAT );
00123 
00124     /* Do not use perspective correction */
00125     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00126 
00127     iRotateObjectLeftEnabled  = EFalse;
00128     iRotateObjectRightEnabled = EFalse;
00129     iObjectRotAngle    = 0;
00130 
00131     // Push the textures into the loading queue.
00132     _LIT(KEnvMapTexture, "envmap.jpg");
00133     iTextureManager->RequestToLoad( KEnvMapTexture, &iEnvMapTexture );
00134 
00135     //Start to load the textures.
00136     iTextureManager->DoLoadL();
00137 }

void CEnvMapping::AppExit (  void   ) 
 

Called upon application exit. Destroys the CTextureManager instance that was created in AppInitL() method.

Definition at line 74 of file EnvMapping.cpp.

References iTextureManager.

Referenced by CEnvMappingContainer::~CEnvMappingContainer().

00075 {
00076     delete iTextureManager;
00077 }

void CEnvMapping::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame  Number of the frame to be rendered.

Definition at line 406 of file EnvMapping.cpp.

References DrawDuck(), iObjectModel, iObjectRotAngle, iRotateObjectLeftEnabled, and iRotateObjectRightEnabled.

Referenced by CEnvMappingContainer::DrawCallBack().

00407 {
00408     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00409 
00410     /* Update user controlled object rotation */
00411     if( iRotateObjectLeftEnabled )
00412     {
00413         iObjectRotAngle -= 2;
00414     }
00415     else if( iRotateObjectRightEnabled )
00416     {
00417         iObjectRotAngle += 2;
00418     }
00419 
00420     if( iObjectModel == DUCK_MODEL )
00421     {
00422         DrawDuck( aFrame );
00423     }
00424     else if ( iObjectModel == HEAD_MODEL )
00425     {
00426         DrawHead( aFrame );
00427     }
00428 }

void CEnvMapping::OnEnterStateL (  TInt  aState  ) 
 

Called when the finite state machine enters a new state. Does nothing in this implementation.

Parameters:
aState  State that is about to be entered.

Definition at line 368 of file EnvMapping.cpp.

00369         {
00370         }

void CEnvMapping::OnStartLoadingTexturesL (   ) 
 

Called when texture manager starts loading the textures. Sets the current state to "loading textures".

Definition at line 377 of file EnvMapping.cpp.

00378         {
00379     SetStateL( ELoadingTextures );
00380         }

void CEnvMapping::OnEndLoadingTexturesL (   ) 
 

Called when texture manager has completed texture loading. Changes the current state to "running".

Definition at line 386 of file EnvMapping.cpp.

References iEnvMapTexture.

00387         {
00388         if ( GetState() == ELoadingTextures )
00389                 {
00390         /* Bind the envmap texture to iEnvMapTexture and set the texture environment. */
00391         glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00392             glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00393         glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
00394 
00395                 SetStateL( ERunning );
00396                 }
00397         }

void CEnvMapping::InitializeArraysL (  void   ) 
 

Initializes arrays used to calculate objects texture coordinates. Reserves dynamically memories for the arrays depending on the size on the models.

Definition at line 147 of file EnvMapping.cpp.

References iDuckTexCoords, iFaceNormals, iNormalCounter, and iObjectModel.

Referenced by CalculateTextureCoordinatesL().

00148 {
00149     _LIT(KModelError, "Incorrect Model");
00150 
00151     if( iFaceNormals )
00152     {
00153         delete iFaceNormals;
00154     }
00155 
00156     if( iNormalCounter )
00157     {
00158         delete iNormalCounter;
00159     }
00160 
00161     if( iObjectModel == DUCK_MODEL )
00162     {
00163         iFaceNormals    = new (ELeave) GLfloat[ duckVertices*3 ];
00164         iNormalCounter  = new (ELeave) TUint8[ duckVertices ];
00165 
00166         for( TInt i = 0; i < duckVertices;   i++ ) { iNormalCounter[i] = 0;  }
00167         for( TInt j = 0; j < 3*duckVertices; j++ ) { iFaceNormals[j]   = 0.; }
00168         for( TInt k = 0; k < 3*duckVertices; k++ ) { iDuckTexCoords[k] = 0;  }
00169     }
00170     else if( iObjectModel == HEAD_MODEL )
00171     {
00172         iFaceNormals    = new (ELeave) GLfloat[ 3*headVertices ];
00173         iNormalCounter  = new (ELeave) TUint8[ headVertices ];
00174 
00175         for( TInt i = 0; i < headVertices;   i++ ) { iNormalCounter[i] = 0;  }
00176         for( TInt j = 0; j < 3*headVertices; j++ ) { iFaceNormals[j]   = 0.; }
00177         for( TInt k = 0; k < 3*headVertices; k++ ) { iHeadTexCoords[k] = 0;  }
00178     }
00179     else User::Panic( KModelError, 1 );
00180 }

void CEnvMapping::CalculateTextureCoordinatesL (  void   ) 
 

Calculates texture coordinates for the models.

Definition at line 191 of file EnvMapping.cpp.

References InitializeArraysL(), iNumFaces, iNumVertices, and iObjectModel.

Referenced by ConstructL().

00192 {
00193     _LIT(KNormalError,    "Normal length 0");
00194     _LIT(KAvgNormalError, "Avg. Normal length 0");
00195 
00196     iObjectModel = HEAD_MODEL; // calculate tex coords first to head model
00197 
00198     GLushort vertex1 = 0; // indexes to the object vertex data
00199     GLushort vertex2 = 0;
00200     GLushort vertex3 = 0;
00201 
00202         GLfloat pnt1[3] = { .0f, .0f, .0f }; // vertex triplet that forms a triangle
00203     GLfloat pnt2[3] = { .0f, .0f, .0f };
00204     GLfloat pnt3[3] = { .0f, .0f, .0f };
00205 
00206     GLfloat vec1[3]; // two vectors calculated from the vertex triplet
00207     GLfloat vec2[3];
00208 
00209     GLfloat norm[3];          // face normal
00210     GLfloat normLen;          // normal lenght
00211     GLint   iNumFaces = 0;    // number of faces in a model
00212     GLint   iNumVertices = 0; // number of vertices in a model
00213 
00214     for( TInt obj = 0; obj < NUM_OF_MODELS; obj++ )
00215     {
00216 
00217         if( iObjectModel == DUCK_MODEL )
00218         {
00219             iNumFaces    = duckFaces;
00220             iNumVertices = duckVertices;
00221             InitializeArraysL(); // initialize all arrays
00222         }
00223         else if( iObjectModel == HEAD_MODEL )
00224         {
00225             iNumFaces    = headFaces;
00226             iNumVertices = headVertices;
00227             InitializeArraysL(); // initialize all arrays
00228         }
00229 
00230         for( TInt i = 0; i < iNumFaces; i++ )
00231         {
00232             // Form two vectors vec1 and vec2 from vertex triplet,
00233             // pnt1/2/3 are the three vertices that form a triangle.
00234             if( iObjectModel == DUCK_MODEL )
00235             {
00236                 vertex1 = objFacedataDuck[i*3];
00237                 vertex2 = objFacedataDuck[i*3+1];
00238                 vertex3 = objFacedataDuck[i*3+2];
00239 
00240                 pnt1[0] = objVertexdataDuck[ 3*vertex1     ];
00241                 pnt1[1] = objVertexdataDuck[ 3*vertex1 + 1 ];
00242                 pnt1[2] = objVertexdataDuck[ 3*vertex1 + 2 ];
00243 
00244                 pnt2[0] = objVertexdataDuck[ 3*vertex2     ];
00245                 pnt2[1] = objVertexdataDuck[ 3*vertex2 + 1 ];
00246                 pnt2[2] = objVertexdataDuck[ 3*vertex2 + 2 ];
00247 
00248                 pnt3[0] = objVertexdataDuck[ 3*vertex3     ];
00249                 pnt3[1] = objVertexdataDuck[ 3*vertex3 + 1 ];
00250                 pnt3[2] = objVertexdataDuck[ 3*vertex3 + 2 ];
00251             }
00252             else if( iObjectModel == HEAD_MODEL )
00253             {
00254                 vertex1 = objFacedataHead[i*3];
00255                 vertex2 = objFacedataHead[i*3+1];
00256                 vertex3 = objFacedataHead[i*3+2];
00257 
00258                 pnt1[0] = objVertexdataHead[ 3*vertex1     ];
00259                 pnt1[1] = objVertexdataHead[ 3*vertex1 + 1 ];
00260                 pnt1[2] = objVertexdataHead[ 3*vertex1 + 2 ];
00261 
00262                 pnt2[0] = objVertexdataHead[ 3*vertex2     ];
00263                 pnt2[1] = objVertexdataHead[ 3*vertex2 + 1 ];
00264                 pnt2[2] = objVertexdataHead[ 3*vertex2 + 2 ];
00265 
00266                 pnt3[0] = objVertexdataHead[ 3*vertex3     ];
00267                 pnt3[1] = objVertexdataHead[ 3*vertex3 + 1 ];
00268                 pnt3[2] = objVertexdataHead[ 3*vertex3 + 2 ];
00269             }
00270 
00271             vec1[0] = pnt2[0] - pnt1[0];
00272             vec1[1] = pnt2[1] - pnt1[1];
00273             vec1[2] = pnt2[2] - pnt1[2];
00274 
00275             vec2[0] = pnt3[0] - pnt1[0];
00276             vec2[1] = pnt3[1] - pnt1[1];
00277             vec2[2] = pnt3[2] - pnt1[2];
00278 
00279             // calculate crossproduct between the two vectors. That way
00280             // we have the face normal.
00281             norm[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1];
00282             norm[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2];
00283             norm[2] = vec1[0]*vec2[1] - vec1[1]*vec2[2];
00284 
00285             normLen = sqrt( norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2] );
00286 
00287             /* If normal lenght is zero, generate panic */
00288             if( normLen == 0.0 )
00289             {
00290                 User::Panic( KNormalError, 1 );
00291             }
00292 
00293             // normalize the calculated normal
00294             norm[0] /= normLen;
00295             norm[1] /= normLen;
00296             norm[2] /= normLen;
00297 
00298             // store normal to each vertex index that were used to calculate
00299             // the normal. Add also corresponding vertex counter
00300             iFaceNormals[ 3*vertex1   ] += norm[0];
00301             iFaceNormals[ 3*vertex1+1 ] += norm[1];
00302             iFaceNormals[ 3*vertex1+2 ] += norm[2];
00303             iNormalCounter[ vertex1 ]   += 1;
00304 
00305             iFaceNormals[ 3*vertex2   ] += norm[0];
00306             iFaceNormals[ 3*vertex2+1 ] += norm[1];
00307             iFaceNormals[ 3*vertex2+2 ] += norm[2];
00308             iNormalCounter[ vertex2 ]   += 1;
00309 
00310             iFaceNormals[ 3*vertex3   ] += norm[0];
00311             iFaceNormals[ 3*vertex3+1 ] += norm[1];
00312             iFaceNormals[ 3*vertex3+2 ] += norm[2];
00313             iNormalCounter[ vertex3 ]   += 1;
00314         }
00315 
00316         // calculate and normalize average normal for each vertex
00317         // scale the resulting normal values by COORD_SCALE for GLshort range
00318         for( TInt j = 0; j < iNumVertices; j++ )
00319         {
00320             /* If iNormalCounter value is zero, skip that vertex.
00321                If the value is zero, it means that the vertex number j is not
00322                used in the object's geometry. */
00323             if( iNormalCounter[j] != 0 )
00324             {
00325 
00326                 // iFaceNormals contains the sum of all the normals common to each vertex
00327                 // divide by the iNormalCounter value to get the average normal
00328                 iFaceNormals[3*j]   = (iFaceNormals[3*j]/iNormalCounter[j]  );
00329                 iFaceNormals[3*j+1] = (iFaceNormals[3*j+1]/iNormalCounter[j]);
00330                 iFaceNormals[3*j+2] = (iFaceNormals[3*j+2]/iNormalCounter[j]);
00331 
00332                 // normalize the result, then scale the normal values by COORD_SCALE to
00333                 // make GLshort range, and store the resulting normal.
00334                 normLen = sqrt( iFaceNormals[3*j]*iFaceNormals[3*j] +
00335                                 iFaceNormals[3*j+1]*iFaceNormals[3*j+1] +
00336                                 iFaceNormals[3*j+2]*iFaceNormals[3*j+2] );
00337 
00338                 /* If normal lenght is zero, generate panic */
00339                 if( normLen == 0.0 )
00340                 {
00341                     User::Panic( KAvgNormalError, 1 );
00342                 }
00343 
00344                 if( iObjectModel == DUCK_MODEL )
00345                 {
00346                     iDuckTexCoords[3*j]   = (GLshort) (COORD_SCALE*iFaceNormals[3*j]/normLen  );
00347                     iDuckTexCoords[3*j+1] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+1]/normLen);
00348                     iDuckTexCoords[3*j+2] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+2]/normLen);
00349                 }
00350                 else if( iObjectModel == HEAD_MODEL )
00351                 {
00352                     iHeadTexCoords[3*j]   = (GLshort) (COORD_SCALE*iFaceNormals[3*j]/normLen  );
00353                     iHeadTexCoords[3*j+1] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+1]/normLen);
00354                     iHeadTexCoords[3*j+2] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+2]/normLen);
00355                 }
00356             }
00357         }
00358         // Change the model to head model. Default start model is duck.
00359         iObjectModel = DUCK_MODEL;
00360     }
00361 }

void CEnvMapping::RotateObjectLeft (  void   ) 
 

Rotates object left.

Definition at line 514 of file EnvMapping.cpp.

References iRotateObjectLeftEnabled.

Referenced by CEnvMappingAppUi::HandleKeyEventL().

void CEnvMapping::RotateObjectRight (  void   ) 
 

Rotates object right.

Definition at line 524 of file EnvMapping.cpp.

References iRotateObjectRightEnabled.

Referenced by CEnvMappingAppUi::HandleKeyEventL().

void CEnvMapping::DrawDuck (  TInt  aFrame  ) 
 

Draw the environment mapped duck model.

Parameters:
aFrame  Current frame in animation

Definition at line 437 of file EnvMapping.cpp.

References iEnvMapTexture, and iObjectRotAngle.

Referenced by AppCycle().

00438 {
00439     /* Set the correct texture matrix */
00440     glMatrixMode( GL_TEXTURE );
00441     glLoadIdentity();
00442     glTranslatef( 0.5f, 0.5f, 0.5f );    // texture coord. values [0,1]
00443     glScalef( 1.0f/(2.0f*COORD_SCALE),   // scale down the input texture
00444               1.0f/(2.0f*COORD_SCALE),   // coord. values to be in range
00445               1.0f/(2.0f*COORD_SCALE) ); // [-0.5, 0.5]
00446 
00447     /* First in texture matrix, insert the current camera and object
00448        rotations. */
00449     glRotatex((-90 << 16) + (GLint) (sin(aFrame * 0.17f) * 15 * 65536), 1 << 16, 0, 0);
00450     glRotatex((GLint) (sin(aFrame * 0.13f) * 10 * 65536), 0, 1 << 16, 0);
00451     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00452 
00453     glMatrixMode( GL_MODELVIEW );
00454     glLoadIdentity();
00455     glTranslatex( 0 , -20 << 16 , -CAMERA_DISTANCE << 16 );
00456     glRotatex((-90 << 16) + (GLint) (sin(aFrame * 0.17f) * 15 * 65536), 1 << 16, 0, 0);
00457     glRotatex((GLint) (sin(aFrame * 0.13f) * 10 * 65536), 0, 1 << 16, 0);
00458     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00459     glScalex( 3 << 6, 3 << 6, 3 << 6 ); // scale the duck to fit the screen
00460 
00461     glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00462     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00463     glDrawElements( GL_TRIANGLES, duckFaces * 3, GL_UNSIGNED_SHORT, objFacedataDuck );
00464 }

void CEnvMapping::DrawHead (  TInt  aFrame  ) 
 

Draw the environment mapped head model.

Parameters:
aFrame  Current frame in animation

Definition at line 473 of file EnvMapping.cpp.

References iEnvMapTexture, and iObjectRotAngle.

00474 {
00475     /* Set the correct texture matrix */
00476     glMatrixMode( GL_TEXTURE );
00477     glLoadIdentity();
00478     glTranslatef( 0.5f, 0.5f, 0.5f );    // texture coord. values [0,1]
00479     glScalef( 1.0f/(2.0f*COORD_SCALE),   // scale down the input texture
00480               1.0f/(2.0f*COORD_SCALE),   // coord. values to be in range
00481               1.0f/(2.0f*COORD_SCALE) ); // [-0.5, 0.5]
00482     /* First in texture matrix, insert the current camera and object
00483        rotations. */
00484     glRotatex( -90 << 16, 1 << 16, 0, 0);
00485     glRotatex( aFrame << 16, 5 << 16, 1 << 12, 0);
00486     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00487 
00488     glMatrixMode( GL_MODELVIEW );
00489     glLoadIdentity();
00490     glTranslatex( 0 , 0, -CAMERA_DISTANCE << 16 );
00491     glRotatex( -90 << 16, 1 << 16, 0, 0);
00492     glRotatex( aFrame << 16, 5 << 16, 1 << 12, 0);
00493     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00494 
00495     glScalex( 1 << 10, 1 << 10, 1 << 10 ); // scale the duck to fit the screen
00496     glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00497     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00498     glDrawElements( GL_TRIANGLES, headFaces * 3, GL_UNSIGNED_SHORT, objFacedataHead );
00499 }

void CEnvMapping::DuckModel (  void   ) 
 

Change to duck model

Definition at line 536 of file EnvMapping.cpp.

References iDuckTexCoords, and iObjectModel.

Referenced by CEnvMappingAppUi::HandleCommandL().

00537 {
00538     iObjectModel = DUCK_MODEL;
00539     glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck );
00540     glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords );
00541 }

void CEnvMapping::HeadModel (  void   ) 
 

Change to head model

Definition at line 550 of file EnvMapping.cpp.

References iHeadTexCoords, and iObjectModel.

Referenced by CEnvMappingAppUi::HandleCommandL().

00551 {
00552     iObjectModel = HEAD_MODEL;
00553     glVertexPointer( 3, GL_SHORT, 0, objVertexdataHead );
00554     glTexCoordPointer( 3, GL_SHORT, 0, iHeadTexCoords );
00555 }

void CEnvMapping::SetScreenSize (  TUint  aWidth,
TUint  aHeight
) 
 

Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size and sets this size to the CTextureManager.

Parameters:
aWidth  New width of the screen.
aHeight  New height of the screen.

Definition at line 562 of file EnvMapping.cpp.

References iScreenHeight, iScreenWidth, and iTextureManager.

Referenced by AppInitL(), and CEnvMappingContainer::SizeChanged().

00563     {
00564     iScreenWidth  = aWidth;
00565     iScreenHeight = aHeight;
00566 
00567     // Notify the texture manager of screen size change
00568     iTextureManager->SetScreenSize( aWidth, aHeight );
00569 
00570     // Reinitialize viewport and projection.
00571     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00572 
00573     // Recalculate the view frustrum
00574     glMatrixMode( GL_PROJECTION );
00575     glLoadIdentity();
00576     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00577     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00578                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00579                 FRUSTUM_NEAR, FRUSTUM_FAR );
00580     glMatrixMode( GL_MODELVIEW );
00581     }

void CEnvMapping::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 44 of file EnvMapping.cpp.

References CalculateTextureCoordinatesL().

00045 {
00046     /* Calculate texture coordinates for the models */
00047     CalculateTextureCoordinatesL();
00048 }


Member Data Documentation

CTextureManager* CEnvMapping::iTextureManager [private]
 

Texture manager that is used to load the used textures.

Definition at line 187 of file EnvMapping.h.

Referenced by AppExit(), AppInitL(), and SetScreenSize().

TTexture CEnvMapping::iEnvMapTexture [private]
 

Environment map texture.

Definition at line 189 of file EnvMapping.h.

Referenced by AppInitL(), DrawDuck(), DrawHead(), and OnEndLoadingTexturesL().

TUint CEnvMapping::iScreenWidth [private]
 

Width of the screen

Definition at line 192 of file EnvMapping.h.

Referenced by AppInitL(), CEnvMapping(), and SetScreenSize().

TUint CEnvMapping::iScreenHeight [private]
 

Height of the screen

Definition at line 194 of file EnvMapping.h.

Referenced by AppInitL(), CEnvMapping(), and SetScreenSize().

GLshort CEnvMapping::iNumFaces [private]
 

Num of object faces. Used when calculating texture coords.

Definition at line 197 of file EnvMapping.h.

Referenced by CalculateTextureCoordinatesL().

GLshort CEnvMapping::iNumVertices [private]
 

Num of object vertices. Used when calculating texture coords.

Definition at line 199 of file EnvMapping.h.

Referenced by CalculateTextureCoordinatesL().

TBool CEnvMapping::iRotateObjectLeftEnabled [private]
 

Whether object is rotated left or not.

Definition at line 202 of file EnvMapping.h.

Referenced by AppCycle(), AppInitL(), and RotateObjectLeft().

TBool CEnvMapping::iRotateObjectRightEnabled [private]
 

Whether object is rotated right or not.

Definition at line 204 of file EnvMapping.h.

Referenced by AppCycle(), AppInitL(), and RotateObjectRight().

GLint CEnvMapping::iObjectRotAngle [private]
 

Current rotation angle of the object.

Definition at line 206 of file EnvMapping.h.

Referenced by AppCycle(), AppInitL(), DrawDuck(), and DrawHead().

GLint CEnvMapping::iObjectModel [private]
 

Currently shown object model (DUCK_MODEL or HEAD_MODEL).

Definition at line 208 of file EnvMapping.h.

Referenced by AppCycle(), CalculateTextureCoordinatesL(), DuckModel(), HeadModel(), and InitializeArraysL().

GLshort CEnvMapping::iDuckTexCoords[duckVertices *3] [private]
 

Vertex normals stored here are used as straight texture coordinates for the duck's environmental mapping.

Definition at line 211 of file EnvMapping.h.

Referenced by AppInitL(), DuckModel(), and InitializeArraysL().

GLshort CEnvMapping::iHeadTexCoords[headVertices *3] [private]
 

Vertex normals stored here are used as straight texture coordinates for the head's environmental mapping.

Definition at line 213 of file EnvMapping.h.

Referenced by HeadModel().

GLfloat* CEnvMapping::iFaceNormals [private]
 

Temporary storage of face normals.

Definition at line 216 of file EnvMapping.h.

Referenced by CEnvMapping(), InitializeArraysL(), and ~CEnvMapping().

GLubyte* CEnvMapping::iNormalCounter [private]
 

Tells how many faces are connected to each vertex. This value is used when calculating an average normal for each vertices. That normal is then used are direct texture coordinate value for that particular vertex.

Definition at line 223 of file EnvMapping.h.

Referenced by CEnvMapping(), InitializeArraysL(), and ~CEnvMapping().


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

© Nokia 2009

Back to top