#### Archived

This topic is now archived and is closed to further replies.

# Help with code

This topic is 5311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Having problems with the frustum culling in a landscape program I am trying to make. Below are the parts of the code. Any help would be greatly appreciated, as I am new to DIrectX and C++.
//This is where I calculate the bounding parameters for the node:

{
int minHeight, maxHeight;
minHeight = 0;
maxHeight = 0;

{
{
if(minHeight > getHeightmapEntry(j,i)) minHeight = getHeightmapEntry(j,i);
if(maxHeight < getHeightmapEntry(j,i)) maxHeight = getHeightmapEntry(j,i);
}
}

//Bounding box for node

//D3DXVECTOR3 box[8];

//Find center of bounding sphere

for(i = 0; i < 8; i++)

//Find furthest point in set

for (i = 0; i < 8; i++)
{
D3DXVECTOR3 v;
float distSq = D3DXVec3LengthSq(&v);
}

}

//This is where i setup the view frustum:

VOID CAMERA::UpdateFrustum()
{

//	D3DXVECTOR3 t_vec(1.0f, 1.0f, 1.0f);

D3DXMATRIXA16 t_mat =*D3DXMatrixIdentity(&t_mat);

//multilply view and projection matrixs to give current view frustum

D3DXMatrixMultiply(&t_mat, &m_matView, &m_matProjection);

//left side

bc_frustum[0] = D3DXPLANE(t_mat._14 + t_mat._11, t_mat._24 + t_mat._21,
t_mat._34 + t_mat._31, t_mat._44 + t_mat._41);
D3DXPlaneNormalize(&bc_frustum[0], &bc_frustum[0]);

//right side

bc_frustum[1] = D3DXPLANE(t_mat._14 - t_mat._11, t_mat._24 - t_mat._21,
t_mat._34 - t_mat._31, t_mat._44 - t_mat._41);
D3DXPlaneNormalize(&bc_frustum[1], &bc_frustum[1]);

//bottom

bc_frustum[2] = D3DXPLANE(t_mat._14 + t_mat._12, t_mat._24 + t_mat._22,
t_mat._34 + t_mat._32, t_mat._44 + t_mat._42);
D3DXPlaneNormalize(&bc_frustum[2], &bc_frustum[2]);

//top

bc_frustum[3] = D3DXPLANE(t_mat._14 - t_mat._12, t_mat._24 - t_mat._22,
t_mat._34 - t_mat._32, t_mat._44 - t_mat._42);
D3DXPlaneNormalize(&bc_frustum[3], &bc_frustum[3]);

//near

bc_frustum[4] = D3DXPLANE(t_mat._14 + t_mat._13, t_mat._24 + t_mat._23,
t_mat._34 + t_mat._33, t_mat._44 + t_mat._43);

D3DXPlaneNormalize(&bc_frustum[4], &bc_frustum[4]);

//far

bc_frustum[5] = D3DXPLANE(t_mat._14 - t_mat._13, t_mat._24 - t_mat._23,
t_mat._34 - t_mat._33, t_mat._44 - t_mat._43);
D3DXPlaneNormalize(&bc_frustum[5], &bc_frustum[5]);

return;
}
// And finally where I check the bounding Sphere:

{
//Make sure radius is in frustum

for(short i = 0; i < 6; i++)
{
FLOAT fPlaneDotCoord = D3DXPlaneDotCoord(&bc_frustum[i], ¢er);
{
return OUTSIDE;
}
}
return INSIDE;
}

Thank you in advance for your help. [Please use [ source ] and [ /source ] tags when posting a lot of code. -Superpig] [edited by - Superpig on May 29, 2004 1:38:12 PM]

##### Share on other sites
Can you tell us about the problem you''re having? Just handing us code and telling us "it don''t work" isn''t very helpful.

##### Share on other sites
Sorry, was my first post. The culling routine seems to over cull. When on the level of the terrain it looks like this:

| |
| \ / |
| \ / |
| --- |
|__________|

And when on a point of level terrain the culling is completly messed up. I am a begginer and new to 3D programming so not sure where I should look.

Thanks again

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013394
×