|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <Hierarchy.h>
Public Member Functions | |
| virtual | ~CHierarchy () |
| void | AppInit (void) |
| void | AppExit (void) |
| void | DrawBox (void) |
| void | DrawCoordSystem (void) |
| void | AppCycle (TInt aFrame) |
| void | RotateObjectUp (TBool aStart) |
| void | RotateObjectDown (TBool aStart) |
| void | SwitchRotateMode (void) |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions | |
| static CHierarchy * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions | |
| CHierarchy (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Attributes | |
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TInt | iRotateMode |
| TBool | iRotateUpEnabled |
| TBool | iRotateDownEnabled |
| TReal32 | iElbowRotAngle |
| TReal32 | iFingersRotAngle |
Definition at line 39 of file Hierarchy.h.
|
|
Destructor. Does nothing. Definition at line 196 of file Hierarchy.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 161 of file Hierarchy.cpp. 00162 :iScreenWidth(aWidth), iScreenHeight(aHeight) 00163 { 00164 }
|
|
||||||||||||
|
Factory method for creating a new CSimpleCube object. Definition at line 182 of file Hierarchy.cpp. References CHierarchy(). 00183 { 00184 /* Symbian 2-phase constructor. Calls both the default 00185 C++ constructor and Symbian ConstructL methods */ 00186 CHierarchy* self = new (ELeave) CHierarchy( aWidth, aHeight ); 00187 CleanupStack::PushL( self ); 00188 self->ConstructL(); 00189 CleanupStack::Pop(); 00190 00191 return self; 00192 }
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode. Definition at line 207 of file Hierarchy.cpp. References iElbowRotAngle, iFingersRotAngle, iRotateDownEnabled, iRotateMode, iRotateUpEnabled, iScreenHeight, and iScreenWidth. 00208 { 00209 /* Set the screen background color. */ 00210 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00211 00212 /* Enable depth test and back face culling. */ 00213 glEnable( GL_DEPTH_TEST ); 00214 glEnable( GL_CULL_FACE ); 00215 00216 /* Initialize viewport and projection. */ 00217 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00218 glMatrixMode( GL_PROJECTION ); 00219 00220 // Calculate the view frustrum 00221 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00222 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00223 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00224 FRUSTUM_NEAR, FRUSTUM_FAR ); 00225 00226 glMatrixMode( GL_MODELVIEW ); 00227 00228 /* Enable vertex and color arrays. */ 00229 glEnableClientState( GL_VERTEX_ARRAY ); 00230 glEnableClientState( GL_COLOR_ARRAY ); 00231 00232 /* Set the initial shading mode */ 00233 glShadeModel( GL_FLAT ); 00234 00235 /* Do not use perspective correction */ 00236 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); 00237 00238 /* Rotate mode switch */ 00239 iRotateMode = ROTATE_ELBOW; 00240 iElbowRotAngle = 0.0; 00241 iFingersRotAngle = 0.0; 00242 iRotateUpEnabled = EFalse; 00243 iRotateDownEnabled = EFalse; 00244 }
|
|
|
Called upon application exit. Does nothing. Definition at line 252 of file Hierarchy.cpp.
|
|
|
Draws a 3D box. Definition at line 271 of file Hierarchy.cpp.
|
|
|
Draw a coordinate system Definition at line 261 of file Hierarchy.cpp.
|
|
|
Renders one frame.
Definition at line 282 of file Hierarchy.cpp. References DrawBox(), iElbowRotAngle, iFingersRotAngle, iRotateDownEnabled, iRotateMode, and iRotateUpEnabled. 00283 { 00284 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 00285 00286 glLoadIdentity(); 00287 00288 /* Update rotate angles*/ 00289 if ( iRotateUpEnabled ) 00290 { 00291 if ( iRotateMode == ROTATE_ELBOW ) 00292 { 00293 iElbowRotAngle += 1.0; 00294 if ( iElbowRotAngle > 90.0 ) 00295 { 00296 iElbowRotAngle = 90.0; 00297 } 00298 } 00299 else if ( iRotateMode == ROTATE_FINGERS ) 00300 { 00301 iFingersRotAngle += 1.0; 00302 if ( iFingersRotAngle > 80.0 ) 00303 { 00304 iFingersRotAngle = 80.0; 00305 } 00306 } 00307 } 00308 00309 if ( iRotateDownEnabled ) 00310 { 00311 if ( iRotateMode == ROTATE_ELBOW ) 00312 { 00313 iElbowRotAngle -= 1.0; 00314 if ( iElbowRotAngle < 0.0 ) 00315 { 00316 iElbowRotAngle = 0.0; 00317 } 00318 } 00319 else if ( iRotateMode == ROTATE_FINGERS ) 00320 { 00321 iFingersRotAngle -= 1.0; 00322 if ( iFingersRotAngle < 0.0 ) 00323 { 00324 iFingersRotAngle = 0.0; 00325 } 00326 } 00327 } 00328 00329 // Move Camera 00330 glTranslatef( -40.0 , -10.0 , -cameraDistance ); 00331 glRotatef( 10., 1., 0., 0. ); 00332 glRotatef( -100., 0., 1., 0. ); 00333 glRotatef( 60., 0., 0., 1. ); 00334 00335 // Draw Arm 00336 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00337 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArm1 ); 00338 glTranslatef( 0.0, 0.0, -30.0 ); 00339 glPushMatrix(); 00340 glScalef( 6.0, 6.0, 15.0 ); 00341 glTranslatef( 0.0, 0.0, 1.0 ); 00342 DrawBox(); 00343 glPopMatrix(); 00344 00345 // Draw Hand 00346 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00347 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArm2 ); 00348 glTranslatef( 6.0, 0.0, 0.0 ); // move coordisystem back to middle 00349 glRotatef( -iElbowRotAngle, 0.0, 1.0, 0.0 ); // rotate object 00350 glTranslatef( -6.0, 0.0, 0.0 ); // move coordsystem to top of the box 00351 glTranslatef( 0.0, 0.0, -30.0 ); // Move origin to the other end of cube 00352 glPushMatrix(); 00353 glScalef( 6.0, 6.0, 15. ); // Scale the vertices 00354 glTranslatef( 0.0, 0.0, 1.0 ); // Translate origin to the side of the cube 00355 DrawBox(); 00356 glPopMatrix(); 00357 00358 // Draw upper finger 00359 glPushMatrix(); // Store the current matrix because we have to draw 00360 // another finger to the same joint, i.e., arm 2. joint 00361 00362 // Red part 00363 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00364 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger1 ); 00365 glTranslatef( 4.5, 0.0, 0.0 ); // move origin near the top of the arm 2. joint 00366 glTranslatef( 1.5, 0.0, 0.0 ); // move origin to the edge of the finger 00367 glRotatef( float(-10.0 - iFingersRotAngle), 0.0, 1.0, 0.0 ); // rotate 1st joint 00368 glTranslatef( -1.5, 0.0, 0.0 ); // move origin to the middle of finger 00369 glTranslatef( 0.0, 0.0, -10.0 ); // move origin to the other end if box 00370 glPushMatrix(); 00371 glScalef( 1.5, 1.5, 5. ); 00372 glTranslatef( 0.0, 0.0, 1.0 ); 00373 DrawBox(); 00374 glPopMatrix(); 00375 00376 // White part 00377 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00378 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger2 ); 00379 glTranslatef( -1.5, 0.0, 0.0 ); 00380 glRotatef( float(80.0 - iFingersRotAngle), 0.0, 1.0, 0.0 ); 00381 glTranslatef( 1.5, 0.0, 0.0 ); 00382 glTranslatef( 0.0, 0.0, -6.0 ); 00383 glPushMatrix(); 00384 glScalef( 1.5, 1.5, 3. ); 00385 glTranslatef( 0.0, 0.0, 1.0 ); 00386 DrawBox(); 00387 glPopMatrix(); 00388 00389 glPopMatrix(); // Pop back to the 'old' matrix in order to draw the second finger 00390 00391 // Draw lower finger 00392 glPushMatrix(); 00393 00394 // Red part 00395 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00396 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger1 ); 00397 glTranslatef( -4.5, 0.0, 0.0 ); // move origin near the bottom of the arm 2. joint 00398 glTranslatef( -1.5, 0.0, 0.0 ); // move origin to the edge of the finger 00399 glRotatef( float(10.0 + iFingersRotAngle), 0.0, 1.0, 0.0 ); // rotate 1st joint 00400 glTranslatef( 1.5, 0.0, 0.0 ); // move origin to the middle of finger 00401 glTranslatef( 0.0, 0.0, -10.0 ); // move origin to the other end if box 00402 glPushMatrix(); 00403 glScalef( 1.5, 1.5, 5. ); 00404 glTranslatef( 0.0, 0.0, 1.0 ); 00405 DrawBox(); 00406 glPopMatrix(); 00407 00408 // White part 00409 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00410 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger2 ); 00411 glTranslatef( 1.5, 0.0, 0.0 ); 00412 glRotatef( float(-80.0 + iFingersRotAngle), 0.0, 1.0, 0.0 ); 00413 glTranslatef( -1.5, 0.0, 0.0 ); 00414 glTranslatef( 0.0, 0.0, -6.0 ); 00415 glPushMatrix(); 00416 glScalef( 1.5, 1.5, 3. ); 00417 glTranslatef( 0.0, 0.0, 1.0 ); 00418 DrawBox(); 00419 glPopMatrix(); 00420 00421 glPopMatrix(); 00422 00423 00424 }
|
|
|
Toggle object "up" rotation on and off based on the given value.
Definition at line 454 of file Hierarchy.cpp. References iRotateDownEnabled, and iRotateUpEnabled. 00455 { 00456 if( aStart ) 00457 { 00458 iRotateUpEnabled = ETrue; 00459 iRotateDownEnabled = EFalse; 00460 } else 00461 { 00462 iRotateUpEnabled = EFalse; 00463 } 00464 }
|
|
|
Toggle object "down" rotation on and off based on the given value.
Definition at line 471 of file Hierarchy.cpp. References iRotateDownEnabled, and iRotateUpEnabled. 00472 { 00473 if( aStart ) 00474 { 00475 iRotateDownEnabled = ETrue; 00476 iRotateUpEnabled = EFalse; 00477 } else 00478 { 00479 iRotateDownEnabled = EFalse; 00480 } 00481 }
|
|
|
Toggles the rotation mode between rotating the arm or the fingers Definition at line 437 of file Hierarchy.cpp. References iRotateMode. 00438 { 00439 if ( iRotateMode == ROTATE_ELBOW ) 00440 { 00441 iRotateMode = ROTATE_FINGERS; 00442 } 00443 else 00444 { 00445 iRotateMode = ROTATE_ELBOW; 00446 } 00447 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size.
Definition at line 488 of file Hierarchy.cpp. References iScreenHeight, and iScreenWidth. 00489 { 00490 iScreenWidth = aWidth; 00491 iScreenHeight = aHeight; 00492 00493 // Reinitialize viewport and projection. 00494 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00495 00496 // Recalculate the view frustrum 00497 glMatrixMode( GL_PROJECTION ); 00498 glLoadIdentity(); 00499 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00500 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00501 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00502 FRUSTUM_NEAR, FRUSTUM_FAR ); 00503 glMatrixMode( GL_MODELVIEW ); 00504 }
|
|
|
Second phase contructor. Does nothing. Definition at line 172 of file Hierarchy.cpp.
|
|
|
Width of the screen Definition at line 127 of file Hierarchy.h. |
|
|
Height of the screen Definition at line 130 of file Hierarchy.h. |
|
|
The current rotation mode (ROTATE_ELBOW or ROTATE_FINGERS). Definition at line 133 of file Hierarchy.h. |
|
|
Whether object should be rotated up during each rendered frame or not. Definition at line 136 of file Hierarchy.h. |
|
|
Whether object should be rotated down during each rendered frame or not. Definition at line 139 of file Hierarchy.h. |
|
|
Current rotation angle of the elbow. Definition at line 142 of file Hierarchy.h. |
|
|
Current rotation angle of the fingers. Definition at line 145 of file Hierarchy.h. |
|
© Nokia 2006 |