|Re: [AD] polygon_cull_criterion()|
[ Thread Index |
| More lists.liballeg.org/allegro-developers Archives
Christian Schler <cschueler@xxxxxxxxxx> writes:
> Allegro has a function called polygon_z_normal() in "math3d.c". This
> function alone is completely ok, but the docs say you can use it for
> backface culling. Sorry, this is downright wrong.
No, it's right. This method of backface culling is done after the
perspective projection: it just looks at the resulting 2d x/y coordinates
to decide whether the face should be culled.
If you want to cull before projection, it's more efficient to do this
with a dot product rather than cross product: use that to measure the
angle between the face normal and the vector from the eye position to the
face, and cull depending on the sign of the result.
> It is easy to prove that a face could be visible even if the return
> value of polygon_z_normal() is negative. "ex3d.c" does a workaround of
> this error in that it depth-sorts faces even if they should be culled
> and a per-face depth sorting should not be necessary.
ex3d is perfectly correct, as it culls after the projection. The depth
sort is only required to sort one cube against another. For an example of
culling before projection, see the 3d bit in test.c, which uses the dot
Shawn Hargreaves - shawn@xxxxxxxxxx - http://www.talula.demon.co.uk/
"A binary is barely software: it's more like hardware on a floppy disk."