33 files changed, 530 insertions, 113 deletions
diff --git a/src/model/base.c b/src/model/base.c new file mode 100644 index 0000000..649fec3 --- a/dev/null +++ b/src/model/base.c | |||
@@ -0,0 +1,417 @@ | |||
1 | static char sqla_program_id[292] = | ||
2 | { | ||
3 | 172,0,65,69,65,78,65,73,86,65,78,55,78,82,73,90,48,49,49,49, | ||
4 | 49,32,50,32,32,32,32,32,32,32,32,32,8,0,68,79,78,32,32,32, | ||
5 | 32,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
6 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
7 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
8 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
9 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
10 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
11 | 0,0,8,0,66,65,83,69,32,32,32,32,0,0,0,0,0,0,0,0, | ||
12 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
13 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
14 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
15 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
16 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
17 | 0,0,0,0,0,0,0,0,0,0,0,0 | ||
18 | }; | ||
19 | |||
20 | #include "sqladef.h" | ||
21 | |||
22 | static struct sqla_runtime_info sqla_rtinfo = | ||
23 | {{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ',' '}}; | ||
24 | |||
25 | |||
26 | static const short sqlIsLiteral = SQL_IS_LITERAL; | ||
27 | static const short sqlIsInputHvar = SQL_IS_INPUT_HVAR; | ||
28 | |||
29 | |||
30 | #line 1 "base.sqc" | ||
31 | /* I seem to need this for glGenBuffers as per | ||
32 | http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */ | ||
33 | #define GL_GLEXT_PROTOTYPES | ||
34 | |||
35 | #include "base.h" | ||
36 | #include "../view/state0.h" | ||
37 | #include "../util/check_error.h" | ||
38 | #include <GL/glut.h> | ||
39 | #include <string.h> | ||
40 | #include <stdlib.h> | ||
41 | #include "sqlca.h" | ||
42 | extern struct sqlca sqlca; | ||
43 | |||
44 | /* | ||
45 | * A simple alias to make the code more readable. | ||
46 | */ | ||
47 | #define S state0 | ||
48 | |||
49 | void | ||
50 | base (void) | ||
51 | { | ||
52 | /* | ||
53 | * This implementation can be improved by mapping the video memory | ||
54 | * directly rather than loading into system memory and then copying | ||
55 | * into video memory. | ||
56 | */ | ||
57 | |||
58 | /* | ||
59 | * db2dclgn -d exp004 -t coordinates | ||
60 | */ | ||
61 | |||
62 | /* | ||
63 | EXEC SQL BEGIN DECLARE SECTION; | ||
64 | */ | ||
65 | |||
66 | #line 31 "base.sqc" | ||
67 | |||
68 | |||
69 | /* | ||
70 | EXEC SQL INCLUDE 'model/coordinates.h'; | ||
71 | */ | ||
72 | |||
73 | #line 1 "/home/don/projects/Research/Experiments/exp005/src/model/coordinates.h" | ||
74 | struct | ||
75 | { | ||
76 | sqlint32 coord_id; | ||
77 | struct | ||
78 | { | ||
79 | short length; | ||
80 | char data[50]; | ||
81 | } gi; | ||
82 | double x; | ||
83 | double y; | ||
84 | } coordinates; | ||
85 | |||
86 | #line 32 "base.sqc" | ||
87 | |||
88 | sqlint32 rows; | ||
89 | |||
90 | /* | ||
91 | EXEC SQL END DECLARE SECTION; | ||
92 | */ | ||
93 | |||
94 | #line 34 "base.sqc" | ||
95 | |||
96 | |||
97 | /* Determine how many nodes have coordinates assigned to them. */ | ||
98 | |||
99 | /* | ||
100 | EXEC SQL SELECT COUNT (*) INTO:rows FROM coordinates; | ||
101 | */ | ||
102 | |||
103 | { | ||
104 | #line 37 "base.sqc" | ||
105 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
106 | #line 37 "base.sqc" | ||
107 | sqlaaloc(3,1,1,0L); | ||
108 | { | ||
109 | struct sqla_setdata_list sql_setdlist[1]; | ||
110 | #line 37 "base.sqc" | ||
111 | sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4; | ||
112 | #line 37 "base.sqc" | ||
113 | sql_setdlist[0].sqldata = (void*)&rows; | ||
114 | #line 37 "base.sqc" | ||
115 | sql_setdlist[0].sqlind = 0L; | ||
116 | #line 37 "base.sqc" | ||
117 | sqlasetdata(3,0,1,sql_setdlist,0L,0L); | ||
118 | } | ||
119 | #line 37 "base.sqc" | ||
120 | sqlacall((unsigned short)24,1,0,3,0L); | ||
121 | #line 37 "base.sqc" | ||
122 | sqlastop(0L); | ||
123 | } | ||
124 | |||
125 | #line 37 "base.sqc" | ||
126 | |||
127 | |||
128 | /* Free any existing coordinates and allocate memory to store the | ||
129 | new values. */ | ||
130 | S.rows = rows; | ||
131 | |||
132 | free (S.selection.set); | ||
133 | S.selection.set = calloc (rows, sizeof (bool)); | ||
134 | |||
135 | free (S.gi_data); | ||
136 | S.gi_data = calloc (rows, sizeof (char) * 20); | ||
137 | |||
138 | free (S.base_vertices_data); | ||
139 | S.base_vertices_data = calloc (rows, sizeof (float) * 2); | ||
140 | |||
141 | free (S.base_colors_data); | ||
142 | S.base_colors_data = calloc (rows, sizeof (float) * 4); | ||
143 | |||
144 | |||
145 | /* | ||
146 | EXEC SQL DECLARE c2 CURSOR FOR SELECT *FROM coordinates; | ||
147 | */ | ||
148 | |||
149 | #line 55 "base.sqc" | ||
150 | |||
151 | |||
152 | |||
153 | /* | ||
154 | EXEC SQL OPEN c2; | ||
155 | */ | ||
156 | |||
157 | { | ||
158 | #line 57 "base.sqc" | ||
159 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
160 | #line 57 "base.sqc" | ||
161 | sqlacall((unsigned short)26,2,0,0,0L); | ||
162 | #line 57 "base.sqc" | ||
163 | sqlastop(0L); | ||
164 | } | ||
165 | |||
166 | #line 57 "base.sqc" | ||
167 | |||
168 | |||
169 | /* | ||
170 | * Initialize the bounding box of the points. | ||
171 | */ | ||
172 | S.bb.min_x = 0.0; | ||
173 | S.bb.max_x = 0.0; | ||
174 | S.bb.min_y = 0.0; | ||
175 | S.bb.max_y = 0.0; | ||
176 | |||
177 | |||
178 | /* | ||
179 | EXEC SQL FETCH c2 INTO:coordinates; | ||
180 | */ | ||
181 | |||
182 | { | ||
183 | #line 67 "base.sqc" | ||
184 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
185 | #line 67 "base.sqc" | ||
186 | sqlaaloc(3,4,2,0L); | ||
187 | { | ||
188 | struct sqla_setdata_list sql_setdlist[4]; | ||
189 | #line 67 "base.sqc" | ||
190 | sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4; | ||
191 | #line 67 "base.sqc" | ||
192 | sql_setdlist[0].sqldata = (void*)&coordinates.coord_id; | ||
193 | #line 67 "base.sqc" | ||
194 | sql_setdlist[0].sqlind = 0L; | ||
195 | #line 67 "base.sqc" | ||
196 | sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50; | ||
197 | #line 67 "base.sqc" | ||
198 | sql_setdlist[1].sqldata = (void*)&coordinates.gi; | ||
199 | #line 67 "base.sqc" | ||
200 | sql_setdlist[1].sqlind = 0L; | ||
201 | #line 67 "base.sqc" | ||
202 | sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8; | ||
203 | #line 67 "base.sqc" | ||
204 | sql_setdlist[2].sqldata = (void*)&coordinates.x; | ||
205 | #line 67 "base.sqc" | ||
206 | sql_setdlist[2].sqlind = 0L; | ||
207 | #line 67 "base.sqc" | ||
208 | sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8; | ||
209 | #line 67 "base.sqc" | ||
210 | sql_setdlist[3].sqldata = (void*)&coordinates.y; | ||
211 | #line 67 "base.sqc" | ||
212 | sql_setdlist[3].sqlind = 0L; | ||
213 | #line 67 "base.sqc" | ||
214 | sqlasetdata(3,0,4,sql_setdlist,0L,0L); | ||
215 | } | ||
216 | #line 67 "base.sqc" | ||
217 | sqlacall((unsigned short)25,2,0,3,0L); | ||
218 | #line 67 "base.sqc" | ||
219 | sqlastop(0L); | ||
220 | } | ||
221 | |||
222 | #line 67 "base.sqc" | ||
223 | |||
224 | while (sqlca.sqlcode != 100) | ||
225 | { | ||
226 | int i = coordinates.coord_id - 1; | ||
227 | |||
228 | strncpy (S.gi_data + i, coordinates.gi.data, sizeof (S.gi_data[i])); | ||
229 | |||
230 | float *v = S.base_vertices_data + (i * 2); | ||
231 | *v = coordinates.x; | ||
232 | v++; | ||
233 | *v = coordinates.y; | ||
234 | |||
235 | v = S.base_vertices_data + (i * 2); | ||
236 | if (*v < S.bb.min_x) | ||
237 | S.bb.min_x = *v; | ||
238 | if (*v > S.bb.max_x) | ||
239 | S.bb.max_x = *v; | ||
240 | |||
241 | v++; | ||
242 | if (*v < S.bb.min_y) | ||
243 | S.bb.min_y = *v; | ||
244 | if (*v > S.bb.max_y) | ||
245 | S.bb.max_y = *v; | ||
246 | |||
247 | /* | ||
248 | * Deselected by default. | ||
249 | */ | ||
250 | S.selection.set[i] = false; | ||
251 | |||
252 | float *c = S.base_colors_data + (i * 4); | ||
253 | *c = DEFAULT_COLOR_R; | ||
254 | c++; | ||
255 | *c = DEFAULT_COLOR_G; | ||
256 | c++; | ||
257 | *c = DEFAULT_COLOR_B; | ||
258 | c++; | ||
259 | *c = DEFAULT_COLOR_A; | ||
260 | |||
261 | |||
262 | /* | ||
263 | EXEC SQL FETCH c2 INTO:coordinates; | ||
264 | */ | ||
265 | |||
266 | { | ||
267 | #line 105 "base.sqc" | ||
268 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
269 | #line 105 "base.sqc" | ||
270 | sqlaaloc(3,4,3,0L); | ||
271 | { | ||
272 | struct sqla_setdata_list sql_setdlist[4]; | ||
273 | #line 105 "base.sqc" | ||
274 | sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4; | ||
275 | #line 105 "base.sqc" | ||
276 | sql_setdlist[0].sqldata = (void*)&coordinates.coord_id; | ||
277 | #line 105 "base.sqc" | ||
278 | sql_setdlist[0].sqlind = 0L; | ||
279 | #line 105 "base.sqc" | ||
280 | sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50; | ||
281 | #line 105 "base.sqc" | ||
282 | sql_setdlist[1].sqldata = (void*)&coordinates.gi; | ||
283 | #line 105 "base.sqc" | ||
284 | sql_setdlist[1].sqlind = 0L; | ||
285 | #line 105 "base.sqc" | ||
286 | sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8; | ||
287 | #line 105 "base.sqc" | ||
288 | sql_setdlist[2].sqldata = (void*)&coordinates.x; | ||
289 | #line 105 "base.sqc" | ||
290 | sql_setdlist[2].sqlind = 0L; | ||
291 | #line 105 "base.sqc" | ||
292 | sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8; | ||
293 | #line 105 "base.sqc" | ||
294 | sql_setdlist[3].sqldata = (void*)&coordinates.y; | ||
295 | #line 105 "base.sqc" | ||
296 | sql_setdlist[3].sqlind = 0L; | ||
297 | #line 105 "base.sqc" | ||
298 | sqlasetdata(3,0,4,sql_setdlist,0L,0L); | ||
299 | } | ||
300 | #line 105 "base.sqc" | ||
301 | sqlacall((unsigned short)25,2,0,3,0L); | ||
302 | #line 105 "base.sqc" | ||
303 | sqlastop(0L); | ||
304 | } | ||
305 | |||
306 | #line 105 "base.sqc" | ||
307 | |||
308 | } | ||
309 | |||
310 | |||
311 | /* | ||
312 | EXEC SQL CLOSE c2; | ||
313 | */ | ||
314 | |||
315 | { | ||
316 | #line 108 "base.sqc" | ||
317 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
318 | #line 108 "base.sqc" | ||
319 | sqlacall((unsigned short)20,2,0,0,0L); | ||
320 | #line 108 "base.sqc" | ||
321 | sqlastop(0L); | ||
322 | } | ||
323 | |||
324 | #line 108 "base.sqc" | ||
325 | |||
326 | |||
327 | |||
328 | /* | ||
329 | EXEC SQL COMMIT; | ||
330 | */ | ||
331 | |||
332 | { | ||
333 | #line 110 "base.sqc" | ||
334 | sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca); | ||
335 | #line 110 "base.sqc" | ||
336 | sqlacall((unsigned short)21,0,0,0,0L); | ||
337 | #line 110 "base.sqc" | ||
338 | sqlastop(0L); | ||
339 | } | ||
340 | |||
341 | #line 110 "base.sqc" | ||
342 | |||
343 | |||
344 | /* | ||
345 | * Find the largest axis and use it to setup the projection. This | ||
346 | * is done to preserve the aspect ratio. The aspect ratio should be | ||
347 | * preserved since relative distance is a meaningful indicator in | ||
348 | * the map. | ||
349 | */ | ||
350 | |||
351 | // Min of min x or min y. | ||
352 | if (S.bb.min_x <= S.bb.min_y) | ||
353 | S.ortho_min = S.bb.min_x; | ||
354 | else | ||
355 | S.ortho_min = S.bb.min_y; | ||
356 | S.ortho_min--; | ||
357 | |||
358 | // Max of max x or max y. | ||
359 | if (S.bb.max_x >= S.bb.max_y) | ||
360 | S.ortho_max = S.bb.max_x; | ||
361 | else | ||
362 | S.ortho_max = S.bb.max_y; | ||
363 | S.ortho_max++; | ||
364 | |||
365 | // Invert the y coordinate to match up with the LGL Java viewer. | ||
366 | float *v = S.base_vertices_data; | ||
367 | for (int i = 0; i < S.rows; i++) | ||
368 | { | ||
369 | v++; | ||
370 | *v = S.ortho_max - *v; | ||
371 | v++; | ||
372 | } | ||
373 | |||
374 | // Move the origin (0,0) to the center of the data. | ||
375 | S.ortho_min = 0.0; | ||
376 | S.ortho_max = 0.0; | ||
377 | |||
378 | v = S.base_vertices_data; | ||
379 | for (int i = 0; i < S.rows; i++) | ||
380 | { | ||
381 | *v = *v - (0.5 * (S.bb.max_x - S.bb.min_x)); | ||
382 | |||
383 | if (S.ortho_min > *v) | ||
384 | S.ortho_min = *v; | ||
385 | |||
386 | if (S.ortho_max < *v) | ||
387 | S.ortho_max = *v; | ||
388 | |||
389 | v++; | ||
390 | |||
391 | *v = *v - (0.5 * (S.bb.max_y - S.bb.min_y)); | ||
392 | |||
393 | if (S.ortho_min > *v) | ||
394 | S.ortho_min = *v; | ||
395 | |||
396 | if (S.ortho_max < *v) | ||
397 | S.ortho_max = *v; | ||
398 | |||
399 | v++; | ||
400 | } | ||
401 | |||
402 | glGenBuffers (2, S.buffers); | ||
403 | |||
404 | glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_VERTICES]); | ||
405 | glVertexPointer (2, GL_FLOAT, 0, 0); | ||
406 | glBufferData (GL_ARRAY_BUFFER, | ||
407 | sizeof (S.base_vertices_data), S.base_vertices_data, | ||
408 | GL_STATIC_DRAW); | ||
409 | |||
410 | glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]); | ||
411 | glColorPointer (4, GL_FLOAT, 0, 0); | ||
412 | glBufferData (GL_ARRAY_BUFFER, | ||
413 | sizeof (S.base_colors_data), S.base_colors_data, | ||
414 | GL_STATIC_DRAW); | ||
415 | |||
416 | return; | ||
417 | } | ||