summaryrefslogtreecommitdiffstats
Unidiff
-rw-r--r--src/model/exp004base.c350
1 files changed, 301 insertions, 49 deletions
diff --git a/src/model/exp004base.c b/src/model/exp004base.c
index 56a20e5..fb07b2c 100644
--- a/src/model/exp004base.c
+++ b/src/model/exp004base.c
@@ -1,65 +1,292 @@
1static char sqla_program_id[292] =
2{
3 172,0,65,69,65,77,65,73,77,65,105,103,79,83,71,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,69,88,80,48,48,52,66,65,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
22static struct sqla_runtime_info sqla_rtinfo =
23{{'S','Q','L','A','R','T','I','N'}, sizeof(wchar_t), 0, {' ',' ',' ',' '}};
24
25
26static const short sqlIsLiteral = SQL_IS_LITERAL;
27static const short sqlIsInputHvar = SQL_IS_INPUT_HVAR;
28
29
30#line 1 "exp004base.sqc"
1/* I seem to need this for glGenBuffers as per31/* I seem to need this for glGenBuffers as per
2 http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */32 http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */
3#define GL_GLEXT_PROTOTYPES33#define GL_GLEXT_PROTOTYPES
434
5#include "exp004base.h"35#include "exp004base.h"
6#include "../view/exp004state0.h"36#include "../view/exp004state0.h"
37#include "../util/check_error.h"
7#include <GL/glut.h>38#include <GL/glut.h>
8#include <stdio.h>39#include <stdio.h>
9#include <string.h>40#include <string.h>
41#include "sqlca.h"
42extern struct sqlca sqlca;
43
44/*
45 * A simple alias to make the code more readable.
46 */
47#define S exp004state0
1048
11void49void
12exp004base (void)50exp004base (void)
13{51{
14 /*
15 * A simple alias to make the code more readable.
16 */
17 EXP004STATE* S = &exp004state0;
18
19 /* 52 /*
20 * This implementation can be improved by mapping the video memory53 * This implementation can be improved by mapping the video memory
21 * directly rather than loading into system memory and then copying54 * directly rather than loading into system memory and then copying
22 * into video memory.55 * into video memory.
23 */56 */
2457
25 FILE* coords = 58 /*
26 fopen ("/home/don/exp004/test/run20090514/run20090514.coords", "r");59 * db2dclgn -d exp004 -t coordinates
27 int i = 0;60 */
61
62/*
63EXEC SQL BEGIN DECLARE SECTION;
64*/
65
66#line 31 "exp004base.sqc"
67
68
69/*
70EXEC SQL INCLUDE 'model/coordinates.h';
71*/
72
73#line 1 "/home/don/projects/Research/Experiments/exp005/src/model/coordinates.h"
74struct
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
87#line 32 "exp004base.sqc"
88
89
90/*
91EXEC SQL END DECLARE SECTION;
92*/
93
94#line 33 "exp004base.sqc"
95
96
97
98/*
99EXEC SQL DECLARE c2 CURSOR FOR
100 SELECT * FROM coordinates;
101*/
102
103#line 36 "exp004base.sqc"
104
105
106
107/*
108EXEC SQL OPEN c2;
109*/
110
111{
112#line 38 "exp004base.sqc"
113 sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
114#line 38 "exp004base.sqc"
115 sqlacall((unsigned short)26,1,0,0,0L);
116#line 38 "exp004base.sqc"
117 sqlastop(0L);
118}
119
120#line 38 "exp004base.sqc"
121
28122
29 /* 123 /*
30 * Initialize the bounding box of the points.124 * Initialize the bounding box of the points.
31 */125 */
32 S->bb.min_x = 0.0;126 S.bb.min_x = 0.0;
33 S->bb.max_x = 0.0;127 S.bb.max_x = 0.0;
34 S->bb.min_y = 0.0;128 S.bb.min_y = 0.0;
35 S->bb.max_y = 0.0;129 S.bb.max_y = 0.0;
130
131
132/*
133EXEC SQL FETCH c2 INTO :coordinates;
134*/
135
136{
137#line 48 "exp004base.sqc"
138 sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
139#line 48 "exp004base.sqc"
140 sqlaaloc(3,4,1,0L);
141 {
142 struct sqla_setdata_list sql_setdlist[4];
143#line 48 "exp004base.sqc"
144 sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
145#line 48 "exp004base.sqc"
146 sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
147#line 48 "exp004base.sqc"
148 sql_setdlist[0].sqlind = 0L;
149#line 48 "exp004base.sqc"
150 sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
151#line 48 "exp004base.sqc"
152 sql_setdlist[1].sqldata = (void*)&coordinates.gi;
153#line 48 "exp004base.sqc"
154 sql_setdlist[1].sqlind = 0L;
155#line 48 "exp004base.sqc"
156 sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
157#line 48 "exp004base.sqc"
158 sql_setdlist[2].sqldata = (void*)&coordinates.x;
159#line 48 "exp004base.sqc"
160 sql_setdlist[2].sqlind = 0L;
161#line 48 "exp004base.sqc"
162 sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
163#line 48 "exp004base.sqc"
164 sql_setdlist[3].sqldata = (void*)&coordinates.y;
165#line 48 "exp004base.sqc"
166 sql_setdlist[3].sqlind = 0L;
167#line 48 "exp004base.sqc"
168 sqlasetdata(3,0,4,sql_setdlist,0L,0L);
169 }
170#line 48 "exp004base.sqc"
171 sqlacall((unsigned short)25,1,0,3,0L);
172#line 48 "exp004base.sqc"
173 sqlastop(0L);
174}
175
176#line 48 "exp004base.sqc"
36177
37 for (i = 0; i < ROWS; i++)178 while (sqlca.sqlcode != 100)
38 {179 {
39 fscanf (coords, "%s %f %f\n",180 int i = coordinates.coord_id - 1;
40 S->gi_data[i],181
41 &S->base_vertices_data[i][0],182 strncpy(S.gi_data[i],
42 &S->base_vertices_data[i][1]);183 coordinates.gi.data,
43184 sizeof (S.gi_data[i]));
44 if (S->base_vertices_data[i][0] < S->bb.min_x)185
45 S->bb.min_x = S->base_vertices_data[i][0];186 S.base_vertices_data[i][0] = coordinates.x;
46 if (S->base_vertices_data[i][0] > S->bb.max_x)187 S.base_vertices_data[i][1] = coordinates.y;
47 S->bb.max_x = S->base_vertices_data[i][0];188
48 if (S->base_vertices_data[i][1] < S->bb.min_y)189 if (S.base_vertices_data[i][0] < S.bb.min_x)
49 S->bb.min_y = S->base_vertices_data[i][1];190 S.bb.min_x = S.base_vertices_data[i][0];
50 if (S->base_vertices_data[i][1] > S->bb.max_y)191 if (S.base_vertices_data[i][0] > S.bb.max_x)
51 S->bb.max_y = S->base_vertices_data[i][1];192 S.bb.max_x = S.base_vertices_data[i][0];
193 if (S.base_vertices_data[i][1] < S.bb.min_y)
194 S.bb.min_y = S.base_vertices_data[i][1];
195 if (S.base_vertices_data[i][1] > S.bb.max_y)
196 S.bb.max_y = S.base_vertices_data[i][1];
52197
53 /*198 /*
54 * Deselected by default.199 * Deselected by default.
55 */200 */
56 S->selection[i] = false;201 S.selection.set[i] = false;
202
203 S.base_colors_data[i][0] = DEFAULT_COLOR_R;
204 S.base_colors_data[i][1] = DEFAULT_COLOR_G;
205 S.base_colors_data[i][2] = DEFAULT_COLOR_B;
206 S.base_colors_data[i][3] = DEFAULT_COLOR_A;
207
208
209/*
210EXEC SQL FETCH c2 INTO :coordinates;
211*/
212
213{
214#line 79 "exp004base.sqc"
215 sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
216#line 79 "exp004base.sqc"
217 sqlaaloc(3,4,2,0L);
218 {
219 struct sqla_setdata_list sql_setdlist[4];
220#line 79 "exp004base.sqc"
221 sql_setdlist[0].sqltype = 496; sql_setdlist[0].sqllen = 4;
222#line 79 "exp004base.sqc"
223 sql_setdlist[0].sqldata = (void*)&coordinates.coord_id;
224#line 79 "exp004base.sqc"
225 sql_setdlist[0].sqlind = 0L;
226#line 79 "exp004base.sqc"
227 sql_setdlist[1].sqltype = 448; sql_setdlist[1].sqllen = 50;
228#line 79 "exp004base.sqc"
229 sql_setdlist[1].sqldata = (void*)&coordinates.gi;
230#line 79 "exp004base.sqc"
231 sql_setdlist[1].sqlind = 0L;
232#line 79 "exp004base.sqc"
233 sql_setdlist[2].sqltype = 480; sql_setdlist[2].sqllen = 8;
234#line 79 "exp004base.sqc"
235 sql_setdlist[2].sqldata = (void*)&coordinates.x;
236#line 79 "exp004base.sqc"
237 sql_setdlist[2].sqlind = 0L;
238#line 79 "exp004base.sqc"
239 sql_setdlist[3].sqltype = 480; sql_setdlist[3].sqllen = 8;
240#line 79 "exp004base.sqc"
241 sql_setdlist[3].sqldata = (void*)&coordinates.y;
242#line 79 "exp004base.sqc"
243 sql_setdlist[3].sqlind = 0L;
244#line 79 "exp004base.sqc"
245 sqlasetdata(3,0,4,sql_setdlist,0L,0L);
246 }
247#line 79 "exp004base.sqc"
248 sqlacall((unsigned short)25,1,0,3,0L);
249#line 79 "exp004base.sqc"
250 sqlastop(0L);
251}
252
253#line 79 "exp004base.sqc"
57254
58 S->base_colors_data[i][0] = DEFAULT_COLOR_R;
59 S->base_colors_data[i][1] = DEFAULT_COLOR_G;
60 S->base_colors_data[i][2] = DEFAULT_COLOR_B;
61 }255 }
62 fclose (coords);256
257
258/*
259EXEC SQL CLOSE c2;
260*/
261
262{
263#line 82 "exp004base.sqc"
264 sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
265#line 82 "exp004base.sqc"
266 sqlacall((unsigned short)20,1,0,0,0L);
267#line 82 "exp004base.sqc"
268 sqlastop(0L);
269}
270
271#line 82 "exp004base.sqc"
272
273
274
275/*
276EXEC SQL COMMIT;
277*/
278
279{
280#line 84 "exp004base.sqc"
281 sqlastrt(sqla_program_id, &sqla_rtinfo, &sqlca);
282#line 84 "exp004base.sqc"
283 sqlacall((unsigned short)21,0,0,0,0L);
284#line 84 "exp004base.sqc"
285 sqlastop(0L);
286}
287
288#line 84 "exp004base.sqc"
289
63290
64 /*291 /*
65 * Find the largest axis and use it to setup the projection. This292 * Find the largest axis and use it to setup the projection. This
@@ -69,38 +296,63 @@ exp004base (void)
69 */296 */
70297
71 // Min of min x or min y.298 // Min of min x or min y.
72 if (S->bb.min_x <= S->bb.min_y)299 if (S.bb.min_x <= S.bb.min_y)
73 S->ortho_min = S->bb.min_x;300 S.ortho_min = S.bb.min_x;
74 else301 else
75 S->ortho_min = S->bb.min_y;302 S.ortho_min = S.bb.min_y;
76 S->ortho_min--;303 S.ortho_min--;
77304
78 // Max of max x or max y.305 // Max of max x or max y.
79 if (S->bb.max_x >= S->bb.max_y)306 if (S.bb.max_x >= S.bb.max_y)
80 S->ortho_max = S->bb.max_x;307 S.ortho_max = S.bb.max_x;
81 else308 else
82 S->ortho_max = S->bb.max_y;309 S.ortho_max = S.bb.max_y;
83 S->ortho_max++;310 S.ortho_max++;
84311
85 // Invert the y coordinate to match up with the LGL Java viewer.312 // Invert the y coordinate to match up with the LGL Java viewer.
86 for (i = 0; i < ROWS; i++)313 for (int i = 0; i < ROWS; i++)
87 S->base_vertices_data[i][1] = 314 S.base_vertices_data[i][1] =
88 S->ortho_max - S->base_vertices_data[i][1];315 S.ortho_max - S.base_vertices_data[i][1];
89316
90 S->points = i;317 // Move the origin (0,0) to the center of the data.
318 S.ortho_min = 0.0;
319 S.ortho_max = 0.0;
320
321 for (int i = 0; i < ROWS; i++)
322 {
323 S.base_vertices_data[i][0] =
324 S.base_vertices_data[i][0] -
325 (0.5 * (S.bb.max_x - S.bb.min_x));
326
327 if (S.ortho_min > S.base_vertices_data[i][0])
328 S.ortho_min = S.base_vertices_data[i][0];
329
330 if (S.ortho_max < S.base_vertices_data[i][0])
331 S.ortho_max = S.base_vertices_data[i][0];
332
333 S.base_vertices_data[i][1] =
334 S.base_vertices_data[i][1] -
335 (0.5 * (S.bb.max_y - S.bb.min_y));
336
337 if (S.ortho_min > S.base_vertices_data[i][1])
338 S.ortho_min = S.base_vertices_data[i][1];
339
340 if (S.ortho_max < S.base_vertices_data[i][1])
341 S.ortho_max = S.base_vertices_data[i][1];
342 }
91343
92 glGenBuffers (2, S->buffers);344 glGenBuffers (2, S.buffers);
93345
94 glBindBuffer (GL_ARRAY_BUFFER, S->buffers[BASE_VERTICES]);346 glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_VERTICES]);
95 glVertexPointer (2, GL_FLOAT, 0, 0);347 glVertexPointer (2, GL_FLOAT, 0, 0);
96 glBufferData (GL_ARRAY_BUFFER, 348 glBufferData (GL_ARRAY_BUFFER,
97 sizeof (S->base_vertices_data), S->base_vertices_data,349 sizeof (S.base_vertices_data), S.base_vertices_data,
98 GL_STATIC_DRAW);350 GL_STATIC_DRAW);
99351
100 glBindBuffer (GL_ARRAY_BUFFER, S->buffers[BASE_COLORS]);352 glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]);
101 glColorPointer (3, GL_FLOAT, 0, 0);353 glColorPointer (4, GL_FLOAT, 0, 0);
102 glBufferData (GL_ARRAY_BUFFER,354 glBufferData (GL_ARRAY_BUFFER,
103 sizeof (S->base_colors_data), S->base_colors_data,355 sizeof (S.base_colors_data), S.base_colors_data,
104 GL_STATIC_DRAW);356 GL_STATIC_DRAW);
105357
106 return;358 return;

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.