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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
static char sqla_program_id[292] =
{
172,0,65,69,65,78,65,73,86,65,78,55,78,82,73,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,66,65,83,69,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
};
#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 "base.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 "base.h"
#include "../view/state0.h"
#include "../util/check_error.h"
#include <GL/glut.h>
#include <string.h>
#include <stdlib.h>
#include "sqlca.h"
extern struct sqlca sqlca;
/*
* A simple alias to make the code more readable.
*/
#define S state0
void
base (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 "base.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 "base.sqc"
sqlint32 rows;
/*
EXEC SQL END DECLARE SECTION;
*/
#line 34 "base.sqc"
/* Determine how many nodes have coordinates assigned to them. */
/*
EXEC SQL SELECT COUNT (*) INTO:rows FROM coordinates;
*/
{
#line 37 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 37 "base.sqc"
sqlaaloc(3,1,1,0L);
{
struct sqla_setdata_list sql_setdlist[1];
#line 37 "base.sqc"
sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
#line 37 "base.sqc"
sql_setdlist[0].sqldata = (void*)&rows;
#line 37 "base.sqc"
sql_setdlist[0].sqlind = 0L;
#line 37 "base.sqc"
sqlasetdata(3,0,1,sql_setdlist,0L,0L);
}
#line 37 "base.sqc"
sqlacall((unsigned short)24,1,0,3,0L);
#line 37 "base.sqc"
sqlastop(0L);
}
#line 37 "base.sqc"
/* Free any existing coordinates and allocate memory to store the
new values. */
S.rows = rows;
free (S.selection.set);
S.selection.set = calloc (rows, sizeof (bool));
free (S.gi_data);
S.gi_data = calloc (rows, sizeof (char) * 20);
free (S.base_vertices_data);
S.base_vertices_data = calloc (rows, sizeof (float) * 2);
free (S.base_colors_data);
S.base_colors_data = calloc (rows, sizeof (float) * 4);
/*
EXEC SQL DECLARE c2 CURSOR FOR SELECT *FROM coordinates;
*/
#line 55 "base.sqc"
/*
EXEC SQL OPEN c2;
*/
{
#line 57 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 57 "base.sqc"
sqlacall((unsigned short)26,2,0,0,0L);
#line 57 "base.sqc"
sqlastop(0L);
}
#line 57 "base.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 67 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 67 "base.sqc"
sqlaaloc(3,4,2,0L);
{
struct sqla_setdata_list sql_setdlist[4];
#line 67 "base.sqc"
sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
#line 67 "base.sqc"
sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
#line 67 "base.sqc"
sql_setdlist[0].sqlind = 0L;
#line 67 "base.sqc"
sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
#line 67 "base.sqc"
sql_setdlist[1].sqldata = (void*)&coordinates.gi;
#line 67 "base.sqc"
sql_setdlist[1].sqlind = 0L;
#line 67 "base.sqc"
sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
#line 67 "base.sqc"
sql_setdlist[2].sqldata = (void*)&coordinates.x;
#line 67 "base.sqc"
sql_setdlist[2].sqlind = 0L;
#line 67 "base.sqc"
sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
#line 67 "base.sqc"
sql_setdlist[3].sqldata = (void*)&coordinates.y;
#line 67 "base.sqc"
sql_setdlist[3].sqlind = 0L;
#line 67 "base.sqc"
sqlasetdata(3,0,4,sql_setdlist,0L,0L);
}
#line 67 "base.sqc"
sqlacall((unsigned short)25,2,0,3,0L);
#line 67 "base.sqc"
sqlastop(0L);
}
#line 67 "base.sqc"
while (sqlca.sqlcode != 100)
{
int i = coordinates.coord_id - 1;
strncpy (S.gi_data + i, coordinates.gi.data, sizeof (S.gi_data[i]));
float *v = S.base_vertices_data + (i * 2);
*v = coordinates.x;
v++;
*v = coordinates.y;
v = S.base_vertices_data + (i * 2);
if (*v < S.bb.min_x)
S.bb.min_x = *v;
if (*v > S.bb.max_x)
S.bb.max_x = *v;
v++;
if (*v < S.bb.min_y)
S.bb.min_y = *v;
if (*v > S.bb.max_y)
S.bb.max_y = *v;
/*
* Deselected by default.
*/
S.selection.set[i] = false;
float *c = S.base_colors_data + (i * 4);
*c = DEFAULT_COLOR_R;
c++;
*c = DEFAULT_COLOR_G;
c++;
*c = DEFAULT_COLOR_B;
c++;
*c = DEFAULT_COLOR_A;
/*
EXEC SQL FETCH c2 INTO:coordinates;
*/
{
#line 105 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 105 "base.sqc"
sqlaaloc(3,4,3,0L);
{
struct sqla_setdata_list sql_setdlist[4];
#line 105 "base.sqc"
sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
#line 105 "base.sqc"
sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
#line 105 "base.sqc"
sql_setdlist[0].sqlind = 0L;
#line 105 "base.sqc"
sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
#line 105 "base.sqc"
sql_setdlist[1].sqldata = (void*)&coordinates.gi;
#line 105 "base.sqc"
sql_setdlist[1].sqlind = 0L;
#line 105 "base.sqc"
sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
#line 105 "base.sqc"
sql_setdlist[2].sqldata = (void*)&coordinates.x;
#line 105 "base.sqc"
sql_setdlist[2].sqlind = 0L;
#line 105 "base.sqc"
sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
#line 105 "base.sqc"
sql_setdlist[3].sqldata = (void*)&coordinates.y;
#line 105 "base.sqc"
sql_setdlist[3].sqlind = 0L;
#line 105 "base.sqc"
sqlasetdata(3,0,4,sql_setdlist,0L,0L);
}
#line 105 "base.sqc"
sqlacall((unsigned short)25,2,0,3,0L);
#line 105 "base.sqc"
sqlastop(0L);
}
#line 105 "base.sqc"
}
/*
EXEC SQL CLOSE c2;
*/
{
#line 108 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 108 "base.sqc"
sqlacall((unsigned short)20,2,0,0,0L);
#line 108 "base.sqc"
sqlastop(0L);
}
#line 108 "base.sqc"
/*
EXEC SQL COMMIT;
*/
{
#line 110 "base.sqc"
sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
#line 110 "base.sqc"
sqlacall((unsigned short)21,0,0,0,0L);
#line 110 "base.sqc"
sqlastop(0L);
}
#line 110 "base.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.
float *v = S.base_vertices_data;
for (int i = 0; i < S.rows; i++)
{
v++;
*v = S.ortho_max - *v;
v++;
}
// Move the origin (0,0) to the center of the data.
S.ortho_min = 0.0;
S.ortho_max = 0.0;
v = S.base_vertices_data;
for (int i = 0; i < S.rows; i++)
{
*v = *v - (0.5 * (S.bb.max_x - S.bb.min_x));
if (S.ortho_min > *v)
S.ortho_min = *v;
if (S.ortho_max < *v)
S.ortho_max = *v;
v++;
*v = *v - (0.5 * (S.bb.max_y - S.bb.min_y));
if (S.ortho_min > *v)
S.ortho_min = *v;
if (S.ortho_max < *v)
S.ortho_max = *v;
v++;
}
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;
}
|