⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils3d.cpp

📁 这是在s60第五版上用Open GL开发的软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{
	return iLookAt;
	}

// -----------------------------------------------------------------------------
// TCamerax::GetUp
// Get camera "up" vector.
// -----------------------------------------------------------------------------
//
TVectorx TCamerax::GetUp()
	{
	return iUp;
	}

// -----------------------------------------------------------------------------
// TCamerax::GetViewMatrix
// Get camera matrix representation (world -> camera transform).
// -----------------------------------------------------------------------------
//
GLfixed* TCamerax::GetViewMatrix()
	{
	return (GLfixed *)&iViewMatrix[0][0];
	};


// -----------------------------------------------------------------------------
// TCamerax::MakeIdentity
// Initializes the matrix aMatrix to identity matrix.
// -----------------------------------------------------------------------------
//
void TCamerax::MakeIdentity(GLfixed * aMatrix)
	{
    aMatrix[0 + 4 * 0] = INT_2_FIXED(1); aMatrix[0 + 4 * 1] = INT_2_FIXED(0);
	aMatrix[0 + 4 * 2] = INT_2_FIXED(0); aMatrix[0 + 4 * 3] = INT_2_FIXED(0);

	aMatrix[1 + 4 * 0] = INT_2_FIXED(0); aMatrix[1 + 4 * 1] = INT_2_FIXED(1);
	aMatrix[1 + 4 * 2] = INT_2_FIXED(0); aMatrix[1 + 4 * 3] = INT_2_FIXED(0);

	aMatrix[2 + 4 * 0] = INT_2_FIXED(0); aMatrix[2 + 4 * 1] = INT_2_FIXED(0);
	aMatrix[2 + 4 * 2] = INT_2_FIXED(1); aMatrix[2 + 4 * 3] = INT_2_FIXED(0);

	aMatrix[3 + 4 * 0] = INT_2_FIXED(0); aMatrix[3 + 4 * 1] = INT_2_FIXED(0);
	aMatrix[3 + 4 * 2] = INT_2_FIXED(0); aMatrix[3 + 4 * 3] = INT_2_FIXED(1);
	}

// =============================================================================
// CParticleEngine
// =============================================================================

// ============================= MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CParticleEngine::CParticleEngine
// C++ default constructor can NOT contain any code, that
// might leave.
// -----------------------------------------------------------------------------
//
CParticleEngine::CParticleEngine()
	{
	}


// -----------------------------------------------------------------------------
// CParticleEngine::ConstructL
// Symbian 2nd phase constructor can leave.
// Constructs a CParticleEngine object with aParticlesCount particles at
// position aPosition.
// -----------------------------------------------------------------------------
//
void CParticleEngine::ConstructL( TInt aParticlesCount, TVector aPosition)
	{
    iParticlesCount = aParticlesCount;
    iParticles = new (ELeave) TParticle[iParticlesCount];

	SetPosition( aPosition );
	}

// Destructor

CParticleEngine::~CParticleEngine()
	{
	delete[] iParticles;
	}

// -----------------------------------------------------------------------------
// CParticleEngine::ResetEngine
// Resets the particle engine
// -----------------------------------------------------------------------------
//
void CParticleEngine::ResetEngine()
	{
    for ( GLint i = 0; i < iParticlesCount; i++ )
		{
        ResetParticle(i);
		}
	}

// -----------------------------------------------------------------------------
// CParticleEngine::GetPosition
// Get the position of this particle engine
// -----------------------------------------------------------------------------
//
TVector CParticleEngine::GetPosition()
	{
	return iPosition;
	}

// -----------------------------------------------------------------------------
// CParticleEngine::GetParticleCount
// Get the number of particles in this effect.
// -----------------------------------------------------------------------------
//
GLint CParticleEngine::GetParticleCount()
	{
	return iParticlesCount;
	}

// -----------------------------------------------------------------------------
// CParticleEngine::SetPosition
// Set the position of this effect.
// -----------------------------------------------------------------------------
//
void CParticleEngine::SetPosition( TVector & aPosition )
	{
	iPosition = aPosition;
	}


// =============================================================================
// CLookUpTable
// =============================================================================

// -----------------------------------------------------------------------------
// CLookUpTable::CLookUpTable
// C++ default constructor can NOT contain any code, that
// might leave.
// -----------------------------------------------------------------------------
//
CLookUpTable::CLookUpTable()
	{
	}

// -----------------------------------------------------------------------------
// CLookUpTable::ConstructL
// Symbian 2nd phase constructor can leave.
// Computes the lookup-tables according to the flags input.
// -----------------------------------------------------------------------------
//
void CLookUpTable::ConstructL(TInt aFlags)
	{
	if ( aFlags & ESin )
		{
		ComputeSinTableL();
		}
	if ( aFlags & ECos )
		{
		ComputeCosTableL();
		}
	if ( aFlags & ETan )
		{
		ComputeTanTableL();
		}

	if ( aFlags & ESinx )
		{
		ComputeSinxTableL();
		}
	if ( aFlags & ECosx )
		{
		ComputeCosxTableL();
		}
	if ( aFlags & ETanx )
		{
		ComputeTanxTableL();
		}
	}

// -----------------------------------------------------------------------------
// CLookUpTable::NewL
// Two-phased constructor
// -----------------------------------------------------------------------------
//
CLookUpTable* CLookUpTable::NewL(TInt aFlags)
	{
	CLookUpTable* self = new (ELeave) CLookUpTable;
	CleanupStack::PushL( self );
	self->ConstructL(aFlags);
	CleanupStack::Pop();

	return self;
	}

// Destructor

CLookUpTable::~CLookUpTable()
	{
	delete[] iSinTable;
	delete[] iCosTable;
	delete[] iTanTable;

	delete[] iSinxTable;
	delete[] iCosxTable;
	delete[] iTanxTable;
	}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeSinTableL
// Precomputes the floating-point sine-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeSinTableL()
	{
	_LIT(KSinErr, "ComputeSinTableL()");
	iSinTable = new GLfloat[360];
	if ( iSinTable == NULL )
		{
		User::Panic( KSinErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal sin;
		TReal alpha = DEG_2_RAD( i );

		User::LeaveIfError( Math::Sin( sin, alpha ) );
		iSinTable[i] = (GLfloat) sin;
		}
	}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeCosTableL
// Precomputes the floating-point cosine-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeCosTableL()
	{
	_LIT(KCosErr, "ComputeCosTableL()");
	iCosTable = new GLfloat[360];
	if ( iCosTable == NULL )
		{
		User::Panic( KCosErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal cos;
		TReal alpha = DEG_2_RAD(i);

		User::LeaveIfError(Math::Cos(cos, alpha));
		iCosTable[i] = (GLfloat)cos;
		}
	}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeTanTableL
// Precomputes the floating-point tan-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeTanTableL()
	{
	_LIT(KTanErr, "ComputeTanTableL()");
	iTanTable = new GLfloat[360];
	if ( iTanTable == NULL )
		{
		User::Panic( KTanErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal tan;
		TReal alpha = DEG_2_RAD(i);

		User::LeaveIfError(Math::Tan(tan, alpha));
		iTanTable[i] = (GLfloat)tan;
		}
	}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeSinxTableL
// Precomputes the fixed-point sin-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeSinxTableL()
{
	_LIT(KSinErr, "ComputeSinxTableL()");
	iSinxTable = new GLfixed[360];
	if ( iSinxTable == NULL )
		{
		User::Panic( KSinErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal sin;
		TReal alpha = DEG_2_RAD(i);

		User::LeaveIfError(Math::Sin(sin, alpha));
		iSinxTable[i] = FLOAT_2_FIXED((GLfloat)sin);
		}
}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeCosxTableL
// Precomputes the fixed-point cos-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeCosxTableL()
{
	_LIT(KCosErr, "ComputeCosxTableL()");
	iCosxTable = new GLfixed[360];
	if ( iCosxTable == NULL )
		{
		User::Panic( KCosErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal cos;
		TReal alpha = DEG_2_RAD(i);

		User::LeaveIfError(Math::Cos(cos, alpha));
		iCosxTable[i] = FLOAT_2_FIXED((GLfloat)cos);
		}
}

// -----------------------------------------------------------------------------
// CLookUpTable::ComputeTanxTableLs
// Precomputes the fixed-point cos-table
// -----------------------------------------------------------------------------
//
void CLookUpTable::ComputeTanxTableL()
{
	_LIT(KTanErr, "ComputeTanxTableL()");
	iTanxTable = new GLfixed[360];
	if ( iTanxTable == NULL )
		{
		User::Panic( KTanErr, 0 );
		}

	for ( GLushort i = 0; i < 360; i++ )
		{
		TReal tan;
		TReal alpha = DEG_2_RAD(i);

		User::LeaveIfError(Math::Tan(tan, alpha));
		iTanxTable[i] = FLOAT_2_FIXED((GLfloat)tan);
		}
}

// -----------------------------------------------------------------------------
// CLookUpTable::Sin
// Fetch floating-point sin from the lookup-table
// -----------------------------------------------------------------------------
//
GLfloat CLookUpTable::Sin(GLushort aAngle)
	{
	return iSinTable[aAngle];
	}

// -----------------------------------------------------------------------------
// CLookUpTable::Cos
// Fetch floating-point cos from the lookup-table
// -----------------------------------------------------------------------------
//
GLfloat CLookUpTable::Cos(GLushort aAngle)
	{
	return iCosTable[aAngle];
	}

// -----------------------------------------------------------------------------
// CLookUpTable::Tan
// Fetch floating-point tan from the lookup-table
// -----------------------------------------------------------------------------
//
GLfloat CLookUpTable::Tan(GLushort aAngle)
	{
	return iTanTable[aAngle];
	}

// -----------------------------------------------------------------------------
// CLookUpTable::Sinx
// Fetch fixed-point sin from the lookup-table
// -----------------------------------------------------------------------------
//
GLfixed CLookUpTable::Sinx(GLfixed aAngle)
	{
    GLfixed v1 = iSinxTable[FIXED_2_INT(aAngle)];
    GLfixed v2 = iSinxTable[(FIXED_2_INT(aAngle) + 1) % 360];
    GLfixed c = aAngle & (FIXED_ONE - 1);
    return (v1 + fixedMul((v2 - v1), c));
	}

// -----------------------------------------------------------------------------
// CLookUpTable::Cosx
// Fetch fixed-point cos from the lookup-table
// -----------------------------------------------------------------------------
//
GLfixed CLookUpTable::Cosx(GLfixed aAngle)
	{
    GLfixed v1 = iCosxTable[FIXED_2_INT(aAngle)];
    GLfixed v2 = iCosxTable[(FIXED_2_INT(aAngle) + 1) % 360];
    GLfixed c = aAngle & (FIXED_ONE - 1);
    return (v1 + fixedMul((v2 - v1), c));
	}

// -----------------------------------------------------------------------------
// CLookUpTable::Tanx
// Fetch fixed-point tan from the lookup-table
// -----------------------------------------------------------------------------
//
GLfixed CLookUpTable::Tanx(GLfixed aAngle)
	{
	return iTanxTable[FIXED_2_INT(aAngle)];
	}

// =============================================================================
// =============================================================================
// Other miscallenous helper functions

// -----------------------------------------------------------------------------
// utilOutputText
// Outputs a text at a given position with a given color and font.
// -----------------------------------------------------------------------------
//
void utilOutputText(CWindowGc & aGc, const TDesC &aString,
	const TPoint &aPosition, const TRgb &aColor, const CFont *aFont )
	{
	aGc.SetPenColor(aColor);
	aGc.UseFont(aFont);
	aGc.DrawText(aString, aPosition);
	}

// -----------------------------------------------------------------------------
// utilOutputText
// Outputs a text at a given position with a given color using the
// CEikonEnv::Static()->SymbolFont() font.
// -----------------------------------------------------------------------------
//
void utilOutputText(CWindowGc & aGc, const TDesC &aString,
	const TPoint &aPosition, const TRgb &aColor )
	{
	utilOutputText(aGc, aString, aPosition, aColor, CEikonEnv::Static()->SymbolFont());
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -