摄像机位置问题
以下程序是创建两个三角形,一个FLAT 显示,另一个以高洛德显示,部分代码如下,主要是D3DXMatrixLookAtLH,为什么我的positon的z轴部分为正数的时候他不能显示任何物体啊?为负数就可以正常显示。
HRESULT hr;
hr=Device->CreateVertexBuffer(3*sizeof(ColorVertex),D3DUSAGE_WRITEONLY,ColorVertex::FVF,D3DPOOL_MANAGED,&Triangle,NULL);
if(FAILED(hr))
{
MessageBox(0,TEXT("createVertexBuffer-----failed"),NULL,MB_OK);
return false;
}
ColorVertex * v;
Triangle->Lock(0,0,(void**)&v,D3DLOCK_DISCARD);
v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0, 0));
v[1] = ColorVertex( 0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB( 0, 255, 0));
v[2] = ColorVertex( 1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB( 0, 0, 255));
Triangle->Unlock();
//create camera
D3DXMATRIX view;
D3DXVECTOR3 position(0,0,10.0f);
D3DXVECTOR3 target(0,0,2);
D3DXVECTOR3 up(0,1.0f,0);
D3DXMatrixLookAtLH(&view,&position,&target,&up);
Device->SetTransform(D3DTS_VIEW,&view);
//pro tansform
D3DXMATRIX pro;
D3DXMatrixPerspectiveFovLH(&pro,D3DX_PI*0.5f,(float)width/(float)height,1.0f,1000.0f);
Device->SetTransform(D3DTS_PROJECTION,&pro);
//render mode
Device->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);
Device->SetRenderState(D3DRS_LIGHTING,false);
显示部分代码如下:
D3DXMATRIX objWorld;
D3DXMatrixTranslation(&objWorld,1.0f,0,0);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_FLAT);
Device->SetTransform(D3DTS_WORLD,&objWorld);
Device->SetStreamSource(0,Triangle,0,sizeof(ColorVertex));
Device->SetFVF(ColorVertex::FVF);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
//shade::gouraud mode
D3DXMatrixTranslation(&objWorld,-1.0f,0,0);
Device->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_GOURAUD);
Device->SetTransform(D3DTS_WORLD,&objWorld);
Device->SetStreamSource(0,Triangle,0,sizeof(ColorVertex));
Device->SetFVF(ColorVertex::FVF);
Device->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
Device->EndScene();
完全不清楚其中的原因,还处于新手阶段,望大虾赐教啊。
[解决办法]
把cull mode设为none再试试。