Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Depth sorting polys!

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    237

    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.

    Thanx in advance, XBTC!

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

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Germany
    Posts
    237

    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....

    Thanx in advance, XBTC!

  3. #3
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Depth sorting polys!

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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Aix en Provence, France
    Posts
    182

    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).
    -----
    Paddy
    Software Engineer
    I/O Labs

  5. #5
    Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Turin
    Posts
    269

    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...
    [rIO^sPINNING kIDS] - rio@nospam.spinningkids.org

    -/- This is a signature virus. Add it to your signature. Help it spreading! -/-

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Caracas/Venezuela
    Posts
    182

    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. #7
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    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.
    - Michael Steinberg

  8. #8
    Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    322

    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. #9
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Hannover, Germany
    Posts
    1,258

    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).]
    - Michael Steinberg

  10. #10
    Guest

    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
  •