|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : EnvMapping.cpp 00004 * Part of : OpenGLEx / EnvMapping 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <e32std.h> 00018 #include <e32math.h> 00019 00020 #include "EnvMapping.h" 00021 00022 00023 // ============================= LOCAL FUNCTIONS =============================== 00024 00025 // ----------------------------------------------------------------------------- 00026 // sin 00027 // Help function to make the duck 'quak'. 00028 // Returns: trg 00029 // ----------------------------------------------------------------------------- 00030 // 00031 00032 GLfloat sin(GLfloat aRad) 00033 { 00034 TReal trg, src = (TReal)aRad; 00035 if (Math::Sin(trg, src) == KErrNone) 00036 { 00037 return (GLfloat)trg; 00038 } 00039 return 0; 00040 00041 } 00042 00043 // ----------------------------------------------------------------------------- 00044 // sqrt 00045 // Help function that is used in CalculateTextureCoordinates 00046 // Returns: trg 00047 // ----------------------------------------------------------------------------- 00048 // 00049 00050 GLfloat sqrt(GLfloat aVal) 00051 { 00052 TReal trg, src = (TReal)aVal; 00053 if( Math::Sqrt(trg, src) == KErrNone ) 00054 { 00055 return (GLfloat)trg; 00056 } 00057 return 0.0; 00058 } 00059 00060 00061 // ============================ MEMBER FUNCTIONS =============================== 00062 00063 // ----------------------------------------------------------------------------- 00064 // CEnvMapping::CEnvMapping 00065 // Default C++ constructor. Cannot leave. 00066 // ----------------------------------------------------------------------------- 00067 // 00068 CEnvMapping::CEnvMapping( TUint aWidth, TUint aHeight ): CFiniteStateMachine() 00069 { 00070 iFaceNormals = 0; // Initialize member variables 00071 iNormalCounter = 0; 00072 00073 iScreenWidth = aWidth; 00074 iScreenHeight = aHeight; 00075 } 00076 00077 00078 // ----------------------------------------------------------------------------- 00079 // CEnvMapping::ConstructL 00080 // Symbian contructor method, which is called when an instance of CEnvMapping 00081 // is created. 00082 // ----------------------------------------------------------------------------- 00083 // 00084 00085 void CEnvMapping::ConstructL( void ) 00086 { 00087 /* Calculate texture coordinates for the models */ 00088 CalculateTextureCoordinatesL(); 00089 } 00090 00091 00092 // ----------------------------------------------------------------------------- 00093 // CEnvMapping::NewL 00094 // Two-phased constructor 00095 // ----------------------------------------------------------------------------- 00096 00097 CEnvMapping* CEnvMapping::NewL( TUint aWidth, TUint aHeight ) 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 } 00108 00109 // ----------------------------------------------------------------------------- 00110 // CEnvMapping::AppExit 00111 // Release any allocations made in AppInit. 00112 // ----------------------------------------------------------------------------- 00113 // 00114 00115 void CEnvMapping::AppExit( void ) 00116 { 00117 delete iTextureManager; 00118 } 00119 00120 // Destructor. 00121 CEnvMapping::~CEnvMapping() 00122 { 00123 delete iFaceNormals; 00124 delete iNormalCounter; 00125 } 00126 00127 00128 // ----------------------------------------------------------------------------- 00129 // CEnvMapping::AppInit 00130 // Initialize OpenGL ES, set the vertex and color arrays and pointers, 00131 // and select the shading mode. 00132 // ----------------------------------------------------------------------------- 00133 // 00134 00135 void CEnvMapping::AppInitL( void ) 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 } 00189 00190 00191 // ----------------------------------------------------------------------------- 00192 // CEnvMapping::InitializeArraysL 00193 // Initialize arrays used to calculate objects texture coordinates. 00194 // Reserves dynamically memories for the arrays depending on the size on the models. 00195 // ----------------------------------------------------------------------------- 00196 // 00197 00198 void CEnvMapping::InitializeArraysL( void ) 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 } 00232 00233 00234 // ----------------------------------------------------------------------------- 00235 // CEnvMapping::CalculateTextureCoordinatesL 00236 // Calculates texture coordinates for the models used. 00237 // Texture coordinates for one vertex is defined by calculating an average 00238 // normal of all the surface normals adjacent to that vertex. 00239 // ----------------------------------------------------------------------------- 00240 // 00241 00242 void CEnvMapping::CalculateTextureCoordinatesL( void ) 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 } 00413 00414 // --------------------------------------------------------- 00415 // CBillboard::OnEnterState( TInt aState ) 00416 // Called by TFiniteStateMachine when the f.s.m enters a new state 00417 // --------------------------------------------------------- 00418 00419 void CEnvMapping::OnEnterStateL( TInt /*aState*/ ) 00420 { 00421 } 00422 00423 // ------------------------------------------------------------------------------------------------------- 00424 // CBillboard::OnStartLoadingTextures() 00425 // Called for a MTextureLoadingListener by the texture manager when texture loading operation starts 00426 // ------------------------------------------------------------------------------------------------------- 00427 00428 void CEnvMapping::OnStartLoadingTexturesL() 00429 { 00430 SetStateL( ELoadingTextures ); 00431 } 00432 00433 // ------------------------------------------------------------------------------------------------------------ 00434 // CBillboard::OnEndLoadingTextures() 00435 // Called for a MTextureLoadingListener by the texture manager when texture loading operation is completed 00436 // ------------------------------------------------------------------------------------------------------------ 00437 void CEnvMapping::OnEndLoadingTexturesL() 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 } 00448 00449 00450 // ----------------------------------------------------------------------------- 00451 // CEnvMapping::AppCycle 00452 // Draws and animates the objects 00453 // ----------------------------------------------------------------------------- 00454 // 00455 00456 void CEnvMapping::AppCycle( TInt aFrame ) 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 } 00479 00480 00481 // ----------------------------------------------------------------------------- 00482 // CEnvMapping::DrawDuck 00483 // Draw the environment mapped duck model. 00484 // ----------------------------------------------------------------------------- 00485 // 00486 00487 void CEnvMapping::DrawDuck( TInt aFrame ) 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 } 00513 00514 00515 // ----------------------------------------------------------------------------- 00516 // CEnvMapping::DrawHead 00517 // Draw the environment mapped head model. 00518 // ----------------------------------------------------------------------------- 00519 // 00520 00521 void CEnvMapping::DrawHead( TInt aFrame ) 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 } 00547 00548 00549 //---------------------------------------------------------- 00550 // The following methods are called by the CEnvMappingAppUi 00551 // class when handling the incoming menu events. 00552 //---------------------------------------------------------- 00553 00554 00555 // ----------------------------------------------------------------------------- 00556 // CEnvMapping::RotateObjectLeft 00557 // Rotares object to left 00558 // ----------------------------------------------------------------------------- 00559 // 00560 00561 void CEnvMapping::RotateObjectLeft( void ) 00562 { 00563 iRotateObjectLeftEnabled = !iRotateObjectLeftEnabled; 00564 } 00565 00566 // ----------------------------------------------------------------------------- 00567 // CEnvMapping::RotateObjectRight 00568 // Rotares object to right 00569 // ----------------------------------------------------------------------------- 00570 // 00571 void CEnvMapping::RotateObjectRight( void ) 00572 { 00573 iRotateObjectRightEnabled = !iRotateObjectRightEnabled; 00574 } 00575 00576 // ----------------------------------------------------------------------------- 00577 // CEnvMapping::DuckModel 00578 // Change to duck model. 00579 // Set the correct vertex and texture coordinate pointers. 00580 // ----------------------------------------------------------------------------- 00581 // 00582 00583 void CEnvMapping::DuckModel( void ) 00584 { 00585 iObjectModel = DUCK_MODEL; 00586 glVertexPointer( 3, GL_SHORT, 0, objVertexdataDuck ); 00587 glTexCoordPointer( 3, GL_SHORT, 0, iDuckTexCoords ); 00588 } 00589 00590 // ----------------------------------------------------------------------------- 00591 // CEnvMapping::HeadModel 00592 // Change to head model. 00593 // Set the correct vertex and texture coordinate pointers. 00594 // ----------------------------------------------------------------------------- 00595 // 00596 00597 void CEnvMapping::HeadModel( void ) 00598 { 00599 iObjectModel = HEAD_MODEL; 00600 glVertexPointer( 3, GL_SHORT, 0, objVertexdataHead ); 00601 glTexCoordPointer( 3, GL_SHORT, 0, iHeadTexCoords ); 00602 } 00603 00604 // ----------------------------------------------------------------------------- 00605 // CEnvMapping::SetScreenSize 00606 // Reacts to the dynamic screen size change during execution of this program. 00607 // ----------------------------------------------------------------------------- 00608 // 00609 void CEnvMapping::SetScreenSize( TUint aWidth, TUint aHeight ) 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 } 00629 00630 00631 00632 // End of File
|
© Nokia 2006 |