# The Industry's Foundation for High Performance Graphics

1. ## Depth sorting polys!

Hi!
Is there a fast + accurate method to depth sort transparent polys if I donīt have the center of the poly?
The actual sorting is no prob I do it with qsort()....
What I need to know is how to calc the distance between the player and the poly.
I tried it with the plane equation but this dosnīt work in some cases(You can be infinetly far away of the poly but still be very near to itīs plane).

Any ideas?

P.s.: I did a search already but I dinīt find what I wanted.

[This message has been edited by XBCT (edited 01-26-2001).]

2. ## Re: Depth sorting polys!

Hi!
I tried it with the following method now:
I calculate the average of the distances between the player and the polyīs vertices.
This gives me correct results, but I think itīs a waste of processing power....There has to be a faster solution....

3. ## Re: Depth sorting polys!

Are the polygons static or dynamic? If they are static you could easily solve it with a BSP tree.

4. ## Re: Depth sorting polys!

You could also calculate the distance from the player to all the vertices of the polygon and use the shortest one (which shows the minimum distance between player and polygon).

5. ## Re: Depth sorting polys!

Just an "optimization" :
U can use bounding "things" (these days there are lot of bounding shapes around! )
and just calculate the distance between the nearest bounding vertex or the bounding center.

Maybe what I'm saying is useless...

6. ## Re: Depth sorting polys!

I think if you want to sort polys correctly, you should test sorting using the projected Z coord of the closets vertex of the object, rather than the distance, so you get correct sorting when objects are in the corners of the screen.

7. ## Re: Depth sorting polys!

Actually, getting the correct distance of a vertex from the near culling plane is easy to implement, more correct for opengl and faster to accomplish than sqrt( x*x+y*y+z*z ).

You have the unit normal vector of the near plane, a point which lies on the near plane. Then the distance is d=(p-q)*n. (Or was it q-p?) Where q is the point on the plane, p the vertex to test and n the unit normal.

8. ## Re: Depth sorting polys!

And you're saying that the resultant 'd' variable would be a vertex? So how do you descern the distance from the vertex? Is the resultant vertex an un-normalized vector or something? What do you do with it once you have it? If you're supposed to then find the length of it, then you havn't saved any CPU at all because you'd have to do a sqrt(x^2+y^2+z^2) anyway. However, I'm sure this isn't what you mean. Please explain as this sounds very interesting. Thanks!

9. ## Re: Depth sorting polys!

No, since p, q and n are vectors (or more correctly, p and q are the place-vectors of points P and Q), the result of the multiplication (in german we call this vector product Skalarprodukt) of two vectors is a scalar. A simple float for example. A simple value for a simple distance.

To get it sorted out:
a*b = a1*b1+a2*b2+a3*b3

Where a and b are vectors of the room R3 I think it is called.

If you divide this product by the product of the lengths of a and b, you'll get the cosine of the (smallest!) angle between these two vectors btw...

[This message has been edited by Michael Steinberg (edited 01-26-2001).]

10. ## Re: Depth sorting polys!

Averaging the vertex coords (the simple
barycenter of the vertexes) is a pretty good
number to use, and isn't that expensive;
especially if you know the number of vertexes
and multiply by the reciprocal instead of
doing a division.

Another way which may very well be good
enough is to just pick one vertex (say, the
first) -- if your billboarding and other
transparent geometry is far enough apart,
this will work quite sufficiently.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•