billboardex.cpp

来自「国外网游源码....除工具源码缺少之外,其余程序都全...至于,什么游戏,因为国」· C++ 代码 · 共 430 行

CPP
430
字号
// BillboardEx.cpp: implementation of the CBillboardEx class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BillboardEx.h"

#include "AnimFrame.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

TCHAR* g_strTextures[] =
{
	_T(".\\data\\Game\\Effect\\Frame01.dds"),
	_T(".\\data\\Game\\Effect\\Frame02.dds"),
	_T(".\\data\\Game\\Effect\\Frame03.dds"),
	_T(".\\data\\Game\\Effect\\Frame04.dds"),
	_T(".\\data\\Game\\Effect\\Frame05.dds"),
	_T(".\\data\\Game\\Effect\\Frame06.dds"),
	_T(".\\data\\Game\\Effect\\Frame07.dds"),
	_T(".\\data\\Game\\Effect\\Frame08.dds")
};

CEffectScrapEx::CEffectScrapEx()
{
	m_nAniCount = 0;
	m_nTexCount = 0;

	m_vbBillboard = NULL;
	m_pTexBillboard = NULL;
}

CEffectScrapEx::~CEffectScrapEx()
{
	InvalidateDeviceObjects();
	SAFE_DELETE_ARRAY(m_pTexBillboard)
}

HRESULT CEffectScrapEx::LoadTexture(const char *strTextureFilename)
{
	HRESULT hr = S_OK;
/*
	m_pTexBillboard = new LPDIRECT3DTEXTURE9[m_nTexCount];

	for( DWORD i=0; i<m_nTexCount; i++ )
	{
		// Create the texture using D3DX
		if( FAILED( hr = D3DXCreateTextureFromFileEx( g_pApp->GetD3dDevice(), g_strTextures[i],
						D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, 
						MEMORY_POOL, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 
						D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 0, NULL, NULL, &m_pTexBillboard[i] ) ) )
			return hr;
	}
	*/
	return S_OK;
}

HRESULT CEffectScrapEx::Create()
{
	
//	if(FAILED( g_pApp->GetD3dDevice()->CreateVertexBuffer( 4*sizeof(VERTEX_BILLBOARD),
//									D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
//									D3DFVF_BILLBOARD,D3DPOOL_DEFAULT, &m_vbBillboard, NULL) ))
	/*
	if(FAILED( g_pApp->GetD3dDevice()->CreateVertexBuffer( 4*sizeof(VERTEX_BILLBOARD),
									D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
									D3DFVF_BILLBOARD,D3DPOOL_DEFAULT, &m_vbBillboard, NULL) ))
	{
		OutputDebugString("[角菩] CMD3Mesh::CreateVertexBuffer");
		return E_FAIL;
	}
*/
	// 技泼 窍技..
	m_fLifeTime = 2.0f;
	m_fDelayTime = 0.05f;
	m_nCurTexIndex = 0;

//	static struct { float x,y,z;DWORD dwColor; float u,v; } s_Verts[] =
//	{
//		{ -0.1f,0.0f,0.0f,0xFFFFFFFF,0.0f,1.0f},
//		{ -0.1f,0.4f,0.0f,0xFFFFFFFF,0.0f,0.0f},
//		{  0.1f,0.0f,0.0f,0xFFFFFFFF,1.0f,1.0f},
//		{  0.1f,0.4f,0.0f,0xFFFFFFFF,1.0f,0.0f},
//	};

//	static struct { float x,y,z;DWORD dwColor; float u,v; } s_Verts[] =
//	{
//		{ -0.1f,-0.1f,0.0f,0xFFFFFFFF,0.0f,1.0f},
//		{ -0.1f,0.1f,0.0f,0xFFFFFFFF,0.0f,0.0f},
//		{  0.1f,-0.1f,0.0f,0xFFFFFFFF,1.0f,1.0f},
//		{  0.1f,0.1f,0.0f,0xFFFFFFFF,1.0f,0.0f},
//	};
/*
	static struct { float x,y,z;DWORD dwColor; float u,v; } s_Verts[] =
	{
		{ -1.0f,-1.0f,0.0f,0xFFFFFFFF,0.0f,1.0f},
		{ -1.0f,1.0f,0.0f,0xFFFFFFFF,0.0f,0.0f},
		{  1.0f,-1.0f,0.0f,0xFFFFFFFF,1.0f,1.0f},
		{  1.0f,1.0f,0.0f,0xFFFFFFFF,1.0f,0.0f},
	};

	VERTEX_BILLBOARD Billvertex[4];
	for(int i=0;i<4;i++)
	{
		Billvertex[i].p = D3DXVECTOR3(s_Verts[i].x,s_Verts[i].y,s_Verts[i].z);
		Billvertex[i].color = s_Verts[i].dwColor;
		Billvertex[i].tu = s_Verts[i].u;
		Billvertex[i].tv = s_Verts[i].v;
	}

	VERTEX_BILLBOARD *pVertex=NULL;
	if( FAILED( m_vbBillboard->Lock(0,0, (void **)&pVertex, 0 ) ))
		return E_FAIL;

	memcpy( pVertex, Billvertex, 4*sizeof(VERTEX_BILLBOARD) );
	
	if( FAILED( m_vbBillboard->Unlock() ) )
		return E_FAIL;
*/
	return S_OK;
}

