Nokia N97 SDK
Example Applications Guide

CHierarchy Class Reference

#include <Hierarchy.h>

Inheritance diagram for CHierarchy:

List of all members.

Detailed Description

Class that does the actual OpenGL ES rendering.

Definition at line 37 of file 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


Constructor & Destructor Documentation

CHierarchy::~CHierarchy (   )  [virtual]
 

Destructor. Does nothing.

Definition at line 191 of file Hierarchy.cpp.

00192     {
00193     }

CHierarchy::CHierarchy (  TUint  aWidth,
TUint  aHeight
)  [protected]
 

Standard constructor that must never Leave. Stores the given screen width and height.

Parameters:
aWidth  Width of the screen.
aHeight  Height of the screen.

Definition at line 156 of file Hierarchy.cpp.

Referenced by NewL().

00157 :iScreenWidth(aWidth), iScreenHeight(aHeight)
00158     {
00159     }


Member Function Documentation

CHierarchy * CHierarchy::NewL (  TUint  aWidth,
TUint  aHeight
)  [static]
 

Factory method for creating a new CSimpleCube object.

Definition at line 177 of file Hierarchy.cpp.

References CHierarchy().

Referenced by CHierarchyContainer::ConstructL().

00178     {
00179     /* Symbian 2-phase constructor. Calls both the default
00180        C++ constructor and Symbian ConstructL methods */
00181     CHierarchy* self = new (ELeave) CHierarchy( aWidth, aHeight );
00182     CleanupStack::PushL( self );
00183     self->ConstructL();
00184     CleanupStack::Pop();
00185 
00186     return self;
00187     }

void CHierarchy::AppInit (  void   ) 
 

Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode.

Definition at line 202 of file Hierarchy.cpp.

References iElbowRotAngle, iFingersRotAngle, iRotateDownEnabled, iRotateMode, iRotateUpEnabled, iScreenHeight, iScreenWidth, and SetScreenSize().

Referenced by CHierarchyContainer::ConstructL().

00203     {
00204     // Initialize viewport and projection.
00205     SetScreenSize( iScreenWidth, iScreenHeight );
00206 
00207     /* Set the screen background color. */
00208     glClearColor( 0.f, 0.f, 0.f, 1.f );
00209 
00210     /* Enable depth test and back face culling. */
00211     glEnable( GL_DEPTH_TEST );
00212     glEnable( GL_CULL_FACE  );
00213 
00214     /* Enable vertex and color arrays. */
00215     glEnableClientState( GL_VERTEX_ARRAY );
00216     glEnableClientState( GL_COLOR_ARRAY );
00217 
00218     /* Set the initial shading mode */
00219     glShadeModel( GL_FLAT );
00220 
00221     /* Do not use perspective correction */
00222     glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
00223 
00224     /* Rotate mode switch */
00225     iRotateMode      = ROTATE_ELBOW;
00226     iElbowRotAngle   = 0.0;
00227     iFingersRotAngle = 0.0;
00228     iRotateUpEnabled        = EFalse;
00229     iRotateDownEnabled      = EFalse;
00230     }

void CHierarchy::AppExit (  void   ) 
 

Called upon application exit. Does nothing.

Definition at line 238 of file Hierarchy.cpp.

Referenced by CHierarchyContainer::~CHierarchyContainer().

00239     {
00240     }

void CHierarchy::DrawBox (  void   ) 
 

Draws a 3D box.

Definition at line 257 of file Hierarchy.cpp.

Referenced by AppCycle().

00258     {
00259     glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles );
00260     }

void CHierarchy::DrawCoordSystem (  void   ) 
 

Draw a coordinate system

Definition at line 247 of file Hierarchy.cpp.

00248     {
00249     glDrawElements( GL_LINES, 3 * 2, GL_UNSIGNED_BYTE, axisInd );
00250     }

void CHierarchy::AppCycle (  TInt  aFrame  ) 
 

Renders one frame.

Parameters:
aFrame  Number of the frame to be rendered.

Definition at line 268 of file Hierarchy.cpp.

References DrawBox(), iElbowRotAngle, iFingersRotAngle, iRotateDownEnabled, iRotateMode, and iRotateUpEnabled.

Referenced by CHierarchyContainer::DrawCallBack().

