S60 3rd Edition SDK for Symbian OS
Example Applications Guide

CEnvMapping Class Reference

#include <EnvMapping.h>

List of all members.

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


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 52 of file EnvMapping.h.


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 181 of file EnvMapping.h.

00182                         {
00183                         ELoadingTextures, 
00184                         ERunning
00185                         };


Constructor & Destructor Documentation

CEnvMapping::~CEnvMapping (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 121 of file EnvMapping.cpp.

References iFaceNormals, and iNormalCounter.

00122 {
00123     delete iFaceNormals;
00124     delete iNormalCounter;
00125 }

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 68 of file EnvMapping.cpp.

References iFaceNormals, iNormalCounter, iScreenHeight, and iScreenWidth.

00068                                                      : CFiniteStateMachine()
00069 {
00070     iFaceNormals   = 0; // Initialize member variables
00071     iNormalCounter = 0;
00072 
00073     iScreenWidth  = aWidth;
00074     iScreenHeight = aHeight;
00075 }


Member Function Documentation

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

Factory method for creating a new CSimpleCube object.

Definition at line 97 of file EnvMapping.cpp.

References CEnvMapping().

00098 {
00099     /* Symbian 2-phase constructor. Calls both the default 
00100        C++ constructor and Symbian ConstructL methods */
00101     CEnvMapping* self = new (ELeave) CEnvMapping( aWidth, aHeight );
00102     CleanupStack::PushL( self );
00103     self->ConstructL();
00104     CleanupStack::Pop();
00105 
00106     return self;
00107 }

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 135 of file EnvMapping.cpp.

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

00136 {
00137     /* Set the screen background color. */
00138     glClearColor( 0.f, 0.f, 0.f, 1.f );
00139 
00140     /* Enable back face culling. */
00141     glEnable( GL_DEPTH_TEST );
00142     glEnable( GL_CULL_FACE  );
00143     glEnable( GL_TEXTURE_2D );
00144 
00145     /* Initialize viewport and projection. */
00146     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00147 
00148 
00149     // Calculate the view frustrum
00150     glMatrixMode( GL_PROJECTION );
00151     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00152     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00153                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00154                 FRUSTUM_NEAR, FRUSTUM_FAR );
00155 
00156     glMatrixMode( GL_MODELVIEW );
00157 
00158     /* Enable vertex arrays. */
00159     glEnableClientState( GL_VERTEX_ARRAY );
00160     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
00161 
00162     /* Set array pointers. */
00163     glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck );
00164     glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords );
00165 
00166     /* Set the initial shading mode */
00167     glShadeModel( GL_FLAT ); 
00168 
00169     /* Do not use perspective correction */
00170     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00171 
00172     iRotateObjectLeftEnabled  = EFalse;
00173     iRotateObjectRightEnabled = EFalse;
00174     iObjectRotAngle    = 0;
00175 
00176         // Construct a texture manager that uses the application's private
00177         // directory as the location for all textures.
00178     iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenWidth,
00179                                               1.f, -1.f, 1.f, -1.f, 3.f,                               
00180                                               this );
00181     
00182     // Push the textures into the loading queue.
00183     _LIT(KEnvMapTexture, "envmap.jpg");
00184     iTextureManager->RequestToLoad( KEnvMapTexture, &iEnvMapTexture );
00185 
00186     //Start to load the textures.
00187     iTextureManager->DoLoadL();
00188 }

void CEnvMapping::AppExit (  void   ) 
 

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

Definition at line 115 of file EnvMapping.cpp.

References iTextureManager.

00116 {
00117     delete iTextureManager;
00118 }

void CEnvMapping::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame Number of the frame to be rendered.

Definition at line 456 of file EnvMapping.cpp.

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

