Frustum Almost Working But Not Quite

Recommended Posts

Hi, I am trying to implement frustum culling in a program I have. I am using the lighthouse 3d < href="http://www.lighthouse3d.com/opengl/viewfrustum/" target="blank">tutorial on frustum culling. I have the program calculating all the corners of the frustum, and it works great...on one condition. As long as the camera is centered around the y axis(IE, I don't change the y values of the camera position and the remain 0) everything works great. However, If I do, it starts going crazy. It culls out way to many objects. I drew the normals of the planes, and they are also pretty crazy. I can't explain as well as show you, so here are some pictures. The normals are the green to blue lines(they are pointing in the direction of the blue, IE, green is the beggining of the vector, blue is the end). I know that the normals are supposed to be pointing in towards the frustum, but when I'm not sure how to change them, and when I try the things I know, every object is culled. Also note that when I check to see which test is failing the objects that should be showing, it's the top and bottom planes that fail the test where they should pass. Pic1 Pic2 Pic3 Can anyone help me out here?? Thank you very much. Levi

Share on other sites
1) copy/paste gone wrong: you forgot to change an x to a y or some such in a line you pasted

2) you're not properly transforming your camera.

3) there's a bug in your object/frustum collision algorithm

you'll need to post your code to get better answers. Post the code for:

1) your frustum extraction
2) your frustum/object collision checks

-me

Share on other sites
What is "transforming your camera"?

The thing that gets me though, is that this is only a problem for the Y axis. If I move my camera left,right, forward or backward(x or z axis), there is no problem.

Here is the code for frustum extraction.

	camdir=camlook-campos;	camdir.Normalize();	right=up*camdir;	right.Normalize(); 	fc=campos+camdir*(float)fardist;	nc=campos+camdir*(float)neardist;	hf=up*(float)(Hfar/2);	wf=right*(float)(Wfar/2);	hn=up*(float)(Hnear/2);	wn=right*(float)(Wnear/2);	//Far Plane	ftl=fc+hf-wf;	ftr=fc+hf+wf;	fbl=fc-hf-wf;	fbr=fc-hf+wf;	//Near Plane	ntl=nc+hn-wn;	ntr=nc+hn+wn;	nbl=nc-hn-wn;	nbr=nc-hn+wn;	//Far Plane	ftl=fc+hf-wf;	ftr=fc+hf+wf;	fbl=fc-hf-wf;	fbr=fc-hf+wf;	//Near Plane	ntl=nc+hn-wn;	ntr=nc+hn+wn;	nbl=nc-hn-wn;	nbr=nc-hn+wn;	pl[0].set3Points(ntr,ntl,ftl);	pl[1].set3Points(nbl,nbr,fbr);	pl[2].set3Points(ntl,nbl,fbl);	pl[3].set3Points(nbr,ntr,fbr);	pl[4].set3Points(ntl,ntr,nbr);	pl[5].set3Points(ftr,ftl,fbl);

Here is the set3Points function

void Plane::set3Points(Vector p1, Vector p2, Vector p3){	Vector v,u;	v=p1-p2;	u=p3-p2;	normal=v*u;	normal.Normalize();	point.SetVect(p2);	d=-normal.DotProduct(point);}

And here is how I'm doing the frustum checks for each object(I'm taking each object to be a point).

//Each time and object is drawn, it calls this//function and passes the objects coordinates.  //It draws or doesn't draw depending on what this //function returns.bool DrawPoint(Vector p){	float dist;	for(int l=0;l<6;l++)	{		if(pl[l].distance(p)<-1)		{			return FALSE;		}	}	return TRUE;}float Plane::distance(Vector p){	return ((float)d+normal.DotProduct(p));}

Share on other sites
Hey,
I figured it out. My CrossProduct function was a little screwy(reveresed an x and a z like paladine say. Also the way I extracted the planes was a little messed up too(though i'm not quite sure how yet). But thanks anyways.

Levi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• Forum Statistics

• Total Topics
628282
• Total Posts
2981805

• 9
• 10
• 11
• 17
• 14