*
* A spherical version of the Realtime Optimally-Adapting Meshes (ROAM)
* algorithm is use for drawing the surface of the planet. ROAM provide a
- * continuous level-of-detail mesh of the planet which is used by #GisOpenGL
- * when drawing surface textures for GisTiles.
+ * continuous level-of-detail mesh of the planet which is used by #GritsOpenGL
+ * when drawing surface textures for GritsTiles.
*
* This implementation of the ROAM algorithm is based on an octahedron as the
* base model.
#include <GL/glu.h>
#include "gpqueue.h"
-#include "gis-util.h"
+#include "grits-util.h"
#include "roam.h"
/*
if (neigh->t.l == old) neigh->t.l = new;
else if (neigh->t.b == old) neigh->t.b = new;
else if (neigh->t.r == old) neigh->t.r = new;
- else g_assert_not_reached();
}
static gboolean roam_triangle_visible(RoamTriangle *triangle, RoamSphere *sphere)
l->pz < 1 && m->pz < 1 && r->pz < 1;
}
+static gboolean roam_triangle_backface(RoamTriangle *triangle, RoamSphere *sphere)
+{
+ RoamPoint *l = triangle->p.l;
+ RoamPoint *m = triangle->p.m;
+ RoamPoint *r = triangle->p.r;
+ roam_point_update_projection(l, sphere->view);
+ roam_point_update_projection(m, sphere->view);
+ roam_point_update_projection(r, sphere->view);
+ double size = -( l->px * (m->py - r->py) +
+ m->px * (r->py - l->py) +
+ r->px * (l->py - m->py) ) / 2.0;
+ return size < 0;
+}
+
/**
* roam_triangle_update_errors:
* @triangle: the triangle
/* Size < 0 == backface */
triangle->error *= size;
+
+ /* Give some preference to "edge" faces */
+ if (roam_triangle_backface(triangle->t.l, sphere) ||
+ roam_triangle_backface(triangle->t.b, sphere) ||
+ roam_triangle_backface(triangle->t.r, sphere))
+ triangle->error *= 500;
}
}
b->kids[0] = b->kids[1] = NULL;
/* Add original triangles */
+ roam_triangle_sync_neighbors(s->t.l, sl, s);
+ roam_triangle_sync_neighbors(s->t.r, sr, s);
+ roam_triangle_sync_neighbors(b->t.l, bl, b);
+ roam_triangle_sync_neighbors(b->t.r, br, b);
+
roam_triangle_add(s, sl->t.b, b, sr->t.b, sphere);
roam_triangle_add(b, bl->t.b, s, br->t.b, sphere);