作业帮 > 综合 > 作业

D3D 物体在镜子、阴影中怎样同步透明?物体渐变透明过程怎样消除挡住镜中物体的情况?

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/30 11:28:59
D3D 物体在镜子、阴影中怎样同步透明?物体渐变透明过程怎样消除挡住镜中物体的情况?
.以下是shadow函数代码,实现透明的时候只捕获了一次变透明按键消息,放开按键又回到原来状态,物体透明了影子还在……何解呀大师前辈们?
void RenderShadow(float timeDelta)
{
Device->SetRenderState(D3DRS_STENCILENABLE,true);
Device->SetRenderState(D3DRS_STENCILFUNC,D3DCMP_EQUAL);
Device->SetRenderState(D3DRS_STENCILREF,0x0);
Device->SetRenderState(D3DRS_STENCILMASK,0xffffffff);
Device->SetRenderState(D3DRS_STENCILWRITEMASK,0xffffffff);
Device->SetRenderState(D3DRS_STENCILZFAIL,D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILFAIL,D3DSTENCILOP_KEEP);
Device->SetRenderState(D3DRS_STENCILPASS,D3DSTENCILOP_INCR); // increment to 1
// position shadow
D3DXVECTOR4 lightDirection(0.707f,-0.707f,0.707f,0.0f);
D3DXPLANE groundPlane(0.0f,-1.0f,0.0f,0.0f);
D3DXMATRIX S;
D3DXMatrixShadow(
&S,
&lightDirection,
&groundPlane);
D3DXMATRIX T;
D3DXMatrixTranslation(
&T,
TeapotPosition.x,
TeapotPosition.y,
TeapotPosition.z);
D3DXMATRIX yRot;
// D3DXMATRIX xRot;
static float y = 0.0f;
D3DXMatrixRotationY(&yRot,y);
if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
y+=5* timeDelta;
if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
y-=5* timeDelta;
if( y>= 6.28f)
y= 0.0f;
D3DXMATRIX W = yRot*T * S;
Device->SetTransform(D3DTS_WORLD,&W);
// alpha blend the shadow
Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
D3DMATERIAL9 mtrl = d3d::InitMtrl(d3d::BLACK,d3d::BLACK,d3d::BLACK,d3d::BLACK,0.0f);
mtrl.Diffuse.a = 0.6f; // 50% transparency.
if( ::GetAsyncKeyState('A') & 0x8000f )
//{angle -= 1.2f * timeDelta;
mtrl.Diffuse.a += 0.1f;
if( ::GetAsyncKeyState('S') & 0x8000f )
mtrl.Diffuse.a -= 0.1f;
if(mtrl.Diffuse.a > 1.0f)
mtrl.Diffuse.a = 1.0f;
if(mtrl.Diffuse.a < 0.0f)
mtrl.Diffuse.a = 0.0f;
// Disable depth buffer so that z-fighting doesn't occur when we
// render the shadow on top of the floor.
Device->SetRenderState(D3DRS_ZENABLE,false);
Device->SetMaterial(&mtrl);
Device->SetTexture(0,0);
Teapot->DrawSubset(0);
Device->SetRenderState(D3DRS_ZENABLE,true);
Device->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
Device->SetRenderState(D3DRS_STENCILENABLE,false);
};
(╯﹏╰)b...
求同解……