I need a little help understanding wallgroups and how they are handled by the Infinity Engine. I would like to understand what set of rules the engine uses to determine if a wallgroup is rendered above or below a creature. I'm not sure because there are exceptions that contradict my current hypothesis yet apparently work fine according to DLTCEP tutorial, so something must be wrong with my understanding.
But a picture is better than a thousand words!

Ok, according to my understanding, here's how the engine determines if a creature is drawn in front of or behind an object like this brown block.
1/ The engine takes the polygon made by the level designer and assumes it is the area represented by the block.
2/ The blue line represents the baseline, every creature with its feet above this line is meant to be drawn below the block. If a creature's feet are below the line, draw it in front of the block.
3/ To be more precise, the engine takes the creature's feet X coordinates, and then checks which point of the base line has the same X coordinates. If the corresponding base line point has an Y coordinate higher than the creature's feet Y coord, draw the cre in front of the block. Draw it behind the block if the Y coordinate of the baseline point is lower (i.e. if the point is further down on the screen than cre's feet).
4/ What's the red dot's purpose? I'm not too sure.
My picture applies these rules, but as you can see in case 1, the orange guy is drawn wrong. So okay, maybe I used the wrong baseline? Well then in case 2, green guy definitely has something wrong now.
That means I don't understand correctly how the engine parses the polygons data (i.e. what algorithm, what rules it uses to determine who goes behind what).
Could someone please give me a hand?
PS: I doubt it, but maybe I'm correct and the engine would produce the same results as my picture when given the same polygon and baseline? (meaning I'm correct and have to break the brown block in two wallgroups for it to look good)
I doubt it because this is a plain convex polygon and I read these don't pose any problem provided the right baseline.