HRESULT CEffectScrapEx::RestoreDeviceObjects()
{
	/*
	for( DWORD i=0; i<m_nTexCount; i++ )
	{
		// Create the texture using D3DX
		if( FAILED( D3DXCreateTextureFromFileEx( g_pApp->GetD3dDevice(), g_strTextures[i],
					D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, 
					MEMORY_POOL, D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 
					D3DX_FILTER_TRIANGLE|D3DX_FILTER_MIRROR, 0, NULL, NULL, &m_pTexBillboard[i] ) ) )
			return E_FAIL;
	}

	if(FAILED( g_pApp->GetD3dDevice()->CreateVertexBuffer( 4*sizeof(VERTEX_BILLBOARD),
									D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
									D3DFVF_BILLBOARD,D3DPOOL_DEFAULT, &m_vbBillboard, NULL) ))
	{
		OutputDebugString("[角菩] CMD3Mesh::CreateVertexBuffer");
		return E_FAIL;
	}

	static struct { float x,y,z;DWORD dwColor; float u,v; } s_Verts[] =
	{
		{ -0.1f,0.0f,0.0f,0xFFFFFFFF,0.0f,1.0f},
		{ -0.1f,0.4f,0.0f,0xFFFFFFFF,0.0f,0.0f},
		{  0.1f,0.0f,0.0f,0xFFFFFFFF,1.0f,1.0f},
		{  0.1f,0.4f,0.0f,0xFFFFFFFF,1.0f,0.0f},
	};

	VERTEX_BILLBOARD Billvertex[4];
	for( i=0;i<4;i++)
	{
		Billvertex[i].p = D3DXVECTOR3(s_Verts[i].x,s_Verts[i].y,s_Verts[i].z);
		Billvertex[i].color = s_Verts[i].dwColor;
		Billvertex[i].tu = s_Verts[i].u;
		Billvertex[i].tv = s_Verts[i].v;
	}

	VERTEX_BILLBOARD *pVertex=NULL;
	if( FAILED( m_vbBillboard->Lock(0,0, (void **)&pVertex, 0 ) ))
		return E_FAIL;

	memcpy( pVertex, Billvertex, 4*sizeof(VERTEX_BILLBOARD) );
	
	if( FAILED( m_vbBillboard->Unlock() ) )
		return E_FAIL;
*/
	return S_OK;
}

void CEffectScrapEx::InvalidateDeviceObjects()
{
	if(m_pTexBillboard)
	{
		for( DWORD i=0; i<m_nTexCount; i++ )
			SAFE_RELEASE( m_pTexBillboard[i] );
	}
	
	SAFE_RELEASE( m_vbBillboard );
}

HRESULT CEffectScrapEx::Update( float fElapsedTime )
{
	m_fLifeTime -= fElapsedTime;
	m_fDelayTime -= fElapsedTime;
	if( m_fDelayTime <= 0.0f){
		m_nCurTexIndex++;
		m_fDelayTime = 0.05f;
	}
	if(m_nCurTexIndex >= m_nTexCount)
		m_nCurTexIndex = 0;

	if(m_fLifeTime <= 0.0f){		// 角犁风绰 磷咯具.. 搭铂..?		// 困摹唱 葛 备繁巴代.. 贸府..
		m_fLifeTime = 2.0f;
		//m_fCurrentSize = m_fEmitterSize;
		return E_FAIL;
	}

	return S_OK;
}