00457 {
00458     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00459     
00460     /* Update user controlled object rotation */
00461     if( iRotateObjectLeftEnabled )
00462     {
00463         iObjectRotAngle -= 2;
00464     }
00465     else if( iRotateObjectRightEnabled )
00466     {
00467         iObjectRotAngle += 2;
00468     }
00469     
00470     if( iObjectModel == DUCK_MODEL )
00471     {
00472         DrawDuck( aFrame );
00473     }
00474     else if ( iObjectModel == HEAD_MODEL )
00475     {
00476         DrawHead( aFrame );
00477     }
00478 }

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 419 of file EnvMapping.cpp.

00420         {
00421         }

void CEnvMapping::OnStartLoadingTexturesL (   ) 
 

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

Definition at line 428 of file EnvMapping.cpp.

00429         {
00430     SetStateL( ELoadingTextures );
00431         }

void CEnvMapping::OnEndLoadingTexturesL (   ) 
 

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

Definition at line 437 of file EnvMapping.cpp.

References iEnvMapTexture.

00438         {
00439         if ( GetState() == ELoadingTextures )
00440                 {
00441         /* Bind the envmap texture to iEnvMapTexture and set the texture environment. */
00442         glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00443         glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
00444         
00445                 SetStateL( ERunning );
00446                 }
00447         }

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 198 of file EnvMapping.cpp.

References iDuckTexCoords, iFaceNormals, iNormalCounter, and iObjectModel.

00199 {
00200     _LIT(KModelError, "Incorrect Model");
00201 
00202     if( iFaceNormals )
00203     {
00204         delete iFaceNormals;
00205     }
00206 
00207     if( iNormalCounter )
00208     {
00209         delete iNormalCounter;
00210     }
00211 
00212     if( iObjectModel == DUCK_MODEL )
00213     {
00214         iFaceNormals    = new (ELeave) GLfloat[ duckVertices*3 ];
00215         iNormalCounter  = new (ELeave) TUint8[ duckVertices ];
00216         
00217         for( TInt i = 0; i < duckVertices;   i++ ) { iNormalCounter[i] = 0;  }
00218         for( TInt j = 0; j < 3*duckVertices; j++ ) { iFaceNormals[j]   = 0.; }
00219         for( TInt k = 0; k < 3*duckVertices; k++ ) { iDuckTexCoords[k] = 0;  }    
00220     }
00221     else if( iObjectModel == HEAD_MODEL )
00222     {
00223         iFaceNormals    = new (ELeave) GLfloat[ 3*headVertices ];
00224         iNormalCounter  = new (ELeave) TUint8[ headVertices ];
00225         
00226         for( TInt i = 0; i < headVertices;   i++ ) { iNormalCounter[i] = 0;  }
00227         for( TInt j = 0; j < 3*headVertices; j++ ) { iFaceNormals[j]   = 0.; }
00228         for( TInt k = 0; k < 3*headVertices; k++ ) { iHeadTexCoords[k] = 0;  }    
00229     }
00230     else User::Panic( KModelError, 1 );
00231 }

void CEnvMapping::CalculateTextureCoordinatesL (  void   ) 
 

Calculates texture coordinates for the models.

Definition at line 242 of file EnvMapping.cpp.

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

