summaryrefslogtreecommitdiffstats
Unidiff
-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 @@
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"
11extern struct sqlca sqlca;12extern struct sqlca sqlca;
1213
@@ -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;
3335
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;
3556
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;
5071
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]));
5273
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;
5578
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;
6490
65 /*91 /*
66 * Deselected by default.92 * Deselected by default.
67 */93 */
68 S.selection.set[i] = false;94 S.selection.set[i] = false;
6995
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;
74104
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++;
102132
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 }
106141
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;
110145
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;
115156
116 if (S.ortho_min > S.base_vertices_data[i][0])157 v++;
117 S.ortho_min = S.base_vertices_data[i][0];
118158
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];
121160
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;
124163
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;
127166
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 }
131169
132 glGenBuffers (2, S.buffers);170 glGenBuffers (2, S.buffers);

Valid XHTML 1.0 Strict

Copyright © 2009 Don Pellegrino All Rights Reserved.