summaryrefslogtreecommitdiffstats
Side-by-side diff
-rw-r--r--src/controller/clear_selection.h6
-rw-r--r--src/controller/clear_selection.sqc45
-rw-r--r--src/controller/keyboard.c28
-rw-r--r--src/controller/keyboard.h6
-rw-r--r--src/controller/selection_from_db.h9
-rw-r--r--src/controller/selection_from_db.sqc21
-rw-r--r--src/controller/selection_to_db.h9
-rw-r--r--src/controller/selection_to_db.sqc38
-rw-r--r--src/model/exp004base.sqc144
-rw-r--r--src/util/pick_convert.c50
-rw-r--r--src/util/pick_convert.h29
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 @@
+#ifndef CLEAR_SELECTION_H
+#define CLEAR_SELECTION_H
+
+void clear_selection (void);
+
+#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 @@
+/* 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 "clear_selection.h"
+#include "../view/exp004state0.h"
+#include <GL/glut.h>
+
+EXEC SQL INCLUDE sqlca;
+
+/*
+ * A simple alias to make the code more readable.
+ */
+#define S exp004state0
+
+void
+clear_selection (void)
+{
+ /*
+ * WHERE gi IS NOT NULL is added to prevent the PRECOMPILE command
+ * from throwing a warning about modifying an entire table. Since
+ * gi is defined as NOT NULL this will clear the entire table.
+ */
+ EXEC SQL DELETE FROM vis_selection WHERE gi IS NOT NULL;
+
+ EXEC SQL COMMIT;
+
+ for (unsigned int i = 0; i < ROWS; i++)
+ {
+ S.selection[i] = false;
+ S.base_colors_data[i][0] = DEFAULT_COLOR_R;
+ S.base_colors_data[i][1] = DEFAULT_COLOR_G;
+ S.base_colors_data[i][2] = DEFAULT_COLOR_B;
+ }
+
+ glBindBuffer (GL_ARRAY_BUFFER, S.buffers[BASE_COLORS]);
+ glColorPointer (3, GL_FLOAT, 0, 0);
+ glBufferData (GL_ARRAY_BUFFER,
+ sizeof (S.base_colors_data), S.base_colors_data,
+ GL_STATIC_DRAW);
+
+ glutPostRedisplay ();
+
+ return;
+}
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 @@
+#include "keyboard.h"
+#include "clear_selection.h"
+#include "selection_from_db.h"
+
+void
+keyboard (unsigned char key, int x, int y)
+{
+ switch (key)
+ {
+ case 27:
+ /*
+ * ESC Pressed.
+ */
+ clear_selection ();
+ break;
+
+ case 'g':
+ /*
+ * g has been pressed. This is used to load a selection from
+ * the database since it is the convention to use g for
+ * refreshing a buffer in Emacs.
+ */
+ selection_from_db ();
+ break;
+ }
+
+ return;
+}
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 @@
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+void keyboard (unsigned char key, int x, int y);
+
+#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 @@
+#ifndef SELECTION_FROM_DB_H
+#define SELECTION_FROM_DB_H
+
+/*
+ * Read a selection from the database into memory.
+ */
+void selection_from_db (void);
+
+#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 @@
+#include "selection_from_db.h"
+#include "../view/exp004state0.h"
+
+EXEC SQL INCLUDE sqlca;
+
+/*
+ * A simple alias to make the code more readable.
+ */
+#define S exp004state0
+
+void
+selection_from_db (void)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+
+ EXEC SQL END DECLARE SECTION;
+
+
+
+ return;
+}
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 @@
+#ifndef SELECTION_TO_DB_H
+#define SELECTION_TO_DB_H
+
+/*
+ * Send the current selection from memory to the database.
+ */
+void selection_to_db (void);
+
+#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 @@
+#include "selection_to_db.h"
+#include "../view/exp004state0.h"
+#include <string.h>
+
+EXEC SQL INCLUDE sqlca;
+
+/*
+ * A simple alias to make the code more readable.
+ */
+#define S exp004state0
+
+void
+selection_to_db (void)
+{
+ EXEC SQL BEGIN DECLARE SECTION;
+ char gi[255];
+ EXEC SQL END DECLARE SECTION;
+
+ /*
+ * WHERE gi IS NOT NULL is added to prevent the PRECOMPILE command
+ * from throwing a warning about modifying an entire table. Since
+ * gi is defined as NOT NULL this will clear the entire table.
+ */
+ EXEC SQL DELETE FROM vis_selection WHERE gi IS NOT NULL;
+
+ for (unsigned int i = 0; i < ROWS; i++)
+ {
+ if (S.selection[i] == true)
+ {
+ strncpy (gi, S.gi_data[i] + 3, sizeof(gi));
+ EXEC SQL INSERT INTO vis_selection VALUES (:gi);
+ }
+ }
+
+ EXEC SQL COMMIT;
+
+ return;
+}
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 @@
+/* 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 "exp004base.h"
+#include "../view/exp004state0.h"
+#include <GL/glut.h>
+#include <stdio.h>
+#include <string.h>
+
+EXEC SQL INCLUDE sqlca;
+
+/*
+ * A simple alias to make the code more readable.
+ */
+#define S exp004state0
+
+void
+exp004base (void)
+{
+ EXEC SQL CONNECT TO exp004;
+
+ /*
+ * 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;
+ EXEC SQL INCLUDE 'model/coordinates.h';
+ EXEC SQL END DECLARE SECTION;
+
+ EXEC SQL DECLARE c2 CURSOR FOR
+ SELECT * FROM coordinates;
+
+ EXEC SQL OPEN c2;
+
+ /*
+ FILE* coords =
+ fopen ("/home/don/exp004/test/run20090514/run20090514.coords", "r");
+ int i = 0;
+ */
+
+ /*
+ * 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;
+
+ // for (i = 0; i < ROWS; i++)
+
+ EXEC SQL FETCH c2 INTO :coordinates;
+ while (sqlca.sqlcode != 100)
+ {
+ /*
+ fscanf (coords, "%s %f %f\n",
+ S.gi_data[i],
+ &S.base_vertices_data[i][0],
+ &S.base_vertices_data[i][1]);
+ */
+
+ int i = coordinates.coord_id;
+
+ strncpy(S.gi_data[i],
+ coordinates.gi.data,
+ sizeof (S.gi_data[i]));
+
+ S.base_vertices_data[i][0] = coordinates.x;
+ S.base_vertices_data[i][1] = coordinates.y;
+
+ if (S.base_vertices_data[i][0] < S.bb.min_x)
+ S.bb.min_x = S.base_vertices_data[i][0];
+ if (S.base_vertices_data[i][0] > S.bb.max_x)
+ S.bb.max_x = S.base_vertices_data[i][0];
+ if (S.base_vertices_data[i][1] < S.bb.min_y)
+ S.bb.min_y = S.base_vertices_data[i][1];
+ if (S.base_vertices_data[i][1] > S.bb.max_y)
+ S.bb.max_y = S.base_vertices_data[i][1];
+
+ /*
+ * Deselected by default.
+ */
+ S.selection[i] = false;
+
+ S.base_colors_data[i][0] = DEFAULT_COLOR_R;
+ S.base_colors_data[i][1] = DEFAULT_COLOR_G;
+ S.base_colors_data[i][2] = DEFAULT_COLOR_B;
+
+ EXEC SQL FETCH c2 INTO :coordinates;
+ }
+
+ EXEC SQL CLOSE c2;
+
+ /*
+ fclose (coords);
+ */
+
+ /*
+ * 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.
+ for (int i = 0; i < ROWS; i++)
+ S.base_vertices_data[i][1] =
+ S.ortho_max - S.base_vertices_data[i][1];
+
+ 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 (3, GL_FLOAT, 0, 0);
+ glBufferData (GL_ARRAY_BUFFER,
+ sizeof (S.base_colors_data), S.base_colors_data,
+ GL_STATIC_DRAW);
+
+ return;
+}
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 @@
+#include "pick_convert.h"
+
+/*
+ * Width and height of a selection box about a single-click selection.
+ */
+#define N 3.0
+
+void pick_convert (int select_x, int select_y, int x, int y,
+ double *c_x, double *c_y, double *w, double *h)
+{
+ /*
+ * Calculate X and the width.
+ */
+ if (x > select_x)
+ {
+ *c_x = (x - select_x) / 2.0 + select_x;
+ *w = x - select_x;
+ }
+ else if (x < select_x)
+ {
+ *c_x = (select_x - x) / 2.0 + x;
+ *w = select_x - x;
+ }
+ else
+ {
+ *c_x = x;
+ *w = N;
+ }
+
+ /*
+ * Calculate Y and the width.
+ */
+ if (y > select_y)
+ {
+ *c_y = (y - select_y) / 2.0 + select_y;
+ *h = y - select_y;
+ }
+ else if (y < select_y)
+ {
+ *c_y = (select_y - y) / 2.0 + y;
+ *h = select_y - y;
+ }
+ else
+ {
+ *c_y = y;
+ *h = N;
+ }
+
+ return;
+}
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 @@
+#ifndef PICK_CONVERT_H
+#define PICK_CONVERT_H
+
+/*
+ * Convert bounding box coordinates to a center point and delta x and
+ * y coordinates. This function initially designed to convert a
+ * two-point mouse selection to the parameters needed for
+ * gluPickMatrix.
+ *
+ * select_x: X coordinate of point used to begin selection.
+ *
+ * select_y: Y coordinate of point used to begin selection.
+ *
+ * x: X coordinate of point used to end selection.
+ *
+ * y: Y coordinate of point used to end selection.
+ *
+ * c_x: X coordinate in the center of the picking region.
+ *
+ * c_y: Y coordinate in the center of the picking region.
+ *
+ * w: Width of the picking region.
+ *
+ * h: Height of the picking region.
+ */
+void pick_convert (int select_x, int select_y, int x, int y,
+ double *c_x, double *c_y, double *w, double *h);
+
+#endif // PICK_CONVERT_H

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.