Nokia N97 SDK
Example Applications Guide

PickSelect.cpp

00001 /*
00002  * ==============================================================================
00003  *  Name        : PickSelect.cpp
00004  *  Part of     : OpenGLEx / PickSelect
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 // INCLUDES
00014 #include <e32std.h>
00015 #include <e32def.h>
00016 
00017 #include "PickSelect.h"
00018 
00019 // MACROS
00020 #define cameraDistance 100
00021 
00022 /** First alpha color value for object selection. */
00023 #define BOX_ALPHA_ONE 22
00024 /** Second alpha color value for object selection. */
00025 #define BOX_ALPHA_TWO 33
00026 
00027 
00028 // LOCAL CONSTANTS
00029 /** Four diagonal line segments, making an 'X' or cross. */
00030 static const GLshort cross[8 * 2] =
00031     {
00032     200,200,
00033     800,800,
00034 
00035     -200,200,
00036     -800,800,
00037 
00038     -200,-200,
00039     -800,-800,
00040 
00041     200,-200,
00042     800,-800
00043     };
00044 
00045 /** Indices for 4 line segments (BTW, colors with current color, not array). */
00046 static const GLubyte crossIndices[4 * 2] =
00047     {
00048     0,1,
00049     2,3,
00050     4,5,
00051     6,7
00052     };
00053 
00054 
00055 /** Vertex coordinates for the cube. */
00056 static const GLbyte vertices[24 * 3] =
00057     {
00058     /* top */
00059     -1,  1,  1,
00060     1,  1,  1,
00061     1, -1,  1,
00062     -1, -1,  1,
00063 
00064     /* front */
00065     1,  1,  1,
00066     1,  1, -1,
00067     1, -1, -1,
00068     1, -1,  1,
00069 
00070     /* right */
00071     -1,  1,  1,
00072     -1,  1, -1,
00073     1,  1, -1,
00074     1,  1,  1,
00075 
00076     /* left */
00077     1, -1,  1,
00078     1, -1, -1,
00079     -1, -1, -1,
00080     -1, -1,  1,
00081 
00082     /* back */
00083     -1, -1,  1,
00084     -1, -1, -1,
00085     -1,  1, -1,
00086     -1,  1,  1,
00087 
00088     /* bottom */
00089     -1,  1, -1,
00090     1,  1, -1,
00091     1, -1, -1,
00092     -1, -1, -1
00093     };
00094 
00095 
00096 /**
00097  * Indices for drawing the triangles Note: these triangles are flat shaded,
00098  * and the color comes from the last vertex of a triangle. Alpha is used
00099  * to give an 'index' for picking a triangle, zero alpha is reserved for background.
00100  */
00101 static const GLubyte triangles[12 * 3] =
00102     {
00103     /* top */
00104     1,0,3,    // alpha 1
00105     1,3,2,    // alpha 2
00106 
00107     /* front */
00108     5,4,7,    // alpha 3
00109     5,7,6,    // alpha 4
00110 
00111     /* right */
00112     9,8,11,   // alpha 5
00113     9,11,10,  // alpha 6
00114 
00115     /* left */
00116     13,12,15, // alpha 7
00117     13,15,14, // alpha 8
00118 
00119     /* back */
00120     17,16,19, // alpha 9
00121     17,19,18, // alpha 10
00122 
00123     /* bottom */
00124     21,22,23, // alpha 11
00125     21,23,20  // alpha 12
00126     };
00127 
00128 
00129 /**
00130  * Colors for vertices (Red, Green, Blue, Alpha) Alpha denotes a triangle index,
00131  * 255 is reserved for debugging (no triangle should get alpha == 255).
00132  */
00133 static const GLubyte colors[24 * 4] =
00134     {
00135     /* top */
00136     255,   0,   0, 255,
00137     255,   0,   0, 255,
00138     200,   0, 200, 2,
00139     200,   0,   0, 1,
00140 
00141     /* front */
00142     0  ,   0, 255, 255,
00143     0  ,   0, 255, 255,
00144     0  , 200, 200, 4,
00145     0  ,   0, 200, 3,
00146 
00147     /* right */
00148     0  , 255,   0, 255,
00149     0  , 255,   0, 255,
00150     200, 200,   0, 6,
00151     0  , 200,   0, 5,
00152 
00153     /* left */
00154     255, 160,   0, 255,
00155     255, 160,   0, 255,
00156     160,   0, 200, 8,
00157     200, 160,   0, 7,
00158 
00159     /* back */
00160     120, 120,   0, 255,
00161     120, 120,   0, 255,
00162     10 , 120,   0, 10,
00163     120, 120,   0, 9,
00164 
00165     /* bottom */
00166     120,   0, 120, 12,
00167     120,   0,   0, 255,
00168     120,   0,   0, 255,
00169     120,   0,   0, 11
00170     };
00171 
00172 
00173 /**
00174  * Define colors for vertices (Red, Green, Blue, Alpha) Alpha denotes a
00175  * triangle index, 255 is reserved for debugging (no triangle should get
00176  * alpha == 255)
00177  */
00178 static const GLubyte colorsBox1[24 * 4] =
00179     {
00180     /* top */
00181     255,   0,   0, 255,
00182     255,   0,   0, 255,
00183     200,   0, 200, BOX_ALPHA_ONE,
00184     200,   0,   0, BOX_ALPHA_ONE,
00185 
00186     /* front */
00187     0  ,   0, 255, 255,
00188     0  ,   0, 255, 255,
00189     0  , 200, 200, BOX_ALPHA_ONE,
00190     0  ,   0, 200, BOX_ALPHA_ONE,
00191 
00192     /* right */
00193     0  , 255,   0, 255,
00194     0  , 255,   0, 255,
00195     200, 200,   0, BOX_ALPHA_ONE,
00196     0  , 200,   0, BOX_ALPHA_ONE,
00197 
00198     /* left */
00199     255, 160,   0, 255,
00200     255, 160,   0, 255,
00201     160,   0, 200, BOX_ALPHA_ONE,
00202     200, 160,   0, BOX_ALPHA_ONE,
00203 
00204     /* back */
00205     120, 120,   0, 255,
00206     120, 120,   0, 255,
00207     10 , 120,   0, BOX_ALPHA_ONE,
00208     120, 120,   0, BOX_ALPHA_ONE,
00209 
00210     /* bottom */
00211     120,   0, 120, BOX_ALPHA_ONE,
00212     120,   0,   0, 255,
00213     120,   0,   0, 255,
00214     120,   0,   0, BOX_ALPHA_ONE
00215     };
00216 
00217 /**
00218  * Colors for vertices (Red, Green, Blue, Alpha) Alpha denotes a
00219  * triangle index, 255 is reserved for debugging (no triangle should
00220  * get alpha == 255).
00221  */
00222 static const GLubyte colorsBox2[24 * 4] =
00223     {
00224     /* top */
00225     255,   0,   0, 255,
00226     255,   0,   0, 255,
00227     200,   0, 200, BOX_ALPHA_TWO,
00228     200,   0,   0, BOX_ALPHA_TWO,
00229 
00230     /* front */
00231     0  ,   0, 255, 255,
00232     0  ,   0, 255, 255,
00233     0  , 200, 200, BOX_ALPHA_TWO,
00234     0  ,   0, 200, BOX_ALPHA_TWO,
00235 
00236     /* right */
00237     0  , 255,   0, 255,
00238     0  , 255,   0, 255,
00239     200, 200,   0, BOX_ALPHA_TWO,
00240     0  , 200,   0, BOX_ALPHA_TWO,
00241 
00242     /* left */
00243     255, 160,   0, 255,
00244     255, 160,   0, 255,
00245     160,   0, 200, BOX_ALPHA_TWO,
00246     200, 160,   0, BOX_ALPHA_TWO,
00247 
00248     /* back */
00249     120, 120,   0, 255,
00250     120, 120,   0, 255,
00251     10 , 120,   0, BOX_ALPHA_TWO,
00252     120, 120,   0, BOX_ALPHA_TWO,
00253 
00254     /* bottom */
00255     120,   0, 120, BOX_ALPHA_TWO,
00256     120,   0,   0, 255,
00257     120,   0,   0, 255,
00258     120,   0,   0, BOX_ALPHA_TWO
00259     };
00260 
00261 
00262 // ============================ MEMBER FUNCTIONS ===============================
00263 
00264 // -----------------------------------------------------------------------------
00265 // CPickSelect::CPickSelect
00266 // C++ default constructor can NOT contain any code, that
00267 // might leave.
00268 // -----------------------------------------------------------------------------
00269 //
00270 CPickSelect::CPickSelect( TUint aWidth, TUint aHeight )
00271 :iScreenWidth(aWidth), iScreenHeight(aHeight)
00272     {
00273     // Recalculate aspect ratio
00274     if ( iScreenHeight != 0 )
00275         {
00276         iAspectRatio = (GLfloat)iScreenWidth / (GLfloat)iScreenHeight;
00277         }
00278     else
00279         {
00280         iAspectRatio = 1.0;
00281         }
00282     }
00283 
00284 
00285 // -----------------------------------------------------------------------------
00286 // CPickSelect::ConstructL
00287 // Symbian 2nd phase constructor can leave.
00288 // -----------------------------------------------------------------------------
00289 //
00290 void CPickSelect::ConstructL( void )
00291     {
00292     }
00293 
00294 
00295 // -----------------------------------------------------------------------------
00296 // CPickSelect::NewL
00297 // Two-phased constructor.
00298 // -----------------------------------------------------------------------------
00299 //
00300 CPickSelect* CPickSelect::NewL( TUint aWidth, TUint aHeight )
00301     {
00302     /* Symbian 2-phase constructor. Calls both the default
00303        C++ constructor and Symbian ConstructL methods */
00304     CPickSelect* self = new (ELeave) CPickSelect( aWidth, aHeight );
00305     CleanupStack::PushL( self );
00306     self->ConstructL();
00307     CleanupStack::Pop();
00308 
00309     return self;
00310     }
00311 
00312 
00313 // Destructor.
00314 CPickSelect::~CPickSelect()
00315     {
00316     }
00317 
00318 
00319 // -----------------------------------------------------------------------------
00320 // CPickSelect::AppInit
00321 // Initialize OpenGL ES, set the vertex and color arrays and pointers,
00322 //  and select the shading mode.
00323 // -----------------------------------------------------------------------------
00324 //
00325 void CPickSelect::AppInit( void )
00326     {
00327     // Initialize viewport.
00328     SetScreenSize( iScreenWidth, iScreenHeight );
00329 
00330     // Set the screen background color.
00331     glClearColor( 0.f, 0.f, 0.f, 0.f );
00332 
00333     glEnable( GL_DEPTH_TEST );   // z-compare enabled
00334     glEnable( GL_CULL_FACE  );   // backface culling enabled
00335 
00336 
00337     // Enable vertex and color arrays.
00338     glEnableClientState( GL_VERTEX_ARRAY );
00339     glEnableClientState( GL_COLOR_ARRAY );
00340 
00341     glLineWidth( 1.0 );
00342 
00343     // Set the initial shading mode
00344     glShadeModel( GL_FLAT );
00345 
00346     iSelectionMode = POLYGON_SELECTION;
00347     iCubeRotX      = GLfloat( 0.0 );
00348     iCubeRotY      = GLfloat( 0.0 );
00349     iCursorPosX    = GLint( 30 );
00350     iCursorPosY    = GLint( 30 );
00351 
00352     iMoveUp       = EFalse;
00353     iMoveDown     = EFalse;
00354     iMoveLeft     = EFalse;
00355     iMoveRight    = EFalse;
00356     iSelectionIdx = 0;
00357 
00358     }
00359 
00360 
00361 // -----------------------------------------------------------------------------
00362 // CPickSelect::AppExit
00363 // Release any allocations made in AppInit, reset NGL if necessary.
00364 // This is called if you want to use the same instance again, without
00365 // creating a new instance.
00366 // -----------------------------------------------------------------------------
00367 //
00368 void CPickSelect::AppExit( void )
00369 {
00370 }
00371 
00372 
00373 // -----------------------------------------------------------------------------
00374 // CPickSelect::AppCycle
00375 // Draws and animates the objects
00376 // -----------------------------------------------------------------------------
00377 //
00378 void CPickSelect::AppCycle( TInt aFrame )
00379     {
00380 
00381     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00382 
00383     if ( iSelectionMode == POLYGON_SELECTION )
00384         {
00385         DrawSingleBox( aFrame );
00386         }
00387     else if ( iSelectionMode == OBJECT_SELECTION )
00388         {
00389         DrawMultipleBoxes( aFrame );
00390         }
00391 
00392     // Update the cursor position and redraw it
00393     UpdateCursorPosition();
00394     DrawCursor();
00395     }
00396 
00397 
00398 // -----------------------------------------------------------------------------
00399 // CPickSelect::UpdateCursorPosition
00400 // Update cursor position data.
00401 // Make sure that the cursor stays inside the screen, because
00402 // the viewport size is 208 x 208. See DrawCursor for more comments.
00403 // -----------------------------------------------------------------------------
00404 //
00405 void CPickSelect::UpdateCursorPosition( void )
00406     {
00407     // Check if cursor should move in up/down direction
00408     if ( iMoveUp )
00409         {
00410         iCursorPosY += 2;
00411         if ( iCursorPosY > iScreenWidth )
00412             {
00413             iCursorPosY = iScreenWidth;
00414             }
00415         }
00416     else if ( iMoveDown )
00417         {
00418         iCursorPosY -= 2;
00419         if ( iCursorPosY < 0 )
00420             {
00421             iCursorPosY = 0;
00422             }
00423         }
00424 
00425     // Check if cursor should move in left/right direction
00426     if ( iMoveLeft )
00427         {
00428         iCursorPosX -= 2;
00429         if ( iCursorPosX < 0 )
00430             {
00431             iCursorPosX = 0;
00432             }
00433         }
00434     else if ( iMoveRight )
00435         {
00436         iCursorPosX += 2;
00437         if ( iCursorPosX > iScreenHeight )
00438             {
00439             iCursorPosX = iScreenHeight;
00440             }
00441         }
00442     }
00443 
00444 
00445 
00446 // -----------------------------------------------------------------------------
00447 // CPickSelect::DrawCursor
00448 // Draw the selector cursor.
00449 // -----------------------------------------------------------------------------
00450 //
00451 void CPickSelect::DrawCursor( void )
00452     {
00453     // Setup orthogonal projection for drawing the cursor to the screen
00454     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00455     glMatrixMode( GL_PROJECTION );
00456     glLoadIdentity();
00457     glOrthof( 0.f, (float) iScreenWidth, 0.f, (float) iScreenHeight, -1, 1 ); // set the same size as viewport
00458 
00459     glMatrixMode( GL_MODELVIEW );
00460     glLoadIdentity();
00461     glTranslatex( iCursorPosX << 16 , iCursorPosY << 16, 0 );
00462     glScalex( 65536 / 100, 65536 / 100, 0); // Scale down the geometry
00463 
00464     glVertexPointer( 2, GL_SHORT, 0, cross );
00465     glDisableClientState( GL_COLOR_ARRAY ); // disable color array
00466     glColor4f( 0.f, 1.f, 1.f, 1.f );        // use current color for drawing
00467     glDrawElements( GL_LINES, 8, GL_UNSIGNED_BYTE, crossIndices );
00468     glEnableClientState( GL_COLOR_ARRAY );  // re-enable color array
00469     // Switch back to original Viewport definitions
00470     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00471 
00472     }
00473 
00474 
00475 // -----------------------------------------------------------------------------
00476 // CPickSelect::DrawSingleBox
00477 // Draw a single cube and white lines around the selected polygon
00478 // if one is selected.
00479 // -----------------------------------------------------------------------------
00480 //
00481 void CPickSelect::DrawSingleBox( TInt aFrame )
00482     {
00483       // Set the projection and modelview matrices
00484     glMatrixMode( GL_PROJECTION );
00485     glLoadIdentity();
00486     glFrustumf( FRUSTUM_LEFT * iAspectRatio, FRUSTUM_RIGHT * iAspectRatio,
00487                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00488                 FRUSTUM_NEAR, FRUSTUM_FAR );
00489 
00490     glMatrixMode( GL_MODELVIEW );
00491     glLoadIdentity();
00492     glTranslatex( 0 , 0 , -cameraDistance << 16 );
00493     glRotatex( aFrame << 16, 1 << 16,    0   ,    0    );
00494     glRotatex( aFrame << 15,    0   , 1 << 16,    0    );
00495     glRotatex( aFrame << 14,    0   ,    0   , 1 << 16 );
00496 
00497     // draw box
00498     glVertexPointer( 3, GL_BYTE, 0, vertices );
00499     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors );
00500     glPushMatrix();
00501     glScalex( 10 << 16, 10 << 16, 10 << 16 );
00502     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00503 
00504 
00505     /* draw white lines around the polygon selected. Zero is for background
00506        and 255 is for debugging purposes only. */
00507     if ( iSelectionIdx != 0 && iSelectionIdx != 255 )
00508         {
00509         // gather indices of the selected polygon
00510         for ( int i = 0; i < 3; i++ )
00511             {
00512             iSelectedPoly[i] = triangles[ 3*(iSelectionIdx - 1) + i ];
00513             }
00514 
00515         glDisable( GL_DEPTH_TEST ); // draw on top of the existing graphics
00516         glDisableClientState( GL_COLOR_ARRAY ); // disable color array
00517         glColor4f( 1.f, 1.f, 1.f, 1.f ); // use white for the selected polygon
00518         glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, iSelectedPoly );
00519         glEnableClientState( GL_COLOR_ARRAY ); // re-enable color array
00520         glEnable( GL_DEPTH_TEST );
00521         }
00522 
00523     glPopMatrix();
00524     }
00525 
00526 
00527 // -----------------------------------------------------------------------------
00528 // CPickSelect::DrawMultipleBoxes
00529 // Draw two rotating boxes.
00530 // The selected cube, if there is one, is draw in wireframe mode.
00531 // -----------------------------------------------------------------------------
00532 //
00533 void CPickSelect::DrawMultipleBoxes( TInt aFrame )
00534     {
00535     // Set the projection and modelview matrices
00536     glMatrixMode( GL_PROJECTION );
00537     glLoadIdentity();
00538     glFrustumf( FRUSTUM_LEFT * iAspectRatio, FRUSTUM_RIGHT * iAspectRatio,
00539                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00540                 FRUSTUM_NEAR, FRUSTUM_FAR );
00541 
00542     glMatrixMode( GL_MODELVIEW );
00543     glLoadIdentity();
00544     glTranslatex( 0 , 0 , -cameraDistance << 16 );
00545 
00546     // Set the correct vertex pointer
00547     glVertexPointer( 3, GL_BYTE, 0, vertices );
00548 
00549     /* Check whether or not the first box was selected.
00550        If it was, draw it completely white, otherwise with filled polygons */
00551     glEnableClientState( GL_COLOR_ARRAY ); // enable color array
00552     glColor4f( 1.f, 1.f, 1.f, 1.f );       // set color to white
00553     if ( iSelectionIdx == BOX_ALPHA_ONE )
00554         {
00555         glDisableClientState( GL_COLOR_ARRAY ); // disable color array
00556         }
00557 
00558     // draw box1
00559     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorsBox1 );
00560     glPushMatrix();
00561     glTranslatex( 12 << 16, 0, 0 );
00562     glRotatex( 40 << 16,       1 << 16,    0   , 1 << 16 );
00563     glRotatex( 2*aFrame << 16, 1 << 16,    0   ,    0    );
00564     glRotatex( 2*aFrame << 15,    0   , 1 << 16,    0    );
00565     glRotatex( 2*aFrame << 14,    0   ,    0   , 1 << 16 );
00566     glScalex( 8 << 16, 8 << 16, 8 << 16 );
00567     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00568     glPopMatrix();
00569 
00570     /* Check whether or not the second box was selected.
00571        If it was, draw it completely white, otherwise with filled polygons */
00572     glEnableClientState( GL_COLOR_ARRAY ); // enable color array
00573     if ( iSelectionIdx == BOX_ALPHA_TWO )
00574         {
00575         glDisableClientState( GL_COLOR_ARRAY ); // disable color array
00576         }
00577 
00578     // draw box2
00579     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorsBox2 );
00580     glPushMatrix();
00581     glTranslatex( -12 << 16, 0, 0 );
00582     glRotatex( 2*aFrame << 16, 1 << 16,    0   ,    0    );
00583     glRotatex( 2*aFrame << 15,    0   , 1 << 16,    0    );
00584     glRotatex( 2*aFrame << 14,    0   ,    0   , 1 << 16 );
00585     glScalex( 8 << 16, 8 << 16, 8 << 16 );
00586     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00587     glPopMatrix();
00588 
00589     // By default we want to use color arrays.
00590     glEnableClientState( GL_COLOR_ARRAY ); // enable color array
00591     }
00592 
00593 
00594 //----------------------------------------------------------
00595 // The following methods are called by the CPickSelectAppUi
00596 // class when handling the incoming menu events.
00597 //----------------------------------------------------------
00598 
00599 
00600 // -----------------------------------------------------------------------------
00601 // CPickSelect::MoveUp
00602 // -----------------------------------------------------------------------------
00603 //
00604 void CPickSelect::MoveUp( TBool move )
00605     {
00606     iMoveUp = move;
00607     }
00608 
00609 // -----------------------------------------------------------------------------
00610 // CPickSelect::MoveDown
00611 // -----------------------------------------------------------------------------
00612 //
00613 void CPickSelect::MoveDown( TBool move )
00614     {
00615     iMoveDown = move;
00616     }
00617 
00618 // -----------------------------------------------------------------------------
00619 // CPickSelect::MoveLeft
00620 // -----------------------------------------------------------------------------
00621 //
00622 void CPickSelect::MoveLeft( TBool move )
00623     {
00624     iMoveLeft = move;
00625     }
00626 
00627 // -----------------------------------------------------------------------------
00628 // CPickSelect::MoveRight
00629 // -----------------------------------------------------------------------------
00630 //
00631 void CPickSelect::MoveRight( TBool move )
00632     {
00633     iMoveRight = move;
00634     }
00635 
00636 // -----------------------------------------------------------------------------
00637 // CPickSelect::SelectObject
00638 // Uses the cursor position to get the current pixel's alpha value.
00639 // -----------------------------------------------------------------------------
00640 //
00641 void CPickSelect::SelectObject( void )
00642     {
00643     /* Read the cursor's position pixel value using glReadPixels. Then get the
00644        3rd byte value, which is the alpha value of the pixel, and store it to
00645        iSelectionIdx that is used to check if a polygon or an object is chosen.*/
00646     GLuint aPixel;
00647     // At the moment GL_RGBA/GL_UNSIGNED_BYTE is the only supported combo.
00648     glReadPixels( iCursorPosX, iCursorPosY, 1, 1, GL_RGBA,
00649                   GL_UNSIGNED_BYTE, &aPixel );
00650 
00651     iSelectionIdx = aPixel >> 24; // get the alpha value of the pixel
00652     }
00653 
00654 // -----------------------------------------------------------------------------
00655 // CPickSelect::SetPolygonSelection
00656 // -----------------------------------------------------------------------------
00657 //
00658 void CPickSelect::SetPolygonSelection( void )
00659     {
00660     iSelectionMode = POLYGON_SELECTION;
00661     iSelectionIdx = 0;
00662     }
00663 
00664 // -----------------------------------------------------------------------------
00665 // CPickSelect::SetObjectSelection
00666 // -----------------------------------------------------------------------------
00667 //
00668 void CPickSelect::SetObjectSelection( void )
00669     {
00670     iSelectionMode = OBJECT_SELECTION;
00671     iSelectionIdx = 0;
00672     }
00673 
00674 // -----------------------------------------------------------------------------
00675 // CPickSelect::SetScreenSize
00676 // Reacts to the dynamic screen size change during execution of this program.
00677 // -----------------------------------------------------------------------------
00678 //
00679 void CPickSelect::SetScreenSize( TUint aWidth, TUint aHeight )
00680     {
00681     iScreenWidth  = aWidth;
00682     iScreenHeight = aHeight;
00683 
00684     // Reinitialize viewport and projection.
00685     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00686 
00687     // Recalculate aspect ratio
00688     if ( iScreenHeight != 0 )
00689         {
00690         iAspectRatio = (GLfloat)iScreenWidth / (GLfloat)iScreenHeight;
00691         }
00692     else
00693         {
00694         iAspectRatio = 1.0;
00695         }
00696 
00697     // Make sure cursor stays on the screen after resolution changes
00698     if ( iCursorPosX > iScreenHeight )
00699         {
00700         iCursorPosX = iScreenHeight;
00701         }
00702     if ( iCursorPosY > iScreenWidth )
00703         {
00704         iCursorPosY = iScreenWidth;
00705         }
00706     }

© Nokia 2009

Back to top