Hi 3d coders out there,
I have a little problem, with visibility testings. Well I have 6 clipping planes top, bottom, left, right, near and far, defined in this way (i call it the Hesse normal form)
o := scalar product
N := normal vector of the Plane, has the length of 1.000000
P := Point (vertex) whose visibility is tested
A := a Point lying in the Plane
sign := is set to make the result poitive when P is visible
sign[-/+] * N[x,y,z] o ( P[x,y,z] - A[x,y,z]) = result
result is the distance from P to the plane, is positive for every P on the right (visible) side of the plane.
And I make this check for every plane. When one of the six results is negative the point is outside the view frustum.
Ok, fine so far. BUT when i test the visibility of polygon which is so large or close that the vertices are ALL outside the view frustum, the test says "outside". But the polygon IS visible.
So how can I modify this test to avoid these errors?
Or should I forget about it , and look for sth else?
i remember wrestling with this, at a time when i didn't even have the use of vectors.. hehe that was funny anyway, if you just want to clip your polys for the viewing frustrum, go to http://pages.infinit.net/jstlouis/3dbhole/ and look at this guy's clipping routines, they solve all the problems. Sorry, just realized the rest of this is screwed up, don't have to read it. if you just want to determine if the poly is in view or not, try this theoretical idea (i never tried this, just from the top of my head): define the 4 vectors of your viewing frustrum (from cam through the front plane, will depend on field of view), keep them updated as you move the cam. find just once the correct sum of angles from these four vectors to any vector IN the frustrum, like the one straight in the middle (going from cam out between all four). when your vertex comes in, get the vector from the cam to it and get the four angles from it to the view vectors (dot prod). THEORETICALLY, these four angles should sum up to the defined sum if the vertex is in the frustrum. otherwise, it isn't. if i am wrong in this intiution, u'll be the first one to tell me. later, Alex
thank you for your reply Alex. As far as i understood you want to calculate the angles between the vector from cam to the tested vertex and the vector from cam to one of the "viewing vertices". And then add these four angles together. When the result isn't a certain angle the vertex is outside. Yes i believe this works(haven't tested but will try soon) but I think this is not very fast because you would have to calculate four cosh values for every vertex you test. With the Hesse normal form you only have some additions and multiplications.
Well my problem remains , because i want to test if a polygon , in my case a window or portal, is visible or not.
u didn't have to be that kind.. hehe. well, you can transform these polys from world to view to projection and just check if its in view or not by clipping against the screen. it's slow. if you need more info on this go to the link, again. if the portal or window is displayed anyway, you can keep the index of the polys in your projection list and go through it to see if that particular poly is to be displayed, or something like that (better yet, have a flag in ur poly struct and in ur trans and clipping routines write the poly's ID into a special list if the flag is on). ur tests will always be 1 frame late if u display the polys as they come in. if you keep a list of the polys instead, u can do ur test before you send the poly list out to be rendered. it will be very efficient, u do vis tests while the polys are going through the pipeline. otherwise, i'm working on an alg right now. in a sense, i've done lots of stuff, but i'm still kinda childish in others.
First off, might i suggest you use a bounding sphere or box for object culling. This way you can limit the testing of polygons to just those polygonal objects which could actually be found in your frustum.
Second, you should use some form of a polygon-clipping algorithm. The Sutherland-Hodgman clip algorithm can be easily extended to 3D.
From there you should have no problems using your Hesse normal form.