7.3 A rotating polygon in animation 211
in Chapter 8 we will see that the menu of available graphics functions and
system dependencies increases considerably with the size and sophistication of
the graphics library.
Interactive drawing of an icosahedron
An icosahedron is a polyhedron with twenty triangular faces defined by
twelve unique vertices. The mapping of faces to vertices is mediated through a
connectivity table.
The following code contained in the filelicosa.ccand adapted from an
example given in theVogledistribution draws an icosahedron and uses the
mouse and keyboard to implement interactive rotation and translation:
include<iostream>
#include "VOGLE/voglec++.h"
#define TRANS 0.06
void drawshape(int fill);
//--- main
int main()
{
char device[10];
float x, y, tdir = TRANS;
int but, nplanes;
int i;
//--- Initiate the graphics window:
prefposition(50, 50);
prefsize(300, 300);
vinit("X11");
nplanes = getdepth(); // color depth
window(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
lookat(0.0, 0.0, 2.1, 0.0, 0.0, 0.0, 0.0);
textsize(0.15, 0.3);
backface(1);
backbuffer();
//--- Green color map:
for (i=1; i<=20; i++)
{
mapcolor(i, 20, 20+i*10, 20);
}