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

📄 c3_shape.cpp

📁 网络游戏魔域的服务端与客户端完整源代码 包括详细的说明文档与开发日志
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		mm = lpShape->lpMotion->lpFrames[lpShape->lpMotion->nFrame];
	else
		D3DXMatrixMultiply ( &mm,
							 &lpShape->lpMotion->lpFrames[lpShape->lpMotion->nFrame],
							 &lpShape->lpMotion->matrix );

	D3DXVECTOR3 vec[2];
	D3DXVec3TransformCoord ( &vec[0],
							 ( D3DXVECTOR3* )&lpShape->lpLine[0].lpVB[0],
							 &mm );
	D3DXVec3TransformCoord ( &vec[1],
							 ( D3DXVECTOR3* )&lpShape->lpLine[0].lpVB[1],
							 &mm );

	
	if ( !lpShape->bFrist )
	{
		// 计算长度
		D3DXVECTOR3 sub;
		D3DXVec3Subtract ( &sub, &vec[0], &vec[1] );
		float len = D3DXVec3Length ( &sub );

		D3DXVECTOR3 last[2];

		last[0] = lpShape->last[0];
		last[1] = lpShape->last[1];

		// 计算插值的点
		for ( DWORD nn = 0; nn < lpShape->dwSmooth; nn++ )
		{
			D3DXVECTOR3 smooths[2];

			D3DXVec3Lerp ( &smooths[0],
						   &lpShape->last[0],
						   &vec[0],
						   1.0f / ( lpShape->dwSmooth + 1 ) * ( nn + 1 ) );
			D3DXVec3Lerp ( &smooths[1],
						   &lpShape->last[1],
						   &vec[1],
						   1.0f / ( lpShape->dwSmooth + 1 ) * ( nn + 1 ) );

			// 计算长度
			D3DXVec3Subtract ( &sub,
							   &smooths[0],
							   &smooths[1] );

			float lennow = D3DXVec3Length ( &sub );

			D3DXVec3Lerp ( &smooths[0],
						   &smooths[1],
						   &smooths[0],
						   len / lennow );

			D3DXVec3Subtract ( &sub,
							   &smooths[0],
							   &smooths[1] );

			lennow = D3DXVec3Length ( &sub );

			// 算刀光
			int cur = lpShape->dwSegmentCur * 6;

			lpShape->vb[cur + 0].x = smooths[0].x;
			lpShape->vb[cur + 0].y = smooths[0].y;
			lpShape->vb[cur + 0].z = smooths[0].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 0].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 0].u = 0;
			lpShape->vb[cur + 0].v = 0;

			lpShape->vb[cur + 1].x = smooths[1].x;
			lpShape->vb[cur + 1].y = smooths[1].y;
			lpShape->vb[cur + 1].z = smooths[1].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 1].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 1].u = 0;
			lpShape->vb[cur + 1].v = 0;

			lpShape->vb[cur + 2].x = last[1].x;
			lpShape->vb[cur + 2].y = last[1].y;
			lpShape->vb[cur + 2].z = last[1].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 2].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 2].u = 0;
			lpShape->vb[cur + 2].v = 0;


			lpShape->vb[cur + 3].x = last[0].x;
			lpShape->vb[cur + 3].y = last[0].y;
			lpShape->vb[cur + 3].z = last[0].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 3].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 3].u = 0;
			lpShape->vb[cur + 3].v = 0;

			lpShape->vb[cur + 4].x = last[1].x;
			lpShape->vb[cur + 4].y = last[1].y;
			lpShape->vb[cur + 4].z = last[1].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 4].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 4].u = 0;
			lpShape->vb[cur + 4].v = 0;

			lpShape->vb[cur + 5].x = smooths[0].x;
			lpShape->vb[cur + 5].y = smooths[0].y;
			lpShape->vb[cur + 5].z = smooths[0].z;
			lpShape->vb[lpShape->dwSegmentCur * 6 + 5].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
			lpShape->vb[cur + 5].u = 0;
			lpShape->vb[cur + 5].v = 0;

		
			// alpha
	/*		DWORD add = lpShape->dwSegment;
			float uvstep = 0.9f / add;
		
			for ( int n = lpShape->dwSegmentCur; n >= 0; n-- )
			{
				float u = add * uvstep + 0.05f;

				lpShape->vb[n * 6 + 0].u = u;
				lpShape->vb[n * 6 + 0].v = 0;

				lpShape->vb[n * 6 + 1].u = u;
				lpShape->vb[n * 6 + 1].v = 1;

				lpShape->vb[n * 6 + 5].u = u;
				lpShape->vb[n * 6 + 5].v = 0;

				u -= uvstep;

				lpShape->vb[n * 6 + 2].u = u;
				lpShape->vb[n * 6 + 2].v = 1;

				lpShape->vb[n * 6 + 3].u = u;
				lpShape->vb[n * 6 + 3].v = 0;

				lpShape->vb[n * 6 + 4].u = u;
				lpShape->vb[n * 6 + 4].v = 1;

				add--;
			}
			for ( n = lpShape->dwSegment - 1; n > ( int )lpShape->dwSegmentCur; n-- )
			{
				float u = add * uvstep + 0.05f;

				lpShape->vb[n * 6 + 0].u = u;
				lpShape->vb[n * 6 + 0].v = 0;

				lpShape->vb[n * 6 + 1].u = u;
				lpShape->vb[n * 6 + 1].v = 1;

				lpShape->vb[n * 6 + 5].u = u;
				lpShape->vb[n * 6 + 5].v = 0;

				u -= uvstep;

				lpShape->vb[n * 6 + 2].u = u;
				lpShape->vb[n * 6 + 2].v = 1;

				lpShape->vb[n * 6 + 3].u = u;
				lpShape->vb[n * 6 + 3].v = 0;

				lpShape->vb[n * 6 + 4].u = u;
				lpShape->vb[n * 6 + 4].v = 1;

				add--;
			}*/
			/*if ( lpShape->nTex == -1 )
			{
				if ( FAILED ( g_D3DDevice->SetTexture ( 0, 0 ) ) )
					return false;
			}
			else
			{
				if ( FAILED ( g_D3DDevice->SetTexture ( 0, g_lpTex[lpShape->nTex]->lpTex ) ) )
					return false;
			}


			D3DXMatrixIdentity ( &mm );
			g_D3DDevice->SetTransform ( D3DTS_WORLD, &mm );

			if ( FAILED ( g_D3DDevice->SetVertexShader ( SHAPE_OUT_VERTEX ) ) )
				return false;

			if ( FAILED ( g_D3DDevice->DrawPrimitiveUP ( D3DPT_TRIANGLELIST,
														 lpShape->dwSegment * 2,
														 lpShape->vb,
														 sizeof ( ShapeOutVertex ) ) ) )
				return false;
*/
			lpShape->dwSegmentCur++;
			if ( lpShape->dwSegmentCur == lpShape->dwSegment )
				lpShape->dwSegmentCur = 0;

			last[0] = smooths[0];
			last[1] = smooths[1];
			
			if ( nn == lpShape->dwSmooth - 1 )
			{
				lpShape->last[0] = smooths[0];
				lpShape->last[1] = smooths[1];
			}
		}
		int cur = lpShape->dwSegmentCur * 6;

		lpShape->vb[cur + 0].x = vec[0].x;
		lpShape->vb[cur + 0].y = vec[0].y;
		lpShape->vb[cur + 0].z = vec[0].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 0].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 0].u = 0;
		lpShape->vb[cur + 0].v = 0;

		lpShape->vb[cur + 1].x = vec[1].x;
		lpShape->vb[cur + 1].y = vec[1].y;
		lpShape->vb[cur + 1].z = vec[1].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 1].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 1].u = 0;
		lpShape->vb[cur + 1].v = 0;

		lpShape->vb[cur + 2].x = lpShape->last[1].x;
		lpShape->vb[cur + 2].y = lpShape->last[1].y;
		lpShape->vb[cur + 2].z = lpShape->last[1].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 2].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 2].u = 0;
		lpShape->vb[cur + 2].v = 0;


		lpShape->vb[cur + 3].x = lpShape->last[0].x;
		lpShape->vb[cur + 3].y = lpShape->last[0].y;
		lpShape->vb[cur + 3].z = lpShape->last[0].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 3].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 3].u = 0;
		lpShape->vb[cur + 3].v = 0;

		lpShape->vb[cur + 4].x = lpShape->last[1].x;
		lpShape->vb[cur + 4].y = lpShape->last[1].y;
		lpShape->vb[cur + 4].z = lpShape->last[1].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 4].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 4].u = 0;
		lpShape->vb[cur + 4].v = 0;

		lpShape->vb[cur + 5].x = vec[0].x;
		lpShape->vb[cur + 5].y = vec[0].y;
		lpShape->vb[cur + 5].z = vec[0].z;
		lpShape->vb[lpShape->dwSegmentCur * 6 + 5].color = D3DCOLOR_ARGB ( 255, 255, 255, 255 );
		lpShape->vb[cur + 5].u = 0;
		lpShape->vb[cur + 5].v = 0;

	
		// alpha
		DWORD add = lpShape->dwSegment;
		float uvstep = 0.9f / add;
		
		for ( int n = lpShape->dwSegmentCur; n >= 0; n-- )
		{
			float u = add * uvstep + 0.05f;

			lpShape->vb[n * 6 + 0].u = u;
			lpShape->vb[n * 6 + 0].v = 0;

			lpShape->vb[n * 6 + 1].u = u;
			lpShape->vb[n * 6 + 1].v = 1;

			lpShape->vb[n * 6 + 5].u = u;
			lpShape->vb[n * 6 + 5].v = 0;

			u -= uvstep;

			lpShape->vb[n * 6 + 2].u = u;
			lpShape->vb[n * 6 + 2].v = 1;

			lpShape->vb[n * 6 + 3].u = u;
			lpShape->vb[n * 6 + 3].v = 0;

			lpShape->vb[n * 6 + 4].u = u;
			lpShape->vb[n * 6 + 4].v = 1;

			add--;
		}
		for ( n = lpShape->dwSegment - 1; n > ( int )lpShape->dwSegmentCur; n-- )
		{
			float u = add * uvstep + 0.05f;

			lpShape->vb[n * 6 + 0].u = u;
			lpShape->vb[n * 6 + 0].v = 0;

			lpShape->vb[n * 6 + 1].u = u;
			lpShape->vb[n * 6 + 1].v = 1;

			lpShape->vb[n * 6 + 5].u = u;
			lpShape->vb[n * 6 + 5].v = 0;

			u -= uvstep;

			lpShape->vb[n * 6 + 2].u = u;
			lpShape->vb[n * 6 + 2].v = 1;

			lpShape->vb[n * 6 + 3].u = u;
			lpShape->vb[n * 6 + 3].v = 0;

			lpShape->vb[n * 6 + 4].u = u;
			lpShape->vb[n * 6 + 4].v = 1;

			add--;
		}

		lpShape->dwSegmentCur++;
		if ( lpShape->dwSegmentCur == lpShape->dwSegment )
			lpShape->dwSegmentCur = 0;

		if ( lpShape->nTex == -1 )
		{
			if ( FAILED ( g_D3DDevice->SetTexture ( 0, 0 ) ) )
				return false;
		}
		else
		{
			if ( FAILED ( g_D3DDevice->SetTexture ( 0, g_lpTex[lpShape->nTex]->lpTex ) ) )
				return false;
		}


		if ( bLocal )
			mm = lpShape->lpMotion->matrix;
		else
			D3DXMatrixIdentity ( &mm );

		g_D3DDevice->SetTransform ( D3DTS_WORLD, &mm );

		if ( FAILED ( g_D3DDevice->SetVertexShader ( SHAPE_OUT_VERTEX ) ) )
			return false;

		if ( FAILED ( g_D3DDevice->DrawPrimitiveUP ( D3DPT_TRIANGLELIST,
													 lpShape->dwSegment * 2,
													 lpShape->vb,
													 sizeof ( ShapeOutVertex ) ) ) )
			return false;
	}
	else
	{
		ZeroMemory ( lpShape->vb, sizeof ( ShapeOutVertex ) * lpShape->dwSegment * 6 );
		lpShape->bFrist = false;
	}

	lpShape->last[0] = vec[0];
	lpShape->last[1] = vec[1];

	return true;
}
C3_CORE_DLL_API
void Shape_Prepare ( void )
{
	SetRenderState ( D3DRS_ZENABLE, true );
	SetRenderState ( D3DRS_ZWRITEENABLE, false );
	SetRenderState ( D3DRS_SHADEMODE, D3DSHADE_FLAT );
	SetRenderState ( D3DRS_DITHERENABLE, true );
	SetRenderState ( D3DRS_CULLMODE, D3DCULL_NONE );
	SetRenderState ( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1 );
	SetRenderState ( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1 );

	SetRenderState ( D3DRS_ALPHABLENDENABLE, true );
	SetRenderState ( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	SetRenderState ( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );

	SetTextureStageState ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	SetTextureStageState ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
	SetTextureStageState ( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

	SetTextureStageState ( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	SetTextureStageState ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	SetTextureStageState ( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

⌨️ 快捷键说明

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