home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / EXAMPLES / TEAPOT.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  16KB  |  559 lines

  1.  
  2. #include <stdio.h>
  3. #include "vogle.h"
  4.  
  5. #define USE_MOUSE 1
  6.  
  7. /*
  8.  *    Draws Newell's Teapot as a heap of Bezier surface patches.
  9.  */
  10.  
  11.  
  12. #define    TEAPOT        1
  13. #define    ESC        27
  14.  
  15. /*
  16.  *    Data for the teapot.
  17.  */
  18. #define    NUM_PNTS    306
  19. #define    NUM_PATCH    32 
  20.  
  21. float    xyz[NUM_PNTS][3] = {
  22.     { 1.400,   0.000,   2.400},
  23.     { 1.400,  -0.784,   2.400},
  24.     { 0.784,  -1.400,   2.400},
  25.     { 0.000,  -1.400,   2.400},
  26.     { 1.337,   0.000,   2.531},
  27.     { 1.337,  -0.749,   2.531},
  28.     { 0.749,  -1.337,   2.531},
  29.     { 0.000,  -1.337,   2.531},
  30.     { 1.438,   0.000,   2.531},
  31.     { 1.438,  -0.805,   2.531},
  32.     { 0.805,  -1.438,   2.531},
  33.     { 0.000,  -1.438,   2.531},
  34.     { 1.500,   0.000,   2.400},
  35.     { 1.500,  -0.840,   2.400},
  36.     { 0.840,  -1.500,   2.400},
  37.     { 0.000,  -1.500,   2.400},
  38.     {-0.784,  -1.400,   2.400},
  39.     {-1.400,  -0.784,   2.400},
  40.     {-1.400,   0.000,   2.400},
  41.     {-0.749,  -1.337,   2.531},
  42.     {-1.337,  -0.749,   2.531},
  43.     {-1.337,   0.000,   2.531},
  44.     {-0.805,  -1.438,   2.531},
  45.     {-1.438,  -0.805,   2.531},
  46.     {-1.438,   0.000,   2.531},
  47.     {-0.840,  -1.500,   2.400},
  48.     {-1.500,  -0.840,   2.400},
  49.     {-1.500,   0.000,   2.400},
  50.     {-1.400,   0.784,   2.400},
  51.     {-0.784,   1.400,   2.400},
  52.     { 0.000,   1.400,   2.400},
  53.     {-1.337,   0.749,   2.531},
  54.     {-0.749,   1.337,   2.531},
  55.     { 0.000,   1.337,   2.531},
  56.     {-1.438,   0.805,   2.531},
  57.     {-0.805,   1.438,   2.531},
  58.     { 0.000,   1.438,   2.531},
  59.     {-1.500,   0.840,   2.400},
  60.     {-0.840,   1.500,   2.400},
  61.     { 0.000,   1.500,   2.400},
  62.     { 0.784,   1.400,   2.400},
  63.     { 1.400,   0.784,   2.400},
  64.     { 0.749,   1.337,   2.531},
  65.     { 1.337,   0.749,   2.531},
  66.     { 0.805,   1.438,   2.531},
  67.     { 1.438,   0.805,   2.531},
  68.     { 0.840,   1.500,   2.400},
  69.     { 1.500,   0.840,   2.400},
  70.     { 1.750,   0.000,   1.875},
  71.     { 1.750,  -0.980,   1.875},
  72.     { 0.980,  -1.750,   1.875},
  73.     { 0.000,  -1.750,   1.875},
  74.     { 2.000,   0.000,   1.350},
  75.     { 2.000,  -1.120,   1.350},
  76.     { 1.120,  -2.000,   1.350},
  77.     { 0.000,  -2.000,   1.350},
  78.     { 2.000,   0.000,   0.900},
  79.     { 2.000,  -1.120,   0.900},
  80.     { 1.120,  -2.000,   0.900},
  81.     { 0.000,  -2.000,   0.900},
  82.     {-0.980,  -1.750,   1.875},
  83.     {-1.750,  -0.980,   1.875},
  84.     {-1.750,   0.000,   1.875},
  85.     {-1.120,  -2.000,   1.350},
  86.     {-2.000,  -1.120,   1.350},
  87.     {-2.000,   0.000,   1.350},
  88.     {-1.120,  -2.000,   0.900},
  89.     {-2.000,  -1.120,   0.900},
  90.     {-2.000,   0.000,   0.900},
  91.     {-1.750,   0.980,   1.875},
  92.     {-0.980,   1.750,   1.875},
  93.     { 0.000,   1.750,   1.875},
  94.     {-2.000,   1.120,   1.350},
  95.     {-1.120,   2.000,   1.350},
  96.     { 0.000,   2.000,   1.350},
  97.     {-2.000,   1.120,   0.900},
  98.     {-1.120,   2.000,   0.900},
  99.     { 0.000,   2.000,   0.900},
  100.     { 0.980,   1.750,   1.875},
  101.     { 1.750,   0.980,   1.875},
  102.     { 1.120,   2.000,   1.350},
  103.     { 2.000,   1.120,   1.350},
  104.     { 1.120,   2.000,   0.900},
  105.     { 2.000,   1.120,   0.900},
  106.     { 2.000,   0.000,   0.450},
  107.     { 2.000,  -1.120,   0.450},
  108.     { 1.120,  -2.000,   0.450},
  109.     { 0.000,  -2.000,   0.450},
  110.     { 1.500,   0.000,   0.225},
  111.     { 1.500,  -0.840,   0.225},
  112.     { 0.840,  -1.500,   0.225},
  113.     { 0.000,  -1.500,   0.225},
  114.     { 1.500,   0.000,   0.150},
  115.     { 1.500,  -0.840,   0.150},
  116.     { 0.840,  -1.500,   0.150},
  117.     { 0.000,  -1.500,   0.150},
  118.     {-1.120,  -2.000,   0.450},
  119.     {-2.000,  -1.120,   0.450},
  120.     {-2.000,   0.000,   0.450},
  121.     {-0.840,  -1.500,   0.225},
  122.     {-1.500,  -0.840,   0.225},
  123.     {-1.500,   0.000,   0.225},
  124.     {-0.840,  -1.500,   0.150},
  125.     {-1.500,  -0.840,   0.150},
  126.     {-1.500,   0.000,   0.150},
  127.     {-2.000,   1.120,   0.450},
  128.     {-1.120,   2.000,   0.450},
  129.     { 0.000,   2.000,   0.450},
  130.     {-1.500,   0.840,   0.225},
  131.     {-0.840,   1.500,   0.225},
  132.     { 0.000,   1.500,   0.225},
  133.     {-1.500,   0.840,   0.150},
  134.     {-0.840,   1.500,   0.150},
  135.     { 0.000,   1.500,   0.150},
  136.     { 1.120,   2.000,   0.450},
  137.     { 2.000,   1.120,   0.450},
  138.     { 0.840,   1.500,   0.225},
  139.     { 1.500,   0.840,   0.225},
  140.     { 0.840,   1.500,   0.150},
  141.     { 1.500,   0.840,   0.150},
  142.     {-1.600,   0.000,   2.025},
  143.     {-1.600,  -0.300,   2.025},
  144.     {-1.500,  -0.300,   2.250},
  145.     {-1.500,   0.000,   2.250},
  146.     {-2.300,   0.000,   2.025},
  147.     {-2.300,  -0.300,   2.025},
  148.     {-2.500,  -0.300,   2.250},
  149.     {-2.500,   0.000,   2.250},
  150.     {-2.700,   0.000,   2.025},
  151.     {-2.700,  -0.300,   2.025},
  152.     {-3.000,  -0.300,   2.250},
  153.     {-3.000,   0.000,   2.250},
  154.     {-2.700,   0.000,   1.800},
  155.     {-2.700,  -0.300,   1.800},
  156.     {-3.000,  -0.300,   1.800},
  157.     {-3.000,   0.000,   1.800},
  158.     {-1.500,   0.300,   2.250},
  159.     {-1.600,   0.300,   2.025},
  160.     {-2.500,   0.300,   2.250},
  161.     {-2.300,   0.300,   2.025},
  162.     {-3.000,   0.300,   2.250},
  163.     {-2.700,   0.300,   2.025},
  164.     {-3.000,   0.300,   1.800},
  165.     {-2.700,   0.300,   1.800},
  166.     {-2.700,   0.000,   1.575},
  167.     {-2.700,  -0.300,   1.575},
  168.     {-3.000,  -0.300,   1.350},
  169.     {-3.000,   0.000,   1.350},
  170.     {-2.500,   0.000,   1.125},
  171.     {-2.500,  -0.300,   1.125},
  172.     {-2.650,  -0.300,   0.938},
  173.     {-2.650,   0.000,   0.938},
  174.     {-2.000,  -0.300,   0.900},
  175.     {-1.900,  -0.300,   0.600},
  176.     {-1.900,   0.000,   0.600},
  177.     {-3.000,   0.300,   1.350},
  178.     {-2.700,   0.300,   1.575},
  179.     {-2.650,   0.300,   0.938},
  180.     {-2.500,   0.300,   1.125},
  181.     {-1.900,   0.300,   0.600},
  182.     {-2.000,   0.300,   0.900},
  183.     { 1.700,   0.000,   1.425},
  184.     { 1.700,  -0.660,   1.425},
  185.     { 1.700,  -0.660,   0.600},
  186.     { 1.700,   0.000,   0.600},
  187.     { 2.600,   0.000,   1.425},
  188.     { 2.600,  -0.660,   1.425},
  189.     { 3.100,  -0.660,   0.825},
  190.     { 3.100,   0.000,   0.825},
  191.     { 2.300,   0.000,   2.100},
  192.     { 2.300,  -0.250,   2.100},
  193.     { 2.400,  -0.250,   2.025},
  194.     { 2.400,   0.000,   2.025},
  195.     { 2.700,   0.000,   2.400},
  196.     { 2.700,  -0.250,   2.400},
  197.     { 3.300,  -0.250,   2.400},
  198.     { 3.300,   0.000,   2.400},
  199.     { 1.700,   0.660,   0.600},
  200.     { 1.700,   0.660,   1.425},
  201.     { 3.100,   0.660,   0.825},
  202.     { 2.600,   0.660,   1.425},
  203.     { 2.400,   0.250,   2.025},
  204.     { 2.300,   0.250,   2.100},
  205.     { 3.300,   0.250,   2.400},
  206.     { 2.700,   0.250,   2.400},
  207.     { 2.800,   0.000,   2.475},
  208.     { 2.800,  -0.250,   2.475},
  209.     { 3.525,  -0.250,   2.494},
  210.     { 3.525,   0.000,   2.494},
  211.     { 2.900,   0.000,   2.475},
  212.     { 2.900,  -0.150,   2.475},
  213.     { 3.450,  -0.150,   2.513},
  214.     { 3.450,   0.000,   2.513},
  215.     { 2.800,   0.000,   2.400},
  216.     { 2.800,  -0.150,   2.400},
  217.     { 3.200,  -0.150,   2.400},
  218.     { 3.200,   0.000,   2.400},
  219.     { 3.525,   0.250,   2.494},
  220.     { 2.800,   0.250,   2.475},
  221.     { 3.450,   0.150,   2.513},
  222.     { 2.900,   0.150,   2.475},
  223.     { 3.200,   0.150,   2.400},
  224.     { 2.800,   0.150,   2.400},
  225.     { 0.000,   0.000,   3.150},
  226.     { 0.000,  -0.002,   3.150},
  227.     { 0.002,   0.000,   3.150},
  228.     { 0.800,   0.000,   3.150},
  229.     { 0.800,  -0.450,   3.150},
  230.     { 0.450,  -0.800,   3.150},
  231.     { 0.000,  -0.800,   3.150},
  232.     { 0.000,   0.000,   2.850},
  233.     { 0.200,   0.000,   2.700},
  234.     { 0.200,  -0.112,   2.700},
  235.     { 0.112,  -0.200,   2.700},
  236.     { 0.000,  -0.200,   2.700},
  237.     {-0.002,   0.000,   3.150},
  238.     {-0.450,  -0.800,   3.150},
  239.     {-0.800,  -0.450,   3.150},
  240.     {-0.800,   0.000,   3.150},
  241.     {-0.112,  -0.200,   2.700},
  242.     {-0.200,  -0.112,   2.700},
  243.     {-0.200,   0.000,   2.700},
  244.     { 0.000,   0.002,   3.150},
  245.     {-0.800,   0.450,   3.150},
  246.     {-0.450,   0.800,   3.150},
  247.     { 0.000,   0.800,   3.150},
  248.     {-0.200,   0.112,   2.700},
  249.     {-0.112,   0.200,   2.700},
  250.     { 0.000,   0.200,   2.700},
  251.     { 0.450,   0.800,   3.150},
  252.     { 0.800,   0.450,   3.150},
  253.     { 0.112,   0.200,   2.700},
  254.     { 0.200,   0.112,   2.700},
  255.     { 0.400,   0.000,   2.550},
  256.     { 0.400,  -0.224,   2.550},
  257.     { 0.224,  -0.400,   2.550},
  258.     { 0.000,  -0.400,   2.550},
  259.     { 1.300,   0.000,   2.550},
  260.     { 1.300,  -0.728,   2.550},
  261.     { 0.728,  -1.300,   2.550},
  262.     { 0.000,  -1.300,   2.550},
  263.     { 1.300,   0.000,   2.400},
  264.     { 1.300,  -0.728,   2.400},
  265.     { 0.728,  -1.300,   2.400},
  266.     { 0.000,  -1.300,   2.400},
  267.     {-0.224,  -0.400,   2.550},
  268.     {-0.400,  -0.224,   2.550},
  269.     {-0.400,   0.000,   2.550},
  270.     {-0.728,  -1.300,   2.550},
  271.     {-1.300,  -0.728,   2.550},
  272.     {-1.300,   0.000,   2.550},
  273.     {-0.728,  -1.300,   2.400},
  274.     {-1.300,  -0.728,   2.400},
  275.     {-1.300,   0.000,   2.400},
  276.     {-0.400,   0.224,   2.550},
  277.     {-0.224,   0.400,   2.550},
  278.     { 0.000,   0.400,   2.550},
  279.     {-1.300,   0.728,   2.550},
  280.     {-0.728,   1.300,   2.550},
  281.     { 0.000,   1.300,   2.550},
  282.     {-1.300,   0.728,   2.400},
  283.     {-0.728,   1.300,   2.400},
  284.     { 0.000,   1.300,   2.400},
  285.     { 0.224,   0.400,   2.550},
  286.     { 0.400,   0.224,   2.550},
  287.     { 0.728,   1.300,   2.550},
  288.     { 1.300,   0.728,   2.550},
  289.     { 0.728,   1.300,   2.400},
  290.     { 1.300,   0.728,   2.400},
  291.     { 0.000,   0.000,   0.000},
  292.     { 1.500,   0.000,   0.150},
  293.     { 1.500,   0.840,   0.150},
  294.     { 0.840,   1.500,   0.150},
  295.     { 0.000,   1.500,   0.150},
  296.     { 1.500,   0.000,   0.075},
  297.     { 1.500,   0.840,   0.075},
  298.     { 0.840,   1.500,   0.075},
  299.     { 0.000,   1.500,   0.075},
  300.     { 1.425,   0.000,   0.000},
  301.     { 1.425,   0.798,   0.000},
  302.     { 0.798,   1.425,   0.000},
  303.     { 0.000,   1.425,   0.000},
  304.     {-0.840,   1.500,   0.150},
  305.     {-1.500,   0.840,   0.150},
  306.     {-1.500,   0.000,   0.150},
  307.     {-0.840,   1.500,   0.075},
  308.     {-1.500,   0.840,   0.075},
  309.     {-1.500,   0.000,   0.075},
  310.     {-0.798,   1.425,   0.000},
  311.     {-1.425,   0.798,   0.000},
  312.     {-1.425,   0.000,   0.000},
  313.     {-1.500,  -0.840,   0.150},
  314.     {-0.840,  -1.500,   0.150},
  315.     { 0.000,  -1.500,   0.150},
  316.     {-1.500,  -0.840,   0.075},
  317.     {-0.840,  -1.500,   0.075},
  318.     { 0.000,  -1.500,   0.075},
  319.     {-1.425,  -0.798,   0.000},
  320.     {-0.798,  -1.425,   0.000},
  321.     { 0.000,  -1.425,   0.000},
  322.     { 0.840,  -1.500,   0.150},
  323.     { 1.500,  -0.840,   0.150},
  324.     { 0.840,  -1.500,   0.075},
  325.     { 1.500,  -0.840,   0.075},
  326.     { 0.798,  -1.425,   0.000},
  327.     { 1.425,  -0.798,   0.000}
  328. };
  329.  
  330. int    patches[NUM_PATCH][16] = {
  331.     {  1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  13,  14,  15,  16},
  332.     {  4,  17,  18,  19,   8,  20,  21,  22,  12,  23,  24,  25,  16,  26,  27,  28},
  333.     { 19,  29,  30,  31,  22,  32,  33,  34,  25,  35,  36,  37,  28,  38,  39,  40},
  334.     { 31,  41,  42,   1,  34,  43,  44,   5,  37,  45,  46,   9,  40,  47,  48,  13},
  335.     { 13,  14,  15,  16,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60},
  336.     { 16,  26,  27,  28,  52,  61,  62,  63,  56,  64,  65,  66,  60,  67,  68,  69},
  337.     { 28,  38,  39,  40,  63,  70,  71,  72,  66,  73,  74,  75,  69,  76,  77,  78},
  338.     { 40,  47,  48,  13,  72,  79,  80,  49,  75,  81,  82,  53,  78,  83,  84,  57},
  339.     { 57,  58,  59,  60,  85,  86,  87,  88,  89,  90,  91,  92,  93,  94,  95,  96},
  340.     { 60,  67,  68,  69,  88,  97,  98,  99,  92, 100, 101, 102,  96, 103, 104, 105},
  341.     { 69,  76,  77,  78,  99, 106, 107, 108, 102, 109, 110, 111, 105, 112, 113, 114},
  342.     { 78,  83,  84,  57, 108, 115, 116,  85, 111, 117, 118,  89, 114, 119, 120,  93},
  343.     {121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136},
  344.     {124, 137, 138, 121, 128, 139, 140, 125, 132, 141, 142, 129, 136, 143, 144, 133},
  345.     {133, 134, 135, 136, 145, 146, 147, 148, 149, 150, 151, 152,  69, 153, 154, 155},
  346.     {136, 143, 144, 133, 148, 156, 157, 145, 152, 158, 159, 149, 155, 160, 161,  69},
  347.     {162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177},
  348.     {165, 178, 179, 162, 169, 180, 181, 166, 173, 182, 183, 170, 177, 184, 185, 174},
  349.     {174, 175, 176, 177, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197},
  350.     {177, 184, 185, 174, 189, 198, 199, 186, 193, 200, 201, 190, 197, 202, 203, 194},
  351.     {204, 204, 204, 204, 207, 208, 209, 210, 211, 211, 211, 211, 212, 213, 214, 215},
  352.     {204, 204, 204, 204, 210, 217, 218, 219, 211, 211, 211, 211, 215, 220, 221, 222},
  353.     {204, 204, 204, 204, 219, 224, 225, 226, 211, 211, 211, 211, 222, 227, 228, 229},
  354.     {204, 204, 204, 204, 226, 230, 231, 207, 211, 211, 211, 211, 229, 232, 233, 212},
  355.     {212, 213, 214, 215, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245},
  356.     {215, 220, 221, 222, 237, 246, 247, 248, 241, 249, 250, 251, 245, 252, 253, 254},
  357.     {222, 227, 228, 229, 248, 255, 256, 257, 251, 258, 259, 260, 254, 261, 262, 263},
  358.     {229, 232, 233, 212, 257, 264, 265, 234, 260, 266, 267, 238, 263, 268, 269, 242},
  359.     {270, 270, 270, 270, 279, 280, 281, 282, 275, 276, 277, 278, 271, 272, 273, 274},
  360.     {270, 270, 270, 270, 282, 289, 290, 291, 278, 286, 287, 288, 274, 283, 284, 285},
  361.     {270, 270, 270, 270, 291, 298, 299, 300, 288, 295, 296, 297, 285, 292, 293, 294},
  362.     {270, 270, 270, 270, 300, 305, 306, 279, 297, 303, 304, 275, 294, 301, 302, 271}
  363. };
  364.  
  365.  
  366. /*
  367.  * patch basis type
  368.  */
  369.  
  370. Matrix    bezier = {
  371.     {-1.0,    3.0,    -3.0,    1.0},
  372.     {3.0,    -6.0,    3.0,    0.0},
  373.     {-3.0,    3.0,    0.0,    0.0},
  374.     {1.0,    0.0,    0.0,    0.0} 
  375. };
  376.  
  377. Matrix    x, y, z;
  378.  
  379. extern    int    atoi();
  380.  
  381. main(argc, argv)
  382.     int    argc;
  383.     char    **argv;
  384. {
  385.     char    dev[20];
  386.     int    but, i, j, k, params[4];
  387.     float    sx, sy;
  388.  
  389. #ifndef USE_MOUSE
  390.     fprintf(stderr, "Using %s:\n\n", argv[0]);
  391.  
  392.     fprintf(stderr, "Use the 'q' key to quit\n");
  393.     fprintf(stderr, "Use the 'x' key to rotate about x\n");
  394.     fprintf(stderr, "Use the 'y' key to rotate about y\n");
  395.     fprintf(stderr, "Use the 'z' key to rotate about z\n");
  396.     fprintf(stderr, "Use the 'e' key to enlarge\n");
  397.     fprintf(stderr, "Use the 'r' key to reduce\n");
  398.     fprintf(stderr, "Use the 'p' key to produce a postscript file\n");
  399.     fprintf(stderr, "   of the current view (teapot.ps)\n");
  400.     fprintf(stderr, "Use the 'h' key to produce a hpgl file\n");
  401.     fprintf(stderr, "   of the current view (teapot.hp)\n\n");
  402. #endif
  403.  
  404.     fprintf(stderr,"Enter output device: ");
  405.     gets(dev);
  406.  
  407.     params[0] = params[1] = 4;
  408.     params[2] = params[3] = 6;
  409.  
  410.     if (argc > 2) 
  411.         for (i = 2; i < argc; i++)
  412.             params[i - 2] = atoi(argv[i]);
  413.  
  414.     vinit(dev);          /* set up device */
  415.  
  416.     color(BLACK);
  417.     clear();
  418.  
  419.     window(-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
  420.     lookat(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0);
  421.  
  422.     patchcurves(params[0], params[1]);
  423.     patchprecision(params[2], params[3]);
  424.     patchbasis(bezier, bezier);
  425.  
  426.     /*
  427.      * Make an object with the teapot in it.
  428.      */
  429.  
  430.     makeobj(TEAPOT);
  431.         color(CYAN);
  432.         for (i = 0; i < NUM_PATCH; i++) {
  433.             /*
  434.              * Set up geometry arrays...
  435.              */
  436.             for (j = 0; j < 4; j++) {
  437.                 x[0][j] = xyz[patches[i][j] - 1][0];
  438.                 x[1][j] = xyz[patches[i][j + 4] - 1][0];
  439.                 x[2][j] = xyz[patches[i][j + 8] - 1][0];
  440.                 x[3][j] = xyz[patches[i][j + 12] - 1][0];
  441.  
  442.                 y[0][j] = xyz[patches[i][j] - 1][1];
  443.                 y[1][j] = xyz[patches[i][j + 4] - 1][1];
  444.                 y[2][j] = xyz[patches[i][j + 8] - 1][1];
  445.                 y[3][j] = xyz[patches[i][j + 12] - 1][1];
  446.  
  447.                 z[0][j] = xyz[patches[i][j] - 1][2];
  448.                 z[1][j] = xyz[patches[i][j + 4] - 1][2];
  449.                 z[2][j] = xyz[patches[i][j + 8] - 1][2];
  450.                 z[3][j] = xyz[patches[i][j + 12] - 1][2];
  451.             }
  452.             /*
  453.              * Draw it...
  454.              */
  455.             patch(x, y, z);
  456.         }
  457.     closeobj();
  458.  
  459.     backbuffer();
  460.  
  461.     while (1) {
  462. #ifdef USE_MOUSE
  463.         but = slocator(&sx, &sy);
  464.         switch(but) {
  465.         case 1:
  466.             rotate(90.0 * sx, 'x');
  467.             break;
  468.         case 2:
  469.             rotate(90.0 * sx, 'y');
  470.             break;
  471.         case 4:
  472.             rotate(90.0 * sx, 'z');
  473.             break;
  474.         default:
  475.             ;
  476.         }
  477.         pushmatrix();
  478.             rotate(90.0 * sx, 'y');
  479.             rotate(90.0 * sy, 'z');
  480.             translate(0.0, 0.0, -1.5);
  481.             color(BLACK);
  482.             clear();
  483.             callobj(TEAPOT);
  484.                 popmatrix();
  485.         swapbuffers();
  486.  
  487.         switch (checkkey()) {
  488.         case 'q':    /* Stop the program */
  489.         case ESC:
  490.             vexit();
  491.             exit(0);
  492.         case 'e':    /* Enlarge */
  493.             scale(1.1, 1.1, 1.1);
  494.             break;
  495.  
  496.         case 'r':    /* Reduce */
  497.             scale(0.9, 0.9, 0.9);
  498.             break;
  499.  
  500.         default:
  501.             ;
  502.         }
  503. #else
  504.         color(BLACK);
  505.         clear();
  506.  
  507.         callobj(TEAPOT);
  508.  
  509.         swapbuffers();
  510.  
  511.         switch (getkey()) {
  512.         case 'q':    /* Stop the program */
  513.         case ESC:
  514.             vexit();
  515.             exit(0);
  516.  
  517.         case 'p':    /* Do a postscript plot of it */
  518.             voutput("teapot.ps");
  519.             vnewdev("postscript");
  520.             fprintf(stderr,"Producing POSTSCRIPT output on file teapot.ps\n");
  521.             callobj(TEAPOT);
  522.             vnewdev(dev);
  523.             break;
  524.  
  525.         case 'h':    /* Do a hpgl plot of it */
  526.             voutput("teapot.hp");
  527.             vnewdev("hpgl");
  528.             fprintf(stderr,"Producing HPGL output on file teapot.hp\n");
  529.             callobj(TEAPOT);
  530.             vnewdev(dev);
  531.             break;
  532.  
  533.         case 'x':    /* Obvious isn't it */
  534.             rotate(10.0, 'x');
  535.             break;
  536.  
  537.         case 'y':
  538.             rotate(10.0, 'y');
  539.             break;
  540.  
  541.         case 'z':
  542.             rotate(10.0, 'z');
  543.             break;
  544.  
  545.         case 'e':    /* Enlarge */
  546.             scale(1.1, 1.1, 1.1);
  547.             break;
  548.  
  549.         case 'r':    /* Reduce */
  550.             scale(0.9, 0.9, 0.9);
  551.             break;
  552.  
  553.         default:
  554.             ;
  555.         }
  556. #endif
  557.     }
  558. }
  559.