   Frutsum Culling
  I am trying to get my frutsum culling working and think its close but the terrain jumps in and out of view when I move the camera around. I think it has to do with my min,max values or I have the math wrong for the frutsum? bool Camera::pointInFrustum(float x, float y, float z){for(unsigned long x = 0; x < 6; ++x){   float dist = frustumPlanes[x].a * x + frustumPlanes[x].b * y + frustumPlanes[x].c * z + frustumPlanes[x].d;// If the distance was negative, the point is outside the frustum.if(dist < 0)return false;}// the point was inside the frustum.return true;}void Camera::buildWorldFrustumPlanes(void){// Note: Extract the frustum planes in world space.D3DXMATRIX VP = mView * mProj;D3DXVECTOR4 col0(VP(0,0), VP(1,0), VP(2,0), VP(3,0));D3DXVECTOR4 col1(VP(0,1), VP(1,1), VP(2,1), VP(3,1));D3DXVECTOR4 col2(VP(0,2), VP(1,2), VP(2,2), VP(3,2));D3DXVECTOR4 col3(VP(0,3), VP(1,3), VP(2,3), VP(3,3));// Planes face inward.frustumPlanes[0] = (D3DXPLANE)(col2);   // nearfrustumPlanes[1] = (D3DXPLANE)(col3 - col2); // farfrustumPlanes[2] = (D3DXPLANE)(col3 + col0); // leftfrustumPlanes[3] = (D3DXPLANE)(col3 - col0); // rightfrustumPlanes[4] = (D3DXPLANE)(col3 - col1); // topfrustumPlanes[5] = (D3DXPLANE)(col3 + col1); // bottomfor(int i = 0; i < 6; i++)D3DXPlaneNormalize(&frustumPlanes, &frustumPlanes);}//renderingfor(unsigned int z = 0; z < (mapData.map_Z - 1) / (PATCH_SIZE - 1); ++z){for(unsigned int x = 0; x < (mapData.map_X - 1) / (PATCH_SIZE - 1); ++x){maxX = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxX;maxY = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxY;maxZ = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].maxZ;minX = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minX;minY = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minY;minZ = patch[z * ((mapData.map_X - 1) / (PATCH_SIZE - 1)) + x].minZ;// Check to see if the corners of the patches are within the frustum.if (!gCamera.pointInFrustum(maxX, maxY, maxZ) &&!gCamera.pointInFrustum(minX, maxY, minZ) &&!gCamera.pointInFrustum(minX, maxY, maxZ) &&!gCamera.pointInFrustum(maxX, maxY, minZ) &&!gCamera.pointInFrustum(maxX, minY, maxZ) &&!gCamera.pointInFrustum(minX, minY, minZ) &&!gCamera.pointInFrustum(minX, minY, maxZ) &&!gCamera.pointInFrustum(maxX, minY, minZ))continue;dxApp.d3dDevice->DrawIndexedPrimitive(type, 0, 0, NUM_VERTICES, indexSum, NUM_POLYGONS);indexSum += INDEX_SUM_OFFSET;}}On the DrawIndexPrimitive is that the correct way to call it in DX with the setu I have? I know in OpenGL it is, I figured it's got to be similar? Thanks   
  Erm, if that's your actual code, I can see one obvious problem straight away:bool Camera::pointInFrustum(float x, float y, float z){for(unsigned long x = 0; x < 6; ++x){   float dist = frustumPlanes[x].a * x +Due to C++ scoping, the variable 'x' used for your for() loop will take precedence over the parameter 'x' passed into the function, so pointInFrustum will be pretty wrong most of the time...Regarding the parameters for DrawIndexedPrimitive(), Tom Forsyth's mini-DirectX FAQ contains a useful explanation: http://tomsdxfaq.blogspot.com/2002_05_01_tomsdxfaq_archive.html#77028718;Quote:Original post by S1CAErm, if that's your actual code, I can see one obvious problem straight away:bool Camera::pointInFrustum(float x, float y, float z){for(unsigned long x = 0; x < 6; ++x){   float dist = frustumPlanes[x].a * x +Due to C++ scoping, the variable 'x' used for your for() loop will take precedence over the parameter 'x' passed into the function, so pointInFrustum will be pretty wrong most of the time...Regarding the parameters for DrawIndexedPrimitive(), Tom Forsyth's mini-DirectX FAQ contains a useful explanation: http://tomsdxfaq.blogspot.com/2002_05_01_tomsdxfaq_archive.html#77028718Mars pulls out gun points at head and pulls trigger! Yes you are correct that should have been obvious, but I am in such a mess trying to learn DX as fast as possible from OpenGL I am over looking simple mistakes... Argh. Thanks I will try this out and see if that works and let you know.   