File: cpinsaltimeter.c

package info (click to toggle)
searchandrescue 0.8.2-10
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,656 kB
  • ctags: 6,111
  • sloc: ansic: 89,072; cpp: 7,691; sh: 90; makefile: 80
file content (209 lines) | stat: -rw-r--r-- 4,637 bytes parent folder | download | duplicates (6)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef __MSW__
# include <windows.h>
#endif
#include <GL/gl.h>
#include "matrixmath.h"
#include "gw.h"
#include "v3dtex.h"
#include "cpvalues.h"
#include "cpins.h"
#include "cpinsaltimeter.h"
#include "cp.h"


CPIns *CPInsAltimeterNew(void *cp);
static void CPInsAltimeterValuesChanged(
	CPIns *ins, ControlPanelValues *v, void *data
);
static void CPInsAltimeterManage(
	CPIns *ins, ControlPanelValues *v, void *data
);
static void CPInsAltimeterDelete(CPIns *ins, void *data);


#ifndef PI
# define PI     3.14159265
#endif

#define ATOI(s)         (((s) != NULL) ? atoi(s) : 0)
#define ATOL(s)         (((s) != NULL) ? atol(s) : 0)
#define ATOF(s)         (((s) != NULL) ? (float)atof(s) : 0.0f)
#define STRDUP(s)       (((s) != NULL) ? strdup(s) : NULL)

#define MAX(a,b)        (((a) > (b)) ? (a) : (b))
#define MIN(a,b)        (((a) < (b)) ? (a) : (b))
#define CLIP(a,l,h)     (MIN(MAX((a),(l)),(h)))

#define RADTODEG(r)     ((r) * 180.0 / PI)
#define DEGTORAD(d)     ((d) * PI / 180.0)

#define NORMAL3F(x,y,z) (glNormal3f(    \
			 (GLfloat)(x),  \
			 (GLfloat)(z),  \
			 (GLfloat)-(y)  \
			))
#define TEXCOORD2F(x,y) (glTexCoord2f(          \
			 (GLfloat)(x),          \
			 (GLfloat)(1.0 - (y))   \
			))
#define VERTEX3FC(x,y,z) (glVertex3f(			\
			 (GLfloat)((x) / 100.0),        \
			 (GLfloat)((z) / 100.0),        \
			 (GLfloat)((y) / -100.0)        \
			))
#define ROTATEH(r)      (glRotatef((GLfloat)-RADTODEG(r), \
			0.0f, 1.0f, 0.0f))
#define ROTATEP(r)      (glRotatef((GLfloat)-RADTODEG(r), \
			1.0f, 0.0f, 0.0f))
#define ROTATEB(r)      (glRotatef((GLfloat)-RADTODEG(r), \
			0.0f, 0.0f, 1.0f))
#define TRANSLATE(x,y,z)        (glTranslatef(          \
			 (GLfloat)((x) / 100.0),        \
			 (GLfloat)((z) / 100.0),        \
			 (GLfloat)((y) / -100.0)        \
			))


/*
 *      Creates a new bearing instrument.
 */
CPIns *CPInsAltimeterNew(void *cp)
{
	CPInsAltimeter *insv;
	CPIns *ins = CPInsNew(
	    sizeof(CPInsAltimeter),
	    cp,
	    CPINS_TYPE_ALTIMETER,
	    "Altimeter"
	);
	if(ins == NULL)
	    return(NULL);

	insv = CPINS_ALTIMETER(ins);

	CPInsSetFunction(
	    ins, "values_changed",
	    CPInsAltimeterValuesChanged, NULL
	);
	CPInsSetFunction(
	    ins, "manage",
	    CPInsAltimeterManage, NULL
	);
	CPInsSetFunction(
	    ins, "delete",
	    CPInsAltimeterDelete, NULL
	);

	return(ins);
}

/*
 *	"values_changed" callback.
 */
static void CPInsAltimeterValuesChanged(
	CPIns *ins, ControlPanelValues *v, void *data
)
{
	ControlPanel *cp;
	gw_display_struct *display;
	int cstate;
	GLfloat width, height;
	v3d_texture_ref_struct *tex_bg, *tex_fg;
	CPInsAltimeter *insv = CPINS_ALTIMETER(ins);
	if((insv == NULL) || (v == NULL))
	    return;

	cp = CONTROL_PANEL(ins->cp);
	display = CONTROL_PANEL_DISPLAY(cp);
	if(display == NULL)
	    return;

	cstate = v->color_state;

	/* At this point the GL perspective matrix should already be
	 * orthoginal and it's size set to match the size of the
	 * frame buffer.  Now get the size of the frame buffer.
	 */
	width = (GLfloat)ins->res_width;
	height = (GLfloat)ins->res_height;

	/* Get instrument background and foreground textures. */
	tex_bg = ins->tex_bg;
	tex_fg = ins->tex_fg;


	/* Begin drawing. */

	/* Draw background. */
	if(tex_bg != NULL)
	{
	    glColor3f(1.0f, 1.0f, 1.0f);
	    StateGLEnable(&display->state_gl, GL_TEXTURE_2D);
	    V3DTextureSelect(tex_bg);

	    glBegin(GL_QUADS);
	    {
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(0.0f, height);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(width, height);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(width, 0.0f);
	    }
	    glEnd();
	}

	/* Draw altitude hands. */



	/* Draw foretround. */
	if(tex_fg != NULL)
	{
	    glColor3f(1.0f, 1.0f, 1.0f);
	    StateGLEnable(&display->state_gl, GL_TEXTURE_2D);
	    V3DTextureSelect(tex_fg);

	    glBegin(GL_QUADS);
	    {
		glTexCoord2f(0.0f, 0.0f);
		glVertex2f(0.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex2f(0.0f, height);
		glTexCoord2f(1.0f, 1.0f);
		glVertex2f(width, height);
		glTexCoord2f(1.0f, 0.0f);
		glVertex2f(width, 0.0f);
	    }
	    glEnd();
	}

	CPInsRealizeTexture(ins);
}

/*
 *      "manage" callback.
 */
static void CPInsAltimeterManage(
	CPIns *ins, ControlPanelValues *v, void *data
)
{
	CPInsAltimeter *insv = CPINS_ALTIMETER(ins);
	if(insv == NULL)
	    return;
}

/*
 *      Deletes resources of instrument but not instrument itself.
 */
static void CPInsAltimeterDelete(CPIns *ins, void *data)
{
	CPInsAltimeter *insv = CPINS_ALTIMETER(ins);
	if(insv == NULL)
	    return;
}