author | Don 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) |
commit | 59a60ef697d44284d89bc8a05990632bb2a56fb8 (patch) (unidiff) | |
tree | 50a2da83b3518e5f45615f183fdb1904992b50f5 | |
parent | cc84337c371ff6b7bebffec6a94ac33ca5061438 (diff) | |
download | exp005-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.sqc | 98 |
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 @@ | |||
7 | #include "../util/check_error.h" | 7 | #include "../util/check_error.h" |
8 | #include <GL/glut.h> | 8 | #include <GL/glut.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <stdlib.h> | ||
10 | #include "sqlca.h" | 11 | #include "sqlca.h" |
11 | extern struct sqlca sqlca; | 12 | extern struct sqlca sqlca; |
12 | 13 | ||
@@ -29,8 +30,28 @@ exp004base (void) | |||
29 | */ | 30 | */ |
30 | EXEC SQL BEGIN DECLARE SECTION; | 31 | EXEC SQL BEGIN DECLARE SECTION; |
31 | EXEC SQL INCLUDE 'model/coordinates.h'; | 32 | EXEC SQL INCLUDE 'model/coordinates.h'; |
33 | sqlint32 rows; | ||
32 | EXEC SQL END DECLARE SECTION; | 34 | EXEC SQL END DECLARE SECTION; |
33 | 35 | ||
36 | /* Determine how many nodes have coordinates assigned to them. */ | ||
37 | EXEC SQL SELECT COUNT(*) INTO :rows FROM coordinates; | ||
38 | |||
39 | /* Free any existing coordinates and allocate memory to store the | ||
40 | new values. */ | ||
41 | S.rows = rows; | ||
42 | |||
43 | free (S.selection.set); | ||
44 | S.selection.set = calloc (rows, sizeof (bool)); | ||
45 | |||
46 | free (S.gi_data); | ||
47 | S.gi_data = calloc (rows * 20, sizeof (char)); | ||
48 | |||
49 | free (S.base_vertices_data); | ||
50 | S.base_vertices_data = calloc (rows * 2, sizeof (float)); | ||
51 | |||
52 | free (S.base_colors_data); | ||
53 | S.base_colors_data = calloc (rows * 4, sizeof (float)); | ||
54 | |||
34 | EXEC SQL DECLARE c2 CURSOR FOR SELECT *FROM coordinates; | 55 | EXEC SQL DECLARE c2 CURSOR FOR SELECT *FROM coordinates; |
35 | 56 | ||
36 | EXEC SQL OPEN c2; | 57 | EXEC SQL OPEN c2; |
@@ -48,29 +69,38 @@ exp004base (void) | |||
48 | { | 69 | { |
49 | int i = coordinates.coord_id - 1; | 70 | int i = coordinates.coord_id - 1; |
50 | 71 | ||
51 | strncpy (S.gi_data[i], coordinates.gi.data, sizeof (S.gi_data[i])); | 72 | strncpy (S.gi_data + i, coordinates.gi.data, sizeof (S.gi_data[i])); |
52 | 73 | ||
53 | S.base_vertices_data[i][0] = coordinates.x; | 74 | float* v = S.base_vertices_data + (i * 2); |
54 | S.base_vertices_data[i][1] = coordinates.y; | 75 | *v = coordinates.x; |
76 | v++; | ||
77 | *v = coordinates.y; | ||
55 | 78 | ||
56 | if (S.base_vertices_data[i][0] < S.bb.min_x) | 79 | v = S.base_vertices_data + (i * 2); |
57 | S.bb.min_x = S.base_vertices_data[i][0]; | 80 | if (*v < S.bb.min_x) |
58 | if (S.base_vertices_data[i][0] > S.bb.max_x) | 81 | S.bb.min_x = *v; |
59 | S.bb.max_x = S.base_vertices_data[i][0]; | 82 | if (*v > S.bb.max_x) |
60 | if (S.base_vertices_data[i][1] < S.bb.min_y) | 83 | S.bb.max_x = *v; |
61 | S.bb.min_y = S.base_vertices_data[i][1]; | 84 | |
62 | if (S.base_vertices_data[i][1] > S.bb.max_y) | 85 | v++; |
63 | S.bb.max_y = S.base_vertices_data[i][1]; | 86 | if (*v < S.bb.min_y) |
87 | S.bb.min_y = *v; | ||
88 | if (*v > S.bb.max_y) | ||
89 | S.bb.max_y = *v; | ||
64 | 90 | ||
65 | /* | 91 | /* |
66 | * Deselected by default. | 92 | * Deselected by default. |
67 | */ | 93 | */ |
68 | S.selection.set[i] = false; | 94 | S.selection.set[i] = false; |
69 | 95 | ||
70 | S.base_colors_data[i][0] = DEFAULT_COLOR_R; | 96 | float* c = S.base_colors_data + (i * 4); |
71 | S.base_colors_data[i][1] = DEFAULT_COLOR_G; | 97 | *c = DEFAULT_COLOR_R; |
72 | S.base_colors_data[i][2] = DEFAULT_COLOR_B; | 98 | c++; |
73 | S.base_colors_data[i][3] = DEFAULT_COLOR_A; | 99 | *c = DEFAULT_COLOR_G; |
100 | c++; | ||
101 | *c = DEFAULT_COLOR_B; | ||
102 | c++; | ||
103 | *c = DEFAULT_COLOR_A; | ||
74 | 104 | ||
75 | EXEC SQL FETCH c2 INTO:coordinates; | 105 | EXEC SQL FETCH c2 INTO:coordinates; |
76 | } | 106 | } |
@@ -101,32 +131,40 @@ exp004base (void) | |||
101 | S.ortho_max++; | 131 | S.ortho_max++; |
102 | 132 | ||
103 | // Invert the y coordinate to match up with the LGL Java viewer. | 133 | // Invert the y coordinate to match up with the LGL Java viewer. |
104 | for (int i = 0; i < ROWS; i++) | 134 | float* v = S.base_vertices_data; |
105 | S.base_vertices_data[i][1] = S.ortho_max - S.base_vertices_data[i][1]; | 135 | for (int i = 0; i < S.rows; i++) |
136 | { | ||
137 | v++; | ||
138 | *v = S.ortho_max - *v; | ||
139 | v++; | ||
140 | } | ||
106 | 141 | ||
107 | // Move the origin (0,0) to the center of the data. | 142 | // Move the origin (0,0) to the center of the data. |
108 | S.ortho_min = 0.0; | 143 | S.ortho_min = 0.0; |
109 | S.ortho_max = 0.0; | 144 | S.ortho_max = 0.0; |
110 | 145 | ||
111 | for (int i = 0; i < ROWS; i++) | 146 | v = S.base_vertices_data; |
147 | for (int i = 0; i < S.rows; i++) | ||
112 | { | 148 | { |
113 | S.base_vertices_data[i][0] = | 149 | *v = *v - (0.5 * (S.bb.max_x - S.bb.min_x)); |
114 | S.base_vertices_data[i][0] - (0.5 * (S.bb.max_x - S.bb.min_x)); | 150 | |
151 | if (S.ortho_min > *v) | ||
152 | S.ortho_min = *v; | ||
153 | |||
154 | if (S.ortho_max < *v) | ||
155 | S.ortho_max = *v; | ||
115 | 156 | ||
116 | if (S.ortho_min > S.base_vertices_data[i][0]) | 157 | v++; |
117 | S.ortho_min = S.base_vertices_data[i][0]; | ||
118 | 158 | ||
119 | if (S.ortho_max < S.base_vertices_data[i][0]) | 159 | *v = *v - (0.5 * (S.bb.max_y - S.bb.min_y)); |
120 | S.ortho_max = S.base_vertices_data[i][0]; | ||
121 | 160 | ||
122 | S.base_vertices_data[i][1] = | 161 | if (S.ortho_min > *v) |
123 | S.base_vertices_data[i][1] - (0.5 * (S.bb.max_y - S.bb.min_y)); | 162 | S.ortho_min = *v; |
124 | 163 | ||
125 | if (S.ortho_min > S.base_vertices_data[i][1]) | 164 | if (S.ortho_max < *v) |
126 | S.ortho_min = S.base_vertices_data[i][1]; | 165 | S.ortho_max = *v; |
127 | 166 | ||
128 | if (S.ortho_max < S.base_vertices_data[i][1]) | 167 | v++; |
129 | S.ortho_max = S.base_vertices_data[i][1]; | ||
130 | } | 168 | } |
131 | 169 | ||
132 | glGenBuffers (2, S.buffers); | 170 | glGenBuffers (2, S.buffers); |