X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Froam.c;h=e58cd1d6e3bbf34f99d555cbbe87dd3f359ce62d;hb=bcb44a16521757b93ace88c710a72ce7b3af1296;hp=768ca35a3100936ac1dae1f86f493eddb45db9c5;hpb=f383c18c9f85a1b439c6bfb2a27d652278ed019a;p=grits diff --git a/src/roam.c b/src/roam.c index 768ca35..e58cd1d 100644 --- a/src/roam.c +++ b/src/roam.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2010 Andy Spencer + * Copyright (C) 2009-2011 Andy Spencer * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,9 +31,8 @@ #include #include #include -#include -#include +#include "gtkgl.h" #include "gpqueue.h" #include "grits-util.h" #include "roam.h" @@ -206,27 +205,10 @@ RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r, // triangle->split->lat, l->lat); /* Update normal */ - double pa[3]; - double pb[3]; - pa[0] = triangle->p.l->x - triangle->p.m->x; - pa[1] = triangle->p.l->y - triangle->p.m->y; - pa[2] = triangle->p.l->z - triangle->p.m->z; - - pb[0] = triangle->p.r->x - triangle->p.m->x; - pb[1] = triangle->p.r->y - triangle->p.m->y; - pb[2] = triangle->p.r->z - triangle->p.m->z; - - triangle->norm[0] = pa[1] * pb[2] - pa[2] * pb[1]; - triangle->norm[1] = pa[2] * pb[0] - pa[0] * pb[2]; - triangle->norm[2] = pa[0] * pb[1] - pa[1] * pb[0]; - - double total = sqrt(triangle->norm[0] * triangle->norm[0] + - triangle->norm[1] * triangle->norm[1] + - triangle->norm[2] * triangle->norm[2]); - - triangle->norm[0] /= total; - triangle->norm[1] /= total; - triangle->norm[2] /= total; + crossd3((gdouble*)triangle->p.l, + (gdouble*)triangle->p.m, + (gdouble*)triangle->p.r, triangle->norm); + normd(triangle->norm); /* Store bounding box, for get_intersect */ RoamPoint *p[] = {l,m,r}; @@ -393,7 +375,7 @@ void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere) 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; + triangle->error *= 50; } } @@ -649,6 +631,7 @@ RoamSphere *roam_sphere_new() sphere->polys = 8; sphere->triangles = g_pqueue_new((GCompareDataFunc)tri_cmp, NULL); sphere->diamonds = g_pqueue_new((GCompareDataFunc)dia_cmp, NULL); + sphere->view = g_new0(RoamView, 1); RoamPoint *vertexes[] = { roam_point_new( 90, 0, 0), // 0 (North) @@ -702,8 +685,6 @@ RoamSphere *roam_sphere_new() */ void roam_sphere_update_view(RoamSphere *sphere) { - if (!sphere->view) - sphere->view = g_new0(RoamView, 1); glGetDoublev (GL_MODELVIEW_MATRIX, sphere->view->model); glGetDoublev (GL_PROJECTION_MATRIX, sphere->view->proj); glGetIntegerv(GL_VIEWPORT, sphere->view->view); @@ -719,11 +700,15 @@ void roam_sphere_update_view(RoamSphere *sphere) void roam_sphere_update_errors(RoamSphere *sphere) { g_debug("RoamSphere: update_errors - polys=%d", sphere->polys); + + static int version = 0; + if (version == sphere->view->version) + return; + version = sphere->view->version; + GPtrArray *tris = g_pqueue_get_array(sphere->triangles); GPtrArray *dias = g_pqueue_get_array(sphere->diamonds); - roam_sphere_update_view(sphere); - for (int i = 0; i < tris->len; i++) { RoamTriangle *triangle = tris->pdata[i]; roam_triangle_update_errors(triangle, sphere); @@ -777,6 +762,7 @@ void roam_sphere_merge_one(RoamSphere *sphere) gint roam_sphere_split_merge(RoamSphere *sphere) { gint iters = 0, max_iters = 500; + //gint target = 20000; //gint target = 4000; gint target = 2000; //gint target = 500;