📄 snow.cpp
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */
// INCLUDE FILES
#include "snow.h"
#include <aknnotewrappers.h>
#include <e32math.h>
// MACROS
#if defined( __WINS__ )
_LIT(KTexturePath, "z:\\pictures\\");
#define TEXTUREPATH KTexturePath
// Path for emulator build.
// For emulator build we assume that textures are located in the
// z:\pictures\ directory
#else
#define TEXTUREPATH Utils::GetAppRootDirectoryL()
// Path for HW release
// for HW release we assume that textures are located in the
// application's root directory
#endif
// CONSTANTS
/* Define vertice coordinates for the ground plane */
static const GLbyte planeVertices[4 * 3] =
{
+1,0,-1,
+1,0,+1,
-1,0,+1,
-1,0,-1
};
/* Define texture coordinates for ground plane */
static const GLbyte planeTextureCoords[4 * 2] =
{
0, 10,
0, 0,
10, 0,
10, 10
};
/* Define indices for drawing the triangles of the ground plane */
static const GLubyte planeTriangles[2 * 3] =
{
0,2,1,
0,3,2
};
/* Define vertice coordinates for tree */
static const GLbyte treeVertices[4 * 3] =
{
+1, 0,0,
+1,+1,0,
-1,+1,0,
-1, 0,0
};
/* Define texture coordinates for tree */
static const GLbyte treeTextureCoords[4 * 2] =
{
0, 1,
0, 0,
1, 0,
1, 1
};
/* Define indices for drawing the tree */
static const GLubyte treeTriangles[2 * 3] =
{
0,1,2,
0,2,3
};
/* Define vertice coordinates drawing the clouds */
static const GLfloat cloudVertices [] =
{
FRUSTUM_RIGHT, (0.125f * FRUSTUM_BOTTOM), -FRUSTUM_NEAR,
FRUSTUM_RIGHT, FRUSTUM_TOP, -FRUSTUM_NEAR,
FRUSTUM_LEFT, FRUSTUM_TOP, -FRUSTUM_NEAR,
FRUSTUM_LEFT, (0.125f * FRUSTUM_BOTTOM), -FRUSTUM_NEAR
};
/* Define indices for drawing the clouds */
static const GLubyte cloudTriangles [] =
{
0,1,2,
0,2,3
};
/* Define texture coordinates for clouds */
static const GLbyte cloudTextureCoords[4 * 2] =
{
0, 1,
0, 0,
1, 0,
1, 1
};
/* Define vertice coordinates for snow */
static const GLbyte snowVertices[4 * 3] =
{
+2, 0,0,
+2,+2,0,
-2,+2,0,
-2, 0,0
};
/* Define texture coordinates for snow */
static const GLbyte snowTextureCoords[4 * 2] =
{
0, 1,
0, 0,
1, 0,
1, 1
};
/* Define indices for drawing the snow */
static const GLubyte snowTriangles[2 * 3] =
{
0,1,2,
0,2,3
};
// LOCAL CONSTANTS AND MACROS
// ============================= MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CSnow::NewL
// Symbian 2-phase constructor. Can leave.
// -----------------------------------------------------------------------------
//
CSnow* CSnow::NewL( TUint aWidth, TUint aHeight )
{
/* Symbian 2-phase constructor. Calls both the default
C++ constructor and Symbian ConstructL methods */
CSnow* self = new (ELeave) CSnow( aWidth, aHeight );
CleanupStack::PushL( self );
self->ConstructL();
CleanupStack::Pop();
return self;
}
// Destructor.
CSnow::~CSnow()
{
}
// -----------------------------------------------------------------------------
// CSnow::GetElapsedTime
// Gets the elapsed time.
// Returns: The elapsed time
// -----------------------------------------------------------------------------
//
GLfloat CSnow::GetElapsedTime()
{
return iElapsedTime;
}
// -----------------------------------------------------------------------------
// CSnow::GetFPSCount
// Gets the frames per second.
// Returns: Frames per second
// -----------------------------------------------------------------------------
//
GLfloat CSnow::GetFPSCount()
{
return iFPSCount;
}
// -----------------------------------------------------------------------------
// CSnow::GetSnowfall
// Gets the particle engine.
// Returns: The owned particle engine pointer
// -----------------------------------------------------------------------------
//
CSnowfall* CSnow::GetSnowfall()
{
return iSnowfall;
}
// -----------------------------------------------------------------------------
// CSnow::SetTextureManager
// Sets the texture manager.
// -----------------------------------------------------------------------------
//
void CSnow::SetTextureManager( CTextureManager * aTextureManager )
{
iTextureManager = aTextureManager;
}
// -----------------------------------------------------------------------------
// CSnow::AppInit
// Application initialization code.
// -----------------------------------------------------------------------------
//
void CSnow::AppInitL( void )
{
/* Set the screen background color. */
glClearColor( 0.f, 0.f, 0.f, 1.f );
/* Enable back face culling. */
glEnable( GL_CULL_FACE );
glEnable( GL_TEXTURE_2D );
glEnable( GL_DEPTH_TEST );
//Enable alpha test for color keying.
glEnable( GL_ALPHA_TEST );
glAlphaFunc( GL_GREATER, 0.0f );
/*Disable lighting */
glDisable( GL_LIGHTING );
/* Initialize viewport and projection. */
glViewport( 0, 0, iScreenWidth, iScreenHeight );
glMatrixMode( GL_PROJECTION );
glFrustumf( FRUSTUM_LEFT, FRUSTUM_RIGHT, FRUSTUM_BOTTOM, FRUSTUM_TOP, FRUSTUM_NEAR, FRUSTUM_FAR );
glMatrixMode( GL_MODELVIEW );
/* Enable vertex arrays. */
glEnableClientState( GL_VERTEX_ARRAY );
/* Enable texture arrays. */
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
//glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
iCloudTextureCoords[0] = 0; iCloudTextureCoords[1] = 1;
iCloudTextureCoords[2] = 0; iCloudTextureCoords[3] = 0;
iCloudTextureCoords[4] = 1; iCloudTextureCoords[5] = 0;
iCloudTextureCoords[6] = 1; iCloudTextureCoords[7] = 1;
iCamera.LookAt(TVector(0, 30.0f, 0), TVector(0, 0, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), TVector(0, 1, 0));
TFileName TexturePath; //Path to directory that contains the textures.
TexturePath = TEXTUREPATH;
iTextureManager = CTextureManager::NewL ( TexturePath,iScreenWidth, iScreenWidth,
FRUSTUM_TOP, FRUSTUM_BOTTOM, FRUSTUM_RIGHT, FRUSTUM_LEFT, FRUSTUM_NEAR,
this );
iSnowfall = CSnowfall::NewL(600, TVector(0, 80, -(FRUSTUM_FAR+FRUSTUM_NEAR)/2), 120, (FRUSTUM_FAR-FRUSTUM_NEAR), 0, iTextureManager);
// Defining a color key interval for the tree texture.
TUint8 MinColor[] = { 50, 0, 50 };
TUint8 MaxColor[] = { 255, 75, 255 };
// Pushing the textures into the loading queue.
_LIT(KSnowyTreeName, "snowy_tree.gif");
_LIT(KSnowyGroundName, "snowy_ground.jpg");
_LIT(KCloudName, "cloud.jpg");
iTextureManager->RequestToLoad(KSnowyTreeName, &iTreeTexture, MinColor, MaxColor );
iTextureManager->RequestToLoad(KSnowyGroundName, &iGroundTexture );
iTextureManager->RequestToLoad(KCloudName, &iCloudTexture );
//Start to load the textures.
iTextureManager->DoLoadL();
}
// -----------------------------------------------------------------------------
// CSnow::AppExit
// Application cleanup code.
// -----------------------------------------------------------------------------
//
void CSnow::AppExit( void )
{
delete iSnowfall;
delete iTextureManager;
}
// -----------------------------------------------------------------------------
// CSnow::DrawPlane
// Draws the ground plane.
// -----------------------------------------------------------------------------
//
void CSnow::DrawPlane()
{
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE );
glLoadIdentity();
T3DModel::MakeWorldViewMatrix(iCamera, TVector(0.0f, 0.0f, 0.0f));
glScalef( 1000, 0, 1000 );
glBindTexture( GL_TEXTURE_2D, iGroundTexture.iID );
glVertexPointer( 3, GL_BYTE, 0, planeVertices );
glTexCoordPointer( 2, GL_BYTE, 0, planeTextureCoords );
glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, planeTriangles );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -