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

📄 animeffect.cpp

📁 我的FTP一般保存在 CuteFTP 里面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	MATRIXF mtRes;

	mtRes.fM11 = fixedMul(m1.fM11,m2.fM11) + fixedMul(m1.fM12,m2.fM21);
	mtRes.fM12 = fixedMul(m1.fM11,m2.fM12) + fixedMul(m1.fM12,m2.fM22);
	mtRes.iM13 = 0;
	mtRes.fM21 = fixedMul(m1.fM21,m2.fM11) + fixedMul(m1.fM22,m2.fM21);
	mtRes.fM22 = fixedMul(m1.fM21,m2.fM12) + fixedMul(m1.fM22,m2.fM22);
	mtRes.iM23 = 0;
	mtRes.iM31 = fixedMul(m1.iM31,m2.fM11) + fixedMul(m1.iM32,m2.fM21) + m2.iM31;
	mtRes.iM32 = fixedMul(m1.iM31,m2.fM12) + fixedMul(m1.iM32,m2.fM22) + m2.iM32;
	mtRes.iM33 = 1;

	return mtRes;
}

MATRIXF	mix( const MATRIXF &matrix1, const MATRIXF &matrix2, FIXED fMix)
{
	MATRIXF mtRes;

	mtRes.fM11 = fixedMul(matrix1.fM11, fMix) + fixedMul(matrix2.fM11,fixed1-fMix);
	mtRes.fM12 = fixedMul(matrix1.fM12, fMix) + fixedMul(matrix2.fM12,fixed1-fMix);
	mtRes.iM13 = fixedMul(matrix1.iM13, fMix) + fixedMul(matrix2.iM13,fixed1-fMix);
	mtRes.fM21 = fixedMul(matrix1.fM21, fMix) + fixedMul(matrix2.fM21,fixed1-fMix);
	mtRes.fM22 = fixedMul(matrix1.fM22, fMix) + fixedMul(matrix2.fM22,fixed1-fMix);
	mtRes.iM23 = fixedMul(matrix1.iM23, fMix) + fixedMul(matrix2.iM23,fixed1-fMix);
	mtRes.iM31 = fixedMul(matrix1.iM31, fMix) + fixedMul(matrix2.iM31,fixed1-fMix);
	mtRes.iM32 = fixedMul(matrix1.iM32, fMix) + fixedMul(matrix2.iM32,fixed1-fMix);
	mtRes.iM33 = fixedMul(matrix1.iM33, fMix) + fixedMul(matrix2.iM33,fixed1-fMix);

	return mtRes;
}

POINT	mix( const POINT &point1, const POINT &point2, FIXED fMix)
{
	POINT ptRes;

	ptRes.x = fixedMul(point1.x,fMix) + fixedMul(point2.x,fixed1-fMix);
	ptRes.y = fixedMul(point1.y,fMix) + fixedMul(point2.y,fixed1-fMix);

	return ptRes;
}

MATRIXF offsetMatrix( int offsetX, int offsetY )
{
	MATRIXF mRes = matrix1;

	mRes.iM31 = offsetX;
	mRes.iM32 = offsetY;

	return mRes;
}

MATRIXF scaleMatrix( FIXED scaleX, FIXED scaleY, POINT ptOrg)
{
	MATRIXF mRes = matrix1;

	mRes.fM11 = scaleX;
	mRes.fM22 = scaleY;

	return offsetMatrix(-ptOrg.x,-ptOrg.y) * mRes * offsetMatrix(ptOrg.x,ptOrg.y);
}

MATRIXF rotateMatrix( FIXED angle, POINT ptOrg)
{
	MATRIXF mRes = matrix1;

	double dAngle = (angle / 65536.0) * 3.141592654 / 180.0;
	FIXED fCos = (FIXED)(65536.0 * cos( dAngle ));
	FIXED fSin = (FIXED)(65536.0 * sin( dAngle ));

	mRes.fM11 =  fCos;
	mRes.fM21 =  -fSin;
	mRes.fM12 =  fSin;
	mRes.fM22 =  fCos;

	return offsetMatrix(-ptOrg.x,-ptOrg.y) * mRes * offsetMatrix(ptOrg.x,ptOrg.y);
}

/////////////////////////////////////////////////////////
// Effects
/////////////////////////////////////////////////////////
BOOL	efSpinFrame( AnimData *pAnimData )
{
	if (pAnimData->animType == AnimDraw ||
		pAnimData->animType == AnimErase ) {
		POINT ptRect[4];

		ptRect[1].x = ptRect[0].x = pAnimData->ptRelRightTop.x;
		ptRect[1].y = -(ptRect[0].y = pAnimData->ptRelRightTop.y);

		MATRIXF matrix;
		FIXED	fxScale;
		fxScale = fixedDiv(pAnimData->iStep,pAnimData->iTotalSteps);

		matrix = scaleMatrix( fxScale, fxScale ) * 	rotateMatrix( 
			fixedDiv( pAnimData->iParameter * ( pAnimData->iStep - pAnimData->iTotalSteps ), pAnimData->iTotalSteps ) );

		ptRect[0] = ptRect[0] * matrix;
		ptRect[1] = ptRect[1] * matrix;
		ptRect[2] = pAnimData->ptCenter + ptRect[0];
		ptRect[3] = pAnimData->ptCenter + ptRect[1];
		ptRect[0] = pAnimData->ptCenter - ptRect[0];
		ptRect[1] = pAnimData->ptCenter - ptRect[1];

		drawPoly(pAnimData->hDC,ptRect,4);
	}

	return TRUE;
}

BOOL efVortexFrames( AnimData *pAnimData )
{
	switch ( pAnimData->animType ) {
		case AnimInit :
			*(MATRIXF*)pAnimData->bBuffer = rotateMatrix( fixed1 * 72 , pAnimData->ptCenter);
			break;
		case AnimDraw:
		case AnimErase: 
			{
				POINT ptBoxRel;

				ptBoxRel.x = pAnimData->ptRelRightTop.x * pAnimData->iStep / pAnimData->iTotalSteps;
				ptBoxRel.y = pAnimData->ptRelRightTop.y * pAnimData->iStep / pAnimData->iTotalSteps;

				MATRIXF matrix;
				FIXED	fxScale;

				fxScale = fixedDiv( (pAnimData->iTotalSteps - pAnimData->iStep) * 4,
					pAnimData->iTotalSteps * 3 );
				
				matrix = offsetMatrix( pAnimData->ptRelRightTop.x, pAnimData->ptRelRightTop.y ) *
					  scaleMatrix( fxScale, fxScale, pAnimData->ptCenter ) *
					  rotateMatrix( fixedDiv(pAnimData->iParameter * pAnimData->iStep, pAnimData->iTotalSteps) , pAnimData->ptCenter );

				POINT ptBoxCenter;
				ptBoxCenter = pAnimData->ptCenter * matrix;

				for( int iLoop = 0; iLoop < 5; iLoop++) {
					drawBox( pAnimData->hDC, ptBoxCenter, ptBoxRel );
					ptBoxCenter = ptBoxCenter * *(MATRIXF *)pAnimData->bBuffer;
				}

				break;
			}
	}

	return TRUE;
}

BOOL efScatterGatherFrames( AnimData *pAnimData )
{
	if ( pAnimData->animType == AnimDraw ||
		pAnimData->animType == AnimErase ) {
		int iDivisor = pAnimData->iParameter;
		POINT ptBoxRel;

		ptBoxRel.x = pAnimData->ptRelRightTop.x *  pAnimData->iStep / (pAnimData->iTotalSteps * iDivisor);
		ptBoxRel.y = pAnimData->ptRelRightTop.y *  pAnimData->iStep / (pAnimData->iTotalSteps * iDivisor);

		MATRIXF matrix;
		FIXED fxScale;

		fxScale = fixedDiv( pAnimData->iTotalSteps * 3 - pAnimData->iStep * 2, pAnimData->iTotalSteps );
		matrix = scaleMatrix( fxScale, fxScale ) * offsetMatrix( pAnimData->ptCenter.x, pAnimData->ptCenter.y );

		for(int iRow = 0; iRow < iDivisor; iRow++) {
			for( int iCol=0; iCol < iDivisor; iCol++) {
				POINT ptTileCenter;

				ptTileCenter.x = (iRow * 2 - iDivisor + 1) * pAnimData->ptRelRightTop.x / iDivisor;
				ptTileCenter.y = (iCol * 2 - iDivisor + 1) * pAnimData->ptRelRightTop.y / iDivisor;
				ptTileCenter = ptTileCenter * matrix;

				drawBox( pAnimData->hDC, ptTileCenter, ptBoxRel );
			}
		}
	}

	return TRUE;
}

