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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
static char sqla_program_id[292] =
{
172,0,65,69,65,77,65,73,77,65,105,103,79,83,71,90,48,49,49,49,
49,32,50,32,32,32,32,32,32,32,32,32,8,0,68,79,78,32,32,32,
32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,8,0,69,88,80,48,48,52,66,65,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0
};
#include "sqladef.h"
static struct sqla_runtime_info sqla_rtinfo =
{{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ',' '}};
static const short sqlIsLiteral = SQL_IS_LITERAL;
static const short sqlIsInputHvar = SQL_IS_INPUT_HVAR;
#line 1 "exp004base.sqc"
/* I seem to need this for glGenBuffers as per
http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */
#define GL_GLEXT_PROTOTYPES
#include "exp004base.h"
#include "../view/exp004state0.h"
#include "../util/check_error.h"
#include <GL/glut.h>
#include <stdio.h>
#include <string.h>
#include "sqlca.h"
extern struct sqlca sqlca;
/*
* A simple alias to make the code more readable.
*/
#define S exp004state0
void
exp004base (void)
{
/*
* This implementation can be improved by mapping the video memory
* directly rather than loading into system memory and then copying
* into video memory.
*/
/*
* db2dclgn -d exp004 -t coordinates
*/
/*
EXEC SQL BEGIN DECLARE SECTION;
*/
#line 31 "exp004base.sqc"
/*
EXEC SQL INCLUDE 'model/coordinates.h';
*/
#line 1 "/home/don/projects/Research/Experiments/exp005/src/model/coordinates.h"
struct
{
sqlint32 coord_id;
struct
{
short length;
char data[50];
} gi;
double x;
double y;
} coordinates;
#line 32 "exp004base.sqc"
/*
EXEC SQL END DECLARE SECTION;
*/
#line 33 "exp004base.sqc"
/*
EXEC SQL DECLARE c2 CURSOR FOR
SELECT * FROM coordinates;
*/
#line 36 "exp004base.sqc"
/*
EXEC SQL OPEN c2;
*/
{
#line 38 "exp004base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 38 "exp004base.sqc"
sqlacall((unsigned short)26,1,0,0,0L);
#line 38 "exp004base.sqc"
sqlastop(0L);
}
#line 38 "exp004base.sqc"
/*
* Initialize the bounding box of the points.
*/
S.bb.min_x = 0.0;
S.bb.max_x = 0.0;
S.bb.min_y = 0.0;
S.bb.max_y = 0.0;
/*
EXEC SQL FETCH c2 INTO :coordinates;
*/
{
#line 48 "exp004base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 48 "exp004base.sqc"
sqlaaloc(3,4,1,0L);
{
struct sqla_setdata_list sql_setdlist[4];
#line 48 "exp004base.sqc"
sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
#line 48 "exp004base.sqc"
sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
#line 48 "exp004base.sqc"
sql_setdlist[0].sqlind = 0L;
#line 48 "exp004base.sqc"
sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
#line 48 "exp004base.sqc"
sql_setdlist[1].sqldata = (void*)&coordinates.gi;
#line 48 "exp004base.sqc"
sql_setdlist[1].sqlind = 0L;
#line 48 "exp004base.sqc"
sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
#line 48 "exp004base.sqc"
sql_setdlist[2].sqldata = (void*)&coordinates.x;
#line 48 "exp004base.sqc"
sql_setdlist[2].sqlind = 0L;
#line 48 "exp004base.sqc"
sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
#line 48 "exp004base.sqc"
sql_setdlist[3].sqldata = (void*)&coordinates.y;
#line 48 "exp004base.sqc"
sql_setdlist[3].sqlind = 0L;
#line 48 "exp004base.sqc"
sqlasetdata(3,0,4,sql_setdlist,0L,0L);
}
#line 48 "exp004base.sqc"
sqlacall((unsigned short)25,1,0,3,0L);
#line 48 "exp004base.sqc"
sqlastop(0L);
}
#line 48 "exp004base.sqc"
while (sqlca.sqlcode != 100)
{
int i = coordinates.coord_id - 1;
strncpy(S.gi_data[i],
coordinates.gi.data,
sizeof (S.gi_data[i]));
S.base_vertices_data[i][0] = coordinates.x;
S.base_vertices_data[i][1] = coordinates.y;
if (S.base_vertices_data[i][0] < S.bb.min_x)
S.bb.min_x = S.base_vertices_data[i][0];
if (S.base_vertices_data[i][0] > S.bb.max_x)
S.bb.max_x = S.base_vertices_data[i][0];
if (S.base_vertices_data[i][1] < S.bb.min_y)
S.bb.min_y = S.base_vertices_data[i][1];
if (S.base_vertices_data[i][1] > S.bb.max_y)
S.bb.max_y = S.base_vertices_data[i][1];
/*
* Deselected by default.
*/
S.selection.set[i] = false;
S.base_colors_data[i][0] = DEFAULT_COLOR_R;
S.base_colors_data[i][1] = DEFAULT_COLOR_G;
S.base_colors_data[i][2] = DEFAULT_COLOR_B;
S.base_colors_data[i][3] = DEFAULT_COLOR_A;
/*
EXEC SQL FETCH c2 INTO :coordinates;
*/
{
#line 79 "exp004base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 79 "exp004base.sqc"
sqlaaloc(3,4,2,0L);
{
struct sqla_setdata_list sql_setdlist[4];
#line 79 "exp004base.sqc"
sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
#line 79 "exp004base.sqc"
sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
#line 79 "exp004base.sqc"
sql_setdlist[0].sqlind = 0L;
#line 79 "exp004base.sqc"
sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
#line 79 "exp004base.sqc"
sql_setdlist[1].sqldata = (void*)&coordinates.gi;
#line 79 "exp004base.sqc"
sql_setdlist[1].sqlind = 0L;
#line 79 "exp004base.sqc"
sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
#line 79 "exp004base.sqc"
sql_setdlist[2].sqldata = (void*)&coordinates.x;
#line 79 "exp004base.sqc"
sql_setdlist[2].sqlind = 0L;
#line 79 "exp004base.sqc"
sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
#line 79 "exp004base.sqc"
sql_setdlist[3].sqldata = (void*)&coordinates.y;
#line 79 "exp004base.sqc"
sql_setdlist[3].sqlind = 0L;
#line 79 "exp004base.sqc"
sqlasetdata(3,0,4,sql_setdlist,0L,0L);
}
#line 79 "exp004base.sqc"
sqlacall((unsigned short)25,1,0,3,0L);
#line 79 "exp004base.sqc"
sqlastop(0L);
}
#line 79 "exp004base.sqc"
}
/*
EXEC SQL CLOSE c2;
*/
{
#line 82 "exp004base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 82 "exp004base.sqc"
sqlacall((unsigned short)20,1,0,0,0L);
#line 82 "exp004base.sqc"
sqlastop(0L);
}
#line 82 "exp004base.sqc"
/*
EXEC SQL COMMIT;
*/
{
#line 84 "exp004base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 84 "exp004base.sqc"
sqlacall((unsigned short)21,0,0,0,0L);
#line 84 "exp004base.sqc"
sqlastop(0L);
}
#line 84 "exp004base.sqc"
/*
* Find the largest axis and use it to setup the projection. This
* is done to preserve the aspect ratio. The aspect ratio should be
* preserved since relative distance is a meaningful indicator in
* the map.
*/
// Min of min x or min y.
if (S.bb.min_x <= S.bb.min_y)
S.ortho_min = S.bb.min_x;
else
S.ortho_min = S.bb.min_y;
S.ortho_min--;
// Max of max x or max y.
if (S.bb.max_x >= S.bb.max_y)
S.ortho_max = S.bb.max_x;
else
S.ortho_max = S.bb.max_y;
S.ortho_max++;
// Invert the y coordinate to match up with the LGL Java viewer.
for (int i = 0; i < ROWS; i++)
S.base_vertices_data[i][1] =
S.ortho_max - S.base_vertices_data[i][1];
// Move the origin (0,0) to the center of the data.
S.ortho_min = 0.0;
S.ortho_max = 0.0;
for (int i = 0; i < ROWS; i++)
{
S.base_vertices_data[i][0] =
S.base_vertices_data[i][0] -
(0.5 * (S.bb.max_x - S.bb.min_x));
if (S.ortho_min > S.base_vertices_data[i][0])
S.ortho_min = S.base_vertices_data[i][0];
if (S.ortho_max < S.base_vertices_data[i][0])
S.ortho_max = S.base_vertices_data[i][0];
S.base_vertices_data[i][1] =
S.base_vertices_data[i][1] -
(0.5 * (S.bb.max_y - S.bb.min_y));
if (S.ortho_min > S.base_vertices_data[i][1])
S.ortho_min = S.base_vertices_data[i][1];
if (S.ortho_max < S.base_vertices_data[i][1])
S.ortho_max = S.base_vertices_data[i][1];
}
glGenBuffers (2, S.buffers);
glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_VERTICES]);
glVertexPointer (2, GL_FLOAT, 0, 0);
glBufferData (GL_ARRAY_BUFFER,
sizeof (S.base_vertices_data), S.base_vertices_data,
GL_STATIC_DRAW);
glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]);
glColorPointer (4, GL_FLOAT, 0, 0);
glBufferData (GL_ARRAY_BUFFER,
sizeof (S.base_colors_data), S.base_colors_data,
GL_STATIC_DRAW);
return;
}
|