|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : game.h 00004 * Part of : OpenC / OpenCOpenglEx 00005 * Interface : 00006 * Description : Contains the class declaration of CGame. 00007 * Version : 00008 * 00009 * Copyright (c) 2007 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 #ifndef __GAME_CLASS__ 00017 #define __GAME_CLASS__ 00018 00019 #include <e32base.h> // for CBase 00020 #include <gles/gl.h> // for opengl es types 00021 #include <e32keys.h> // for TStdScanCode 00022 00023 // CONSTANTS 00024 00025 // The number of microseconds that can be spent on one frame. 00026 // 10000000 microseconds = 1 second 00027 // Frame rate = 25 fps. 00028 const TInt timeForOneFrame = 1000000 / 25; 00029 00030 00031 // Vertice coordinates for the cube. 00032 static const GLbyte vertices[8 * 3] = 00033 { 00034 -1, 1, 1, 00035 1, 1, 1, 00036 1, -1, 1, 00037 -1, -1, 1, 00038 00039 -1, 1, -1, 00040 1, 1, -1, 00041 1, -1, -1, 00042 -1, -1, -1 00043 }; 00044 00045 // Colors for vertices (Red, Green, Blue, Alpha). 00046 static const GLubyte colors[8 * 4] = 00047 { 00048 0 ,255, 0,255, 00049 0 , 0,255,255, 00050 0 ,255, 0,255, 00051 255, 0, 0,255, 00052 00053 0 , 0,255,255, 00054 255, 0, 0,255, 00055 0 , 0,255,255, 00056 0 ,255, 0,255 00057 }; 00058 00059 // Indices for drawing the triangles. 00060 static const GLubyte triangles[12 * 3] = 00061 { 00062 // front 00063 1,0,3, 00064 1,3,2, 00065 00066 // right 00067 2,6,5, 00068 2,5,1, 00069 00070 // back 00071 7,4,5, 00072 7,5,6, 00073 00074 // left 00075 0,4,7, 00076 0,7,3, 00077 00078 // top 00079 5,4,0, 00080 5,0,1, 00081 00082 // bottom 00083 3,7,6, 00084 3,6,2 00085 }; 00086 00087 // MACROS 00088 // Used for specifying the viewing frustum. 00089 #define FRUSTUM_LEFT -1.f //left vertical clipping plane 00090 #define FRUSTUM_RIGHT 1.f //right vertical clipping plane 00091 #define FRUSTUM_BOTTOM -1.f //bottom horizontal clipping plane 00092 #define FRUSTUM_TOP 1.f //top horizontal clipping plane 00093 #define FRUSTUM_NEAR 3.f //near depth clipping plane 00094 #define FRUSTUM_FAR 1000.f //far depth clipping plane 00095 00096 // CLASS DECLARATION 00097 00098 /** 00099 * Class that does the actual OpenGL ES rendering. 00100 */ 00101 class CGame : public CBase 00102 { 00103 public: // Static Constructor and destructor. 00104 /** 00105 * Factory method for creating a new CGame object. 00106 */ 00107 static CGame* NewLC(); 00108 00109 /** 00110 * Destructor. 00111 */ 00112 ~CGame(); 00113 protected: // Constructors 00114 /** 00115 * Standard constructor that must never Leave. 00116 */ 00117 CGame(); 00118 00119 /** 00120 * Second phase contructor. 00121 */ 00122 void ConstructL(); 00123 public: 00124 /** 00125 * Intializes the Game. 00126 * 00127 * @param aScreenWidth Width of the screen. 00128 * @param aScreenHeight Height of the screen. 00129 */ 00130 void Initialize( TUint aScreenWidth, TUint aScreenHeight ); 00131 00132 /** 00133 * Renders the next frame using opengl es calls. 00134 * 00135 * @param aDurationSinceLastVisit The time (in microseconds) since 00136 * the function was last visited. 00137 */ 00138 TBool RenderFrame( TInt64 aDurationSinceLastVisit ); 00139 00140 /** 00141 * Cleanups any resources. 00142 */ 00143 void Cleanup(); 00144 00145 /** 00146 * Handles a Key up / down event. 00147 * 00148 * @param aKey The TStdScanCode of the key. 00149 * @param aIsKeyUp ETrue if the Key is released, else EFalse. 00150 */ 00151 void HandleKeyEvent( TUint32 aKey, TBool aIsKeyUp ); 00152 00153 /** 00154 * Handle screen size changes. 00155 * 00156 * @param aScreenWidth Width of the screen. 00157 * @param aScreenHeight Height of the screen. 00158 */ 00159 void SetScreenSize( TUint aScreenWidth, TUint aScreenHeight ); 00160 00161 /** 00162 * Get the current frame number. 00163 * 00164 */ 00165 TUint GetCurrentFrame() const 00166 { 00167 return iFrame; 00168 } 00169 00170 private: // Data 00171 /** Width of the screen */ 00172 TInt iScreenWidth; 00173 00174 /** Height of the screen */ 00175 TInt iScreenHeight; 00176 00177 /** Flags if the game needs to exit */ 00178 TBool iGameOver; 00179 00180 /** The z co-ordinate of the cube */ 00181 TInt iZPos; 00182 00183 /** Flags if the up key is pressed */ 00184 TBool iIsUpPressed; 00185 00186 /** Flags if the down key is pressed */ 00187 TBool iIsDownPressed; 00188 00189 /** The current frame being rendered */ 00190 TUint iFrame; 00191 }; // CGame 00192 00193 #endif //__GAME_CLASS__
|
© Nokia 2009 |