Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Directx 当我画镜子反射(dx9)时,场景变得一团糟_Directx_Directx 9 - Fatal编程技术网

Directx 当我画镜子反射(dx9)时,场景变得一团糟

Directx 当我画镜子反射(dx9)时,场景变得一团糟,directx,directx-9,Directx,Directx 9,在我的项目中,我画了一座房子,它由墙、地板、镜子、一个开关组成,用来打开或关闭消防系统。这里一切都很顺利。 最后,我想在镜子上画一个人的倒影,但在我添加了drawReflection功能后,事情发生了错误,场景变得一团糟。为什么?我根据书写函数 void House::draw(float timeDelta) { _device->SetFVF(d3d::Vertex::FVF); _device->SetStreamSource(0, _vb, 0, sizeof(d3d

在我的项目中,我画了一座房子,它由墙、地板、镜子、一个开关组成,用来打开或关闭消防系统。这里一切都很顺利。 最后,我想在镜子上画一个人的倒影,但在我添加了
drawReflection
功能后,事情发生了错误,场景变得一团糟。为什么?我根据书写函数

 void House::draw(float timeDelta)
   {
_device->SetFVF(d3d::Vertex::FVF);
_device->SetStreamSource(0, _vb, 0, sizeof(d3d::Vertex));

// draw wall

_device->SetMaterial(&d3d::WHITE_MTRL);
_device->SetTexture(0, _wall);
_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 10);

// draw floor

_device->SetMaterial(&d3d::WHITE_MTRL);
_device->SetTexture(0, _floor);
_device->DrawPrimitive(D3DPT_TRIANGLELIST, 30, 2);

// draw mirror

_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
_device->SetMaterial(&d3d::WHITE_MTRL);
_device->SetTexture(0, _mirror);
_device->DrawPrimitive(D3DPT_TRIANGLELIST, 36, 2);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);


// draw switch button

D3DXMATRIX T, Ry, P;

D3DXMatrixTranslation(&T, -4.95f, 2.0f, 3.0f);
D3DXMatrixRotationY(&Ry, D3DX_PI * 1.5f);
P = Ry * T;
_device->SetTransform(D3DTS_WORLD, &P);
_device->SetMaterial(&d3d::BLUE_MTRL);
_device->SetTexture(0, NULL);
_switch->DrawSubset(0);

// draw fire system

D3DXMATRIX I;
D3DXMatrixIdentity(&I);
_device->SetTransform(D3DTS_WORLD, &I);
if(_fSwitchOn)
{
    if(_fs->isDead())
        _fs->reset();
    _fs->update(timeDelta);
    _fs->render();
}

// draw reflection of person
//drawReflection();
}
但在我向它添加
drawReflection()
函数之后,它变得一团糟。为什么?
drawReflection()
函数如下:

 void House::drawReflection()
 {
// enable stencil
_device->SetRenderState(D3DRS_STENCILENABLE,        true);
_device->SetRenderState(D3DRS_STENCILFUNC,          D3DCMP_ALWAYS);
_device->SetRenderState(D3DRS_STENCILREF,           0x1);
_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_REPLACE);

// stop write to target buffer and depth buffer
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
_device->SetRenderState(D3DRS_SRCBLEND,         D3DBLEND_ZERO);
_device->SetRenderState(D3DRS_DESTBLEND,        D3DBLEND_ONE);
_device->SetRenderState(D3DRS_ZWRITEENABLE,     false);

// draw the mirror to stencil buffer
_device->SetFVF(d3d::Vertex::FVF);
_device->SetStreamSource(0, _vb, 0, sizeof(d3d::Vertex));
_device->SetMaterial(&d3d::WHITE_MTRL);
_device->SetTexture(0, _mirror);
D3DXMATRIX I;
D3DXMatrixIdentity(&I);
_device->SetTransform(D3DTS_WORLD, &I);
_device->DrawPrimitive(D3DPT_TRIANGLELIST, 36, 2);
_device->SetRenderState(D3DRS_ZWRITEENABLE,     true);

// transform the mesh
_device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL);
_device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);

D3DXMATRIX Reflect, S, T, P;
D3DXPLANE plane(0.0f, 0.0f, 1.0f, -5.0f);
D3DXMatrixReflect(&Reflect, &plane);
 // D3DXMatrixScaling(&S, 0.2f, 0.2f, 0.2f);
D3DXVECTOR3 pos;
_person->getPosition(&pos);
D3DXMatrixTranslation(&T, pos.x, pos.y, pos.z);

P = T * Reflect;
_device->Clear(0, NULL, D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
_device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_DESTCOLOR);
_device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);
_device->SetTransform(D3DTS_WORLD, &P);
_person->draw();

_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
_device->SetRenderState(D3DRS_STENCILENABLE,    false);
_device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);

 }

怎么了?你希望看到什么?你能发布一个屏幕截图吗?thx,我已经修复了它,我没有将变换添加到我绘制的第一个对象,所以当最后一个对象绘制完成后,变换一直保留到第一个对象,因此它被拉伸。我已经修复了它,thx仍然如此