Exemplo n.º 1
0
void CSprite::DrawSmooth(LPDIRECT3DDEVICE7 lpDevice,const D3DVECTOR pos,const float w,const float h,const DWORD color,const int spritenr)
{
    D3DVECTOR rightVect,upVect;
    D3DMATRIX mat;
    {
        lpDevice->GetTransform(D3DTRANSFORMSTATE_VIEW,&mat);
        rightVect=Normalize(D3DVECTOR(mat._11,mat._21,mat._31))*w*0.5f;
        upVect=Normalize(D3DVECTOR(mat._12,mat._22,mat._32))*h*0.5f;
    }

    const D3DVECTOR n=D3DVECTOR(0,0,0);
    D3DLVERTEX verts[4]=
    {
        D3DLVERTEX(pos-rightVect+upVect, color,0, 1.0f, 0.0f),
        D3DLVERTEX(pos+rightVect+upVect, color,0, 0.0f, 0.0f),
        D3DLVERTEX(pos-rightVect-upVect, color,0, 1.0f, 1.0f),
        D3DLVERTEX(pos+rightVect-upVect, color,0, 0.0f, 1.0f)
    };

    D3DUtil_SetIdentityMatrix(mat);

    lpDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&mat);

    if (Config.alpha)
    {
        lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,FALSE);

        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,   TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,FALSE);
        lpDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1,         D3DTA_TEXTURE);
        lpDevice->SetTextureStageState(0, D3DTSS_ALPHAOP,           D3DTOP_SELECTARG1);
        lpDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);

        lpDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCCOLOR);
        lpDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCCOLOR);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,0x08);
    }

    lpDevice->SetTexture(0,GetSurface(spritenr));
    lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_LVERTEX,verts,4,0);
    lpDevice->SetTexture(0,NULL);

    if (Config.alpha)
    {
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,   FALSE);
        lpDevice->SetRenderState(D3DRENDERSTATE_LIGHTING,TRUE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,FALSE);
        lpDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE,TRUE);
    }
}
Exemplo n.º 2
0
VOID CLightFog::Init(DWORD dwLightColor)
{
	m_dwLightColor = dwLightColor;

	for ( INT nCntY = 0; nCntY < (NUM_CNTY_LIGHTTILE+1); nCntY++ )
	{
		for ( INT nCntX = 0; nCntX < (NUM_CNTX_LIGHTTILE+1); nCntX++ )
		{
			m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR((FLOAT)(TILE_START_XPOS+(nCntX*TILE_WIDTH)), (FLOAT)(-TILE_START_YPOS-(nCntY*TILE_HEIGHT)), 0),
								  			     m_dwLightColor, RGB(0, 0, 0),  0, 0); 
		}
	}

	memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(NUM_CNTY_LIGHTTILE+1)*(NUM_CNTX_LIGHTTILE+1));

	// 타일폴리곤의 인덱스 생성.
    WORD* pwIndex = m_pwLightIndices;
	for ( nCntY = 0; nCntY < NUM_CNTY_LIGHTTILE; nCntY++ )
	{
		for ( INT nCntX = 0; nCntX < NUM_CNTX_LIGHTTILE; nCntX++ )
		{
			*pwIndex++ = (nCntX+1)+((NUM_CNTX_LIGHTTILE+1)*nCntY);  
			*pwIndex++ = nCntX+((NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
			*pwIndex++ = (nCntX+1)+((NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
			*pwIndex++ = nCntX+((NUM_CNTX_LIGHTTILE+1)*(nCntY+1));  
			*pwIndex++ = (nCntX+1)+((NUM_CNTX_LIGHTTILE+1)*nCntY);  
			*pwIndex++ = (nCntX)+((NUM_CNTX_LIGHTTILE+1)*nCntY);
		}
	}
}
Exemplo n.º 3
0
BOOL Setup()
{
	InitMaterial();

	D3DXCreateTeapot( g_pDevice, &g_pMesh, 0 );
	//////////////////////////////////////////////////////////////////////////////

	D3DXVECTOR3 pos(0,0,-5);
	D3DXVECTOR3 target(0,0,0);
	D3DXVECTOR3 up(0,1,0);
	D3DXMatrixLookAtLH( &g_mCamera, &pos, &target, &up );
	g_pDevice->SetTransform( D3DTS_VIEW, &g_mCamera );

	D3DXMATRIX proj;
	//	D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI *.5f, (float)WIDTH/(float)HEIGHT, 1.0f, 1000.0f );
	D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI *.25f, (float)WIDTH/(float)HEIGHT, 1.0f, 1000.0f );
	g_pDevice->SetTransform( D3DTS_PROJECTION, &proj );

	D3DXCreateTextureFromFile( g_pDevice, "crate.jpg", &g_pTex1);
	D3DXCreateTextureFromFile( g_pDevice, "Maksim022.bmp", &g_pTex2);

	InitAlphaTexture();

	g_pDevice->CreateVertexBuffer( vertexSize*sizeof(SVtxNormTex), 0, D3DLVERTEX::FVF, D3DPOOL_MANAGED, &g_pvtxBuff1, NULL );
	g_pDevice->CreateVertexBuffer( vertexSize*sizeof(SVtxNormTex), 0, D3DLVERTEX::FVF, D3DPOOL_MANAGED, &g_pvtxBuff2, NULL );

	D3DLVERTEX *pv;
	// A vertex
	g_pvtxBuff1->Lock(0, 0, (void**)&pv, 0);
	pv[ 0] = D3DLVERTEX(Vector3(-1.0f, -1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0, 1);
	pv[ 1] = D3DLVERTEX(Vector3(-1.0f,  1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0, 0);
	pv[ 2] = D3DLVERTEX(Vector3( 0.0f,  0.0f, -1.25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0.5f, 0.5f);
	pv[ 3] = D3DLVERTEX(Vector3( 1.0f,  1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 1, 0);
	pv[ 4] = D3DLVERTEX(Vector3( 1.0f,  -1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 1, 1);
	g_pvtxBuff1->Unlock();

	// B vertex
	g_pvtxBuff2->Lock(0, 0, (void**)&pv, 0);
	pv[ 0] = D3DLVERTEX(Vector3(1.0f, -1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 0, 1);
	pv[ 1] = D3DLVERTEX(Vector3(1.0f,  1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 0, 0);
	pv[ 2] = D3DLVERTEX(Vector3(3.0f,  1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 1, 0);
	pv[ 3] = D3DLVERTEX(Vector3(3.0f,  -1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 1, 1);
	g_pvtxBuff2->Unlock();

	//
	// 1     3
	//    2
	// 0     4
	// 
	g_pDevice->CreateIndexBuffer( indexSize*sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pidxBuff1, NULL );
	WORD *pi = NULL;
	g_pidxBuff1->Lock(0, 0, (void**)&pi, 0);
	pi[ 0] = 0; pi[ 1] = 1; pi[ 2] = 2;
	pi[ 3] = 1; pi[ 4] = 3; pi[ 5] = 2;
	pi[ 6] = 2; pi[ 7] = 3; pi[ 8] = 4;
	pi[ 9] = 2; pi[ 10] = 4; pi[ 11] = 0;
	g_pidxBuff1->Unlock();

	InitNormal();

	return TRUE;
}
BOOL Setup()
{
	InitMaterial();

	D3DXCreateTeapot( g_pDevice, &g_pMesh, 0 );
	//////////////////////////////////////////////////////////////////////////////

	D3DXVECTOR3 pos(0,0,-5);
	D3DXVECTOR3 target(0,0,0);
	D3DXVECTOR3 up(0,1,0);
	D3DXMatrixLookAtLH( &g_mCamera, &pos, &target, &up );
	g_pDevice->SetTransform( D3DTS_VIEW, &g_mCamera );

	D3DXMATRIX proj;
	//	D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI *.5f, (float)WIDTH/(float)HEIGHT, 1.0f, 1000.0f );
	D3DXMatrixPerspectiveFovLH( &proj, D3DX_PI *.25f, (float)WIDTH/(float)HEIGHT, 1.0f, 1000.0f );
	g_pDevice->SetTransform( D3DTS_PROJECTION, &proj );

	D3DXCreateTextureFromFile( g_pDevice, "crate.jpg", &g_pTex1);
	D3DXCreateTextureFromFile( g_pDevice, "Maksim022.bmp", &g_pTex2);

	g_pDevice->CreateVertexBuffer( 6*sizeof(SVtxNormTex), 0, D3DLVERTEX::FVF, D3DPOOL_MANAGED, &g_pvtxBuff, NULL );
	g_pDevice->CreateVertexBuffer( 6*sizeof(SVtxNormTex), 0, D3DLVERTEX::FVF, D3DPOOL_MANAGED, &g_pvtxBuff2, NULL );

	D3DLVERTEX *pv;
	g_pvtxBuff->Lock(0, 0, (void**)&pv, 0);

	// A vertex
	pv[ 0] = D3DLVERTEX(Vector3(-1.0f, -1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0, 1);
	pv[ 1] = D3DLVERTEX(Vector3(-1.0f,  1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0, 0);
	pv[ 2] = D3DLVERTEX(Vector3( 1.0f,  1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 1, 0);

	pv[ 3] = D3DLVERTEX(Vector3(-1.0f, -1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 0, 1);
	pv[ 4] = D3DLVERTEX(Vector3( 1.0f,  1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 1, 0);
	pv[ 5] = D3DLVERTEX(Vector3( 1.0f, -1.0f, .25f), Vector3(0,0,-1), D3DXCOLOR(1,0,0,0), 1, 1);

	g_pvtxBuff->Unlock();

	g_pvtxBuff2->Lock(0, 0, (void**)&pv, 0);

	// B vertex
	pv[ 0] = D3DLVERTEX(Vector3(1.0f, -1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 0, 1);
	pv[ 1] = D3DLVERTEX(Vector3(1.0f,  1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 0, 0);
	pv[ 2] = D3DLVERTEX(Vector3(3.0f,  1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 1, 0);

	pv[ 3] = D3DLVERTEX(Vector3(1.0f, -1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 0, 1);
	pv[ 4] = D3DLVERTEX(Vector3(3.0f,  1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 1, 0);
	pv[ 5] = D3DLVERTEX(Vector3(3.0f, -1.0f, 1.25f), Vector3(0,0,-1), D3DXCOLOR(0,0,1,0), 1, 1);

	g_pvtxBuff2->Unlock();

	return TRUE;
}
Exemplo n.º 5
0
VOID CWater::ShowLightFog(BOOL bShowFog)
{
    if ( g_xMainWnd.Get3DDevice() )
    {
        if( SUCCEEDED(g_xMainWnd.Get3DDevice()->BeginScene()) )
        {
            D3DVECTOR vTrans;
            D3DMATRIX matTrans;
            D3DMATRIX matWorldOriginal;

            g_xMainWnd.Get3DDevice()->GetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);

//			if ( bShowFog )
//				SetLightRadiusWithElipse(400, 242, 6, 6, 230, 230, 230);
//				SetLightRadiusWithElipse(400, 242, 1, 1, 230, 230, 230);
//				SetLightRadiusWithCircle(400, 242, 8, 230, 230, 230);
            /*				SetLightRadiusWithCircle(586, 248, 3, 230, 230, 230);
            				SetLightRadiusWithCircle(604, 248, 3, 230, 230, 230);
            *///				SetLightRadiusWithRing(400, 242, 7, 230, 230, 230, 8, 230, 230, 230);
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ZERO);
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR);

            /*			BYTE bOpa = 255;
            			D3DMATERIAL7 mtrl;
            			D3DUtil_InitMaterial(mtrl,
            								 (FLOAT)255/255.0f,
            								 (FLOAT)255/255.0f,
            								 (FLOAT)255/255.0f);
            			mtrl.diffuse.a = (bOpa+1)/255.0f;
            			g_xMainWnd.Get3DDevice()->SetMaterial(&mtrl);
            			SetBlendRenderState(g_xMainWnd.Get3DDevice(), _BLEND_NORMAL, mtrl);
            */
            vTrans.x = -400;
            vTrans.y = 300;
            vTrans.z = 0;
            D3DUtil_SetTranslateMatrix(matTrans, vTrans);
            g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matTrans);
//			g_xMainWnd.Get3DDevice()->SetTexture(0, NULL);


            static int a = 0;
            static int b = 0;
            static float scrlcnt = 0.0f;
            if ( scrlcnt >= WATER_NUM_CNTX_LIGHTTILE )		scrlcnt = 0;
            a++;
            if ( a >= 1 )
            {
                for ( INT nCntY = 0; nCntY < (WATER_NUM_CNTY_LIGHTTILE+1); nCntY++ )
                {
                    FLOAT av = (FLOAT)((FLOAT)nCntY/(FLOAT)WATER_NUM_CNTY_LIGHTTILE);

                    for ( INT nCntX = 0; nCntX < (WATER_NUM_CNTX_LIGHTTILE+1); nCntX++ )
                    {
                        FLOAT au = (FLOAT)((FLOAT)nCntX/(FLOAT)WATER_NUM_CNTX_LIGHTTILE) + scrlcnt;
                        if ( au > 1 )							au = 1-au;
                        FLOAT az = m_avLight[nCntY][nCntX].z;
                        if ( b > 10 )
                        {
//							az = (FLOAT)GetRandomNum(0, 50);
                        }
                        FLOAT ax = /*(FLOAT)GetRandomNum(0, 10) + */(FLOAT)(WATER_TILE_START_XPOS+(nCntX*WATER_TILE_WIDTH));
                        FLOAT ay = /*(FLOAT)GetRandomNum(0, 1) + */(FLOAT)(-WATER_TILE_START_YPOS-(nCntY*WATER_TILE_HEIGHT));

//						if ( av > 1 )							av = 1-av;

                        m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR(ax, ay, az),
                                                             m_dwLightColor, RGB(0, 0, 0), au, av);
                    }
                }
                memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));
                a = 0;
            }
            scrlcnt += 0.0006f;
            if ( b > 10 )
            {
                b = 0;
            }
            b++;

            g_xMainWnd.Get3DDevice()->SetTexture(0, D3DTextr_GetSurface(m_szWater[m_bCurrTexIdx]));

            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
            g_xMainWnd.Get3DDevice()->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
                    D3DFVF_LVERTEX,
                    m_avLight, WATER_NUM_LIGHTTILE_VERTICES,
                    m_pwLightIndices, WATER_NUM_LIGHTTILE_INDICES, NULL );
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_LIGHTING, TRUE);

//			ResetBlendenderState(g_xMainWnd.Get3DDevice());
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_SRCBLEND,  D3DBLEND_ONE);
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO);
            g_xMainWnd.Get3DDevice()->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE);

            g_xMainWnd.Get3DDevice()->SetTransform(D3DTRANSFORMSTATE_WORLD, &matWorldOriginal);

            g_xMainWnd.Get3DDevice()->EndScene();
        }
    }
}
Exemplo n.º 6
0
VOID CWater::Init(DWORD dwLightColor)
{
    m_dwLightColor = dwLightColor;
    m_bShowFog = FALSE;

    for ( INT nCntY = 0; nCntY < (WATER_NUM_CNTY_LIGHTTILE+1); nCntY++ )
    {
        for ( INT nCntX = 0; nCntX < (WATER_NUM_CNTX_LIGHTTILE+1); nCntX++ )
        {
            FLOAT az = (FLOAT)GetRandomNum(0, 17);
            m_avLight[nCntY][nCntX] = D3DLVERTEX(D3DVECTOR((FLOAT)(WATER_TILE_START_XPOS+(nCntX*WATER_TILE_WIDTH)), (FLOAT)(-WATER_TILE_START_YPOS-(nCntY*WATER_TILE_HEIGHT)), az),
                                                 m_dwLightColor, RGB(0, 0, 0), (FLOAT)((FLOAT)nCntX/(FLOAT)WATER_NUM_CNTX_LIGHTTILE), (FLOAT)((FLOAT)nCntY/(FLOAT)WATER_NUM_CNTY_LIGHTTILE));
        }
    }

    memcpy(m_avSaveLight, m_avLight, sizeof(D3DLVERTEX)*(WATER_NUM_CNTY_LIGHTTILE+1)*(WATER_NUM_CNTX_LIGHTTILE+1));

    // 타일폴리곤의 인덱스 생성.
    WORD* pwIndex = m_pwLightIndices;
    for ( nCntY = 0; nCntY < WATER_NUM_CNTY_LIGHTTILE; nCntY++ )
    {
        for ( INT nCntX = 0; nCntX < WATER_NUM_CNTX_LIGHTTILE; nCntX++ )
        {
            *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
            *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
            *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
            *pwIndex++ = nCntX+((WATER_NUM_CNTX_LIGHTTILE+1)*(nCntY+1));
            *pwIndex++ = (nCntX+1)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
            *pwIndex++ = (nCntX)+((WATER_NUM_CNTX_LIGHTTILE+1)*nCntY);
        }
    }

    m_bCurrTexIdx = 0;
    CHAR* szFileList[] =
    {
        "Water00.bmp",
        "Water01.bmp",
        "Water02.bmp",
        "Water03.bmp",
        "Water04.bmp",
        "Water05.bmp",
        "Water06.bmp",
        "Water07.bmp",
        "Water08.bmp",
        "Water09.bmp",
        "Water10.bmp",
        "Water11.bmp",
        "Water12.bmp",
        "Water13.bmp",
        "Water14.bmp",
        "Water15.bmp",
        "Water16.bmp",
        "Water17.bmp",
        "Water18.bmp",
        "Water19.bmp",
        "Water20.bmp",
        "Water21.bmp",
        "Water22.bmp",
        "Water23.bmp",
        "Water24.bmp",
        "Water25.bmp",
    };
    for ( INT nCnt = 0; nCnt < 26; nCnt++ )
    {
        strcpy(m_szWater[nCnt], szFileList[nCnt]);
        D3DTextr_CreateTextureFromFile(m_szWater[nCnt]);
        D3DTextr_Restore(m_szWater[nCnt], g_xMainWnd.Get3DDevice());
    }
}