Additional tesselation tweaks
@@ -46,6 +46,7 @@ namespace carto {
}
void SphericalProjectionSurface::tesselateSegment(const MapPos& mapPos0, const MapPos& mapPos1, std::vector<MapPos>& mapPoses) const {
+ // TODO: make it faster, non-recursive
MapPos mapPosM;
if (SplitSegment(mapPos0, mapPos1, mapPosM)) {
tesselateSegment(mapPos0, mapPosM, mapPoses);
@@ -62,24 +63,25 @@ namespace carto {
const MapPos& mapPos1 = mapPoses.at(i1);
const MapPos& mapPos2 = mapPoses.at(i2);
+ // TODO: make it faster, non-recursive
MapPos mapPosM;
if (SplitSegment(mapPos0, mapPos1, mapPosM)) {
unsigned int iM = static_cast<int>(mapPoses.size());
mapPoses.push_back(mapPosM);
- tesselateTriangle(i0, iM, i2, indices, mapPoses);
- tesselateTriangle(iM, i1, i2, indices, mapPoses);
+ tesselateTriangle(i2, i0, iM, indices, mapPoses);
+ tesselateTriangle(i1, i2, iM, indices, mapPoses);
return;
} else if (SplitSegment(mapPos0, mapPos2, mapPosM)) {
unsigned int iM = static_cast<int>(mapPoses.size());
mapPoses.push_back(mapPosM);
tesselateTriangle(i0, i1, iM, indices, mapPoses);
- tesselateTriangle(iM, i1, i2, indices, mapPoses);
+ tesselateTriangle(i1, i2, iM, indices, mapPoses);
return;
} else if (SplitSegment(mapPos1, mapPos2, mapPosM)) {
unsigned int iM = static_cast<int>(mapPoses.size());
mapPoses.push_back(mapPosM);
tesselateTriangle(i0, i1, iM, indices, mapPoses);
- tesselateTriangle(iM, i2, i0, indices, mapPoses);
+ tesselateTriangle(i2, i0, iM, indices, mapPoses);
return;
}
@@ -145,8 +147,8 @@ namespace carto {
}
bool SphericalProjectionSurface::SplitSegment(const MapPos& mapPos0, const MapPos& mapPos1, MapPos& mapPosM) {
- cglib::vec3<double> pos0 = InternalToSpherical(mapPos0);
- cglib::vec3<double> pos1 = InternalToSpherical(mapPos1);
+ cglib::vec3<double> pos0 = cglib::unit(InternalToSpherical(mapPos0));
+ cglib::vec3<double> pos1 = cglib::unit(InternalToSpherical(mapPos1));
double dot = cglib::dot_product(pos0, pos1);
if (dot <= -1) {
return false; // exactly on the opposite side, no way to split
@@ -203,6 +205,6 @@ namespace carto {
const double SphericalProjectionSurface::PLANAR_APPROX_ANGLE = 1.0e-6;
- const double SphericalProjectionSurface::SEGMENT_SPLIT_THRESHOLD = Const::WORLD_SIZE / 500.0;
+ const double SphericalProjectionSurface::SEGMENT_SPLIT_THRESHOLD = Const::EARTH_CIRCUMFERENCE / 180.0;
}