BOOL efSpikeFrames( AnimData *pAnimData )
{
	struct SpikeData {
		POINT ptTriangleEnd[16][3], ptEndCenter[16], ptTriangleCenter[16];
		MATRIXF matrixCircle[16];
	};

	switch (pAnimData->animType) {
	case AnimInit: {
		int xLeft	= pAnimData->rcWnd.left;
		int xRight	= pAnimData->rcWnd.right;
		int yTop	= pAnimData->rcWnd.bottom;
		int yBottom = pAnimData->rcWnd.top;

		POINT *pTriangle = ((SpikeData*)pAnimData->bBuffer)->ptTriangleEnd[0],
			  *pCenter	 = ((SpikeData*)pAnimData->bBuffer)->ptEndCenter;
		
		for( int iNdx = 0; iNdx < 16; iNdx++, pTriangle +=3, pCenter++) {
			pTriangle[0] = pAnimData->ptCenter;

			if (iNdx < 4) {
				pTriangle[1].y = pTriangle[2].y = yTop;
				pTriangle[1].x = (xLeft * (4 - iNdx) + xRight * iNdx) / 4;
				pTriangle[2].x = (xLeft * (3 - iNdx) + xRight * (iNdx+1)) / 4;
			} else if (iNdx < 8) {
				pTriangle[1].x = pTriangle[2].x = xRight;
				pTriangle[1].y = (yTop * (8 - iNdx) + yBottom * (iNdx-4)) / 4;
				pTriangle[2].y = (yTop * (7 - iNdx) + yBottom * (iNdx-3)) / 4;
			} else if (iNdx < 12) {
				pTriangle[1].y = pTriangle[2].y = yBottom;
				pTriangle[1].x = (xRight * (12 - iNdx) + xLeft * (iNdx-8)) / 4;
				pTriangle[2].x = (xRight * (11 - iNdx) + xLeft * (iNdx-7)) / 4;
			} else {
				pTriangle[1].x = pTriangle[2].x = xLeft;
				pTriangle[1].y = (yBottom * (16 - iNdx) + yTop * (iNdx-12)) / 4;
				pTriangle[2].y = (yBottom * (15 - iNdx) + yTop * (iNdx-11)) / 4;
			}

			pCenter->x = (pTriangle[0].x + pTriangle[1].x + pTriangle[2].x) / 3;
			pCenter->y = (pTriangle[0].y + pTriangle[1].y + pTriangle[2].y) / 3;
		}

		pCenter = ((SpikeData*)pAnimData->bBuffer)->ptTriangleCenter;
		POINT ptTrgCenter;

		ptTrgCenter.x = pAnimData->ptCenter.x;
		ptTrgCenter.y = pAnimData->ptCenter.y + (pAnimData->ptRelRightTop.x + pAnimData->ptRelRightTop.y) * 4/5;

		for( iNdx =0;iNdx < 16; iNdx++ ) {
			MATRIXF matrix;

			matrix = rotateMatrix( (33 * fixed1) + (-22 * fixed1) * iNdx, pAnimData->ptCenter );
			pCenter[iNdx] = ptTrgCenter * matrix;

			POINT ptTemp = pCenter[iNdx] - ((SpikeData*)pAnimData->bBuffer)->ptEndCenter[iNdx];
			((SpikeData*)pAnimData->bBuffer)->matrixCircle[iNdx] = offsetMatrix( ptTemp.x, ptTemp.y );
		}

		break;
	}
	case AnimDraw:
	case AnimErase: {
		POINT ptTriangle[3];
		FIXED fixedFactor;

		MATRIXF matrix;
		FIXED fxScale;
		fxScale = fixedDiv(pAnimData->iStep, pAnimData->iTotalSteps);

		if (pAnimData->iStep < pAnimData->iTotalSteps / 2) {
			fixedFactor = (fixed1 - fixedDiv(pAnimData->iStep*2, pAnimData->iTotalSteps)) *
				pAnimData->iParameter;

			for( int iNdx=0;iNdx < 16; iNdx++ ) {
				matrix = scaleMatrix( fxScale, fxScale, ((SpikeData*)pAnimData->bBuffer)->ptEndCenter[iNdx] ) *
					rotateMatrix( fixedFactor, ((SpikeData*)pAnimData->bBuffer)->ptEndCenter[iNdx] );
				matrix = matrix * ((SpikeData*)pAnimData->bBuffer)->matrixCircle[iNdx];

				for(int iAngle=0;iAngle < 3;iAngle++) {
					ptTriangle[iAngle] = 
						((SpikeData*)pAnimData->bBuffer)->ptTriangleEnd[iNdx][iAngle] * matrix;
				}

				drawPoly( pAnimData->hDC, ptTriangle, 3 );
			}
		} else {
			fixedFactor = fixedDiv(pAnimData->iStep*2 - pAnimData->iTotalSteps, pAnimData->iTotalSteps);

			for( int iNdx=0; iNdx < 16; iNdx++) {
				matrix = scaleMatrix( fxScale, fxScale, ((SpikeData*)pAnimData->bBuffer)->ptEndCenter[iNdx]);
				matrix *= mix( matrix1, ((SpikeData*)pAnimData->bBuffer)->matrixCircle[iNdx], fixedFactor );

				for( int iAngle=0; iAngle < 3; iAngle++ ) {
					ptTriangle[iAngle] = 
						((SpikeData*)pAnimData->bBuffer)->ptTriangleEnd[iNdx][iAngle] * matrix;
				}

				drawPoly(pAnimData->hDC, ptTriangle, 3 );
			}
		}


		break;
	}
	}

	return TRUE;
}

