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 #include #include #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; }