|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : EnvMapping.h 00004 * Part of : OpenGLEx / EnvMapping 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 #ifndef ENVMAPPING_H 00017 #define ENVMAPPING_H 00018 00019 // INCLUDES 00020 #include <e32base.h> // for CBase definition 00021 #include <GLES/gl.h> // OpenGL ES header file 00022 #include "duck.h" // Data for Duck model 00023 #include "head.h" // Data for Head model 00024 #include "utils.h" // Utilities (state machine, texture handler etc.) 00025 00026 // MACROS 00027 #define DUCK_MODEL 11 00028 #define HEAD_MODEL 22 00029 00030 #define NUM_OF_MODELS 2 // i.e., duck and head models 00031 00032 #define COORD_SCALE 16384 // a value used to scale the texture coordinates 00033 #define CAMERA_DISTANCE 270 // object distance from the camera 00034 00035 #define TEX_WIDTH 256 // Texture size must be power of two and max size 00036 #define TEX_HEIGHT 256 // for textures is 256 x 256 00037 00038 #define FRUSTUM_LEFT -1.f //left vertical clipping plane 00039 #define FRUSTUM_RIGHT 1.f //right vertical clipping plane 00040 #define FRUSTUM_BOTTOM -1.f //bottom horizontal clipping plane 00041 #define FRUSTUM_TOP 1.f //top horizontal clipping plane 00042 #define FRUSTUM_NEAR 3.f //near depth clipping plane 00043 #define FRUSTUM_FAR 1000.f //far depth clipping plane 00044 00045 // CLASS DECLARATION 00046 00047 /** 00048 * Class that does the actual OpenGL ES rendering. 00049 * Subclass of CFiniteStateMachine because the application 00050 * needs to handle loading textures and running states. 00051 */ 00052 class CEnvMapping : public CFiniteStateMachine, public MTextureLoadingListener 00053 { 00054 public: // Constructors and destructor 00055 00056 /** 00057 * Factory method for creating a new CSimpleCube object. 00058 */ 00059 static CEnvMapping* NewL( TUint aWidth, TUint aHeight ); 00060 00061 /** 00062 * Destructor. Does nothing. 00063 */ 00064 virtual ~CEnvMapping(); 00065 00066 public: // New functions 00067 00068 /** 00069 * Initializes OpenGL ES, sets the vertex and color 00070 * arrays and pointers. Also selects the shading mode and 00071 * creates the CTextureManager instance and starts loading 00072 * of required textures. 00073 */ 00074 void AppInitL( void ); 00075 00076 /** 00077 * Called upon application exit. Destroys the CTextureManager 00078 * instance that was created in AppInitL() method. 00079 */ 00080 void AppExit( void ); 00081 00082 /** 00083 * Renders one frame. 00084 * @param aFrame Number of the frame to be rendered. 00085 */ 00086 void AppCycle( TInt aFrame ); 00087 00088 /** 00089 * Called when the finite state machine enters a new state. 00090 * Does nothing in this implementation. 00091 * @param aState State that is about to be entered. 00092 */ 00093 void OnEnterStateL( TInt aState ); 00094 00095 /** 00096 * Called when texture manager starts loading the textures. 00097 * Sets the current state to "loading textures". 00098 */ 00099 void OnStartLoadingTexturesL(); 00100 00101 /** 00102 * Called when texture manager has completed texture loading. 00103 * Changes the current state to "running". 00104 */ 00105 void OnEndLoadingTexturesL(); 00106 00107 /** 00108 * Initializes arrays used to calculate objects texture coordinates. 00109 * Reserves dynamically memories for the arrays depending on the size on the models. 00110 */ 00111 void InitializeArraysL( void ); 00112 00113 /** 00114 * Calculates texture coordinates for the models. 00115 */ 00116 void CalculateTextureCoordinatesL( void ); 00117 00118 /** 00119 * Rotates object left. 00120 */ 00121 void RotateObjectLeft( void ); 00122 00123 /** 00124 * Rotates object right. 00125 */ 00126 void RotateObjectRight( void ); 00127 00128 /** 00129 * Draw the environment mapped duck model. 00130 * @param aFrame Current frame in animation 00131 */ 00132 void DrawDuck( TInt aFrame ); 00133 00134 /** 00135 * Draw the environment mapped head model. 00136 * @param aFrame Current frame in animation 00137 */ 00138 void DrawHead( TInt aFrame ); 00139 00140 /** 00141 * Change to duck model 00142 */ 00143 void DuckModel( void ); 00144 00145 /** 00146 * Change to head model 00147 */ 00148 void HeadModel( void ); 00149 00150 /** 00151 * Notifies that the screen size has dynamically changed during execution of 00152 * this program. Resets the viewport to this new size and sets this size 00153 * to the CTextureManager. 00154 * @param aWidth New width of the screen. 00155 * @param aHeight New height of the screen. 00156 */ 00157 void SetScreenSize( TUint aWidth, TUint aHeight ); 00158 00159 protected: 00160 00161 /** 00162 * Standard constructor that must never Leave. 00163 * Stores the given screen width and height. 00164 * @param aWidth Width of the screen. 00165 * @param aHeight Height of the screen. 00166 */ 00167 CEnvMapping( TUint aWidth, TUint aHeight ); 00168 00169 /** 00170 * Second phase contructor. Does nothing. 00171 */ 00172 void ConstructL( void ); 00173 00174 public: // Data 00175 00176 /** 00177 * Application states: 00178 * ELoadingTextures - indicates that the app. is loading textures. 00179 * ERunning - indicates that the app. is running. 00180 */ 00181 enum 00182 { 00183 ELoadingTextures, 00184 ERunning 00185 }; 00186 00187 private: // Data 00188 00189 /** Texture manager that is used to load the used textures. */ 00190 CTextureManager* iTextureManager; 00191 /** Environment map texture. */ 00192 TTexture iEnvMapTexture; 00193 00194 /** Width of the screen */ 00195 TUint iScreenWidth; 00196 /** Height of the screen */ 00197 TUint iScreenHeight; 00198 00199 /** Num of object faces. Used when calculating texture coords. */ 00200 GLshort iNumFaces; 00201 /** Num of object vertices. Used when calculating texture coords. */ 00202 GLshort iNumVertices; 00203 00204 /** Whether object is rotated left or not. */ 00205 TBool iRotateObjectLeftEnabled; 00206 /** Whether object is rotated right or not. */ 00207 TBool iRotateObjectRightEnabled; 00208 /** Current rotation angle of the object. */ 00209 GLint iObjectRotAngle; 00210 /** Currently shown object model (DUCK_MODEL or HEAD_MODEL). */ 00211 GLint iObjectModel; 00212 00213 /** Vertex normals stored here are used as straight texture coordinates for the duck's environmental mapping. */ 00214 GLshort iDuckTexCoords[duckVertices * 3]; 00215 /** Vertex normals stored here are used as straight texture coordinates for the head's environmental mapping. */ 00216 GLshort iHeadTexCoords[headVertices * 3]; // headVertices == MAX_VERTEX_NUM 00217 00218 /** Temporary storage of face normals. */ 00219 GLfloat* iFaceNormals; 00220 00221 /** 00222 * Tells how many faces are connected to each vertex. This value is used 00223 * when calculating an average normal for each vertices. That normal is 00224 * then used are direct texture coordinate value for that particular vertex. 00225 */ 00226 GLubyte* iNormalCounter; 00227 }; 00228 00229 #endif
|
© Nokia 2006 |