/* * cylinder drawing demo * * FUNCTION: * Basic demo illustrating how to write code to draw * the most basic cylinder shape. * * HISTORY: * Linas Vepstas March 1995 * Copyright (c) 1995 Linas Vepstas * * Hacked quite a bit to draw borromean rings embedded * in an icosahedron * Copyright (c) 2003 * Kapil Hari Paranjape * */ /* required include files */ #include #include #include #include #include "main.h" /* the arrays in which we will store the rings */ #define RINGPTS 8 double ring1 [RINGPTS][3]; double ring2 [RINGPTS][3]; double ring3 [RINGPTS][3]; float coloring1 [RINGPTS][3]; float coloring2 [RINGPTS][3]; float coloring3 [RINGPTS][3]; /* The remaining 8 triangles of the icosahedron */ /* Each side is split to incorporate the twisted extrusion */ #define TSPLIT 34 #define TRIPTS 105 /* 3+3*TSPLIT */ double triangle [8] [TRIPTS][3]; float colortri [TRIPTS][3]; /* Contour business */ double twisttri [TRIPTS]; #define CONTPTS 69 double contour [CONTPTS][2]; double contnorm [CONTPTS][2]; double uptri [8] [3]; /* some utilities for filling that array */ #define PNT(points,x,y,z) { \ points[idx][0] = x; \ points[idx][1] = y; \ points[idx][2] = z; \ idx ++; \ } #define COL(colors,r,g,b) { \ colors[idx][0] = r; \ colors[idx][1] = g; \ colors[idx][2] = b; \ } #define PLN(cont,norm,x,y,xn,yn) { \ cont[idx][0] = x; \ cont[idx][1] = y; \ norm[idx][0] = xn; \ norm[idx][1] = yn; \ idx ++; \ } /* * NOTE that neither the first, nor the last segment are drawn. * The first & last segment serve only to determine that angle * at which the endcaps are drawn. */ void InitStuff (void) { int i, j, sgnx, sgny, sgnz; int idx = 0; /* The important lengths */ double short_side; /* Short side of Golden rectangle */ double long_side; /* Long side of Golden rectangle */ /* Initialize lengths */ long_side = 6.0*(sqrt(5.0)+1.0)/2.0; short_side = 6.0; /* initialize the join style here */ gleSetJoinStyle (TUBE_NORM_EDGE | TUBE_JN_ROUND | TUBE_JN_CAP); /* Ring one */ idx=0; PNT (ring1, -short_side, long_side, 0.0); PNT (ring1, short_side, long_side, 0.0); PNT (ring1, short_side, -long_side, 0.0); PNT (ring1, -short_side, -long_side, 0.0); PNT (ring1, -short_side, long_side, 0.0); PNT (ring1, short_side, long_side, 0.0); PNT (ring1, short_side, -long_side, 0.0); PNT (ring1, -short_side, -long_side, 0.0); /* Ring Colors */ for(idx=0;idx < RINGPTS;++idx){ COL (coloring1, 0.2, 0.2, 0.8); } /* First and last edge are not drawn and are * used only to fix the capping shapes */ idx=0; COL (coloring1, 0.0, 0.0, 0.0); idx=RINGPTS-1; COL (coloring1, 0.0, 0.0, 0.0); /* Ring two */ idx=0; PNT (ring2, 0.0, -short_side, long_side); PNT (ring2, 0.0, short_side, long_side); PNT (ring2, 0.0, short_side, -long_side); PNT (ring2, 0.0, -short_side, -long_side); PNT (ring2, 0.0, -short_side, long_side); PNT (ring2, 0.0, short_side, long_side); PNT (ring2, 0.0, short_side, -long_side); PNT (ring2, 0.0, -short_side, -long_side); /* Ring Colors */ for(idx=0;idx < RINGPTS;++idx){ COL (coloring2, 0.8, 0.2, 0.2); } /* First and last edge are not drawn and are * used only to fix the capping shapes */ idx=0; COL (coloring2, 0.0, 0.0, 0.0); idx=RINGPTS-1; COL (coloring2, 0.0, 0.0, 0.0); /* Ring three */ idx=0; PNT (ring3, long_side, 0.0, -short_side); PNT (ring3, long_side, 0.0, short_side); PNT (ring3, -long_side, 0.0, short_side); PNT (ring3, -long_side, 0.0, -short_side); PNT (ring3, long_side, 0.0, -short_side); PNT (ring3, long_side, 0.0, short_side); PNT (ring3, -long_side, 0.0, short_side); PNT (ring3, -long_side, 0.0, -short_side); /* Ring Colors */ for(idx=0;idx < RINGPTS;++idx){ COL (coloring3, 0.2, 0.8, 0.2); } /* First and last edge are not drawn and are * used only to fix the capping shapes */ idx=0; COL (coloring3, 0.0, 0.0, 0.0); idx=RINGPTS-1; COL (coloring3, 0.0, 0.0, 0.0); /* Triangles */ for(idx=0;idx < TRIPTS;++idx){ /* COL (colortri, 0.5, 0.2, 0.2); */ /* COL (colortri, 1.0, 0.4, 0.4); */ COL (colortri, 0.4, 0.4, 0.4); } /* First and last edge are not drawn and are * used only to fix the capping shapes */ idx=0; COL (colortri, 0.0, 0.0, 0.0); idx=TRIPTS-1; COL (colortri, 0.0, 0.0, 0.0); for( i=0; i < 8 ; ++i){ /* One triangle in each quadrant * so we us the binary bits of the * index to decide the quadrant */ sgnx = (i & 1) ? 1 : -1; sgny = (i & 2) ? 1 : -1; sgnz = (i & 4) ? 1 : -1; idx=0; /* Start with dummy side */ PNT (triangle[i], sgnx*short_side, sgnz*long_side, sgny*0.0); for(j=0; j