This is a bit of a tricky question as I suspect the problem is a more technical C++ issue than a algorithm issue.
I understand that when drawing transparent objects it is desirable to sort them by distance from the viewer so that they are drawn on top of each other in the correct sequence i.e. draw the furthest away first followed by the next furthest away etc.
I have a C++ algorithm at work to do the sorting. I am making use of the standard template library. I have code which will calculate the distance of an object from the viewer. The transparent objects are stored in a vector. The objects are then taken out of this vector and put one by one into a map with the distance as the key. This results in my objects stored sorted by their distance. I then use a reverse iterator on the map to get the objects back out in distance order and put them back into the vector they came from.
The vector is iterated over in sequence when drawing. The problem is that my transparent objects start dissappearing one by one until there is only one left. Not good. I have used the debugger to trace through the algorithm and it works properly. The problem I think could be some kind of wierd concurrent modification problem where the timer animation routine and the rendering routine may both be trying to work on the same vector and the vector is going wrong.
I am going to try storing in a plain array and perhaps that will fix the problem. It makes me wonder how others go about sorting their transparent objects.