00243 {
00244     _LIT(KNormalError,    "Normal length 0");
00245     _LIT(KAvgNormalError, "Avg. Normal length 0");
00246 
00247     iObjectModel = HEAD_MODEL; // calculate tex coords first to head model
00248 
00249     GLushort vertex1 = 0; // indexes to the object vertex data
00250     GLushort vertex2 = 0;
00251     GLushort vertex3 = 0;
00252 
00253         GLfloat pnt1[3] = { .0f, .0f, .0f }; // vertex triplet that forms a triangle
00254     GLfloat pnt2[3] = { .0f, .0f, .0f };
00255     GLfloat pnt3[3] = { .0f, .0f, .0f };
00256 
00257     GLfloat vec1[3]; // two vectors calculated from the vertex triplet
00258     GLfloat vec2[3];
00259 
00260     GLfloat norm[3];          // face normal
00261     GLfloat normLen;          // normal lenght
00262     GLint   iNumFaces = 0;    // number of faces in a model
00263     GLint   iNumVertices = 0; // number of vertices in a model
00264 
00265     for( TInt obj = 0; obj < NUM_OF_MODELS; obj++ )
00266     {
00267         
00268         if( iObjectModel == DUCK_MODEL )
00269         {
00270             iNumFaces    = duckFaces;
00271             iNumVertices = duckVertices;
00272             InitializeArraysL(); // initialize all arrays
00273         }
00274         else if( iObjectModel == HEAD_MODEL )
00275         {
00276             iNumFaces    = headFaces;
00277             iNumVertices = headVertices;
00278             InitializeArraysL(); // initialize all arrays
00279         }
00280         
00281         for( TInt i = 0; i < iNumFaces; i++ )
00282         {
00283             // Form two vectors vec1 and vec2 from vertex triplet, 
00284             // pnt1/2/3 are the three vertices that form a triangle.
00285             if( iObjectModel == DUCK_MODEL )
00286             {
00287                 vertex1 = objFacedataDuck[i*3];
00288                 vertex2 = objFacedataDuck[i*3+1];
00289                 vertex3 = objFacedataDuck[i*3+2];
00290                 
00291                 pnt1[0] = objVertexdataDuck[ 3*vertex1     ];
00292                 pnt1[1] = objVertexdataDuck[ 3*vertex1 + 1 ];
00293                 pnt1[2] = objVertexdataDuck[ 3*vertex1 + 2 ];
00294                 
00295                 pnt2[0] = objVertexdataDuck[ 3*vertex2     ];
00296                 pnt2[1] = objVertexdataDuck[ 3*vertex2 + 1 ];
00297                 pnt2[2] = objVertexdataDuck[ 3*vertex2 + 2 ];
00298                 
00299                 pnt3[0] = objVertexdataDuck[ 3*vertex3     ];
00300                 pnt3[1] = objVertexdataDuck[ 3*vertex3 + 1 ];
00301                 pnt3[2] = objVertexdataDuck[ 3*vertex3 + 2 ];
00302             }
00303             else if( iObjectModel == HEAD_MODEL )
00304             {
00305                 vertex1 = objFacedataHead[i*3];
00306                 vertex2 = objFacedataHead[i*3+1];
00307                 vertex3 = objFacedataHead[i*3+2];
00308                 
00309                 pnt1[0] = objVertexdataHead[ 3*vertex1     ];
00310                 pnt1[1] = objVertexdataHead[ 3*vertex1 + 1 ];
00311                 pnt1[2] = objVertexdataHead[ 3*vertex1 + 2 ];
00312                 
00313                 pnt2[0] = objVertexdataHead[ 3*vertex2     ];
00314                 pnt2[1] = objVertexdataHead[ 3*vertex2 + 1 ];
00315                 pnt2[2] = objVertexdataHead[ 3*vertex2 + 2 ];
00316                 
00317                 pnt3[0] = objVertexdataHead[ 3*vertex3     ];
00318                 pnt3[1] = objVertexdataHead[ 3*vertex3 + 1 ];
00319                 pnt3[2] = objVertexdataHead[ 3*vertex3 + 2 ];
00320             }
00321             
00322             vec1[0] = pnt2[0] - pnt1[0]; 
00323             vec1[1] = pnt2[1] - pnt1[1];
00324             vec1[2] = pnt2[2] - pnt1[2];
00325             
00326             vec2[0] = pnt3[0] - pnt1[0];
00327             vec2[1] = pnt3[1] - pnt1[1];
00328             vec2[2] = pnt3[2] - pnt1[2];
00329             
00330             // calculate crossproduct between the two vectors. That way
00331             // we have the face normal.
00332             norm[0] = vec1[1]*vec2[2] - vec1[2]*vec2[1];
00333             norm[1] = vec1[2]*vec2[0] - vec1[0]*vec2[2];
00334             norm[2] = vec1[0]*vec2[1] - vec1[1]*vec2[2];
00335             
00336             normLen = sqrt( norm[0]*norm[0] + norm[1]*norm[1] + norm[2]*norm[2] );
00337             
00338             /* If normal lenght is zero, generate panic */
00339             if( normLen == 0.0 )
00340             {
00341                 User::Panic( KNormalError, 1 );
00342             }
00343             
00344             // normalize the calculated normal
00345             norm[0] /= normLen;
00346             norm[1] /= normLen;
00347             norm[2] /= normLen;
00348             
00349             // store normal to each vertex index that were used to calculate
00350             // the normal. Add also corresponding vertex counter
00351             iFaceNormals[ 3*vertex1   ] += norm[0];
00352             iFaceNormals[ 3*vertex1+1 ] += norm[1];
00353             iFaceNormals[ 3*vertex1+2 ] += norm[2];
00354             iNormalCounter[ vertex1 ]   += 1;
00355             
00356             iFaceNormals[ 3*vertex2   ] += norm[0];
00357             iFaceNormals[ 3*vertex2+1 ] += norm[1];
00358             iFaceNormals[ 3*vertex2+2 ] += norm[2];
00359             iNormalCounter[ vertex2 ]   += 1;
00360             
00361             iFaceNormals[ 3*vertex3   ] += norm[0];
00362             iFaceNormals[ 3*vertex3+1 ] += norm[1];
00363             iFaceNormals[ 3*vertex3+2 ] += norm[2];
00364             iNormalCounter[ vertex3 ]   += 1;
00365         }
00366         
00367         // calculate and normalize average normal for each vertex
00368         // scale the resulting normal values by COORD_SCALE for GLshort range
00369         for( TInt j = 0; j < iNumVertices; j++ )
00370         {
00371             /* If iNormalCounter value is zero, skip that vertex. 
00372                If the value is zero, it means that the vertex number j is not
00373                used in the object's geometry. */
00374             if( iNormalCounter[j] != 0 )
00375             {
00376                 
00377                 // iFaceNormals contains the sum of all the normals common to each vertex
00378                 // divide by the iNormalCounter value to get the average normal
00379                 iFaceNormals[3*j]   = (iFaceNormals[3*j]/iNormalCounter[j]  );
00380                 iFaceNormals[3*j+1] = (iFaceNormals[3*j+1]/iNormalCounter[j]);
00381                 iFaceNormals[3*j+2] = (iFaceNormals[3*j+2]/iNormalCounter[j]);
00382                 
00383                 // normalize the result, then scale the normal values by COORD_SCALE to 
00384                 // make GLshort range, and store the resulting normal.
00385                 normLen = sqrt( iFaceNormals[3*j]*iFaceNormals[3*j] +
00386                                 iFaceNormals[3*j+1]*iFaceNormals[3*j+1] + 
00387                                 iFaceNormals[3*j+2]*iFaceNormals[3*j+2] );
00388                 
00389                 /* If normal lenght is zero, generate panic */
00390                 if( normLen == 0.0 )
00391                 {
00392                     User::Panic( KAvgNormalError, 1 );
00393                 }
00394                 
00395                 if( iObjectModel == DUCK_MODEL )
00396                 {
00397                     iDuckTexCoords[3*j]   = (GLshort) (COORD_SCALE*iFaceNormals[3*j]/normLen  );
00398                     iDuckTexCoords[3*j+1] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+1]/normLen);
00399                     iDuckTexCoords[3*j+2] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+2]/normLen);
00400                 }
00401                 else if( iObjectModel == HEAD_MODEL )
00402                 {
00403                     iHeadTexCoords[3*j]   = (GLshort) (COORD_SCALE*iFaceNormals[3*j]/normLen  );
00404                     iHeadTexCoords[3*j+1] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+1]/normLen);
00405                     iHeadTexCoords[3*j+2] = (GLshort) (COORD_SCALE*iFaceNormals[3*j+2]/normLen);
00406                 }
00407             }
00408         }
00409         // Change the model to head model. Default start model is duck.
00410         iObjectModel = DUCK_MODEL;
00411     }
00412 }

