S60 3rd Edition SDK for Symbian OS
Example Applications Guide

PickSelect.cpp

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

© Nokia 2006

Back to top