|
|

楼主 |
发表于 2007-1-25 13:25:00
|
显示全部楼层
Re:如何让directx 只 render 看到的地形
谢谢大家, 我上网找了这个来测试vertex是否在视锥内:
float abs_f(float f)
{
if( f<0 ) return -f;
return f;
}
bool FrustrumCheck(float x, float y, float z)
{
D3DXMATRIX matWorld, matView, matProjection;
g_pd3dDevice->GetTransform(D3DTS_WORLD, &matWorld);
g_pd3dDevice->GetTransform(D3DTS_VIEW, &matView);
g_pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProjection);
// I chaned this line, so you could change the projection view here, adjusting
// the near and far plane...alternatively you can just use the GetTransform
// DX call, and use the pre-set one.
D3DXMATRIX Cull = matWorld * matView * matProjection;
D3DXVECTOR4 vNode = D3DXVECTOR4(x,y,z,1);
D3DXVECTOR4 vTestVert;
D3DXVec4Transform(&vTestVert, &vNode, &Cull);
if( abs_f(vTestVert.x) > abs_f(vTestVert.w) ) // Outside our X Frustum Plane
return false;
if( abs_f(vTestVert.y) > abs_f(vTestVert.w) ) // Outside our Y Frustum Plane
return false;
if( (vTestVert.z<0.0f) || (vTestVert.z>vTestVert.w)) // Outside our z Frustum Plane
return false;
return true;
}
可是时间都花到cpu之上, 只多了10左右的fps... |
|