|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
#include <SimpleCube.h>
Public Member Functions | |
| virtual | ~CSimpleCube () |
| void | AppInit (void) |
| void | AppExit (void) |
| void | DrawBox (GLfloat aSizeX, GLfloat aSizeY, GLfloat aSizeZ) |
| void | AppCycle (TInt aFrame) |
| void | FlatShading (void) |
| void | SmoothShading (void) |
| void | TriangleMode (void) |
| void | TriangleFanMode (void) |
| void | SetScreenSize (TUint aWidth, TUint aHeight) |
Static Public Member Functions | |
| static CSimpleCube * | NewL (TUint aWidth, TUint aHeight) |
Protected Member Functions | |
| CSimpleCube (TUint aWidth, TUint aHeight) | |
| void | ConstructL (void) |
Private Attributes | |
| TUint | iScreenWidth |
| TUint | iScreenHeight |
| TRenderingMode | iDrawingMode |
Definition at line 40 of file SimpleCube.h.
|
|
Destructor. Does nothing. Definition at line 152 of file SimpleCube.cpp.
|
|
||||||||||||
|
Standard constructor that must never Leave. Stores the given screen width and height.
Definition at line 139 of file SimpleCube.cpp. 00139 : 00140 iScreenWidth( aWidth ), 00141 iScreenHeight( aHeight ) 00142 { 00143 }
|
|
||||||||||||
|
Factory method for creating a new CSimpleCube object. Definition at line 120 of file SimpleCube.cpp. References CSimpleCube(). 00121 { 00122 /* Symbian 2-phase constructor. Calls both the default 00123 C++ constructor and Symbian ConstructL methods */ 00124 CSimpleCube* self = new (ELeave) CSimpleCube( aWidth, aHeight ); 00125 CleanupStack::PushL( self ); 00126 self->ConstructL(); 00127 CleanupStack::Pop(); 00128 00129 return self; 00130 }
|
|
|
Initializes OpenGL ES, sets the vertex and color arrays and pointers. Also selects the shading mode. Definition at line 175 of file SimpleCube.cpp. References iDrawingMode, iScreenHeight, and iScreenWidth. 00176 { 00177 // Set the screen background color. 00178 glClearColor( 0.f, 0.f, 0.f, 1.f ); 00179 00180 // Enable back face culling. 00181 glEnable( GL_CULL_FACE ); 00182 00183 // Initialize viewport and projection. 00184 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00185 glMatrixMode( GL_PROJECTION ); 00186 00187 // Calculate the view frustrum 00188 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00189 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00190 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00191 FRUSTUM_NEAR, FRUSTUM_FAR ); 00192 00193 glMatrixMode( GL_MODELVIEW ); 00194 00195 // Enable vertex arrays. 00196 glEnableClientState( GL_VERTEX_ARRAY ); 00197 00198 // Set array pointers. 00199 glVertexPointer( 3, GL_BYTE, 0, vertices ); 00200 00201 // Enable color arrays. 00202 glEnableClientState( GL_COLOR_ARRAY ); 00203 00204 // Set color pointers. 00205 glColorPointer( 4, GL_UNSIGNED_BYTE, 0, colors ); 00206 00207 // Set the initial shading mode 00208 glShadeModel( GL_FLAT ); 00209 00210 // Do not use perspective correction 00211 glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); 00212 00213 // Set the initial drawing mode 00214 iDrawingMode = ETriangles; 00215 }
|
|
|
Called upon application exit. Does nothing. Definition at line 224 of file SimpleCube.cpp.
|
|
||||||||||||||||
|
Draws a 3D box with triangles or triangle fans depending on the current rendering mode.Scales the box to the given size using glScalef.
Definition at line 236 of file SimpleCube.cpp. References iDrawingMode. 00237 { 00238 glScalef( aSizeX, aSizeY, aSizeZ ); 00239 00240 if ( iDrawingMode == ETriangles ) 00241 { 00242 glDrawElements( GL_TRIANGLES, 12 * 3, GL_UNSIGNED_BYTE, triangles ); 00243 } 00244 else if ( iDrawingMode == ETriangleFans ) 00245 { 00246 glDrawElements( GL_TRIANGLE_FAN, 6 * 3, GL_UNSIGNED_BYTE, fanOne ); 00247 glDrawElements( GL_TRIANGLE_FAN, 6 * 3, GL_UNSIGNED_BYTE, fanTwo ); 00248 } 00249 }
|
|
|
Renders one frame.
Definition at line 259 of file SimpleCube.cpp. References DrawBox(). 00260 { 00261 const GLint cameraDistance = 100; 00262 00263 glClear( GL_COLOR_BUFFER_BIT ); 00264 00265 /* Animate and draw box */ 00266 glLoadIdentity(); 00267 glTranslatex( 0 , 0 , -cameraDistance << 16 ); 00268 glRotatex( aFrame << 16, 1 << 16, 0 , 0 ); 00269 glRotatex( aFrame << 15, 0 , 1 << 16, 0 ); 00270 glRotatex( aFrame << 14, 0 , 0 , 1 << 16 ); 00271 DrawBox( 15.f, 15.f, 15.f ); 00272 }
|
|
|
Sets the shading mode to flat. Definition at line 286 of file SimpleCube.cpp.
|
|
|
Sets the shading to smooth (gradient). Definition at line 298 of file SimpleCube.cpp.
|
|
|
Sets the rendering to use triangles. Definition at line 310 of file SimpleCube.cpp. References iDrawingMode. 00311 { 00312 iDrawingMode = ETriangles; 00313 }
|
|
|
Sets the rendering to use triangle fans. Definition at line 322 of file SimpleCube.cpp. References iDrawingMode. 00323 { 00324 iDrawingMode = ETriangleFans; 00325 }
|
|
||||||||||||
|
Notifies that the screen size has dynamically changed during execution of this program. Resets the viewport to this new size.
Definition at line 332 of file SimpleCube.cpp. References iScreenHeight, and iScreenWidth. 00333 { 00334 iScreenWidth = aWidth; 00335 iScreenHeight = aHeight; 00336 00337 // Reinitialize viewport and projection. 00338 glViewport( 0, 0, iScreenWidth, iScreenHeight ); 00339 00340 // Recalculate the view frustrum 00341 glMatrixMode( GL_PROJECTION ); 00342 glLoadIdentity(); 00343 GLfloat aspectRatio = (GLfloat)(iScreenWidth) / (GLfloat)(iScreenHeight); 00344 glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, 00345 FRUSTUM_BOTTOM, FRUSTUM_TOP, 00346 FRUSTUM_NEAR, FRUSTUM_FAR ); 00347 glMatrixMode( GL_MODELVIEW ); 00348 }
|
|
|
Second phase contructor. Does nothing. Definition at line 163 of file SimpleCube.cpp.
|
|
|
Width of the screen Definition at line 128 of file SimpleCube.h. |
|
|
Height of the screen Definition at line 131 of file SimpleCube.h. |
|
|
The current rendering mode Definition at line 134 of file SimpleCube.h. |
|
© Nokia 2006 |