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

Definition at line 37 of file Billboard.h.
Public Types |
|
| enum | { ELoadingTextures, ERunning } |
Public Member Functions |
|
| virtual | ~CBillboard () |
| void | AppInitL (void) |
| void | AppExit (void) |
| void | AppCycle (GLuint aFrame, GLfloat aTimeSecs, GLfloat aDeltaTimeSecs) |
| void | DrawPlane () |
| void | DrawTree (TInt aRow, TInt aCol) |
| void | DrawCloud (GLfloat aTimeSecs) |
| void | OnEnterStateL (TInt aState) |
| void | OnStartLoadingTexturesL () |
| void | OnEndLoadingTexturesL () |
| void | TurnCamera (GLfixed aDeltaTimeSecs) |
| void | MoveCamera (GLfixed aDeltaTimeSecs) |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions |
|
| static CBillboard * | NewL (TUint aWidth, TUint aHeight, CBillboardInput *aInputHandler) |
Protected Member Functions |
|
| CBillboard (TUint aWidth, TUint aHeight, CBillboardInput *aInputHandler) | |
| void | ConstructL (void) |
Private Attributes |
|
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| CTextureManager * | iTextureManager |
| TTexture | iTreeTexture |
| TTexture | iGrassTexture |
| TTexture | iCloudTexture |
| GLfixed | iCloudTextureCoords [8] |
| GLfixed | iTextureOffset |
| CBillboardInput * | iInputHandler |
| TBool | iIsAutorotateOn |
| TCamerax | iCamera |
| GLfixed | iAzimuth |
| GLfixed | iDistance |
| GLfloat | iCloudVertices [12] |
| CLookUpTable * | iLookUpTable |
|
|
Application states: ELoadingTextures - indicates that the app. is loading textures. ERunning - indicates that the app. is running. Definition at line 163 of file Billboard.h.
|
|
|
Destructor. Does nothing. Definition at line 120 of file Billboard.cpp.
|
|
||||||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 345 of file Billboard.cpp. References iInputHandler, iIsAutorotateOn, iScreenHeight, and iScreenWidth. Referenced by NewL(). 00346 : CFiniteStateMachine() 00347 { 00348 iScreenWidth = aWidth; 00349 iScreenHeight = aHeight; 00350 iInputHandler = aInputHandler; 00351 iIsAutorotateOn = ETrue; 00352 }
|
|
||||||||||||||||
|
Factory method for creating a new CBillboard object.
Definition at line 107 of file Billboard.cpp. References CBillboard(). 00108 { 00109 /* Symbian 2-phase constructor. Calls both the default 00110 C++ constructor and Symbian ConstructL methods */ 00111 CBillboard* self = new (ELeave) CBillboard( aWidth, aHeight, aInputHandler ); 00112 CleanupStack::PushL( self ); 00113 self->ConstructL(); 00114 CleanupStack::Pop(); 00115 00116 return self; 00117 }
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode and creates the CTextureManager instance and starts loading of required textures. Definition at line 129 of file Billboard.cpp. References iCloudTexture, iCloudTextureCoords, iDistance, iGrassTexture, iLookUpTable, iScreenHeight, iScreenWidth, iTextureManager, iTreeTexture, and SetScreenSize(). 00130 { 00131 // Construct a texture manager that uses the application's private 00132 // directory as the source location for all textures. 00133 iTextureManager = CTextureManager::NewL ( iScreenWidth, iScreenHeight, 00134 FRUSTUM_TOP, FRUSTUM_BOTTOM, 00135 FRUSTUM_RIGHT, FRUSTUM_LEFT, 00136 FRUSTUM_NEAR, this ); 00137 00138 // Initialize viewport and projection. 00139 SetScreenSize( iScreenWidth, iScreenHeight ); 00140 00141 /* Set the screen background color. */ 00142 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00143 00144 /* Enable back face culling. */ 00145 glEnable( GL_CULL_FACE ); 00146 glEnable( GL_TEXTURE_2D ); 00147 glEnable( GL_DEPTH_TEST ); 00148 00149 /*Disable lighting */ 00150 glDisable( GL_LIGHTING ); 00151 00152 //Enable alpha test for color keying. 00153 glEnable( GL_ALPHA_TEST ); 00154 glAlphaFuncx( GL_GREATER, FLOAT_2_FIXED(0.0f)); 00155 00156 glMatrixMode( GL_TEXTURE ); 00157 glLoadIdentity(); 00158 glScalex( fixedDiv( FIXED_ONE, INT_2_FIXED(100) ), 00159 fixedDiv( FIXED_ONE, INT_2_FIXED(100) ), 00160 FIXED_ONE ); 00161 00162 00163 glMatrixMode( GL_MODELVIEW ); 00164 00165 /* Enable vertex arrays. */ 00166 glEnableClientState( GL_VERTEX_ARRAY ); 00167 /* Enable texture arrays. */ 00168 glEnableClientState( GL_TEXTURE_COORD_ARRAY ); 00169 00170 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00171 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00172 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ); 00173 00174 iCloudTextureCoords[0] = INT_2_FIXED( 0 ); iCloudTextureCoords[1] = INT_2_FIXED( 50 ); 00175 iCloudTextureCoords[2] = INT_2_FIXED( 0 ); iCloudTextureCoords[3] = INT_2_FIXED( 0 ); 00176 iCloudTextureCoords[4] = INT_2_FIXED( 50 ); iCloudTextureCoords[5] = INT_2_FIXED( 0 ); 00177 iCloudTextureCoords[6] = INT_2_FIXED( 50 ); iCloudTextureCoords[7] = INT_2_FIXED( 50 ); 00178 00179 // Initiallly distance is 40 and camera is only rotating counter-clockwise. 00180 iDistance = FLOAT_2_FIXED( 40.f ); 00181 00182 iLookUpTable = CLookUpTable::NewL( CLookUpTable::ESinx | CLookUpTable::ECosx ); 00183 00184 // Defining a color key interval for the tree texture. 00185 TUint8 MinColor[] = { 50, 0, 50}; 00186 TUint8 MaxColor[] = { 200, 0, 200}; 00187 00188 // Push the textures into the loading queue. 00189 _LIT( KTreeTexture, "tree.gif" ); 00190 _LIT( KGrassTexture, "grass.jpg" ); 00191 _LIT( KCloudTexture, "cloud.jpg" ); 00192 iTextureManager->RequestToLoad( KTreeTexture , &iTreeTexture, MinColor, MaxColor, false ); 00193 iTextureManager->RequestToLoad( KGrassTexture, &iGrassTexture, false ); 00194 iTextureManager->RequestToLoad( KCloudTexture, &iCloudTexture, false ); 00195 00196 //Start to load the textures. 00197 iTextureManager->DoLoadL(); 00198 }
|
|
|
Called upon application exit. Destroys the CTextureManager instance that was created in AppInitL() method. Definition at line 205 of file Billboard.cpp. References iLookUpTable, and iTextureManager. Referenced by CBillboardContainer::~CBillboardContainer(). 00206 { 00207 delete iTextureManager; 00208 delete iLookUpTable; 00209 }
|
|
||||||||||||||||
|
Renders one frame.
Definition at line 304 of file Billboard.cpp. References DrawCloud(), DrawPlane(), DrawTree(), iAzimuth, iCamera, iDistance, iLookUpTable, MoveCamera(), and TurnCamera(). Referenced by CBillboardContainer::DrawCallBack(). 00305 { 00306 glClear( GL_DEPTH_BUFFER_BIT ); 00307 00308 GLfixed fixedDeltaTimeSecs = FLOAT_2_FIXED( aDeltaTimeSecs ); 00309 00310 // Rotate the camera 00311 TurnCamera( fixedDeltaTimeSecs ); 00312 00313 // Move the camera forwards/backwards; 00314 MoveCamera( fixedDeltaTimeSecs ); 00315 00316 // Calculate the current camera transform 00317 GLfixed x = fixedMul( iDistance, iLookUpTable->Cosx( iAzimuth ) ); 00318 GLfixed z = fixedMul( iDistance, iLookUpTable->Sinx( iAzimuth ) ); 00319 iCamera.LookAt( TVectorx( x, INT_2_FIXED( 3 ), z ), 00320 TVectorx( INT_2_FIXED( 0 ), INT_2_FIXED( 0 ), INT_2_FIXED( 0 ) ), 00321 TVectorx( INT_2_FIXED( 0 ), INT_2_FIXED( 1 ), INT_2_FIXED( 0 ) ) ); 00322 00323 // Draws the clouds, the gound plane and the trees 00324 glDisable( GL_DEPTH_TEST ); 00325 DrawCloud( aTimeSecs ); 00326 DrawPlane(); 00327 glEnable( GL_DEPTH_TEST ); 00328 00329 for ( TInt row = 0;row < KNumberOfTreeInRow; row++ ) 00330 { 00331 for ( TInt column = 0;column < KNumberOfTreeInCol; column++ ) 00332 { 00333 DrawTree( row, column ); 00334 } 00335 } 00336 }
|
|
|
Draws the ground plane. The plane is always drawn at fixed location. Definition at line 216 of file Billboard.cpp. References iCamera, and iGrassTexture. Referenced by AppCycle(). 00217 { 00218 glBindTexture( GL_TEXTURE_2D, iGrassTexture.iID ); 00219 00220 // Disable texture filtering 00221 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST); 00222 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST); 00223 00224 glLoadIdentity(); 00225 T3DModelx::MakeWorldViewMatrix( 00226 iCamera, 00227 TVectorx( INT_2_FIXED( 0 ), 00228 INT_2_FIXED( 0 ), 00229 INT_2_FIXED( 0 ) ) ); 00230 glScalex( INT_2_FIXED( 100 ), INT_2_FIXED( 0 ), INT_2_FIXED( 100 ) ); 00231 00232 glVertexPointer( 3, GL_BYTE, 0, planeVertices ); 00233 glTexCoordPointer( 2, GL_SHORT, 0, planeTextureCoords ); 00234 00235 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles ); 00236 00237 }
|
|
||||||||||||
|
Draws a tree. The tree is always drawn at a fixed location based on the row and column, but the orientation of the tree depends on the current camera angle. Trees are always rotated so that they face the camera.
Definition at line 271 of file Billboard.cpp. References iCamera, and iTreeTexture. Referenced by AppCycle(). 00272 { 00273 GLint x = KTreeStep * ( aCol - ( KNumberOfTreeInCol >> 1 ) ); 00274 GLint z = KTreeStep * ( aRow - ( KNumberOfTreeInRow >> 1 ) ); 00275 00276 glLoadIdentity(); 00277 00278 // Turns the tree so that it always faces the camera. (Billboarding technique) 00279 T3DModelx::MakeBillboardWorldViewMatrix( 00280 iCamera, 00281 TVectorx( INT_2_FIXED( x ), 00282 INT_2_FIXED( 0 ), 00283 INT_2_FIXED( z ) ) ); 00284 glScalex( INT_2_FIXED( 1 ), INT_2_FIXED( 3 ), INT_2_FIXED( 1 ) ); 00285 glBindTexture( GL_TEXTURE_2D, iTreeTexture.iID ); 00286 00287 // Disable texture filtering 00288 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00289 glTexParameterf( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST ); 00290 glVertexPointer( 3, GL_BYTE, 0, treeVertices ); 00291 glTexCoordPointer( 2, GL_BYTE, 0, treeTextureCoords ); 00292 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, treeTriangles ); 00293 }
|
|
|
Draws and animates the clouds based on the time that has elapsed since last frame.
Definition at line 244 of file Billboard.cpp. References iCloudTexture, iCloudTextureCoords, iCloudVertices, and iTextureOffset. Referenced by AppCycle(). 00245 { 00246 //Moving the clouds. 00247 iTextureOffset = FLOAT_2_FIXED( aTimeSecs ); 00248 GLfixed leftEdge = iTextureOffset; 00249 GLfixed rightEdge = iTextureOffset + INT_2_FIXED( 50 ); 00250 iCloudTextureCoords[0] = iCloudTextureCoords[2] = leftEdge; 00251 iCloudTextureCoords[4] = iCloudTextureCoords[6] = rightEdge; 00252 00253 glLoadIdentity(); 00254 00255 glBindTexture( GL_TEXTURE_2D, iCloudTexture.iID ); 00256 // Enable texture filtering 00257 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00258 glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00259 00260 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); 00261 glVertexPointer( 3, GL_FLOAT, 0, iCloudVertices ); 00262 glTexCoordPointer( 2, GL_FIXED, 0, iCloudTextureCoords ); 00263 glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, cloudTriangles ); 00264 }
|
|
|
Called when the finite state machine enters a new state. Does nothing in this implementation.
Definition at line 368 of file Billboard.cpp.
|
|
|
Called when texture manager starts loading the textures. Sets the current state to "loading textures". Definition at line 377 of file Billboard.cpp.
|
|
|
Called when texture manager has completed texture loading. Changes the current state to "running". Definition at line 386 of file Billboard.cpp. 00387 { 00388 if ( GetState() == ELoadingTextures ) 00389 { 00390 SetStateL( ERunning ); 00391 } 00392 }
|
|
|
Turn the camera in azimuth based on the joystick movement or if the automatic rotation is on based on the current iCamRotation value.
Definition at line 442 of file Billboard.cpp. References iAzimuth, and iIsAutorotateOn. Referenced by AppCycle(). 00443 { 00444 if( iIsAutorotateOn ) 00445 { 00446 // Autorotation is on: rotate the camera at constant speed 00447 iAzimuth += fixedMul( KCamRotationSpeed, aDeltaTimeSecs ); 00448 } 00449 // Autorotation is off: read joystick left/right movement and rotate the camera 00450 if( iInputHandler->IsInputPressed( EJoystickLeft ) ) 00451 { 00452 iIsAutorotateOn = EFalse; 00453 iAzimuth += fixedMul( KCamRotationSpeed, aDeltaTimeSecs ); 00454 } 00455 else if( iInputHandler->IsInputPressed( EJoystickRight ) ) 00456 { 00457 iIsAutorotateOn = EFalse; 00458 iAzimuth -= fixedMul( KCamRotationSpeed, aDeltaTimeSecs ); 00459 } 00460 else if( iInputHandler->IsInputPressed( EJoystickFire ) ) 00461 { 00462 // User pressed joystick button, turn autorotation on 00463 iIsAutorotateOn = ETrue; 00464 } 00465 00466 00467 // Keep the azimuth within range of [0, 359] 00468 while( iAzimuth < INT_2_FIXED( 0 ) ) 00469 { 00470 iAzimuth += INT_2_FIXED( 360 ); 00471 } 00472 00473 while( iAzimuth >= INT_2_FIXED( 360 ) ) 00474 { 00475 iAzimuth -= INT_2_FIXED( 360 ); 00476 } 00477 }
|
|
|
Move the camera forwards or backwards based on joystick movement and the delta time.
Definition at line 483 of file Billboard.cpp. References iDistance, iInputHandler, and CBillboardInput::IsInputPressed(). Referenced by AppCycle(). 00484 { 00485 if( iInputHandler->IsInputPressed( EJoystickUp ) ) 00486 { 00487 iDistance -= fixedMul( KCamMovementSpeed, aDeltaTimeSecs ); 00488 if ( iDistance < KMinCamDistance ) 00489 { 00490 iDistance = KMinCamDistance; 00491 } 00492 } 00493 if( iInputHandler->IsInputPressed( EJoystickDown ) ) 00494 { 00495 iDistance += fixedMul( KCamMovementSpeed, aDeltaTimeSecs ); 00496 if ( iDistance > KMaxCamDistance ) 00497 { 00498 iDistance = KMaxCamDistance; 00499 } 00500 } 00501 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size and sets this size to the CTextureManager.
Definition at line 399 of file Billboard.cpp. References iCloudVertices, iScreenHeight, iScreenWidth, and iTextureManager. Referenced by AppInitL(), and CBillboardContainer::SizeChanged(). 00400 { 00401 iScreenWidth = aWidth; 00402 iScreenHeight = aHeight; 00403 00404 // Notify the texture manager of screen size change 00405 iTextureManager->SetScreenSize( aWidth, aHeight ); 00406 00407 // Reinitialize viewport and projection. 00408 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00409 00410 // Recalculate the view frustrum 00411 glMatrixMode( GL_PROJECTION ); 00412 glLoadIdentity(); 00413 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00414 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00415 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00416 FRUSTUM_NEAR, FRUSTUM_FAR ); 00417 glMatrixMode( GL_MODELVIEW ); 00418 00419 // Recalculate cloud vertices based on the aspect ratio 00420 // Recalculate cloud vertices based on the aspect ratio 00421 iCloudVertices[ 0 ] = FRUSTUM_RIGHT * aspectRatio; 00422 iCloudVertices[ 1 ] = 0.f; 00423 iCloudVertices[ 2 ] = -FRUSTUM_NEAR; 00424 00425 iCloudVertices[ 3 ] = FRUSTUM_RIGHT * aspectRatio; 00426 iCloudVertices[ 4 ] = FRUSTUM_TOP; 00427 iCloudVertices[ 5 ] = -FRUSTUM_NEAR; 00428 00429 iCloudVertices[ 6 ] = FRUSTUM_LEFT * aspectRatio; 00430 iCloudVertices[ 7 ] = FRUSTUM_TOP; 00431 iCloudVertices[ 8 ] = -FRUSTUM_NEAR; 00432 00433 iCloudVertices[ 9 ] = FRUSTUM_LEFT * aspectRatio; 00434 iCloudVertices[ 10 ] = 0.f; 00435 iCloudVertices[ 11 ] = -FRUSTUM_NEAR; 00436 }
|
|
|
Second phase contructor. Does nothing. Definition at line 359 of file Billboard.cpp.
|
|
|
Width of the screen Definition at line 173 of file Billboard.h. Referenced by AppInitL(), CBillboard(), and SetScreenSize(). |
|
|
Height of the screen Definition at line 175 of file Billboard.h. Referenced by AppInitL(), CBillboard(), and SetScreenSize(). |
|
|
Texture manager that is used to load the used textures. Definition at line 178 of file Billboard.h. Referenced by AppExit(), AppInitL(), and SetScreenSize(). |
|
|
Tree texture. Definition at line 181 of file Billboard.h. Referenced by AppInitL(), and DrawTree(). |
|
|
Grass texture. Definition at line 183 of file Billboard.h. Referenced by AppInitL(), and DrawPlane(). |
|
|
Cloud texture. Definition at line 185 of file Billboard.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture coordinates. Definition at line 187 of file Billboard.h. Referenced by AppInitL(), and DrawCloud(). |
|
|
Cloud texture offset. Used to animate the clouds in the sky. Definition at line 189 of file Billboard.h. Referenced by DrawCloud(). |
|
|
Input handler that maps keycodes to inputs and stores the current state for each key. Owned by the C::Name::Container. Definition at line 195 of file Billboard.h. Referenced by CBillboard(), and MoveCamera(). |
|
|
Indicates whether the camera should be automatically rotated around the scene or if the camera is controlled by the joystick's left/right movements. Definition at line 200 of file Billboard.h. Referenced by CBillboard(), and TurnCamera(). |
|
|
Camera. Definition at line 202 of file Billboard.h. Referenced by AppCycle(), DrawPlane(), and DrawTree(). |
|
|
Camera azimuth. Definition at line 204 of file Billboard.h. Referenced by AppCycle(), and TurnCamera(). |
|
|
Camera distance. Definition at line 206 of file Billboard.h. Referenced by AppCycle(), AppInitL(), and MoveCamera(). |
|
|
Vertice coordinates drawing the clouds. Definition at line 209 of file Billboard.h. Referenced by DrawCloud(), and SetScreenSize(). |
|
|
Lookup-table for sin, cos, tan. Definition at line 212 of file Billboard.h. Referenced by AppCycle(), AppExit(), and AppInitL(). |
|
© Nokia 2009 |