home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Indicators.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  6.2 KB  |  312 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include "Indicators.h"
  18. #include "Render.h"
  19.  
  20. void draw_needle(Boolean draw_it)
  21. {
  22.     static float data1_1[][3] = {
  23.         {-12.0, 0.0, 0.0}, {-11.0, -1.0, 0.0}, {-11.0, 0.0, 0.0}};
  24.     static float data1_2[][3] = {
  25.         {-11.0, -1.0, 0.0}, {0.0,-1.0,0.0}, {0.0, 0.0,0.0}, {-11.0, 0.0, 0.0}};
  26.     static float data1_3[][3] = {
  27.         {0.0, -1.0, 0.0}, {1.0, -1.0, 0.0}, {0.0, 0.0, 0.0}};
  28.  
  29.     static float data2_1[][3] = {
  30.         {-12.0, 0.0, 0.0}, {-11.0, 0.0, 0.0}, {-11.0, 1.0, 0.0}};
  31.     static float data2_2[][3] = {
  32.         {-11.0, 0.0, 0.0}, {0.0,0.0,0.0}, {0.0, 1.0,0.0}, {-11.0, 1.0, 0.0}};
  33.     static float data2_3[][3] = {
  34.         {0.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0}};
  35.  
  36.     static float data3[][3] = {
  37.         {0.0, 0.0, 0.0}, {1.0, -1.0, 0.0}, {1.0, 1.0, 0.0}};
  38.  
  39.     if (!draw_it)
  40.         color(CLEAR);
  41.  
  42.     pushmatrix();
  43.     
  44.     scale(1.0/12.0,1.0/12.0,1.0/12.0);
  45.     
  46.     if (draw_it)
  47.         color(GREY1);
  48.     bgnpolygon();
  49.         v3f(data1_1[0]);
  50.         v3f(data1_1[1]);
  51.         v3f(data1_1[2]);
  52.     endpolygon();
  53.     bgnpolygon();
  54.         v3f(data1_2[0]);
  55.         v3f(data1_2[1]);
  56.         v3f(data1_2[2]);
  57.         v3f(data1_2[3]);
  58.     endpolygon();
  59.     bgnpolygon();
  60.         v3f(data1_3[0]);
  61.         v3f(data1_3[1]);
  62.         v3f(data1_3[2]);
  63.     endpolygon();
  64.     
  65.     if (draw_it)
  66.         color(GREY2);
  67.     bgnpolygon();
  68.         v3f(data2_1[0]);
  69.         v3f(data2_1[1]);
  70.         v3f(data2_1[2]);
  71.     endpolygon();
  72.     bgnpolygon();
  73.         v3f(data2_2[0]);
  74.         v3f(data2_2[1]);
  75.         v3f(data2_2[2]);
  76.         v3f(data2_2[3]);
  77.     endpolygon();
  78.     bgnpolygon();
  79.         v3f(data2_3[0]);
  80.         v3f(data2_3[1]);
  81.         v3f(data2_3[2]);
  82.     endpolygon();
  83.     
  84.     if (draw_it)
  85.         color(GREY3);
  86.     bgnpolygon();
  87.         v3f(data3[0]);
  88.         v3f(data3[1]);
  89.         v3f(data3[2]);
  90.     endpolygon();
  91.  
  92.     popmatrix();
  93. }
  94.  
  95.  
  96. // Draws a generic counter-clockwise dial.
  97. // Leaves the font set appropriate for gage units labelling.
  98. void draw_dial(
  99.     float world_diam, 
  100.     float world_per_pixel,
  101.     float start_angle, float end_angle,
  102.     float small_tick_size, float big_tick_size,
  103.     float label_pos,
  104.     int start_value, int end_value,
  105.     int small_tick_increment,
  106.     float label_multiplier,
  107.     int small_ticks_per_big_tick,
  108.     int big_ticks_per_label)
  109. {
  110.     static float outside[2], small[2], big[2], label[2];
  111.  
  112.     // starting locations at zero degrees (pos-x axis)
  113.     outside[0] = world_diam;
  114.     outside[1] = 0.0;
  115.  
  116.     small[0] = small_tick_size*world_diam;
  117.     small[1] = 0.0;
  118.  
  119.     big[0] = big_tick_size*world_diam;
  120.     big[1] = 0.0;
  121.  
  122.     float angle_step = 
  123.     (start_angle - end_angle)/((float)end_value/(float)small_tick_increment);
  124.         
  125.     float angle = start_angle;
  126.     
  127.     fmfonthandle font1 = fmfindfont("Hlv");
  128.     float pnt_size = (world_diam/world_per_pixel)/10.0;
  129.     fmfonthandle font = fmscalefont(font1, pnt_size);
  130.     fmsetfont(font);
  131.  
  132.     int small_tick_count = 0;
  133.     int big_tick_count = 0;
  134.  
  135.     for (int i = start_value; i <= end_value; i += small_tick_increment)
  136.     {
  137.         // draw major tick?
  138.         if (small_tick_count++%small_ticks_per_big_tick == 0)
  139.         {
  140.             pushmatrix();
  141.                 rot(angle,'z');
  142.                 cpack(ORANGE);
  143.                 bgnline();
  144.                     v2f(outside); v2f(big);
  145.                 endline();
  146.             popmatrix();
  147.  
  148.             // label the major tick?
  149.  
  150.             if ((big_tick_count++%big_ticks_per_label == 0) &&
  151.             (label_multiplier != 0.0))
  152.             {
  153.                 
  154.                 char buf[8];
  155.                 sprintf(buf,"%d",(int)((float)i * label_multiplier));
  156.             
  157.                 long width = fmgetstrwidth(font, buf);
  158.  
  159.                 // position text string
  160.  
  161.                 // XXX ANSI cosf and sinf undefined!!!
  162.                 float c = (float) cos(angle*M_PI/180.0);
  163.                 float s = (float) sin(angle*M_PI/180.0);
  164.                 
  165.                 label[0] = label_pos*world_diam*c;
  166.                 label[1] = label_pos*world_diam*s;
  167.  
  168.                 // Correct for lower left origin of character string
  169.                 label[0] -= world_per_pixel*((float)width/2.0);
  170.                 label[1] -= world_per_pixel*(pnt_size/2.0);
  171.  
  172.                 cmov2(label[0],label[1]);
  173.                 fmprstr(buf);
  174.             }
  175.  
  176.         }
  177.         else
  178.         {
  179.             // draw minor tick
  180.             pushmatrix();
  181.                 rot(angle,'z');
  182.                 cpack(ORANGE);
  183.                 bgnline();
  184.                     v2f(outside); v2f(small);
  185.                 endline();
  186.             popmatrix();
  187.         }
  188.  
  189.         angle -= angle_step;
  190.     }
  191. }
  192.  
  193. // bulbous box 
  194. void bulbous_box(float x1, float y1, float x2, float y2, float diam)
  195. {
  196.     float width, height, left, bottom;
  197.     
  198.     if (x1 < x2)
  199.     {
  200.         width = x2 - x1;
  201.         left = x1;
  202.     }
  203.     else
  204.     {
  205.         width = x1 - x2;
  206.         left = x2;
  207.     }
  208.         
  209.     if (y1 < y2)
  210.     {
  211.         height = y2 - y1;
  212.         bottom = y1;
  213.     }
  214.     else
  215.     {
  216.         height = y1 - y2;
  217.         bottom = y2;
  218.     }
  219.  
  220.     pushmatrix();
  221.     translate(left+width/2.0,bottom+height/2.0,0.0);
  222.  
  223.     /// this draws a rect about the origin
  224.     pushmatrix();
  225.         translate(width/2.0,0.0,0.0);
  226.         scale(diam,height,diam);
  227.         rotate(900,'x');
  228.         fcylinder();
  229.     popmatrix();
  230.     
  231.     pushmatrix();
  232.         translate(-width/2.0,0.0,0.0);
  233.         scale(diam,height,diam);
  234.         rotate(900,'x');
  235.         fcylinder();
  236.     popmatrix();
  237.     
  238.     pushmatrix();
  239.         translate(0.0,height/2.0,0.0);
  240.         scale(width,diam,diam);
  241.         rotate(900,'y');
  242.         fcylinder();
  243.     popmatrix();
  244.     
  245.     pushmatrix();
  246.         translate(0.0,-height/2.0,0.0);
  247.         scale(width,diam,diam);
  248.         rotate(900,'y');
  249.         fcylinder();
  250.     popmatrix();
  251.  
  252.     popmatrix();
  253. }
  254.  
  255.  
  256.  
  257. void draw_steering_spoke(Boolean draw_it)
  258. {
  259.     int i;
  260.     
  261.     static float spoke1_data[][3] = {
  262.         {1.3, -.4, 0.0},
  263.         {6.45, -.4, 0.0},
  264.         {6.45, -.3, 0.0},
  265.         {1.3, -.3, 0.0},
  266.     };
  267.  
  268.     static float spoke2_data[][3] = {
  269.         {1.3, -.3, 0.0},
  270.         {6.45, -.3, 0.0},
  271.         {6.45, .3, 0.0},
  272.         {1.3, .3, 0.0},
  273.     };
  274.  
  275.     static float spoke3_data[][3] = {
  276.         {1.3, .3, 0.0},
  277.         {6.45, .3, 0.0},
  278.         {6.45, .4, 0.0},
  279.         {1.3, .4, 0.0},
  280.     };
  281.  
  282.     if (draw_it)
  283.         color(GREY1);
  284.     else
  285.         color(CLEAR);
  286.     bgnpolygon();
  287.         for (i = 0; i < np(spoke2_data); i++)
  288.             v3f(spoke1_data[i]);
  289.     endpolygon();
  290.     
  291.     if (draw_it)
  292.         color(GREY2);
  293.     else
  294.         color(CLEAR);
  295.     bgnpolygon();
  296.         for (i = 0; i < np(spoke2_data); i++)
  297.             v3f(spoke2_data[i]);
  298.     endpolygon();
  299.     
  300.     if (draw_it)
  301.         color(GREY3);
  302.     else
  303.         color(CLEAR);
  304.     bgnpolygon();
  305.         for (i = 0; i < np(spoke2_data); i++)
  306.             v3f(spoke3_data[i]);
  307.     endpolygon();
  308. }
  309.  
  310.  
  311.  
  312.