00269     {
00270     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
00271 
00272     glLoadIdentity();
00273 
00274     /* Update rotate angles*/
00275     if ( iRotateUpEnabled )
00276         {
00277         if ( iRotateMode == ROTATE_ELBOW )
00278             {
00279             iElbowRotAngle += 1.0;
00280             if ( iElbowRotAngle > 90.0 )
00281                 {
00282                 iElbowRotAngle = 90.0;
00283                 }
00284             }
00285         else if ( iRotateMode == ROTATE_FINGERS )
00286             {
00287             iFingersRotAngle += 1.0;
00288             if ( iFingersRotAngle > 80.0 )
00289                 {
00290                 iFingersRotAngle = 80.0;
00291                 }
00292             }
00293         }
00294 
00295     if ( iRotateDownEnabled )
00296         {
00297         if ( iRotateMode == ROTATE_ELBOW )
00298             {
00299             iElbowRotAngle -= 1.0;
00300             if ( iElbowRotAngle < 0.0 )
00301                 {
00302                 iElbowRotAngle = 0.0;
00303                 }
00304             }
00305         else if ( iRotateMode == ROTATE_FINGERS )
00306             {
00307             iFingersRotAngle -= 1.0;
00308             if ( iFingersRotAngle < 0.0 )
00309                 {
00310                 iFingersRotAngle = 0.0;
00311                 }
00312             }
00313         }
00314 
00315     // Move Camera
00316     gluLookAt(   40.f, 10.f, 150.f,  // Camera location
00317                   50.f,    10.f, 0.f,  // Look at point
00318                    0.f,    1.f, 0.f ); // Up vector
00319 
00320     // Rotate the arm
00321     glRotatef( -100.f, 0., 1., 0. );
00322     glRotatef(   60.f, 0., 0., 1. );
00323 
00324     // Draw Arm
00325     glVertexPointer( 3, GL_BYTE, 0, vertices );
00326     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArm1 );
00327     glTranslatef( 0.0, 0.0, -30.0 );
00328     glPushMatrix();
00329     glScalef( 6.0, 6.0, 15.0 );
00330     glTranslatef( 0.0, 0.0, 1.0 );
00331     DrawBox();
00332     glPopMatrix();
00333 
00334     // Draw Hand
00335     glVertexPointer( 3, GL_BYTE, 0, vertices );
00336     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorArm2 );
00337     glTranslatef( 6.0, 0.0, 0.0 );   // move coordisystem back to middle
00338     glRotatef( -iElbowRotAngle, 0.0, 1.0, 0.0 ); // rotate object
00339     glTranslatef( -6.0, 0.0, 0.0 );  // move coordsystem to top of the box
00340     glTranslatef( 0.0, 0.0, -30.0 ); // Move origin to the other end of cube
00341     glPushMatrix();
00342     glScalef( 6.0, 6.0, 15. );       // Scale the vertices
00343     glTranslatef( 0.0, 0.0, 1.0 );   // Translate origin to the side of the cube
00344     DrawBox();
00345     glPopMatrix();
00346 
00347     // Draw upper finger
00348     glPushMatrix(); // Store the current matrix because we have to draw
00349                        // another finger to the same joint, i.e., arm 2. joint
00350 
00351     // Red part
00352     glVertexPointer( 3, GL_BYTE, 0, vertices );
00353     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger1 );
00354     glTranslatef( 4.5, 0.0, 0.0 );   // move origin near the top of the arm 2. joint
00355     glTranslatef( 1.5, 0.0, 0.0 );   // move origin to the edge of the finger
00356     glRotatef( float(-10.0 - iFingersRotAngle), 0.0, 1.0, 0.0 ); // rotate 1st joint
00357     glTranslatef( -1.5, 0.0, 0.0 );  // move origin to the middle of finger
00358     glTranslatef( 0.0, 0.0, -10.0 ); // move origin to the other end if box
00359     glPushMatrix();
00360     glScalef( 1.5, 1.5, 5. );
00361     glTranslatef( 0.0, 0.0, 1.0 );
00362     DrawBox();
00363     glPopMatrix();
00364 
00365     // White part
00366     glVertexPointer( 3, GL_BYTE, 0, vertices );
00367     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger2 );
00368     glTranslatef( -1.5, 0.0, 0.0 );
00369     glRotatef( float(80.0 - iFingersRotAngle), 0.0, 1.0, 0.0 );
00370     glTranslatef( 1.5, 0.0, 0.0 );
00371     glTranslatef( 0.0, 0.0, -6.0 );
00372     glPushMatrix();
00373     glScalef( 1.5, 1.5, 3. );
00374     glTranslatef( 0.0, 0.0, 1.0 );
00375     DrawBox();
00376     glPopMatrix();
00377 
00378     glPopMatrix(); // Pop back to the 'old' matrix in order to draw the second finger
00379 
00380     // Draw lower finger
00381     glPushMatrix();
00382 
00383     // Red part
00384     glVertexPointer( 3, GL_BYTE, 0, vertices );
00385     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger1 );
00386     glTranslatef( -4.5, 0.0, 0.0 );  // move origin near the bottom of the arm 2. joint
00387     glTranslatef( -1.5, 0.0, 0.0 );  // move origin to the edge of the finger
00388     glRotatef( float(10.0 + iFingersRotAngle), 0.0, 1.0, 0.0 ); // rotate 1st joint
00389     glTranslatef( 1.5, 0.0, 0.0 );   // move origin to the middle of finger
00390     glTranslatef( 0.0, 0.0, -10.0 ); // move origin to the other end if box
00391     glPushMatrix();
00392     glScalef( 1.5, 1.5, 5. );
00393     glTranslatef( 0.0, 0.0, 1.0 );
00394     DrawBox();
00395     glPopMatrix();
00396 
00397     // White part
00398     glVertexPointer( 3, GL_BYTE, 0, vertices );
00399     glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colorFinger2 );
00400     glTranslatef( 1.5, 0.0, 0.0 );
00401     glRotatef( float(-80.0 + iFingersRotAngle), 0.0, 1.0, 0.0 );
00402     glTranslatef( -1.5, 0.0, 0.0 );
00403     glTranslatef( 0.0, 0.0, -6.0 );
00404     glPushMatrix();
00405     glScalef( 1.5, 1.5, 3. );
00406     glTranslatef( 0.0, 0.0, 1.0 );
00407     DrawBox();
00408     glPopMatrix();
00409 
00410     glPopMatrix();
00411 
00412 
00413     }

