Jump to content
  • Advertisement

Archived

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

Plasmite

*#!&#! this BSP-tree is difficult!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''ve been trying to sort faces with a BSP-tree for some time, but I can''t get it work correctly. I have it somehow ready, and I have made testes where three triangles move around each others, and intersect each others. It works well in this kind of simple cases. When I try to use it on a model that has 72 faces, it doesn''t work anymore. Some faces that are behind other faces suddenly jump above everything, and the model looks really bad. I think the tutorial I read about BSP-trees was rather old and not so detailed, and I have needed to come up with some own solutions. The tutorial I read explained the basic idea in 2D, and then said that do the same thing in 3D, (and gave couple of equations to start with). I believe the biggest problem right now is this: Two triangles intersect each others, so other one is splitted into three smaller triangles. One of them goes to the other side, and two of them to the other side. Everything else is easy, but about those two little triangles that went to the same side; obviously, it doesn''t matter which of them gets drawn earlier, because they are on a same plane. They cannot be behind each others (unless they both would show as a thin line to the camera). The problem is: How can I prevent my program from trying to split one triangle with other, that lies on the same plane? Clearly nothing good comes out of that, if my program would try to perform that kind of splitting. The way I solved it: I have the equation of plane (that is used to split faces) Ax+By+Cz+D=0. I substitute cordinates of triangle corners into this, and check how close to zero Ax+By+Cz+D gets. If they all get close enough, I conclude that the face lies on the plane, and must not be splitted. I assumed, that the values would rarely be exactly zero (even if they should, mathematicly), so the problem is, that actually I don''t know how close they should be. I''ve tried 2e-4 and 2e-6 and so on... as allowed values. Any better ways to do this? Maybe this works, and my problems have come from somewhere else, but to me this looks the most probable cause for bugs right now.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
This really reminds me of a similar problem I have for a map compiler I made that builds a bsp tree and splits polygons like you are describing. You explanation is a little hazy but from what I can gather your problem lies in defining when a point is on the partitioning plane (the plane you are splitting the world with)

The solution I used was to assume that points that lie exactly on the partitioning plane are considered to be on neither side of the plane. So that when you are calculating if a polygon is inside a hyperplane you can say:

- classify the three points
- if none are out, the polygon is in the hyperplane
- if none are in, the polygon is not in the hyperplane
- if any are in and any are out, the polygon needs to be split

if you split, if 1 point is on the partioning plane, you only need to split your triangle into 2 triangles.

yea I eaplained it pretty badly but you probably get the idea

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Its been awhile since I have done any bsp stuff but..

Working out bsp.

1. Grab a triangle, calc its normal(face direction) and the distance the plane is from origin using that normal vector
2. Get next triangle and compare its 3 vertices to the bsp tree.
If all 3 points are infront of the plane at the bsp node then go down the "infront branch", if all 3 behind go down the "behind branch" and test against the next node on that branch.
If all 3 are on or are very near to the plane (very near is up to you to decide) then add the triangle to a linked list of triangles that fall on that plane ( this will help to reduce the depth of the tree and the time required to traverse it).
If 1 point infront, 1 behind, and 1 on the plane then spilt triangle into 2 triangles. Send those 2 triangles down the appropiate branches.
If 1 point infront/behind and other two are on opposite side of plane then split triangle into 3. send 1 down one branch and the other 2 down the other.
if 1 or 2 points lay on plane and other 1 or 2 points infront/behind, then count that traingle as being infront or behind depending on those two points.

Your problem may be stemming from the fact that 2 opposite facing triangles (ie both have the opposite normal) can still share the same plane. If i remember correctly ( i may be wrong ) you should use the normal of vector from the origin to the plane and not the face normal, (or it maybe use the face normal, not the origin vector I can''t remember ). Anyway try both aproaches and see if it helps after all 1 is right and the other wrong, or even maybe both are right! Its been a long time .

Spectre.

Share this post


Link to post
Share on other sites
Sounds like you have been reading old Quake 1 docs. Triangle splitting is depreciated. Quake 3 never splits triangles. It uses a different kind of BSP, a solid-space leafy BSP. This means that the splitting planes only split between solid and nonsolid space, and that once you end up in a leaf, yuo are in a convex room and the leaf holds all polygons that make up the walls of that cell.
This is a much easier way to approach a BSP. You can even separate the rendering from the space-division you use for collision.

Share this post


Link to post
Share on other sites
ok thanks,
I don''t know how long your posts were here, sorry, I can''t reply very quickly because I''m in military right now, and I cannot access my computer very often. Mostly on weekends only.

Actually I got my BSP-tree working, but unfortunately it required a little slow down. I tried to optimize my BSP-trees like this: I calculate the plane for a face A. I find a face B that lies partially on one side of the plane, and partially on other side. But then, before I started to split that face, I checked the maximun and minimun depth values for the face A and face B. And if it turned out, that face B was obviously farther away from the screen than face A (say, closest corner of face B lies on distance 10, and farthest away corner of face A lies on distance 5), then I decided to not split the face B, but instead just draw it before face A. Sounds smart way to optimize BSP-tree? Well, it doesn''t work. I''m not sure why, but I think it gets a bit more complicated than one would quickly assume. So, I switched that optimization off, and it started to work. Slower.

Linked lists for faces on the same plane! Yes, that is very smart, I''ll try to use that. I was considering some kind of array for those faces, but I couldn''t know how many faces there would be, so it wouldn''t have worked.

... and uh. Quake 3 solid-space leafy BSP sounded a bit too smart. Too smart because I didn''t understand them. Maybe I should try to find some tutorial stuff on that.

Yep, that was helpfull, thanks.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!