static FILE *input_f;
static struct stat input_stab;
static const char *input_filename;
+static int pause_updates;
static void read_input(void) {
int r;
}
}
+static int vertex_in_triangles[N], vertex_in_triangles_checked;
+
static void addtriangle(int va, int vb, int vc) {
Triangle *t= &trisbuffer[ntris];
int k;
t->vertex[1][k]= conformation[vb][k];
t->vertex[2][k]= conformation[vc][k];
}
+ if (!vertex_in_triangles_checked) {
+ vertex_in_triangles[va]++;
+ vertex_in_triangles[vb]++;
+ vertex_in_triangles[vc]++;
+ }
displaylist[ntris++]= t;
}
static void generate_display_list(void) {
- int vb, ve[3], e;
+ int vb, ve[V6], e;
ntris= 0;
FOR_VERTEX(vb) {
- /* We use the two triangles in the parallelogram vb, vb+e0, vb+e1, vb+e2.
+ /* We use the two triangles in the parallelogram vb, vb+e5, vb+e0, vb+e1.
* We go round each triangle clockwise (although our surface is non-
- * orientable so it shouldn't matter).
+ * orientable so it shouldn't matter). Picking the parallelogram
+ * to our right avoids getting it wrong at the join.
*/
- for (e=0; e<3; e++) ve[e]= EDGE_END2(vb,e);
- if (ve[1]>=0) {
- if (ve[0]>=0) addtriangle(vb,ve[0],ve[1]);
- if (ve[2]>=0) addtriangle(vb,ve[1],ve[2]);
+//if ((vb & YMASK) > Y1) continue;
+//if ((vb & XMASK) > 2) continue;
+ for (e=0; e<V6; e++) ve[e]= EDGE_END2(vb,e);
+ assert(ve[0]>=0);
+ if (ve[5]>=0) addtriangle(vb,ve[0],ve[5]);
+//continue;
+ if (ve[1]>=0) addtriangle(vb,ve[1],ve[0]);
+ }
+
+ if (!vertex_in_triangles_checked) {
+ int v, expd;
+ FOR_VERTEX(v) {
+ expd= RIM_VERTEX_P(v) ? 3 : 6;
+ if (vertex_in_triangles[v] != expd) {
+ fprintf(stderr,"vertex %02x used for %d triangles, expected %d\n",
+ v, vertex_in_triangles[v], expd);
+// abort();
+ }
}
+ vertex_in_triangles_checked= 1;
}
}
static int dl_compare(const void *tav, const void *tbv) {
int i;
const Triangle *const *tap= tav, *ta= *tap;
- const Triangle *const *tbp= tbp, *tb= *tbp;
+ const Triangle *const *tbp= tbv, *tb= *tbp;
double za=0, zb=0;
for (i=0; i<3; i++) {
za += ta->vertex[i][2];
int i;
for (i=0; i<3; i++) {
- double *v= t->vertex[i];
+ const double *v= t->vertex[i];
double x= v[0];
double y= v[1];
double z= v[2];
static const unsigned long core_event_mask=
ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ButtonMotionMask|
- KeyPressMask;
+ KeyPressMask|SubstructureNotifyMask;
static void mkpixmaps(void) {
for (currentbuffer=0; currentbuffer<2; currentbuffer++) {
return;
}
- if (!strcmp(buf,"q")) exit(0);
- if (!strcmp(buf,"w")) {
+ if (!strcmp(buf,"q"))
+ exit(0);
+ else if (!strcmp(buf,"p"))
+ pause_updates= !pause_updates;
+ else if (!strcmp(buf,"w")) {
wireframe= !wireframe;
show();
return;
- }
- if (!strcmp(buf,"d")) {
+ } else if (!strcmp(buf,"d")) {
eyes_apart= eyes_apart>0 ? eyes_apart_min : eyes_apart_preferred;
show();
return;
+ } else {
+ printf("unknown key keycode=%d state=0x%x char=%c 0x%02x\n",
+ e->keycode, e->state, buf[0]>' ' && buf[0]<127 ? buf[0] : '?',
+ buf[0]);
}
}
show();
}
+static void topocheck(void) {
+ int v1,e,v2,eprime,v1prime, count;
+ FOR_EDGE(v1,e,v2) {
+ count= 0;
+ FOR_VEDGE(v2,eprime,v1prime)
+ if (v1prime==v1) count++;
+ if (count!=1) {
+ fprintf(stderr,"%02x -%d-> %02x reverse edge count = %d!\n",
+ v1,e,v2, count);
+ FOR_VEDGE(v2,eprime,v1prime)
+ fprintf(stderr,"%02x -%d-> %02x -> %d -> %02x\n",
+ v1,e,v2,eprime,v1prime);
+ exit(-1);
+ }
+ }
+}
+
int main(int argc, const char *const *argv) {
static const int wantedevents= POLLIN|POLLPRI|POLLERR|POLLHUP;
int k, i, r, *xfds, nxfds, polls_alloc=0;
struct pollfd *polls=0;
int motion_deferred=0, motion_x=-1, motion_y=-1;
+
+ topocheck();
+ if (argc==1) { printf("topology self-consistent, ok\n"); exit(0); }
if (argc != 2 || argv[1][0]=='-') {
fputs("need filename\n",stderr); exit(8);
polls[i].fd= ConnectionNumber(display);
polls[i].events= wantedevents;
- r= poll(polls, nxfds+1, motion_deferred ? 0 : 200);
- if (r<0) diee("poll");
+ r= poll(polls, nxfds+1, motion_deferred ? 0 : pause_updates ? -1 : 200);
+ if (r<0) {
+ if (errno==EINTR) continue;
+ diee("poll");
+ }
for (i=0; i<nxfds; i++)
if (polls[i].revents)
event_motion(motion_x, motion_y);
motion_deferred=0;
}
- check_input();
+ if (!pause_updates)
+ check_input();
continue;
}