Nokia N97 SDK
Example Applications Guide

PickSelect.h

00001 /*
00002  * ==============================================================================
00003  *  Name        : PickSelect.h
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 <e32base.h> // for CBase definition
00015 #include <GLES/gl.h> // OpenGL ES header file
00016 
00017 // MACROS
00018 #define POLYGON_SELECTION 1
00019 #define OBJECT_SELECTION  2
00020 #define FRUSTUM_LEFT   -1.f     //left vertical clipping plane
00021 #define FRUSTUM_RIGHT   1.f     //right vertical clipping plane
00022 #define FRUSTUM_BOTTOM -1.f     //bottom horizontal clipping plane
00023 #define FRUSTUM_TOP     1.f     //top horizontal clipping plane
00024 #define FRUSTUM_NEAR    3.f     //near depth clipping plane
00025 #define FRUSTUM_FAR  1000.f     //far depth clipping plane
00026 
00027 
00028 // CLASS DECLARATION
00029 
00030 /**
00031  * Class that does the actual OpenGL ES rendering.
00032  */
00033 class CPickSelect : public CBase
00034     {
00035     public:  // Constructors and destructor
00036 
00037         /**
00038          * Factory method for creating a new CPickSelect object.
00039          */
00040         static CPickSelect* NewL( TUint aWidth, TUint aHeight);
00041 
00042         /**
00043          * Destructor. Does nothing.
00044          */
00045           virtual ~CPickSelect();
00046 
00047     public: // New functions
00048 
00049         /**
00050          * Initializes OpenGL ES, sets the vertex and color
00051          * arrays and pointers etc.
00052          */
00053         void AppInit( void );
00054 
00055         /**
00056          * Called upon application exit. Does nothing.
00057          */
00058         void AppExit( void );
00059 
00060         /**
00061          * Renders one frame.
00062          * @param aFrame Number of the frame to be rendered.
00063          */
00064         void AppCycle( TInt aFrame );
00065 
00066         /**
00067          * Updates cursor position.
00068          */
00069         void UpdateCursorPosition( void );
00070 
00071         /**
00072          * Draws the cursor.
00073          */
00074         void DrawCursor( void );
00075 
00076         /**
00077          * Draw a single cube and white lines around the selected polygon
00078          * if one is selected.
00079          * @param aFrame The number of the frame to be rendered.
00080          */
00081         void DrawSingleBox( TInt aFrame );
00082 
00083         /**
00084          * Draw two rotating boxes.
00085          * The selected cube, if there is one, is draw in wireframe mode.
00086          * @param aFrame The number of the frame to be rendered.
00087          */
00088         void DrawMultipleBoxes( TInt aFrame );
00089 
00090 
00091         /**
00092          * Sets the move up flag to the given value.
00093          * @param move True if cursor should move upwards each frame.
00094          *             False if cursor shouldn't move up.
00095          */
00096         void MoveUp( TBool move );
00097 
00098         /**
00099          * Sets the move down flag to the given value.
00100          * @param move True if cursor should move downwards each frame.
00101          *             False if cursor shouldn't move down.
00102          */
00103         void MoveDown( TBool move );
00104 
00105         /**
00106          * Sets the move left flag to the given value.
00107          * @param move True if cursor should move left each frame.
00108          *             False if cursor shouldn't move left.
00109          */
00110         void MoveLeft( TBool move );
00111 
00112         /**
00113          * Sets the move right flag to the given value.
00114          * @param move True if cursor should move right each frame.
00115          *             False if cursor shouldn't move right.
00116          */
00117         void MoveRight( TBool move );
00118 
00119         /**
00120          * Tries to select the object currently under the cursor.
00121          * Uses the cursor position to get the current pixel's alpha value and stores
00122          * it to iSelectionIdx. The iSelectionIdx is then used to check if a polygon or
00123          * an object is chosen.
00124          */
00125         void SelectObject( void );
00126 
00127         /**
00128          * Changes selection mode to polygon selection.
00129          */
00130         void SetPolygonSelection( void );
00131 
00132         /**
00133          * Changes selection mode to object selection.
00134          */
00135         void SetObjectSelection( void );
00136 
00137         /**
00138          * Notifies that the screen size has dynamically changed during execution of
00139          * this program. Resets the viewport to this new size.
00140          * @param aWidth New width of the screen.
00141          * @param aHeight New height of the screen.
00142          */
00143         void SetScreenSize( TUint aWidth, TUint aHeight );
00144 
00145     protected: // New functions
00146 
00147         /**
00148          * Standard constructor that must never Leave.
00149          * Stores the given screen width and height.
00150          * @param aWidth Width of the screen.
00151          * @param aHeight Height of the screen.
00152          */
00153         CPickSelect( TUint aWidth, TUint aHeight );
00154 
00155         /**
00156          * Second phase contructor. Does nothing.
00157          */
00158         void ConstructL( void );
00159 
00160     private: // Data
00161 
00162         /** Width of the screen */
00163         TUint iScreenWidth;
00164 
00165         /** Height of the screen */
00166         TUint iScreenHeight;
00167 
00168         /** Current selection mode (either POLYGON_SELECTION or OBJECT_SELECTION). */
00169         TInt iSelectionMode;
00170 
00171         /** Whether cursor should move up every frame or not. */
00172         TBool iMoveUp;
00173 
00174         /** Whether cursor should move down every frame or not. */
00175         TBool iMoveDown;
00176 
00177         /** Whether cursor should move left every frame or not. */
00178         TBool iMoveLeft;
00179 
00180         /** Whether cursor should move right every frame or not. */
00181         TBool iMoveRight;
00182 
00183         /** Selection ID. */
00184         TInt iSelectionIdx;
00185 
00186         /** Current X axis rotation of the cube(s). */
00187         GLfloat iCubeRotX;
00188 
00189         /** Current Y axis rotation of the cube(s). */
00190         GLfloat iCubeRotY;
00191 
00192         /** Current X coordinate of the cursor. */
00193         GLint iCursorPosX;
00194 
00195         /** Current Y coordinate of the cursor. */
00196         GLint iCursorPosY;
00197 
00198 
00199         /** Currently selected pelected polygon. */
00200         GLbyte iSelectedPoly[3];
00201 
00202         /** Current screen aspect ratio (width/height). */
00203         GLfloat iAspectRatio;
00204     };

© Nokia 2009

Back to top