Nokia N97 SDK
Example Applications Guide

EnvMapping.cpp

00001 /*
00002  * ==============================================================================
00003  *  Name        : EnvMapping.cpp
00004  *  Part of     : OpenGLEx / EnvMapping
00005  *
00006  *  Copyright (c) 2004-2006 Nokia Corporation.
00007  *  This material, including documentation and any related
00008  *  computer programs, is protected by copyright controlled by
00009  *  Nokia Corporation.
00010  * ==============================================================================
00011  */
00012 
00013 // INCLUDE FILES
00014 #include <e32std.h>
00015 #include <e32math.h>
00016 
00017 #include "EnvMapping.h"
00018 
00019 
00020 // ============================ MEMBER FUNCTIONS ===============================
00021 
00022 // -----------------------------------------------------------------------------
00023 // CEnvMapping::CEnvMapping
00024 // Default C++ constructor. Cannot leave.
00025 // -----------------------------------------------------------------------------
00026 //
00027 CEnvMapping::CEnvMapping( TUint aWidth, TUint aHeight ): CFiniteStateMachine()
00028 {
00029     iFaceNormals   = 0; // Initialize member variables
00030     iNormalCounter = 0;
00031 
00032     iScreenWidth  = aWidth;
00033     iScreenHeight = aHeight;
00034 }
00035 
00036 
00037 // -----------------------------------------------------------------------------
00038 // CEnvMapping::ConstructL
00039 // Symbian contructor method, which is called when an instance of CEnvMapping
00040 // is created.
00041 // -----------------------------------------------------------------------------
00042 //
00043 
00044 void CEnvMapping::ConstructL( void )
00045 {
00046     /* Calculate texture coordinates for the models */
00047     CalculateTextureCoordinatesL();
00048 }
00049 
00050 
00051 // -----------------------------------------------------------------------------
00052 // CEnvMapping::NewL
00053 // Two-phased constructor
00054 // -----------------------------------------------------------------------------
00055 
00056 CEnvMapping* CEnvMapping::NewL( TUint aWidth, TUint aHeight )
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 }
00067 
00068 // -----------------------------------------------------------------------------
00069 // CEnvMapping::AppExit
00070 // Release any allocations made in AppInit.
00071 // -----------------------------------------------------------------------------
00072 //
00073 
00074 void CEnvMapping::AppExit( void )
00075 {
00076     delete iTextureManager;
00077 }
00078 
00079 // Destructor.
00080 CEnvMapping::~CEnvMapping()
00081 {
00082     delete iFaceNormals;
00083     delete iNormalCounter;
00084 }
00085 
00086 
00087 // -----------------------------------------------------------------------------
00088 // CEnvMapping::AppInit
00089 // Initialize OpenGL ES, set the vertex and color arrays and pointers,
00090 // and select the shading mode.
00091 // -----------------------------------------------------------------------------
00092 //
00093 
00094 void CEnvMapping::AppInitL( void )
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 }
00138 
00139 
00140 // -----------------------------------------------------------------------------
00141 // CEnvMapping::InitializeArraysL
00142 // Initialize arrays used to calculate objects texture coordinates.
00143 // Reserves dynamically memories for the arrays depending on the size on the models.
00144 // -----------------------------------------------------------------------------
00145 //
00146 
00147 void CEnvMapping::InitializeArraysL( void )
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 }
00181 
00182 
00183 // -----------------------------------------------------------------------------
00184 // CEnvMapping::CalculateTextureCoordinatesL
00185 // Calculates texture coordinates for the models used.
00186 // Texture coordinates for one vertex is defined by calculating an average
00187 // normal of all the surface normals adjacent to that vertex.
00188 // -----------------------------------------------------------------------------
00189 //
00190 
00191 void CEnvMapping::CalculateTextureCoordinatesL( void )
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 }
00362 
00363 // ---------------------------------------------------------
00364 // CBillboard::OnEnterState( TInt aState )
00365 // Called by TFiniteStateMachine when the f.s.m enters a new state
00366 // ---------------------------------------------------------
00367 
00368 void CEnvMapping::OnEnterStateL( TInt /*aState*/ )
00369         {
00370         }
00371 
00372 // -------------------------------------------------------------------------------------------------------
00373 // CBillboard::OnStartLoadingTextures()
00374 // Called for a MTextureLoadingListener by the texture manager when texture loading operation starts
00375 // -------------------------------------------------------------------------------------------------------
00376 
00377 void CEnvMapping::OnStartLoadingTexturesL()
00378         {
00379     SetStateL( ELoadingTextures );
00380         }
00381 
00382 // ------------------------------------------------------------------------------------------------------------
00383 // CBillboard::OnEndLoadingTextures()
00384 // Called for a MTextureLoadingListener by the texture manager when texture loading operation is completed
00385 // ------------------------------------------------------------------------------------------------------------
00386 void CEnvMapping::OnEndLoadingTexturesL()
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         }
00398 
00399 
00400 // -----------------------------------------------------------------------------
00401 // CEnvMapping::AppCycle
00402 // Draws and animates the objects
00403 // -----------------------------------------------------------------------------
00404 //
00405 
00406 void CEnvMapping::AppCycle( TInt aFrame )
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 }
00429 
00430 
00431 // -----------------------------------------------------------------------------
00432 // CEnvMapping::DrawDuck
00433 // Draw the environment mapped duck model.
00434 // -----------------------------------------------------------------------------
00435 //
00436 
00437 void CEnvMapping::DrawDuck( TInt aFrame )
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 }
00465 
00466 
00467 // -----------------------------------------------------------------------------
00468 // CEnvMapping::DrawHead
00469 // Draw the environment mapped head model.
00470 // -----------------------------------------------------------------------------
00471 //
00472 
00473 void CEnvMapping::DrawHead( TInt aFrame )
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 }
00500 
00501 
00502 //----------------------------------------------------------
00503 // The following methods are called by the CEnvMappingAppUi
00504 // class when handling the incoming menu events.
00505 //----------------------------------------------------------
00506 
00507 
00508 // -----------------------------------------------------------------------------
00509 // CEnvMapping::RotateObjectLeft
00510 // Rotares object to left
00511 // -----------------------------------------------------------------------------
00512 //
00513 
00514 void CEnvMapping::RotateObjectLeft( void )
00515 {
00516     iRotateObjectLeftEnabled = !iRotateObjectLeftEnabled;
00517 }
00518 
00519 // -----------------------------------------------------------------------------
00520 // CEnvMapping::RotateObjectRight
00521 // Rotares object to right
00522 // -----------------------------------------------------------------------------
00523 //
00524 void CEnvMapping::RotateObjectRight( void )
00525 {
00526     iRotateObjectRightEnabled = !iRotateObjectRightEnabled;
00527 }
00528 
00529 // -----------------------------------------------------------------------------
00530 // CEnvMapping::DuckModel
00531 // Change to duck model.
00532 // Set the correct vertex and texture coordinate pointers.
00533 // -----------------------------------------------------------------------------
00534 //
00535 
00536 void CEnvMapping::DuckModel( void )
00537 {
00538     iObjectModel = DUCK_MODEL;
00539     glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck );
00540     glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords );
00541 }
00542 
00543 // -----------------------------------------------------------------------------
00544 // CEnvMapping::HeadModel
00545 // Change to head model.
00546 // Set the correct vertex and texture coordinate pointers.
00547 // -----------------------------------------------------------------------------
00548 //
00549 
00550 void CEnvMapping::HeadModel( void )
00551 {
00552     iObjectModel = HEAD_MODEL;
00553     glVertexPointer( 3, GL_SHORT, 0, objVertexdataHead );
00554     glTexCoordPointer( 3, GL_SHORT, 0, iHeadTexCoords );
00555 }
00556 
00557 // -----------------------------------------------------------------------------
00558 // CEnvMapping::SetScreenSize
00559 // Reacts to the dynamic screen size change during execution of this program.
00560 // -----------------------------------------------------------------------------
00561 //
00562 void CEnvMapping::SetScreenSize( TUint aWidth, TUint aHeight )
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     }
00582 
00583 
00584 
00585 //  End of File

© Nokia 2009

Back to top