Skip to main content
GameDev.net gamedev.net
🔒 Locked

Planes

Started by okonomiyaki May 18, 2003 at 5:43 PM 1 replies 450+ views
Original Post
okonomiyaki
okonomiyaki
A Plane (specifcally D3DXPLANE) defined by 4 floats is supposed to be an infinitely long flat surface right? Therefore, when testing a point on either side, if you set the plane perpendicular to the ground, the "height" of the point makes absoltely no difference, right? Just whether it is to the left or right? Well how in the world is this happening in my program? I''m taking the left and right planes and testing all the points just according to those. I don''t really need culling top and bottom nor behind and far, I''m just trying to to simple culling by these 2 planes. This works fine when looking a little bit up but when I start to look down my terrain starts dissapearing. Height is obviously factored in here somewhere, but where could it be?
JuNC
JuNC
How are these two planes being defined?

You''ll have to describe your problem a bit more (mathematically or code-wise).
okonomiyaki
okonomiyaki
Sure thing.
I'll go ahead and post some code. This is my code that extracts the left and right planes of the view frustum, and checks each "box" if it's in the frustum.


      
float **frustum = new float*[2];
float t;
for(int i=0; i<2; i++)
frustum[i] = new float[4];

//The RIGHT plane

frustum[0][0] = planes->_14 - planes->_11;
frustum[0][1] = planes->_24 - planes->_21;
frustum[0][2] = planes->_34 - planes->_31;
frustum[0][3] = planes->_44 - planes->_41;
t = sqrt( frustum[0][0] * frustum[0][0] + frustum[0][1] * frustum[0][1] + frustum[0][2] * frustum[0][2] );
frustum[0][0] /= t;
frustum[0][1] /= t;
frustum[0][2] /= t;
frustum[0][3] /= t;


//The LEFT plane

frustum[1][0] = planes->_14 + planes->_11;
frustum[1][1] = planes->_24 + planes->_21;
frustum[1][2] = planes->_34 + planes->_31;
frustum[1][3] = planes->_44 + planes->_41;
t = sqrt( frustum[1][0] * frustum[1][0] + frustum[1][1] * frustum[1][1] + frustum[1][2] * frustum[1][2] );
frustum[1][0] /= t;
frustum[1][1] /= t;
frustum[1][2] /= t;
frustum[1][3] /= t;

for(i=0; i<YTerrain/16; i++) {
for(int k=0; k<XTerrain/16; k++) {


BOOL draw = TRUE;


for(int p=0; p<2; p++) {
if( frustum[p][0] * (k*16) + frustum[p][1] * 0.0f + frustum[p][2] * (i*16) + frustum[p][3] > 0)
continue;
if( frustum[p][0] * (k*16+16) + frustum[p][1] * 0.0f + frustum[p][2] * (i*16) + frustum[p][3] > 0)
continue;
if( frustum[p][0] * (k*16) + frustum[p][1] * 0.0f + frustum[p][2] * (i*16+16) + frustum[p][3] > 0)
continue;
if( frustum[p][0] * (k*16+16) + frustum[p][1] * 0.0f + frustum[p][2] * (i*16+16) + frustum[p][3] > 0)
continue;

draw = FALSE;
break;
}

if(draw)
Octree[i*(YTerrain/16) + k]->Draw();



}

}

delete[] frustum[0];
delete[] frustum[1];
delete[] frustum;


I got the basics of it from this page: http://www.markmorley.com/opengl/frustumculling.html
I know what the coordinates are of my quadtree nodes because right now the vertices are evenly spaced out. Each node contains 16x16 vertices. So I basically check a grid of 32x32 of these boxes (the terrain is 513x513).
When I looked up at a 45 degree angle, everything is fine. But as I start looking down, the terrain starts dissappearing in a "V" shape, as if the virtual frustum is moving forward. Around looking down at about 45 degrees, the terrain dissapears altogether. See any flagrant errors in my code?


edit: fixed a tag error
edit: forget to mention that "planes" is a D3DXMATRIX that represents the projection matrix multiplied by the view matrix.

[edited by - okonomiyaki on May 18, 2003 7:48:17 PM]

[edited by - okonomiyaki on May 18, 2003 7:49:24 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.