|
Nokia N97 SDK Example Applications Guide |
#include <PickSelect.h>
Inheritance diagram for CPickSelect:

Definition at line 33 of file PickSelect.h.
Public Member Functions |
|
| virtual | ~CPickSelect () |
| void | AppInit (void) |
| void | AppExit (void) |
| void | AppCycle (TInt aFrame) |
| void | UpdateCursorPosition (void) |
| void | DrawCursor (void) |
| void | DrawSingleBox (TInt aFrame) |
| void | DrawMultipleBoxes (TInt aFrame) |
| void | MoveUp (TBool move) |
| void | MoveDown (TBool move) |
| void | MoveLeft (TBool move) |
| void | MoveRight (TBool move) |
| void | SelectObject (void) |
| void | SetPolygonSelection (void) |
| void | SetObjectSelection (void) |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions |
|
| static CPickSelect * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions |
|
| CPickSelect (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Attributes |
|
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TInt | iSelectionMode |
| TBool | iMoveUp |
| TBool | iMoveDown |
| TBool | iMoveLeft |
| TBool | iMoveRight |
| TInt | iSelectionIdx |
| GLfloat | iCubeRotX |
| GLfloat | iCubeRotY |
| GLint | iCursorPosX |
| GLint | iCursorPosY |
| GLbyte | iSelectedPoly [3] |
| GLfloat | iAspectRatio |
|
|
Destructor. Does nothing. Definition at line 314 of file PickSelect.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 270 of file PickSelect.cpp. References iAspectRatio, iScreenHeight, and iScreenWidth. Referenced by NewL(). 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 }
|
|
||||||||||||
|
Factory method for creating a new CPickSelect object. Definition at line 300 of file PickSelect.cpp. References CPickSelect(). Referenced by CPickSelectContainer::ConstructL(). 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 }
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers etc. Definition at line 325 of file PickSelect.cpp. References iCubeRotX, iCubeRotY, iCursorPosX, iCursorPosY, iMoveDown, iMoveLeft, iMoveRight, iMoveUp, iScreenHeight, iScreenWidth, iSelectionIdx, iSelectionMode, and SetScreenSize(). Referenced by CPickSelectContainer::ConstructL(). 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 }
|
|
|
Called upon application exit. Does nothing. Definition at line 368 of file PickSelect.cpp. Referenced by CPickSelectContainer::~CPickSelectContainer().
|
|
|
Renders one frame.
Definition at line 378 of file PickSelect.cpp. References DrawCursor(), DrawMultipleBoxes(), DrawSingleBox(), iSelectionMode, and UpdateCursorPosition(). Referenced by CPickSelectContainer::DrawCallBack(). 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 }
|
|
|
Updates cursor position. Definition at line 405 of file PickSelect.cpp. References iCursorPosX, iCursorPosY, iMoveDown, iMoveLeft, iMoveRight, iMoveUp, iScreenHeight, and iScreenWidth. Referenced by AppCycle(). 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 }
|
|
|
Draws the cursor. Definition at line 451 of file PickSelect.cpp. References iCursorPosX, iCursorPosY, iScreenHeight, and iScreenWidth. Referenced by AppCycle(). 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 }
|
|
|
Draw a single cube and white lines around the selected polygon if one is selected.
Definition at line 481 of file PickSelect.cpp. References iAspectRatio, iSelectedPoly, and iSelectionIdx. Referenced by AppCycle(). 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 }
|
|
|
Draw two rotating boxes. The selected cube, if there is one, is draw in wireframe mode.
Definition at line 533 of file PickSelect.cpp. References iSelectionIdx. Referenced by AppCycle(). 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 }
|
|
|
Sets the move up flag to the given value.
Definition at line 604 of file PickSelect.cpp. References iMoveUp. Referenced by CPickSelectAppUi::HandleKeyEventL(). 00605 { 00606 iMoveUp = move; 00607 }
|
|
|
Sets the move down flag to the given value.
Definition at line 613 of file PickSelect.cpp. References iMoveDown. Referenced by CPickSelectAppUi::HandleKeyEventL(). 00614 { 00615 iMoveDown = move; 00616 }
|
|
|
Sets the move left flag to the given value.
Definition at line 622 of file PickSelect.cpp. References iMoveLeft. Referenced by CPickSelectAppUi::HandleKeyEventL(). 00623 { 00624 iMoveLeft = move; 00625 }
|
|
|
Sets the move right flag to the given value.
Definition at line 631 of file PickSelect.cpp. References iMoveRight. Referenced by CPickSelectAppUi::HandleKeyEventL(). 00632 { 00633 iMoveRight = move; 00634 }
|
|
|
Tries to select the object currently under the cursor. Uses the cursor position to get the current pixel's alpha value and stores it to iSelectionIdx. The iSelectionIdx is then used to check if a polygon or an object is chosen. Definition at line 641 of file PickSelect.cpp. References iCursorPosX, iCursorPosY, and iSelectionIdx. Referenced by CPickSelectAppUi::HandleKeyEventL(). 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 }
|
|
|
Changes selection mode to polygon selection. Definition at line 658 of file PickSelect.cpp. References iSelectionIdx, and iSelectionMode. Referenced by CPickSelectAppUi::HandleCommandL(). 00659 { 00660 iSelectionMode = POLYGON_SELECTION; 00661 iSelectionIdx = 0; 00662 }
|
|
|
Changes selection mode to object selection. Definition at line 668 of file PickSelect.cpp. References iSelectionIdx, and iSelectionMode. Referenced by CPickSelectAppUi::HandleCommandL(). 00669 { 00670 iSelectionMode = OBJECT_SELECTION; 00671 iSelectionIdx = 0; 00672 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size.
Definition at line 679 of file PickSelect.cpp. References iCursorPosX, iCursorPosY, iScreenHeight, and iScreenWidth. Referenced by AppInit(), and CPickSelectContainer::SizeChanged(). 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 }
|
|
|
Second phase contructor. Does nothing. Definition at line 290 of file PickSelect.cpp.
|
|
|
Width of the screen Definition at line 163 of file PickSelect.h. Referenced by AppInit(), CPickSelect(), DrawCursor(), SetScreenSize(), and UpdateCursorPosition(). |
|
|
Height of the screen Definition at line 166 of file PickSelect.h. Referenced by AppInit(), CPickSelect(), DrawCursor(), SetScreenSize(), and UpdateCursorPosition(). |
|
|
Current selection mode (either POLYGON_SELECTION or OBJECT_SELECTION). Definition at line 169 of file PickSelect.h. Referenced by AppCycle(), AppInit(), SetObjectSelection(), and SetPolygonSelection(). |
|
|
Whether cursor should move up every frame or not. Definition at line 172 of file PickSelect.h. Referenced by AppInit(), MoveUp(), and UpdateCursorPosition(). |
|
|
Whether cursor should move down every frame or not. Definition at line 175 of file PickSelect.h. Referenced by AppInit(), MoveDown(), and UpdateCursorPosition(). |
|
|
Whether cursor should move left every frame or not. Definition at line 178 of file PickSelect.h. Referenced by AppInit(), MoveLeft(), and UpdateCursorPosition(). |
|
|
Whether cursor should move right every frame or not. Definition at line 181 of file PickSelect.h. Referenced by AppInit(), MoveRight(), and UpdateCursorPosition(). |
|
|
Selection ID. Definition at line 184 of file PickSelect.h. Referenced by AppInit(), DrawMultipleBoxes(), DrawSingleBox(), SelectObject(), SetObjectSelection(), and SetPolygonSelection(). |
|
|
Current X axis rotation of the cube(s). Definition at line 187 of file PickSelect.h. Referenced by AppInit(). |
|
|
Current Y axis rotation of the cube(s). Definition at line 190 of file PickSelect.h. Referenced by AppInit(). |
|
|
Current X coordinate of the cursor. Definition at line 193 of file PickSelect.h. Referenced by AppInit(), DrawCursor(), SelectObject(), SetScreenSize(), and UpdateCursorPosition(). |
|
|
Current Y coordinate of the cursor. Definition at line 196 of file PickSelect.h. Referenced by AppInit(), DrawCursor(), SelectObject(), SetScreenSize(), and UpdateCursorPosition(). |
|
|
Currently selected pelected polygon. Definition at line 200 of file PickSelect.h. Referenced by DrawSingleBox(). |
|
|
Current screen aspect ratio (width/height). Definition at line 203 of file PickSelect.h. Referenced by CPickSelect(), and DrawSingleBox(). |
|
© Nokia 2009 |