summaryrefslogtreecommitdiffstats
authorDon Pellegrino <don@coffee.donpellegrino.com>2009-08-14 19:23:49 (GMT)
committer Don Pellegrino <don@coffee.donpellegrino.com>2009-08-14 19:23:49 (GMT)
commit59a60ef697d44284d89bc8a05990632bb2a56fb8 (patch) (side-by-side diff)
tree50a2da83b3518e5f45615f183fdb1904992b50f5
parentcc84337c371ff6b7bebffec6a94ac33ca5061438 (diff)
downloadexp005-59a60ef697d44284d89bc8a05990632bb2a56fb8.zip
exp005-59a60ef697d44284d89bc8a05990632bb2a56fb8.tar.gz
exp005-59a60ef697d44284d89bc8a05990632bb2a56fb8.tar.bz2
Modified to use dynamic memory allocation for the number of nodes.
-rw-r--r--src/model/exp004base.sqc98
1 files changed, 68 insertions, 30 deletions
diff --git a/src/model/exp004base.sqc b/src/model/exp004base.sqc
index 5c2d8d2..2879263 100644
--- a/src/model/exp004base.sqc
+++ b/src/model/exp004base.sqc
@@ -7,6 +7,7 @@
#include "../util/check_error.h"
#include <GL/glut.h>
#include <string.h>
+#include <stdlib.h>
#include "sqlca.h"
extern struct sqlca sqlca;
@@ -29,8 +30,28 @@ exp004base (void)
*/
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL INCLUDE 'model/coordinates.h';
+ sqlint32 rows;
EXEC SQL END DECLARE SECTION;
+ /* Determine how many nodes have coordinates assigned to them. */
+ EXEC SQL SELECT COUNT(*) INTO :rows FROM coordinates;
+
+ /* 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 * 20, sizeof (char));
+
+ free (S.base_vertices_data);
+ S.base_vertices_data = calloc (rows * 2, sizeof (float));
+
+ free (S.base_colors_data);
+ S.base_colors_data = calloc (rows * 4, sizeof (float));
+
EXEC SQL DECLARE c2 CURSOR FOR SELECT *FROM coordinates;
EXEC SQL OPEN c2;
@@ -48,29 +69,38 @@ exp004base (void)
{
int i = coordinates.coord_id - 1;
- strncpy (S.gi_data[i], coordinates.gi.data, sizeof (S.gi_data[i]));
+ 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;
+ float* v = S.base_vertices_data + (i * 2);
+ *v = coordinates.x;
+ v++;
+ *v = 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];
+ 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;
- 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;
- S.base_colors_data[i][3] = DEFAULT_COLOR_A;
+ 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;
}
@@ -101,32 +131,40 @@ exp004base (void)
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];
+ 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;
- for (int i = 0; i < ROWS; i++)
+ v = S.base_vertices_data;
+ for (int i = 0; i < S.rows; i++)
{
- S.base_vertices_data[i][0] =
- S.base_vertices_data[i][0] - (0.5 * (S.bb.max_x - S.bb.min_x));
+ *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;
- if (S.ortho_min > S.base_vertices_data[i][0])
- S.ortho_min = S.base_vertices_data[i][0];
+ v++;
- if (S.ortho_max < S.base_vertices_data[i][0])
- S.ortho_max = S.base_vertices_data[i][0];
+ *v = *v - (0.5 * (S.bb.max_y - S.bb.min_y));
- S.base_vertices_data[i][1] =
- S.base_vertices_data[i][1] - (0.5 * (S.bb.max_y - S.bb.min_y));
+ if (S.ortho_min > *v)
+ S.ortho_min = *v;
- if (S.ortho_min > S.base_vertices_data[i][1])
- S.ortho_min = S.base_vertices_data[i][1];
+ if (S.ortho_max < *v)
+ S.ortho_max = *v;
- if (S.ortho_max < S.base_vertices_data[i][1])
- S.ortho_max = S.base_vertices_data[i][1];
+ v++;
}
glGenBuffers (2, S.buffers);

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.