author | Don Pellegrino <don@drexel.edu> | 2009-06-13 21:50:12 (GMT) |
---|---|---|
committer | Don Pellegrino <don@drexel.edu> | 2009-06-13 21:50:12 (GMT) |
commit | 4459e82efa9e8f52e52b03ac01bd865fc38babd0 (patch) (unidiff) | |
tree | c0288c114ad2fe87373b1dad1976b327f46d3a65 | |
parent | 71e4f71cba6379ad026548227b5d7deeaf98b068 (diff) | |
download | exp005-4459e82efa9e8f52e52b03ac01bd865fc38babd0.zip exp005-4459e82efa9e8f52e52b03ac01bd865fc38babd0.tar.gz exp005-4459e82efa9e8f52e52b03ac01bd865fc38babd0.tar.bz2 |
Added use of database.
-rw-r--r-- | src/controller/clear_selection.h | 6 | ||||
-rw-r--r-- | src/controller/clear_selection.sqc | 45 | ||||
-rw-r--r-- | src/controller/keyboard.c | 28 | ||||
-rw-r--r-- | src/controller/keyboard.h | 6 | ||||
-rw-r--r-- | src/controller/selection_from_db.h | 9 | ||||
-rw-r--r-- | src/controller/selection_from_db.sqc | 21 | ||||
-rw-r--r-- | src/controller/selection_to_db.h | 9 | ||||
-rw-r--r-- | src/controller/selection_to_db.sqc | 38 | ||||
-rw-r--r-- | src/model/exp004base.sqc | 144 | ||||
-rw-r--r-- | src/util/pick_convert.c | 50 | ||||
-rw-r--r-- | src/util/pick_convert.h | 29 |
11 files changed, 385 insertions, 0 deletions
diff --git a/src/controller/clear_selection.h b/src/controller/clear_selection.h new file mode 100644 index 0000000..c57e358 --- a/dev/null +++ b/src/controller/clear_selection.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef CLEAR_SELECTION_H | ||
2 | #define CLEAR_SELECTION_H | ||
3 | |||
4 | void clear_selection (void); | ||
5 | |||
6 | #endif // CLEAR_SELECTION_H | ||
diff --git a/src/controller/clear_selection.sqc b/src/controller/clear_selection.sqc new file mode 100644 index 0000000..cf04681 --- a/dev/null +++ b/src/controller/clear_selection.sqc | |||
@@ -0,0 +1,45 @@ | |||
1 | /* I seem to need this for glGenBuffers as per | ||
2 | http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */ | ||
3 | #define GL_GLEXT_PROTOTYPES | ||
4 | |||
5 | #include "clear_selection.h" | ||
6 | #include "../view/exp004state0.h" | ||
7 | #include <GL/glut.h> | ||
8 | |||
9 | EXEC SQL INCLUDE sqlca; | ||
10 | |||
11 | /* | ||
12 | * A simple alias to make the code more readable. | ||
13 | */ | ||
14 | #define S exp004state0 | ||
15 | |||
16 | void | ||
17 | clear_selection (void) | ||
18 | { | ||
19 | /* | ||
20 | * WHERE gi IS NOT NULL is added to prevent the PRECOMPILE command | ||
21 | * from throwing a warning about modifying an entire table. Since | ||
22 | * gi is defined as NOT NULL this will clear the entire table. | ||
23 | */ | ||
24 | EXEC SQL DELETE FROM vis_selection WHERE gi IS NOT NULL; | ||
25 | |||
26 | EXEC SQL COMMIT; | ||
27 | |||
28 | for (unsigned int i = 0; i < ROWS; i++) | ||
29 | { | ||
30 | S.selection[i] = false; | ||
31 | S.base_colors_data[i][0] = DEFAULT_COLOR_R; | ||
32 | S.base_colors_data[i][1] = DEFAULT_COLOR_G; | ||
33 | S.base_colors_data[i][2] = DEFAULT_COLOR_B; | ||
34 | } | ||
35 | |||
36 | glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]); | ||
37 | glColorPointer (3, GL_FLOAT, 0, 0); | ||
38 | glBufferData (GL_ARRAY_BUFFER, | ||
39 | sizeof (S.base_colors_data), S.base_colors_data, | ||
40 | GL_STATIC_DRAW); | ||
41 | |||
42 | glutPostRedisplay (); | ||
43 | |||
44 | return; | ||
45 | } | ||
diff --git a/src/controller/keyboard.c b/src/controller/keyboard.c new file mode 100644 index 0000000..c6e3c48 --- a/dev/null +++ b/src/controller/keyboard.c | |||
@@ -0,0 +1,28 @@ | |||
1 | #include "keyboard.h" | ||
2 | #include "clear_selection.h" | ||
3 | #include "selection_from_db.h" | ||
4 | |||
5 | void | ||
6 | keyboard (unsigned char key, int x, int y) | ||
7 | { | ||
8 | switch (key) | ||
9 | { | ||
10 | case 27: | ||
11 | /* | ||
12 | * ESC Pressed. | ||
13 | */ | ||
14 | clear_selection (); | ||
15 | break; | ||
16 | |||
17 | case 'g': | ||
18 | /* | ||
19 | * g has been pressed. This is used to load a selection from | ||
20 | * the database since it is the convention to use g for | ||
21 | * refreshing a buffer in Emacs. | ||
22 | */ | ||
23 | selection_from_db (); | ||
24 | break; | ||
25 | } | ||
26 | |||
27 | return; | ||
28 | } | ||
diff --git a/src/controller/keyboard.h b/src/controller/keyboard.h new file mode 100644 index 0000000..c01fc5f --- a/dev/null +++ b/src/controller/keyboard.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef KEYBOARD_H | ||
2 | #define KEYBOARD_H | ||
3 | |||
4 | void keyboard (unsigned char key, int x, int y); | ||
5 | |||
6 | #endif // KEYBOARD_H | ||
diff --git a/src/controller/selection_from_db.h b/src/controller/selection_from_db.h new file mode 100644 index 0000000..8f0d8a2 --- a/dev/null +++ b/src/controller/selection_from_db.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef SELECTION_FROM_DB_H | ||
2 | #define SELECTION_FROM_DB_H | ||
3 | |||
4 | /* | ||
5 | * Read a selection from the database into memory. | ||
6 | */ | ||
7 | void selection_from_db (void); | ||
8 | |||
9 | #endif // SELECTION_FROM_DB_H | ||
diff --git a/src/controller/selection_from_db.sqc b/src/controller/selection_from_db.sqc new file mode 100644 index 0000000..20d277e --- a/dev/null +++ b/src/controller/selection_from_db.sqc | |||
@@ -0,0 +1,21 @@ | |||
1 | #include "selection_from_db.h" | ||
2 | #include "../view/exp004state0.h" | ||
3 | |||
4 | EXEC SQL INCLUDE sqlca; | ||
5 | |||
6 | /* | ||
7 | * A simple alias to make the code more readable. | ||
8 | */ | ||
9 | #define S exp004state0 | ||
10 | |||
11 | void | ||
12 | selection_from_db (void) | ||
13 | { | ||
14 | EXEC SQL BEGIN DECLARE SECTION; | ||
15 | |||
16 | EXEC SQL END DECLARE SECTION; | ||
17 | |||
18 | |||
19 | |||
20 | return; | ||
21 | } | ||
diff --git a/src/controller/selection_to_db.h b/src/controller/selection_to_db.h new file mode 100644 index 0000000..4344e0b --- a/dev/null +++ b/src/controller/selection_to_db.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef SELECTION_TO_DB_H | ||
2 | #define SELECTION_TO_DB_H | ||
3 | |||
4 | /* | ||
5 | * Send the current selection from memory to the database. | ||
6 | */ | ||
7 | void selection_to_db (void); | ||
8 | |||
9 | #endif // SELECTION_TO_DB_H | ||
diff --git a/src/controller/selection_to_db.sqc b/src/controller/selection_to_db.sqc new file mode 100644 index 0000000..a6c91b9 --- a/dev/null +++ b/src/controller/selection_to_db.sqc | |||
@@ -0,0 +1,38 @@ | |||
1 | #include "selection_to_db.h" | ||
2 | #include "../view/exp004state0.h" | ||
3 | #include <string.h> | ||
4 | |||
5 | EXEC SQL INCLUDE sqlca; | ||
6 | |||
7 | /* | ||
8 | * A simple alias to make the code more readable. | ||
9 | */ | ||
10 | #define S exp004state0 | ||
11 | |||
12 | void | ||
13 | selection_to_db (void) | ||
14 | { | ||
15 | EXEC SQL BEGIN DECLARE SECTION; | ||
16 | char gi[255]; | ||
17 | EXEC SQL END DECLARE SECTION; | ||
18 | |||
19 | /* | ||
20 | * WHERE gi IS NOT NULL is added to prevent the PRECOMPILE command | ||
21 | * from throwing a warning about modifying an entire table. Since | ||
22 | * gi is defined as NOT NULL this will clear the entire table. | ||
23 | */ | ||
24 | EXEC SQL DELETE FROM vis_selection WHERE gi IS NOT NULL; | ||
25 | |||
26 | for (unsigned int i = 0; i < ROWS; i++) | ||
27 | { | ||
28 | if (S.selection[i] == true) | ||
29 | { | ||
30 | strncpy (gi, S.gi_data[i] + 3, sizeof(gi)); | ||
31 | EXEC SQL INSERT INTO vis_selection VALUES (:gi); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | EXEC SQL COMMIT; | ||
36 | |||
37 | return; | ||
38 | } | ||
diff --git a/src/model/exp004base.sqc b/src/model/exp004base.sqc new file mode 100644 index 0000000..6189b72 --- a/dev/null +++ b/src/model/exp004base.sqc | |||
@@ -0,0 +1,144 @@ | |||
1 | /* I seem to need this for glGenBuffers as per | ||
2 | http://www.gamedev.net/community/forums/topic.asp?topic_id=422358 */ | ||
3 | #define GL_GLEXT_PROTOTYPES | ||
4 | |||
5 | #include "exp004base.h" | ||
6 | #include "../view/exp004state0.h" | ||
7 | #include <GL/glut.h> | ||
8 | #include <stdio.h> | ||
9 | #include <string.h> | ||
10 | |||
11 | EXEC SQL INCLUDE sqlca; | ||
12 | |||
13 | /* | ||
14 | * A simple alias to make the code more readable. | ||
15 | */ | ||
16 | #define S exp004state0 | ||
17 | |||
18 | void | ||
19 | exp004base (void) | ||
20 | { | ||
21 | EXEC SQL CONNECT TO exp004; | ||
22 | |||
23 | /* | ||
24 | * This implementation can be improved by mapping the video memory | ||
25 | * directly rather than loading into system memory and then copying | ||
26 | * into video memory. | ||
27 | */ | ||
28 | |||
29 | /* | ||
30 | * db2dclgn -d exp004 -t coordinates | ||
31 | */ | ||
32 | EXEC SQL BEGIN DECLARE SECTION; | ||
33 | EXEC SQL INCLUDE 'model/coordinates.h'; | ||
34 | EXEC SQL END DECLARE SECTION; | ||
35 | |||
36 | EXEC SQL DECLARE c2 CURSOR FOR | ||
37 | SELECT * FROM coordinates; | ||
38 | |||
39 | EXEC SQL OPEN c2; | ||
40 | |||
41 | /* | ||
42 | FILE* coords = | ||
43 | fopen ("/home/don/exp004/test/run20090514/run20090514.coords", "r"); | ||
44 | int i = 0; | ||
45 | */ | ||
46 | |||
47 | /* | ||
48 | * Initialize the bounding box of the points. | ||
49 | */ | ||
50 | S.bb.min_x = 0.0; | ||
51 | S.bb.max_x = 0.0; | ||
52 | S.bb.min_y = 0.0; | ||
53 | S.bb.max_y = 0.0; | ||
54 | |||
55 | // for (i = 0; i < ROWS; i++) | ||
56 | |||
57 | EXEC SQL FETCH c2 INTO :coordinates; | ||
58 | while (sqlca.sqlcode != 100) | ||
59 | { | ||
60 | /* | ||
61 | fscanf (coords, "%s %f %f\n", | ||
62 | S.gi_data[i], | ||
63 | &S.base_vertices_data[i][0], | ||
64 | &S.base_vertices_data[i][1]); | ||
65 | */ | ||
66 | |||
67 | int i = coordinates.coord_id; | ||
68 | |||
69 | strncpy(S.gi_data[i], | ||
70 | coordinates.gi.data, | ||
71 | sizeof (S.gi_data[i])); | ||
72 | |||
73 | S.base_vertices_data[i][0] = coordinates.x; | ||
74 | S.base_vertices_data[i][1] = coordinates.y; | ||
75 | |||
76 | if (S.base_vertices_data[i][0] < S.bb.min_x) | ||
77 | S.bb.min_x = S.base_vertices_data[i][0]; | ||
78 | if (S.base_vertices_data[i][0] > S.bb.max_x) | ||
79 | S.bb.max_x = S.base_vertices_data[i][0]; | ||
80 | if (S.base_vertices_data[i][1] < S.bb.min_y) | ||
81 | S.bb.min_y = S.base_vertices_data[i][1]; | ||
82 | if (S.base_vertices_data[i][1] > S.bb.max_y) | ||
83 | S.bb.max_y = S.base_vertices_data[i][1]; | ||
84 | |||
85 | /* | ||
86 | * Deselected by default. | ||
87 | */ | ||
88 | S.selection[i] = false; | ||
89 | |||
90 | S.base_colors_data[i][0] = DEFAULT_COLOR_R; | ||
91 | S.base_colors_data[i][1] = DEFAULT_COLOR_G; | ||
92 | S.base_colors_data[i][2] = DEFAULT_COLOR_B; | ||
93 | |||
94 | EXEC SQL FETCH c2 INTO :coordinates; | ||
95 | } | ||
96 | |||
97 | EXEC SQL CLOSE c2; | ||
98 | |||
99 | /* | ||
100 | fclose (coords); | ||
101 | */ | ||
102 | |||
103 | /* | ||
104 | * Find the largest axis and use it to setup the projection. This | ||
105 | * is done to preserve the aspect ratio. The aspect ratio should be | ||
106 | * preserved since relative distance is a meaningful indicator in | ||
107 | * the map. | ||
108 | */ | ||
109 | |||
110 | // Min of min x or min y. | ||
111 | if (S.bb.min_x <= S.bb.min_y) | ||
112 | S.ortho_min = S.bb.min_x; | ||
113 | else | ||
114 | S.ortho_min = S.bb.min_y; | ||
115 | S.ortho_min--; | ||
116 | |||
117 | // Max of max x or max y. | ||
118 | if (S.bb.max_x >= S.bb.max_y) | ||
119 | S.ortho_max = S.bb.max_x; | ||
120 | else | ||
121 | S.ortho_max = S.bb.max_y; | ||
122 | S.ortho_max++; | ||
123 | |||
124 | // Invert the y coordinate to match up with the LGL Java viewer. | ||
125 | for (int i = 0; i < ROWS; i++) | ||
126 | S.base_vertices_data[i][1] = | ||
127 | S.ortho_max - S.base_vertices_data[i][1]; | ||
128 | |||
129 | glGenBuffers (2, S.buffers); | ||
130 | |||
131 | glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_VERTICES]); | ||
132 | glVertexPointer (2, GL_FLOAT, 0, 0); | ||
133 | glBufferData (GL_ARRAY_BUFFER, | ||
134 | sizeof (S.base_vertices_data), S.base_vertices_data, | ||
135 | GL_STATIC_DRAW); | ||
136 | |||
137 | glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]); | ||
138 | glColorPointer (3, GL_FLOAT, 0, 0); | ||
139 | glBufferData (GL_ARRAY_BUFFER, | ||
140 | sizeof (S.base_colors_data), S.base_colors_data, | ||
141 | GL_STATIC_DRAW); | ||
142 | |||
143 | return; | ||
144 | } | ||
diff --git a/src/util/pick_convert.c b/src/util/pick_convert.c new file mode 100644 index 0000000..baafcfb --- a/dev/null +++ b/src/util/pick_convert.c | |||
@@ -0,0 +1,50 @@ | |||
1 | #include "pick_convert.h" | ||
2 | |||
3 | /* | ||
4 | * Width and height of a selection box about a single-click selection. | ||
5 | */ | ||
6 | #define N 3.0 | ||
7 | |||
8 | void pick_convert (int select_x, int select_y, int x, int y, | ||
9 | double *c_x, double *c_y, double *w, double *h) | ||
10 | { | ||
11 | /* | ||
12 | * Calculate X and the width. | ||
13 | */ | ||
14 | if (x > select_x) | ||
15 | { | ||
16 | *c_x = (x - select_x) / 2.0 + select_x; | ||
17 | *w = x - select_x; | ||
18 | } | ||
19 | else if (x < select_x) | ||
20 | { | ||
21 | *c_x = (select_x - x) / 2.0 + x; | ||
22 | *w = select_x - x; | ||
23 | } | ||
24 | else | ||
25 | { | ||
26 | *c_x = x; | ||
27 | *w = N; | ||
28 | } | ||
29 | |||
30 | /* | ||
31 | * Calculate Y and the width. | ||
32 | */ | ||
33 | if (y > select_y) | ||
34 | { | ||
35 | *c_y = (y - select_y) / 2.0 + select_y; | ||
36 | *h = y - select_y; | ||
37 | } | ||
38 | else if (y < select_y) | ||
39 | { | ||
40 | *c_y = (select_y - y) / 2.0 + y; | ||
41 | *h = select_y - y; | ||
42 | } | ||
43 | else | ||
44 | { | ||
45 | *c_y = y; | ||
46 | *h = N; | ||
47 | } | ||
48 | |||
49 | return; | ||
50 | } | ||
diff --git a/src/util/pick_convert.h b/src/util/pick_convert.h new file mode 100644 index 0000000..a532b6e --- a/dev/null +++ b/src/util/pick_convert.h | |||
@@ -0,0 +1,29 @@ | |||
1 | #ifndef PICK_CONVERT_H | ||
2 | #define PICK_CONVERT_H | ||
3 | |||
4 | /* | ||
5 | * Convert bounding box coordinates to a center point and delta x and | ||
6 | * y coordinates. This function initially designed to convert a | ||
7 | * two-point mouse selection to the parameters needed for | ||
8 | * gluPickMatrix. | ||
9 | * | ||
10 | * select_x: X coordinate of point used to begin selection. | ||
11 | * | ||
12 | * select_y: Y coordinate of point used to begin selection. | ||
13 | * | ||
14 | * x: X coordinate of point used to end selection. | ||
15 | * | ||
16 | * y: Y coordinate of point used to end selection. | ||
17 | * | ||
18 | * c_x: X coordinate in the center of the picking region. | ||
19 | * | ||
20 | * c_y: Y coordinate in the center of the picking region. | ||
21 | * | ||
22 | * w: Width of the picking region. | ||
23 | * | ||
24 | * h: Height of the picking region. | ||
25 | */ | ||
26 | void pick_convert (int select_x, int select_y, int x, int y, | ||
27 | double *c_x, double *c_y, double *w, double *h); | ||
28 | |||
29 | #endif // PICK_CONVERT_H | ||