void CEnvMapping::RotateObjectLeft (  void   ) 
 

Rotates object left.

Definition at line 561 of file EnvMapping.cpp.

References iRotateObjectLeftEnabled.

void CEnvMapping::RotateObjectRight (  void   ) 
 

Rotates object right.

Definition at line 571 of file EnvMapping.cpp.

References iRotateObjectRightEnabled.

void CEnvMapping::DrawDuck (  TInt  aFrame  ) 
 

Draw the environment mapped duck model.

Parameters:
aFrame Current frame in animation

Definition at line 487 of file EnvMapping.cpp.

References iEnvMapTexture, and iObjectRotAngle.

00488 {
00489     /* Set the correct texture matrix */
00490     glMatrixMode( GL_TEXTURE );
00491     glLoadIdentity();
00492     glTranslatef( 0.5f, 0.5f, 0.5f );    // texture coord. values [0,1]
00493     glScalef( 1.0f/(2.0f*COORD_SCALE),   // scale down the input texture
00494               1.0f/(2.0f*COORD_SCALE),   // coord. values to be in range
00495               1.0f/(2.0f*COORD_SCALE) ); // [-0.5, 0.5]
00496     /* First in texture matrix, insert the current camera and object
00497        rotations. */
00498     glRotatex((-90 << 16) + (GLint) (sin(aFrame * 0.17f) * 15 * 65536), 1 << 16, 0, 0);
00499     glRotatex((GLint) (sin(aFrame * 0.13f) * 10 * 65536), 0, 1 << 16, 0);
00500     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00501     
00502     glMatrixMode( GL_MODELVIEW );
00503     glLoadIdentity();
00504     glTranslatex( 0 , -20 << 16 , -CAMERA_DISTANCE << 16 );
00505     glRotatex((-90 << 16) + (GLint) (sin(aFrame * 0.17f) * 15 * 65536), 1 << 16, 0, 0);
00506     glRotatex((GLint) (sin(aFrame * 0.13f) * 10 * 65536), 0, 1 << 16, 0);
00507     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00508     
00509     glScalex( 3 << 6, 3 << 6, 3 << 6 ); // scale the duck to fit the screen
00510     glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00511     glDrawElements( GL_TRIANGLES, duckFaces * 3, GL_UNSIGNED_SHORT, objFacedataDuck );
00512 }

