* Caches a set of polygons. * @param polygons Pointer to list of polygons. * @param cache Pointer to cache. */
| 945 | * @param cache Pointer to cache. |
| 946 | */ |
| 947 | void Globe::cache(std::list<Polygon*> *polygons, std::list<Polygon*> *cache) |
| 948 | { |
| 949 | // Clear existing cache |
| 950 | for (std::list<Polygon*>::iterator i = cache->begin(); i != cache->end(); ++i) |
| 951 | { |
| 952 | delete *i; |
| 953 | } |
| 954 | cache->clear(); |
| 955 | |
| 956 | // Pre-calculate values to cache |
| 957 | for (std::list<Polygon*>::iterator i = polygons->begin(); i != polygons->end(); ++i) |
| 958 | { |
| 959 | // Is quad on the back face? |
| 960 | double closest = 0.0; |
| 961 | double z; |
| 962 | double furthest = 0.0; |
| 963 | for (int j = 0; j < (*i)->getPoints(); ++j) |
| 964 | { |
| 965 | z = cos(_cenLat) * cos((*i)->getLatitude(j)) * cos((*i)->getLongitude(j) - _cenLon) + sin(_cenLat) * sin((*i)->getLatitude(j)); |
| 966 | if (z > closest) |
| 967 | closest = z; |
| 968 | else if (z < furthest) |
| 969 | furthest = z; |
| 970 | } |
| 971 | if (-furthest > closest) |
| 972 | continue; |
| 973 | |
| 974 | Polygon* p = new Polygon(**i); |
| 975 | |
| 976 | // Convert coordinates |
| 977 | for (int j = 0; j < p->getPoints(); ++j) |
| 978 | { |
| 979 | Sint16 x, y; |
| 980 | polarToCart(p->getLongitude(j), p->getLatitude(j), &x, &y); |
| 981 | p->setX(j, x); |
| 982 | p->setY(j, y); |
| 983 | } |
| 984 | |
| 985 | cache->push_back(p); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Replaces a certain amount of colors in the palette of the globe. |
nothing calls this directly
no test coverage detected