BOOL efFireworxFrames( AnimData *pAnimData )
{
	const int NRECT = 10;
	struct FWData {
		POINT ptCenter[NRECT];
	};

	switch ( pAnimData->animType ) {
	case AnimInit: {
		POINT *ptCenter = ((FWData*)pAnimData->bBuffer)->ptCenter;
		POINT ptRectCenter;
		
		ptRectCenter.x = pAnimData->ptCenter.x;
		ptRectCenter.y = pAnimData->ptCenter.y + (pAnimData->ptRelRightTop.x + pAnimData->ptRelRightTop.y) * 5/3;

		for(int iNdx=0;iNdx < NRECT;iNdx++) {
			MATRIXF matrix = rotateMatrix( iNdx * (360 * fixed1 / NRECT), pAnimData->ptCenter );

			ptCenter[iNdx] = ptRectCenter * matrix;
			
		}
		break;
	}
	case AnimDraw:
	case AnimErase: {
		POINT ptTemp;
		FIXED fixedFactor = fixedDiv( pAnimData->iStep, pAnimData->iTotalSteps );

		MATRIXF matrix;
		POINT ptRect[4], ptTmp[4];
		ptRect[0].x = ptRect[3].x = -pAnimData->ptRelRightTop.x;
		ptRect[1].x = ptRect[2].x = pAnimData->ptRelRightTop.x;
		ptRect[0].y = ptRect[1].y = pAnimData->ptRelRightTop.y;
		ptRect[2].y = ptRect[3].y = -pAnimData->ptRelRightTop.y;

		for(int iNdx=0; iNdx < NRECT; iNdx++) {
			matrix = scaleMatrix( fixedFactor, fixedFactor ) *
				rotateMatrix( (fixed1-fixedFactor)*pAnimData->iParameter);

			ptTemp = mix(pAnimData->ptCenter, ((FWData*)pAnimData->bBuffer)->ptCenter[iNdx], fixedFactor);
			matrix = matrix * offsetMatrix( ptTemp.x, ptTemp.y );

			for(int iAngle=0; iAngle < 4; iAngle++) 
				ptTmp[iAngle] = ptRect[iAngle] * matrix;
			
			drawPoly( pAnimData->hDC, ptTmp, 4 );
		}

		break;
	}
	}

	return TRUE;
}

/////////////////////////////////////////////////////////
// Primitives
/////////////////////////////////////////////////////////

void drawBox( HDC hDC, POINT &ptCenter, POINT &ptRelRightTop )
{
	if (ptRelRightTop.x == 0 && ptRelRightTop.y == 0) return;

	POINT ptTemp[4];

	ptTemp[0].x = ptCenter.x - ptRelRightTop.x;
	ptTemp[0].y = ptCenter.y + ptRelRightTop.y;
	ptTemp[1].x = ptCenter.x + ptRelRightTop.x;
	ptTemp[1].y = ptCenter.y + ptRelRightTop.y;
	ptTemp[2].x = ptCenter.x + ptRelRightTop.x;
	ptTemp[2].y = ptCenter.y - ptRelRightTop.y;
	ptTemp[3].x = ptCenter.x - ptRelRightTop.x;
	ptTemp[3].y = ptCenter.y - ptRelRightTop.y;

	MoveToEx( hDC, ptTemp[3].x, ptTemp[3].y , NULL );
	PolylineTo( hDC, ptTemp, 4 );
}

void drawPoly( HDC hDC, POINT *pPts, DWORD dwPoints )
{
	if (pPts == NULL || dwPoints == 0) return;

	if (pPts[dwPoints-1].x == pPts[0].x &&
		pPts[dwPoints-1].y == pPts[0].y ) return;
	MoveToEx(hDC, pPts[dwPoints-1].x,pPts[dwPoints-1].y,NULL);
	PolylineTo( hDC, pPts, dwPoints );
}

⌨️ 快捷键说明

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