void CEnvMapping::DrawHead (  TInt  aFrame  ) 
 

Draw the environment mapped head model.

Parameters:
aFrame Current frame in animation

Definition at line 521 of file EnvMapping.cpp.

References iEnvMapTexture, and iObjectRotAngle.

00522 {
00523     /* Set the correct texture matrix */
00524     glMatrixMode( GL_TEXTURE );
00525     glLoadIdentity();
00526     glTranslatef( 0.5f, 0.5f, 0.5f );    // texture coord. values [0,1]
00527     glScalef( 1.0f/(2.0f*COORD_SCALE),   // scale down the input texture
00528               1.0f/(2.0f*COORD_SCALE),   // coord. values to be in range
00529               1.0f/(2.0f*COORD_SCALE) ); // [-0.5, 0.5]
00530     /* First in texture matrix, insert the current camera and object
00531        rotations. */
00532     glRotatex( -90 << 16, 1 << 16, 0, 0);
00533     glRotatex( aFrame << 16, 5 << 16, 1 << 12, 0);
00534     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00535     
00536     glMatrixMode( GL_MODELVIEW );
00537     glLoadIdentity();
00538     glTranslatex( 0 , 0, -CAMERA_DISTANCE << 16 );
00539     glRotatex( -90 << 16, 1 << 16, 0, 0);
00540     glRotatex( aFrame << 16, 5 << 16, 1 << 12, 0);
00541     glRotatex( iObjectRotAngle << 16, 0, 0, 1 << 16);
00542     
00543     glScalex( 1 << 10, 1 << 10, 1 << 10 ); // scale the duck to fit the screen
00544     glBindTexture( GL_TEXTURE_2D, iEnvMapTexture.iID );
00545     glDrawElements( GL_TRIANGLES, headFaces * 3, GL_UNSIGNED_SHORT, objFacedataHead );
00546 }