void CHierarchy::RotateObjectUp (  TBool  aStart  ) 
 

Toggle object "up" rotation on and off based on the given value.

Parameters:
aStart  True if object should be rotated up every frame. False if object shouldn't be rotated up every frame.

Definition at line 443 of file Hierarchy.cpp.

References iRotateDownEnabled, and iRotateUpEnabled.

Referenced by CHierarchyAppUi::HandleKeyEventL().

00444     {
00445     if( aStart )
00446         {
00447         iRotateUpEnabled = ETrue;
00448         iRotateDownEnabled = EFalse;
00449         } else
00450         {
00451         iRotateUpEnabled = EFalse;
00452         }
00453     }

void CHierarchy::RotateObjectDown (  TBool  aStart  ) 
 

Toggle object "down" rotation on and off based on the given value.

Parameters:
aStart  True if object should be rotated down every frame. False if object shouldn't be rotated down every frame.

Definition at line 460 of file Hierarchy.cpp.

References iRotateDownEnabled, and iRotateUpEnabled.

Referenced by CHierarchyAppUi::HandleKeyEventL().

00461     {
00462     if( aStart )
00463         {
00464         iRotateDownEnabled = ETrue;
00465         iRotateUpEnabled = EFalse;
00466         } else
00467         {
00468         iRotateDownEnabled = EFalse;
00469         }
00470     }

void CHierarchy::SwitchRotateMode (  void   ) 
 

Toggles the rotation mode between rotating the arm or the fingers

Definition at line 426 of file Hierarchy.cpp.

References iRotateMode.

Referenced by CHierarchyAppUi::HandleKeyEventL().

00427     {
00428     if ( iRotateMode == ROTATE_ELBOW )
00429         {
00430         iRotateMode = ROTATE_FINGERS;
00431         }
00432     else
00433         {
00434         iRotateMode = ROTATE_ELBOW;
00435         }
00436     }

void CHierarchy::SetScreenSize (  TUint  aWidth,
TUint  aHeight
) 
 

Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size.

Parameters:
aWidth  New width of the screen.
aHeight  New height of the screen.

Definition at line 477 of file Hierarchy.cpp.

References iScreenHeight, and iScreenWidth.

Referenced by AppInit(), and CHierarchyContainer::SizeChanged().

00478     {
00479     iScreenWidth  = aWidth;
00480     iScreenHeight = aHeight;
00481 
00482     // Reinitialize viewport and projection.
00483     glViewport( 0, 0, iScreenWidth, iScreenHeight );
00484 
00485     // Recalculate the view frustrum
00486     glMatrixMode( GL_PROJECTION );
00487     glLoadIdentity();
00488     GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight);
00489     glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio,
00490                 FRUSTUM_BOTTOM, FRUSTUM_TOP,
00491                 FRUSTUM_NEAR, FRUSTUM_FAR );
00492     glMatrixMode( GL_MODELVIEW );
00493     }

void CHierarchy::ConstructL (  void   )  [protected]
 

Second phase contructor. Does nothing.

Definition at line 167 of file Hierarchy.cpp.

00168     {
00169     }


Member Data Documentation

TUint CHierarchy::iScreenWidth [private]
 

Width of the screen

Definition at line 125 of file Hierarchy.h.

Referenced by AppInit(), and SetScreenSize().

TUint CHierarchy::iScreenHeight [private]
 

Height of the screen

Definition at line 128 of file Hierarchy.h.

Referenced by AppInit(), and SetScreenSize().

TInt CHierarchy::iRotateMode [private]
 

The current rotation mode (ROTATE_ELBOW or ROTATE_FINGERS).

Definition at line 131 of file Hierarchy.h.

Referenced by AppCycle(), AppInit(), and SwitchRotateMode().

TBool CHierarchy::iRotateUpEnabled [private]
 

Whether object should be rotated up during each rendered frame or not.

Definition at line 134 of file Hierarchy.h.

Referenced by AppCycle(), AppInit(), RotateObjectDown(), and RotateObjectUp().

TBool CHierarchy::iRotateDownEnabled [private]
 

Whether object should be rotated down during each rendered frame or not.

Definition at line 137 of file Hierarchy.h.

Referenced by AppCycle(), AppInit(), RotateObjectDown(), and RotateObjectUp().

TReal32 CHierarchy::iElbowRotAngle [private]
 

Current rotation angle of the elbow.

Definition at line 140 of file Hierarchy.h.

Referenced by AppCycle(), and AppInit().

TReal32 CHierarchy::iFingersRotAngle [private]
 

Current rotation angle of the fingers.

Definition at line 143 of file Hierarchy.h.

Referenced by AppCycle(), and AppInit().


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top