Still working on this problem ?
Do you remember the way i suggested to find the outline of those boxes ?
Step 1.ii does exactly that: test which sides are facing to the camera. For a convex shape like a box this is the visibility property you want. Except for overlapping with other shapes in the scene of course.1. Compute the outline of an object. Your objects - at least in your examples - are boxes. A box is convex, so computing its outline comes down to:
i. transform all vertices (8) to screen coordinates
ii. compute frontfacing/backfacing property of all faces (6). this can be done by either applying the winding rule to all vertice of each face, or by the sign of the z-component of the eye-space face normal.
iii. each edge (12) between two faces with different front-/backfacing property is part of the outline.
Be aware of the fact that the general case will have tree sides visible, but only two (when looking perpendicular at an axis of the box) or even a single one (when looking perpendicular at a side) are possible.
yes, before In order to get a bound of a bar. I transform all faces ( 6 faces) of the bar to screen coordinates then I union all polygons (6 polygon ) that made from the faces ( 6 faces) after transform tho screen coordinates.
but for now, I want to transform only visible faces
In order to determine if a given face is visible with respect to your camera placement you need to transform the face to eye space. Or, going the other way round, compute the inverse transformation and transform your camera into world space or even object space.
But you can exploit certain properties of your scene instead of solving your problem for the general case.
For example you seem to use a parallel projection and aligned boxes. This allows you to compute the visible sides of one box and be sure that all the other boxes will have the same sides visible.
So you will have to transform all faces of the first box (for visibility determination), but only the visible ones for the following boxes.
But you wont save too much on transformations. Look at your boxes: in the general case (three sides visible) you need seven of eight vertice anyway. Nevertheless, you will save the visibility determination on all but the first box.
Restricting the computation of the union of your screen space faces (6) to the visible ones (3) can save you half (!) the cpu cycles spend on that computation.