void CEnvMapping::DuckModel (  void   ) 
 

Change to duck model

Definition at line 583 of file EnvMapping.cpp.

References iDuckTexCoords, and iObjectModel.

00584 {
00585     iObjectModel = DUCK_MODEL;
00586     glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck );
00587     glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords );
00588 }

void CEnvMapping::HeadModel (  void   ) 
 

Change to head model

Definition at line 597 of file EnvMapping.cpp.

References iHeadTexCoords, and iObjectModel.

00598 {
00599     iObjectModel = HEAD_MODEL;
00600     glVertexPointer( 3, GL_SHORT, 0, objVertexdataHead );
00601     glTexCoordPointer( 3, GL_SHORT, 0, iHeadTexCoords );
00602 }

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

References iScreenHeight, iScreenWidth, and iTextureManager.

00610     {
00611     iScreenWidth  = aWidth;
00612     iScreenHeight = aHeight;
00613     
00614     // Notify the texture manager of screen size change
00615     iTextureManager->SetScreenSize( aWidth, aHeight );
00616 
00617     // Reinitialize viewport and projection.
00618     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00619 
00620     // Recalculate the view frustrum
00621     glMatrixMode( GL_PROJECTION );
00622     glLoadIdentity();
00623     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00624     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00625                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00626                 FRUSTUM_NEAR, FRUSTUM_FAR );
00627     glMatrixMode( GL_MODELVIEW );
00628     }

void CEnvMapping::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 85 of file EnvMapping.cpp.

References CalculateTextureCoordinatesL().

00086 {
00087     /* Calculate texture coordinates for the models */
00088     CalculateTextureCoordinatesL(); 
00089 }


Member Data Documentation

CTextureManager* CEnvMapping::iTextureManager [private]
 

Texture manager that is used to load the used textures.

Definition at line 190 of file EnvMapping.h.

TTexture CEnvMapping::iEnvMapTexture [private]
 

Environment map texture.

Definition at line 192 of file EnvMapping.h.

TUint CEnvMapping::iScreenWidth [private]
 

Width of the screen

Definition at line 195 of file EnvMapping.h.

TUint CEnvMapping::iScreenHeight [private]
 

Height of the screen

Definition at line 197 of file EnvMapping.h.

GLshort CEnvMapping::iNumFaces [private]
 

Num of object faces. Used when calculating texture coords.

Definition at line 200 of file EnvMapping.h.

GLshort CEnvMapping::iNumVertices [private]
 

Num of object vertices. Used when calculating texture coords.

Definition at line 202 of file EnvMapping.h.

TBool CEnvMapping::iRotateObjectLeftEnabled [private]
 

Whether object is rotated left or not.

Definition at line 205 of file EnvMapping.h.

TBool CEnvMapping::iRotateObjectRightEnabled [private]
 

Whether object is rotated right or not.

Definition at line 207 of file EnvMapping.h.

GLint CEnvMapping::iObjectRotAngle [private]
 

Current rotation angle of the object.

Definition at line 209 of file EnvMapping.h.

GLint CEnvMapping::iObjectModel [private]
 

Currently shown object model (DUCK_MODEL or HEAD_MODEL).

Definition at line 211 of file EnvMapping.h.

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 214 of file EnvMapping.h.

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 216 of file EnvMapping.h.

GLfloat* CEnvMapping::iFaceNormals [private]
 

Temporary storage of face normals.

Definition at line 219 of file EnvMapping.h.

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 226 of file EnvMapping.h.


© Nokia 2006

Back to top