HRESULT CEffectScrapEx::Render()
{
	/*
	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity( &matWorld );
	g_pApp->GetD3dDevice()->SetTransform( D3DTS_WORLD, &matWorld );
	
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHAREF,        0x08 );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
	
	// Loop through and render all trees
	g_pApp->GetD3dDevice()->SetStreamSource( 0, m_vbBillboard, 0, sizeof(VERTEX_BILLBOARD) );
	g_pApp->GetD3dDevice()->SetFVF( D3DFVF_BILLBOARD );

	g_pApp->GetD3dDevice()->SetTexture( 0, m_pTexBillboard[m_nCurTexIndex] );

	D3DXMATRIX mBillboard = g_pCamera->GetBillboardMatrix();
	mBillboard._41 = m_vPos.x;
	mBillboard._42 = m_vPos.y;
	mBillboard._43 = m_vPos.z;

	g_pApp->GetD3dDevice()->SetTransform( D3DTS_WORLD, &mBillboard );
	g_pApp->GetD3dDevice()->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
*/
	return S_OK;
}

//////////////////////////////////////////////////////////////////////////
//	Fire Nomal
//////////////////////////////////////////////////////////////////////////
/*
CEffectFireNomal::CEffectFireNomal()
{
	m_pAniMation = NULL;
	m_sprMuzzleFlare = NULL;
}

CEffectFireNomal::~CEffectFireNomal()
{
	InvalidateDeviceObjects();
//	SAFE_DELETE(m_pAniMation);
//	SAFE_DELETE(m_sprMuzzleFlare);
	//SAFE_DELETE(m_Timer);
}

HRESULT CEffectFireNomal::LoadTexture(const char *strTextureFilename)
{
	return S_OK;
}

HRESULT CEffectFireNomal::Create()
{
	if(!m_pAniMation)
	{
		m_pAniMation = new CAnimSequence;
		m_pAniMation->Create();
		if(!m_pAniMation->AddFrame(".\\data\\Game\\Effect\\GunFlare.dds", 0.025f))
			return E_FAIL;
		m_sprMuzzleFlare = new CSpriteEx;
		m_sprMuzzleFlare->SetAnim(m_pAniMation);
	}

	// 技泼 窍技..
	m_fLifeTime = 2.0f;
	m_fDelayTime = 0.05f;
	m_nCurTexIndex = 0;

	m_vPos = D3DXVECTOR3(0.0f,0.0f,0.0f);

	if(!m_Timer)
		m_Timer = new CMCGTimer;
	m_Timer->Start();
	m_sprMuzzleFlare->Timer().Begin();

//	m_sprMuzzleFlare->SetSize(RandomNumber(0.1f, 0.3f));
	m_sprMuzzleFlare->SetSize(RandomNumber(1.0f, 3.0f));
	m_sprMuzzleFlare->SetRotationRoll(RandomNumber(0.0f, 2.0f*(float)D3DX_PI));

	return S_OK;
}

HRESULT CEffectFireNomal::RestoreDeviceObjects()
{
	if(!m_pAniMation)
	{
		m_pAniMation = new CAnimSequence;
		m_pAniMation->Create();
		if(!m_pAniMation->AddFrame(".\\data\\Game\\Effect\\GunFlare.dds", 0.025f))
			return E_FAIL;
		m_sprMuzzleFlare = new CSpriteEx;
		m_sprMuzzleFlare->SetAnim(m_pAniMation);
	}

	return S_OK;
}

void CEffectFireNomal::InvalidateDeviceObjects()
{
	SAFE_DELETE(m_pAniMation);
	//SAFE_DELETE(m_sprMuzzleFlare);
}

HRESULT CEffectFireNomal::Update( float fElapsedTime )
{
//	CMCGTimer::UpdateAll(fElapsedTime);
	//float fTime = m_Timer->GetTime();
	if ( m_Timer->GetTime() > 0.05f ) {
		m_Timer->Stop();
		return E_FAIL;
	}
	return S_OK;
}

HRESULT CEffectFireNomal::Render()
{
	if(!m_Timer)
		return S_OK;

	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity( &matWorld );
	g_pApp->GetD3dDevice()->SetTransform( D3DTS_WORLD, &matWorld );

	D3DLIGHT9 light;
	ZeroMemory(&light, sizeof(D3DLIGHT9));
	light.Type        = D3DLIGHT_DIRECTIONAL;
//	light.Type = D3DLIGHT_POINT; // 促捞发记 堡盔~
	light.Ambient.a = 1.0f; 
	light.Ambient.g = 0.1f;
	light.Ambient.b = 0.1f;
	light.Ambient.r = 0.1f;
	light.Diffuse.a = 1.0f; 
	light.Diffuse.g = 0.3f;
	light.Diffuse.b = 0.3f;
	light.Diffuse.r = 0.3f;
	D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &D3DXVECTOR3(-10.0f, 20.0f, -20.0f) );
	light.Direction = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
	light.Position.x   = m_vPos.x;
	light.Position.y   = m_vPos.x;
	light.Position.z   = m_vPos.x;
	light.Range        = 1000.0f;

	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_LIGHTING, TRUE);
	g_pApp->GetD3dDevice()->SetLight(0, &light);
	g_pApp->GetD3dDevice()->LightEnable(0, TRUE);
	
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE,   TRUE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHAREF,        0x08 );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );

	if (m_Timer->IsRunning()) {
		D3DXMATRIX matEmitterWorld, matInvView, matTrans, matRot, matGunTrans;
		float fDet;
		D3DXMATRIX mView = g_pCamera->GetViewMatrix();
		D3DXMatrixInverse(&matInvView, &fDet, &mView);
		D3DXMatrixTranslation(&matTrans, 0.0f, 0.0f, 2.8f);
		D3DXMatrixRotationYawPitchRoll(&matRot, (float)D3DX_PI, 0.0f, 0.0f);
		D3DXMatrixTranslation(&matGunTrans, m_vPos.x, m_vPos.y, m_vPos.z);
		matEmitterWorld = matRot * matGunTrans * matTrans * matInvView;
//		matEmitterWorld = matGunTrans;

		m_sprMuzzleFlare->Pos() = D3DXVECTOR3( matEmitterWorld._41, matEmitterWorld._42, matEmitterWorld._43);
	
		g_pApp->GetD3dDevice()->SetRenderState( D3DRS_LIGHTING, FALSE);
		g_pApp->GetD3dDevice()->SetRenderState(D3DRS_ZENABLE, FALSE);
		g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
		g_pApp->GetD3dDevice()->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_ONE );
		g_pApp->GetD3dDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

		g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
		
		g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
		g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );

		g_pApp->GetD3dDevice()->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
		g_pApp->GetD3dDevice()->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

		m_sprMuzzleFlare->Render(mView);
	}
	
	// Loop through and render all trees
//	g_pApp->GetD3dDevice()->SetStreamSource( 0, m_vbBillboard, 0, sizeof(VERTEX_BILLBOARD) );
//	g_pApp->GetD3dDevice()->SetFVF( D3DFVF_BILLBOARD );
//
//	g_pApp->GetD3dDevice()->SetTexture( 0, m_pTexBillboard[m_nCurTexIndex] );
//
//	D3DXMATRIX mBillboard = g_pCamera->GetBillboardMatrix();
//	mBillboard._41 = m_vPos.x;
//	mBillboard._42 = m_vPos.y;
//	mBillboard._43 = m_vPos.z;
//
//	g_pApp->GetD3dDevice()->SetTransform( D3DTS_WORLD, &mBillboard );
//	g_pApp->GetD3dDevice()->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
//
//	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_LIGHTING, FALSE);
//	g_pApp->GetD3dDevice()->SetRenderState(D3DRS_ZENABLE, FALSE);
//	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
//	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_ONE );
//	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
//	
//	g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
//	g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
//	
//	g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
//	g_pApp->GetD3dDevice()->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
//	
//	g_pApp->GetD3dDevice()->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
//	g_pApp->GetD3dDevice()->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
//	
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
	g_pApp->GetD3dDevice()->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );

	return S_OK;
}
*/

⌨️ 快捷键说明

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