File: instrument.c

package info (click to toggle)
xlander 19920427-4
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 168 kB
  • ctags: 147
  • sloc: ansic: 1,028; makefile: 48
file content (87 lines) | stat: -rw-r--r-- 2,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/******************************************************************************
** XLander - A three-dimensional view-oriented lunar landing simulation for X
**
** Authors:
** Paul Riddle (paulr@umbc3.umbc.edu)
** Mike Friedman (mikef@umbc3.umbc.edu)
**
** University of Maryland, Baltimore Campus
**
** This program may be freely distributed in any form, providing the authors'
** names stay with it.  If you use any portion of this code, please give us
** credit.  Let us know if you like it!
******************************************************************************/

/*
 * instrument.c contains routines that update the gauges at the bottom of
 * the window.
 */

#include "xlander.h"
#include "globals.h"

/******************************************************************************
** setupInstrBuffer
**
** This creates and zeros out a pixmap to be used when updating the control
** panel.
******************************************************************************/

void setupInstrBuffer ()
{
   instrBuffer = XCreatePixmap (d, instrWin, viewWidth, panelHeight,
				DefaultDepth (d, DefaultScreen (d)));
   XSetForeground (d, gcInstr, WhitePixel (d, DefaultScreen (d)));
   XFillRectangle (d, instrBuffer, gcInstr, 0, 0, viewWidth, panelHeight);
}

/******************************************************************************
** UpdateInstruments
**
** Given heading and direction of thrust in radians, this routine updates
** the indicators on the control panel.
******************************************************************************/

void UpdateInstruments (heading, roc, fuel, x, y)
   float heading, roc, fuel;
   int x, y;
{
   static int heading_x = 50, heading_y = 15;
   static int fuel_level = 80, old_x = 290, old_y = 10;
   int new_fuel_level = (int) fuel / 4;
   char buf[32];

   /*
    * Update heading indicator
    */
   XDrawLine (d, instrBuffer, gcXor, 50, 50, heading_x, heading_y);
   heading_x = 50 + 35 * cos (heading);
   heading_y = 50 - 35 * sin (heading);
   XDrawLine (d, instrBuffer, gcXor, 50, 50, heading_x, heading_y);

   /*
    * Update fuel gauge
    */
   XFillRectangle (d, instrBuffer, gcXor, 210, 90 - fuel_level, 20,
		   fuel_level);
   XFillRectangle (d, instrBuffer, gcXor, 210, 90 - new_fuel_level, 20,
		   new_fuel_level);
   fuel_level = new_fuel_level;

   /*
    * Display vertical speed
    */
   sprintf (buf, "%06.2f ft/s", roc);
   XDrawImageString
      (d, instrBuffer, gcInstr,
       120, 50 + ((font->ascent + font->descent) >> 1) - font->descent,
       buf, strlen (buf));

   /*
    * Update "radar"
    */
   XDrawPoint (d, instrBuffer, gcXor, old_x, old_y);
   old_x = WorldToRadarX (x);
   old_y = WorldToRadarY (y);
   XDrawPoint (d, instrBuffer, gcXor, old_x, old_y);
}