7fd59977 |
1 | #include <OpenGl_tgl_all.hxx> |
2 | #include <OpenGl_graduatedtrihedron.hxx> |
3 | |
4 | #include <stddef.h> |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | #include <math.h> |
8 | |
9 | #include <GL/gl.h> |
10 | #include <GL/glu.h> |
11 | |
12 | #include <InterfaceGraphic_Graphic3d.hxx> |
13 | #include <InterfaceGraphic_Aspect.hxx> |
14 | #include <InterfaceGraphic_Visual3d.hxx> |
15 | |
16 | #include <OpenGl_tgl_funcs.hxx> |
17 | #include <OpenGl_tgl_subrs.hxx> |
18 | #include <OpenGl_TextRender.hxx> |
19 | |
20 | #ifdef HAVE_CONFIG_H |
21 | #include <config.h> |
22 | #endif |
23 | #ifdef HAVE_STRING_H |
24 | #include <string.h> |
25 | #endif |
26 | |
27 | /* Graduated trihedron data */ |
28 | static int nbWsIds = 0; /* Number of the views (size of the arrays below */ |
29 | static int* WsIds = 0; /* The array contans indices of graduated trihedron data corresponding to the view ID */ |
30 | static CALL_DEF_GRADUATEDTRIHEDRON** graduatedTrihedronData = 0; /* The array contains graduated trihedron data of all views */ |
31 | |
32 | /* Bounding box */ |
33 | float xmin = 0.0f, ymin = 0.0f, zmin = 0.0f, xmax = 100.0f, ymax = 100.0f, zmax = 100.0f; |
34 | |
35 | static void copyData(CALL_DEF_GRADUATEDTRIHEDRON* fromData, CALL_DEF_GRADUATEDTRIHEDRON* toData) |
36 | { |
37 | int len; |
38 | |
39 | /* Names of axes */ |
40 | /* X-name */ |
41 | if (fromData->xname) |
42 | len = strlen(fromData->xname) + 1; |
43 | else |
44 | len = 1; |
45 | toData->xname = (char*) malloc(len * sizeof(char)); |
46 | if (fromData->xname) |
47 | strcpy(toData->xname, fromData->xname); |
48 | else |
49 | toData->xname[0] = '\0'; |
50 | /* Y-name */ |
51 | if (fromData->yname) |
52 | len = strlen(fromData->yname) + 1; |
53 | else |
54 | len = 1; |
55 | toData->yname = (char*) malloc(len * sizeof(char)); |
56 | if (fromData->yname) |
57 | strcpy(toData->yname, fromData->yname); |
58 | else |
59 | toData->yname[0] = '\0'; |
60 | /* Z-name */ |
61 | if (fromData->zname) |
62 | len = strlen(fromData->zname) + 1; |
63 | else |
64 | len = 1; |
65 | toData->zname = (char*) malloc(len * sizeof(char)); |
66 | if (fromData->zname) |
67 | strcpy(toData->zname, fromData->zname); |
68 | else |
69 | toData->zname[0] = '\0'; |
70 | /* Draw names */ |
71 | toData->xdrawname = fromData->xdrawname; |
72 | toData->ydrawname = fromData->ydrawname; |
73 | toData->zdrawname = fromData->zdrawname; |
74 | /* Draw values */ |
75 | toData->xdrawvalues = fromData->xdrawvalues; |
76 | toData->ydrawvalues = fromData->ydrawvalues; |
77 | toData->zdrawvalues = fromData->zdrawvalues; |
78 | /* Draw grid */ |
79 | toData->drawgrid = fromData->drawgrid; |
80 | /* Draw axes */ |
81 | toData->drawaxes = fromData->drawaxes; |
82 | /* Number of splits along axes */ |
83 | toData->nbx = fromData->nbx; |
84 | toData->nby = fromData->nby; |
85 | toData->nbz = fromData->nbz; |
86 | /* Offset for drawing values */ |
87 | toData->xoffset = fromData->xoffset; |
88 | toData->yoffset = fromData->yoffset; |
89 | toData->zoffset = fromData->zoffset; |
90 | /* Offset for drawing names of axes */ |
91 | toData->xaxisoffset = fromData->xaxisoffset; |
92 | toData->yaxisoffset = fromData->yaxisoffset; |
93 | toData->zaxisoffset = fromData->zaxisoffset; |
94 | /* Draw tickmarks */ |
95 | toData->xdrawtickmarks = fromData->xdrawtickmarks; |
96 | toData->ydrawtickmarks = fromData->ydrawtickmarks; |
97 | toData->zdrawtickmarks = fromData->zdrawtickmarks; |
98 | /* Length of tickmarks */ |
99 | toData->xtickmarklength = fromData->xtickmarklength; |
100 | toData->ytickmarklength = fromData->ytickmarklength; |
101 | toData->ztickmarklength = fromData->ztickmarklength; |
102 | /* Grid color */ |
103 | memcpy(toData->gridcolor, fromData->gridcolor, 3 * sizeof(float)); |
104 | /* X name color */ |
105 | memcpy(toData->xnamecolor, fromData->xnamecolor, 3 * sizeof(float)); |
106 | /* Y name color */ |
107 | memcpy(toData->ynamecolor, fromData->ynamecolor, 3 * sizeof(float)); |
108 | /* Z name color */ |
109 | memcpy(toData->znamecolor, fromData->znamecolor, 3 * sizeof(float)); |
110 | /* X color of axis and values */ |
111 | memcpy(toData->xcolor, fromData->xcolor, 3 * sizeof(float)); |
112 | /* Y color of axis and values */ |
113 | memcpy(toData->ycolor, fromData->ycolor, 3 * sizeof(float)); |
114 | /* Z color of axis and values */ |
115 | memcpy(toData->zcolor, fromData->zcolor, 3 * sizeof(float)); |
116 | /* Font name of names of axes: Courier, Arial, ... */ |
117 | if (fromData->fontOfNames) |
118 | len = strlen(fromData->fontOfNames) + 1; |
119 | else |
120 | len = 1; |
121 | toData->fontOfNames = (char*) malloc(len * sizeof(char)); |
122 | if (fromData->fontOfNames) |
123 | strcpy(toData->fontOfNames, fromData->fontOfNames); |
124 | else |
125 | toData->fontOfNames[0] = '\0'; |
126 | /* Style of names of axes: OSD_FA_Regular, OSD_FA_Bold, ... */ |
127 | toData->styleOfNames = fromData->styleOfNames; |
128 | /* Size of names of axes: 8, 10, 12, 14, ... */ |
129 | toData->sizeOfNames = fromData->sizeOfNames; |
130 | /* Font name of values: Courier, Arial, ... */ |
131 | if (fromData->fontOfValues) |
132 | len = strlen(fromData->fontOfValues) + 1; |
133 | else |
134 | len = 1; |
135 | toData->fontOfValues = (char*) malloc(len * sizeof(char)); |
136 | if (fromData->fontOfValues) |
137 | strcpy(toData->fontOfValues, fromData->fontOfValues); |
138 | else |
139 | toData->fontOfValues[0] = '\0'; |
140 | /* Style of values: OSD_FA_Regular, OSD_FA_Bold, ... */ |
141 | toData->styleOfValues = fromData->styleOfValues; |
142 | /* Size of values: 8, 10, 12, 14, ... */ |
143 | toData->sizeOfValues = fromData->sizeOfValues; |
144 | /* Callback - updater of boundary box */ |
145 | toData->cbCubicAxes = fromData->cbCubicAxes; |
146 | toData->ptrVisual3dView = fromData->ptrVisual3dView; |
147 | } |
148 | |
149 | static void freeGraduatedTrihedronData(CALL_DEF_GRADUATEDTRIHEDRON* data) |
150 | { |
151 | /* Names of axes */ |
152 | if (data->xname) |
153 | free(data->xname); |
154 | if (data->yname) |
155 | free(data->yname); |
156 | if (data->zname) |
157 | free(data->zname); |
158 | |
159 | /* Fonts */ |
160 | if (data->fontOfNames) |
161 | free(data->fontOfNames); |
162 | if (data->fontOfValues) |
163 | free(data->fontOfValues); |
164 | |
165 | free(data); |
166 | } |
167 | |
168 | static void freeData() |
169 | { |
170 | int i; |
171 | |
172 | if (WsIds) |
173 | { |
174 | free(WsIds); |
175 | for (i = 0; i < nbWsIds; i++) |
176 | { |
177 | freeGraduatedTrihedronData(graduatedTrihedronData[i]); |
178 | } |
179 | free(graduatedTrihedronData); |
180 | |
181 | WsIds = 0; |
182 | graduatedTrihedronData = 0; |
183 | } |
184 | } |
185 | |
186 | static int getGraduatedTrihedronDataIndex(int WsId) |
187 | { |
188 | int i = 0; |
189 | |
190 | if (!nbWsIds) |
191 | return -1; |
192 | |
193 | for (; i < nbWsIds; i++) |
194 | { |
195 | if (WsIds[i] == WsId) |
196 | return i; |
197 | } |
198 | |
199 | return -1; |
200 | } |
201 | |
202 | static unsigned char initView(int WsId) |
203 | { |
204 | int i; |
205 | int* newWsIds; |
206 | CALL_DEF_GRADUATEDTRIHEDRON** newGraduatedTrihedronData; |
207 | |
208 | /* Extend arrays for +1 */ |
209 | nbWsIds++; |
210 | newWsIds = (int*) calloc(nbWsIds, sizeof(int)); |
211 | newGraduatedTrihedronData = (CALL_DEF_GRADUATEDTRIHEDRON**) calloc(nbWsIds, sizeof(CALL_DEF_GRADUATEDTRIHEDRON*)); |
212 | for (i = 0; i < nbWsIds; i++) |
213 | { |
214 | newGraduatedTrihedronData[i] = (CALL_DEF_GRADUATEDTRIHEDRON*) calloc(1, sizeof(CALL_DEF_GRADUATEDTRIHEDRON)); |
215 | } |
216 | |
217 | /* Copy data from current arrays to the newly created */ |
218 | if (nbWsIds > 1) |
219 | { |
220 | for (i = 0; i < nbWsIds - 1; i++) |
221 | { |
222 | newWsIds[i] = WsIds[i]; |
223 | copyData(graduatedTrihedronData[i], newGraduatedTrihedronData[i]); |
224 | } |
225 | } |
226 | |
227 | /* Delete the previous used arrays */ |
228 | nbWsIds--; /* Don't delete just created graduated trihedron data */ |
229 | freeData(); |
230 | nbWsIds++; /* Return the counter back */ |
231 | |
232 | /* Switch to new arrays */ |
233 | WsIds = newWsIds; |
234 | graduatedTrihedronData = newGraduatedTrihedronData; |
235 | |
236 | /* Set view ID */ |
237 | WsIds[nbWsIds - 1] = WsId; |
238 | |
239 | return TSuccess; |
240 | } |
241 | |
242 | /* Erases the trihedron from the view */ |
243 | static TStatus removeView(int WsId) |
244 | { |
245 | int index, i, j; |
246 | int* newWsIds; |
247 | CALL_DEF_GRADUATEDTRIHEDRON** newGraduatedTrihedronData; |
248 | |
249 | index = getGraduatedTrihedronDataIndex(WsId); |
250 | if (index == -1) |
251 | return TSuccess; /* Nothing to remove */ |
252 | |
253 | /* If trihedron is displayed only in one view, |
254 | just free the arrays and set nbWsIds equal to 0. */ |
255 | if (nbWsIds == 1) |
256 | { |
257 | freeData(); |
258 | nbWsIds = 0; |
259 | return TSuccess; |
260 | } |
261 | |
262 | /* create new arrays with nbWsIds - 1 length. */ |
263 | nbWsIds--; |
264 | newWsIds = (int*) calloc(nbWsIds, sizeof(int)); |
265 | newGraduatedTrihedronData = (CALL_DEF_GRADUATEDTRIHEDRON**) calloc(nbWsIds, sizeof(CALL_DEF_GRADUATEDTRIHEDRON*)); |
266 | for (i = 0; i < nbWsIds; i++) |
267 | { |
268 | newGraduatedTrihedronData[i] = (CALL_DEF_GRADUATEDTRIHEDRON*) calloc(1, sizeof(CALL_DEF_GRADUATEDTRIHEDRON)); |
269 | } |
270 | |
271 | /* Copy data from current arrays to the newly created */ |
272 | for (i = 0, j = 0; j <= nbWsIds; j++) |
273 | { |
274 | if (j != index) |
275 | { |
276 | newWsIds[i] = WsIds[j]; |
277 | copyData(graduatedTrihedronData[j], newGraduatedTrihedronData[i]); |
278 | i++; |
279 | } |
280 | } |
281 | |
282 | return TSuccess; |
283 | } |
284 | |
285 | /* Normal of the view (not normalized!) */ |
286 | static float getNormal(float* normal) |
287 | { |
288 | GLint viewport[4]; |
289 | GLdouble model_matrix[16], proj_matrix[16]; |
290 | double x1, y1, z1, x2, y2, z2, x3, y3, z3; |
291 | double dx1, dy1, dz1, dx2, dy2, dz2, width; |
292 | |
293 | glGetDoublev(GL_MODELVIEW_MATRIX, model_matrix); |
294 | glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix); |
295 | glGetIntegerv(GL_VIEWPORT, viewport); |
296 | |
297 | gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x1, &y1, &z1); |
298 | gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x2, &y2, &z2); |
299 | gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x3, &y3, &z3); |
300 | |
301 | /* Normal out of user is p1p3^p1p2 */ |
302 | dx1 = x3 - x1; dy1 = y3 - y1; dz1 = z3 - z1; |
303 | dx2 = x2 - x1; dy2 = y2 - y1; dz2 = z2 - z1; |
304 | normal[0] = (float) (dy1 * dz2 - dz1 * dy2); |
305 | normal[1] = (float) (dz1 * dx2 - dx1 * dz2); |
306 | normal[2] = (float) (dx1 * dy2 - dy1 * dx2); |
307 | |
308 | /* Distance corresponding to 1 pixel */ |
309 | width = sqrt(dx2 * dx2 + dy2 * dy2 + dz2 * dz2); |
310 | return (float) width / (float) viewport[2]; |
311 | } |
312 | |
313 | static float getDistance2Corner(float* normal, float* center, float x, float y, float z) |
314 | { |
315 | return normal[0] * (x - center[0]) + normal[1] * (y - center[1]) + normal[2] * (z - center[2]); |
316 | } |
317 | |
318 | static char getFarestCorner(float d000, float d100, float d010, float d001, |
319 | float d110, float d101, float d011, float d111) |
320 | { |
321 | if (d000 > 0.0f && |
322 | d000 > d100 && d000 > d010 && d000 > d001 && d000 > d110 && |
323 | d000 > d101 && d000 > d011 && d000 > d111) |
324 | { |
325 | return 1; |
326 | } |
327 | else if (d100 > 0.0f && |
328 | d100 > d000 && d100 > d010 && d100 > d001 && d100 > d110 && |
329 | d100 > d101 && d100 > d011 && d100 > d111) |
330 | { |
331 | return 2; |
332 | } |
333 | else if (d010 > 0.0f && |
334 | d010 > d000 && d010 > d100 && d010 > d001 && d010 > d110 && |
335 | d010 > d101 && d010 > d011 && d010 > d111) |
336 | { |
337 | return 3; |
338 | } |
339 | else if (d001 > 0.0f && |
340 | d001 > d000 && d001 > d100 && d001 > d010 && d001 > d110 && |
341 | d001 > d101 && d001 > d011 && d001 > d111) |
342 | { |
343 | return 4; |
344 | } |
345 | else if (d110 > 0.0f && |
346 | d110 > d000 && d110 > d100 && d110 > d010 && d110 > d001 && |
347 | d110 > d101 && d110 > d011 && d110 > d111) |
348 | { |
349 | return 5; |
350 | } |
351 | else if (d101 > 0.0f && |
352 | d101 > d000 && d101 > d100 && d101 > d010 && d101 > d001 && |
353 | d101 > d110 && d101 > d011 && d101 > d111) |
354 | { |
355 | return 6; |
356 | } |
357 | else if (d011 > 0.0f && |
358 | d011 > d000 && d011 > d100 && d011 > d010 && d011 > d001 && |
359 | d011 > d110 && d011 > d101 && d011 > d111) |
360 | { |
361 | return 7; |
362 | } |
363 | return 8; /* d111 */ |
364 | } |
365 | |
366 | static void drawText(char* text, char* font, OSD_FontAspect style, int size, float x, float y, float z) |
367 | { |
368 | GLuint fontBase = 0; |
369 | OpenGl_TextRender* textRenderer = OpenGl_TextRender::instance(); |
370 | fontBase = textRenderer->FindFont((Tchar*) font, style, (float) size); |
371 | textRenderer->RenderText(text, fontBase, 0, x, y, z); |
372 | |
373 | /* 4 OCC 6.3.1 and older: |
374 | GLuint fontBase; |
375 | |
376 | #ifndef WNT |
377 | fontBase = tXfmsetfont (1.0F, 1.0F); |
378 | #else |
379 | fontBase = WNTSetFont (1.0F, 1.0F); |
380 | #endif |
381 | |
382 | #ifndef WNT |
383 | tXfmprstr(text, fontBase, x, y, z); |
384 | #else |
385 | WNTPuts(text, fontBase, 0, x, y, z); |
386 | #endif |
387 | */ |
388 | } |
389 | |
390 | static void drawArrow(float x1, float y1, float z1, |
391 | float x2, float y2, float z2, |
392 | float xn, float yn, float zn) |
393 | { |
394 | float h, r; |
395 | float xa, ya, za; |
396 | float x0, y0, z0; |
397 | float xr, yr, zr; |
398 | float xa1, ya1, za1, xa2, ya2, za2; |
399 | |
400 | /* Start of arrow: at 10% from the end */ |
401 | x0 = x1 + 0.9f * (x2 - x1); y0 = y1 + 0.9f * (y2 - y1); z0 = z1 + 0.9f * (z2 - z1); |
402 | |
403 | /* Base of the arrow */ |
404 | xa = (x2 - x0); ya = (y2 - y0); za = (z2 - z0); |
405 | |
406 | /* Height of the arrow */ |
407 | h = sqrtf(xa * xa + ya * ya + za * za); |
408 | if (h <= 0.0f) |
409 | return; |
410 | xa = xa / h; ya = ya / h; za = za / h; |
411 | |
412 | /* Radial direction to the arrow */ |
413 | xr = ya * zn - za * yn; |
414 | yr = za * xn - xa * zn; |
415 | zr = xa * yn - ya * xn; |
416 | |
417 | /* Normalize the radial vector */ |
418 | r = sqrtf(xr * xr + yr * yr + zr * zr); |
419 | if (r <= 0.0f) |
420 | return; |
421 | xr = xr / r; yr = yr / r; zr = zr / r; |
422 | |
423 | /* First point of the base of the arrow */ |
424 | r = 0.2f * h; |
425 | xr = r * xr; yr = r * yr; zr = r * zr; |
426 | xa1 = x0 + xr; ya1 = y0 + yr; za1 = z0 + zr; |
427 | |
428 | /* Second point of the base of the arrow */ |
429 | xa2 = x0 - xr; ya2 = y0 - yr; za2 = z0 - zr; |
430 | |
431 | /* Draw a line to the arrow */ |
432 | glBegin(GL_LINES); |
433 | glVertex3f(x1, y1, z1); |
434 | glVertex3f(x0, y0, z0); |
435 | glEnd(); |
436 | |
437 | /* Draw a triangle of the arrow */ |
438 | glBegin(GL_LINE_LOOP); |
439 | glVertex3f(xa1, ya1, za1); |
440 | glVertex3f(xa2, ya2, za2); |
441 | glVertex3f(x2, y2, z2); |
442 | glEnd(); |
443 | } |
444 | |
445 | TStatus call_graduatedtrihedron_get(int WsId, CALL_DEF_GRADUATEDTRIHEDRON* data) |
446 | { |
447 | int index; |
448 | |
449 | /* Get index of the view */ |
450 | index = getGraduatedTrihedronDataIndex(WsId); |
451 | if (index == -1) |
452 | { |
453 | /* Default values */ |
454 | data->xname = "X\0"; |
455 | data->yname = "Y\0"; |
456 | data->zname = "Z\0"; |
457 | data->xdrawname = 1; |
458 | data->ydrawname = 1; |
459 | data->zdrawname = 1; |
460 | data->xdrawvalues = 1; |
461 | data->ydrawvalues = 1; |
462 | data->zdrawvalues = 1; |
463 | data->drawgrid = 1; |
464 | data->drawaxes = 1; |
465 | data->nbx = 3; |
466 | data->nby = 3; |
467 | data->nbz = 3; |
468 | data->xoffset = 10; |
469 | data->yoffset = 10; |
470 | data->zoffset = 10; |
471 | data->xaxisoffset = 30; |
472 | data->yaxisoffset = 30; |
473 | data->zaxisoffset = 30; |
474 | data->xdrawtickmarks = 1; |
475 | data->ydrawtickmarks = 1; |
476 | data->zdrawtickmarks = 1; |
477 | data->xtickmarklength = 10; |
478 | data->ytickmarklength = 10; |
479 | data->ztickmarklength = 10; |
480 | /*Quantity_NOC_WHITE*/; |
481 | data->gridcolor[0] = 1.0f; |
482 | data->gridcolor[1] = 1.0f; |
483 | data->gridcolor[2] = 1.0f; |
484 | /* Quantity_NOC_RED */ |
485 | data->xnamecolor[0] = 1.0f; |
486 | data->xnamecolor[1] = 0.0f; |
487 | data->xnamecolor[2] = 0.0f; |
488 | /* Quantity_NOC_GREEN */ |
489 | data->ynamecolor[0] = 0.0f; |
490 | data->ynamecolor[1] = 1.0f; |
491 | data->ynamecolor[2] = 0.0f; |
492 | /* Quantity_NOC_BLUE1 */ |
493 | data->znamecolor[0] = 0.0f; |
494 | data->znamecolor[1] = 0.0f; |
495 | data->znamecolor[2] = 1.0f; |
496 | /* Quantity_NOC_RED */ |
497 | data->xcolor[0] = 1.0f; |
498 | data->xcolor[1] = 0.0f; |
499 | data->xcolor[2] = 0.0f; |
500 | /* Quantity_NOC_GREEN */ |
501 | data->ycolor[0] = 0.0f; |
502 | data->ycolor[1] = 1.0f; |
503 | data->ycolor[2] = 0.0f; |
504 | /* Quantity_NOC_BLUE1 */ |
505 | data->zcolor[0] = 0.0f; |
506 | data->zcolor[1] = 0.0f; |
507 | data->zcolor[2] = 1.0f; |
508 | } |
509 | else |
510 | { |
511 | copyData(graduatedTrihedronData[index], data); |
512 | } |
513 | return TSuccess; |
514 | } |
515 | |
516 | TStatus call_graduatedtrihedron_display(int WsId, CALL_DEF_GRADUATEDTRIHEDRON* data) |
517 | { |
518 | int index; |
519 | |
520 | /* Initialize data for a new view */ |
521 | index = getGraduatedTrihedronDataIndex(WsId); |
522 | if (index == -1) |
523 | { |
524 | initView(WsId); |
525 | index = getGraduatedTrihedronDataIndex(WsId); |
526 | } |
527 | copyData(data, graduatedTrihedronData[index]); |
528 | return call_graduatedtrihedron_redraw(WsId); |
529 | } |
530 | |
531 | TStatus call_graduatedtrihedron_erase(int WsId) |
532 | { |
533 | return removeView(WsId); |
534 | } |
535 | |
536 | TStatus call_graduatedtrihedron_redraw(int WsId) |
537 | { |
538 | GLboolean light; |
539 | unsigned int i, offset; |
540 | unsigned char farestCorner; |
541 | float normal[3], center[3]; |
542 | CALL_DEF_GRADUATEDTRIHEDRON* data; |
543 | float d000, d100, d010, d001, d110, d101, d011, d111; /* 0 - min, 1 - max */ |
544 | float LX1[6], LX2[6], LX3[6]; /* Lines along X direction */ |
545 | float LY1[6], LY2[6], LY3[6]; /* Lines along Y direction */ |
546 | float LZ1[6], LZ2[6], LZ3[6]; /* Lines along Z direction */ |
547 | unsigned char LX1draw, LX2draw, LX3draw; /* Allows drawing of X-line (000 - 100 is forbidden) */ |
548 | unsigned char LY1draw, LY2draw, LY3draw; /* Allows drawing of Y-line (000 - 010 is forbidden) */ |
549 | unsigned char LZ1draw, LZ2draw, LZ3draw; /* Allows drawing of Z-line (000 - 001 is forbidden) */ |
550 | float m1[3], m2[3]; |
551 | float step, d, dpix, dx, dy, dz; |
552 | char textValue[128]; |
553 | int index; |
554 | |
555 | /* Get index of the trihedron data */ |
556 | index = getGraduatedTrihedronDataIndex(WsId); |
557 | if (index == -1) |
558 | return TFailure; |
559 | data = graduatedTrihedronData[index]; |
560 | |
561 | /* Update boundary box */ |
562 | if (data->cbCubicAxes) |
563 | data->cbCubicAxes(data->ptrVisual3dView); |
564 | |
565 | /* Disable lighting for lines */ |
566 | light = glIsEnabled(GL_LIGHTING); |
567 | if (light) |
568 | glDisable(GL_LIGHTING); |
569 | |
570 | /* Find the farest point of bounding box */ |
571 | |
572 | /* Get normal of the view out of user. */ |
573 | /* Also, the method return distance corresponding to 1 pixel */ |
574 | dpix = getNormal(normal); |
575 | |
576 | /* Normalize normal */ |
577 | d = sqrtf(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); |
578 | normal[0] = normal[0] / d; |
579 | normal[1] = normal[1] / d; |
580 | normal[2] = normal[2] / d; |
581 | |
582 | /* Get central point of bounding box */ |
583 | center[0] = 0.5f * (xmin + xmax); |
584 | center[1] = 0.5f * (ymin + ymax); |
585 | center[2] = 0.5f * (zmin + zmax); |
586 | |
587 | /* Check distance to corners of bounding box along the normal*/ |
588 | d000 = getDistance2Corner(normal, center, xmin, ymin, zmin); |
589 | d100 = getDistance2Corner(normal, center, xmax, ymin, zmin); |
590 | d010 = getDistance2Corner(normal, center, xmin, ymax, zmin); |
591 | d001 = getDistance2Corner(normal, center, xmin, ymin, zmax); |
592 | d110 = getDistance2Corner(normal, center, xmax, ymax, zmin); |
593 | d101 = getDistance2Corner(normal, center, xmax, ymin, zmax); |
594 | d011 = getDistance2Corner(normal, center, xmin, ymax, zmax); |
595 | d111 = getDistance2Corner(normal, center, xmax, ymax, zmax); |
596 | farestCorner = getFarestCorner(d000, d100, d010, d001, d110, d101, d011, d111); |
597 | |
598 | /* Choose axes for the grid. */ |
599 | /* The first axis will be used for drawing the text and the values. */ |
600 | switch (farestCorner) |
601 | { |
602 | case 1: /* d000 */ |
603 | { |
604 | /* 001 - 101 */ |
605 | LX1draw = 1; |
606 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; |
607 | /* 000 - 100 */ |
608 | LX2draw = 0; /* forbidden! */ |
609 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; |
610 | /* 010 - 110 */ |
611 | LX3draw = 1; |
612 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; |
613 | |
614 | /* 100 - 110 */ |
615 | LY1draw = 1; |
616 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; |
617 | /* 000 - 010 */ |
618 | LY2draw = 0; /* forbidden! */ |
619 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; |
620 | /* 001 - 011 */ |
621 | LY3draw = 1; |
622 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; |
623 | |
624 | /* 100 - 101 */ |
625 | LZ1draw = 1; |
626 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; |
627 | /* 000 - 001 */ |
628 | LZ2draw = 0; /* forbidden! */ |
629 | LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; |
630 | /* 010 - 011 */ |
631 | LZ3draw = 1; |
632 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; |
633 | |
634 | break; |
635 | } |
636 | case 2: /* d100 */ |
637 | { |
638 | /* 001 - 101 */ |
639 | LX1draw = 1; |
640 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; |
641 | /* 000 - 100 */ |
642 | LX2draw = 0; /* forbidden! */ |
643 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; |
644 | /* 010 - 110 */ |
645 | LX3draw = 1; |
646 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; |
647 | |
648 | /* 000 - 010 */ |
649 | LY1draw = 0; /* forbidden! */ |
650 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; |
651 | /* 100 - 110 */ |
652 | LY2draw = 1; |
653 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; |
654 | /* 101 - 111 */ |
655 | LY3draw = 1; |
656 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; |
657 | |
658 | /* 000 - 001 */ |
659 | LZ1draw = 0; /* forbidden! */ |
660 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; |
661 | /* 100 - 101 */ |
662 | LZ2draw = 1; |
663 | LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; |
664 | /* 110 - 111 */ |
665 | LZ3draw = 1; |
666 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; |
667 | |
668 | break; |
669 | } |
670 | case 3: /* d010 */ |
671 | { |
672 | /* 000 - 100 */ |
673 | LX1draw = 0; /* forbidden */ |
674 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; |
675 | /* 010 - 110 */ |
676 | LX2draw = 1; |
677 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; |
678 | /* 011 - 111 */ |
679 | LX3draw = 1; |
680 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; |
681 | |
682 | /* 100 - 110 */ |
683 | LY1draw = 1; |
684 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; |
685 | /* 000 - 010 */ |
686 | LY2draw = 0; /* forbidden */ |
687 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; |
688 | /* 001 - 011 */ |
689 | LY3draw = 1; |
690 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; |
691 | |
692 | /* 110 - 111 */ |
693 | LZ1draw = 1; |
694 | LZ1[0] = xmax; LZ1[1] = ymax; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymax; LZ1[5] = zmax; |
695 | /* 010 - 011 */ |
696 | LZ2draw = 1; |
697 | LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; |
698 | /* 000 - 001 */ |
699 | LZ3draw = 0; /* forbidden */ |
700 | LZ3[0] = xmin; LZ3[1] = ymin; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymin; LZ3[5] = zmax; |
701 | |
702 | break; |
703 | } |
704 | case 4: /* d001 */ |
705 | { |
706 | /* 000 - 100 */ |
707 | LX1draw = 0; /* forbidden */ |
708 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; |
709 | /* 001 - 101 */ |
710 | LX2draw = 1; |
711 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; |
712 | /* 011 - 111 */ |
713 | LX3draw = 1; |
714 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; |
715 | |
716 | /* 000 - 010 */ |
717 | LY1draw = 0; /* forbidden */ |
718 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; |
719 | /* 001 - 011 */ |
720 | LY2draw = 1; |
721 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; |
722 | /* 101 - 111 */ |
723 | LY3draw = 1; |
724 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; |
725 | |
726 | /* 100 - 101 */ |
727 | LZ1draw = 1; |
728 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; |
729 | /* 000 - 001 */ |
730 | LZ2draw = 0; /* forbidden */ |
731 | LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; |
732 | /* 010 - 011 */ |
733 | LZ3draw = 1; |
734 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; |
735 | |
736 | break; |
737 | } |
738 | case 5: /* d110 */ |
739 | { |
740 | /* 000 - 100 */ |
741 | LX1draw = 0; /* forbidden */ |
742 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; |
743 | /* 010 - 110 */ |
744 | LX2draw = 1; |
745 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; |
746 | /* 011 - 111 */ |
747 | LX3draw = 1; |
748 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; |
749 | |
750 | /* 000 - 010 */ |
751 | LY1draw = 0; /* forbidden */ |
752 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; |
753 | /* 100 - 110 */ |
754 | LY2draw = 1; |
755 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; |
756 | /* 101 - 111 */ |
757 | LY3draw = 1; |
758 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; |
759 | |
760 | /* 100 - 101 */ |
761 | LZ1draw = 1; |
762 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; |
763 | /* 110 - 111 */ |
764 | LZ2draw = 1; |
765 | LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; |
766 | /* 010 - 011 */ |
767 | LZ3draw = 1; |
768 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; |
769 | |
770 | break; |
771 | } |
772 | case 6: /* d101 */ |
773 | { |
774 | /* 000 - 100 */ |
775 | LX1draw = 0; /* forbidden */ |
776 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; |
777 | /* 001 - 101 */ |
778 | LX2draw = 1; |
779 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; |
780 | /* 011 - 111 */ |
781 | LX3draw = 1; |
782 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; |
783 | |
784 | /* 100 - 110 */ |
785 | LY1draw = 1; |
786 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; |
787 | /* 101 - 111 */ |
788 | LY2draw = 1; |
789 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; |
790 | /* 001 - 011 */ |
791 | LY3draw = 1; |
792 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; |
793 | |
794 | /* 000 - 001 */ |
795 | LZ1draw = 0; /* forbidden */ |
796 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; |
797 | /* 100 - 101 */ |
798 | LZ2draw = 1; |
799 | LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; |
800 | /* 110 - 111 */ |
801 | LZ3draw = 1; |
802 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; |
803 | |
804 | break; |
805 | } |
806 | case 7: /* d011 */ |
807 | { |
808 | /* 001 - 101 */ |
809 | LX1draw = 1; |
810 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; |
811 | /* 011 - 111 */ |
812 | LX2draw = 1; |
813 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; |
814 | /* 010 - 110 */ |
815 | LX3draw = 1; |
816 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; |
817 | |
818 | /* 000 - 010 */ |
819 | LY1draw = 0; /* forbidden */ |
820 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; |
821 | /* 001 - 011 */ |
822 | LY2draw = 1; |
823 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; |
824 | /* 101 - 111 */ |
825 | LY3draw = 1; |
826 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; |
827 | |
828 | /* 000 - 001 */ |
829 | LZ1draw = 0; /* forbidden */ |
830 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; |
831 | /* 010 - 011 */ |
832 | LZ2draw = 1; |
833 | LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; |
834 | /* 110 - 111 */ |
835 | LZ3draw = 1; |
836 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; |
837 | |
838 | break; |
839 | } |
840 | case 8: /* d111 */ |
841 | { |
842 | /* 010 - 110 */ |
843 | LX1draw = 1; |
844 | LX1[0] = xmin; LX1[1] = ymax; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymax; LX1[5] = zmin; |
845 | /* 011 - 111 */ |
846 | LX2draw = 1; |
847 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; |
848 | /* 001 - 101 */ |
849 | LX3draw = 1; |
850 | LX3[0] = xmin; LX3[1] = ymin; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymin; LX3[5] = zmax; |
851 | |
852 | /* 100 - 110 */ |
853 | LY1draw = 1; |
854 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; |
855 | /* 101 - 111 */ |
856 | LY2draw = 1; |
857 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; |
858 | /* 001 - 011 */ |
859 | LY3draw = 1; |
860 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; |
861 | |
862 | /* 100 - 101 */ |
863 | LZ1draw = 1; |
864 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; |
865 | /* 110 - 111 */ |
866 | LZ2draw = 1; |
867 | LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; |
868 | /* 010 - 011 */ |
869 | LZ3draw = 1; |
870 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; |
871 | |
872 | break; |
873 | } |
874 | } |
875 | |
876 | /* Draw the graduated trihedron */ |
877 | |
878 | /* Grid */ |
879 | if (data->drawgrid) |
880 | { |
881 | glColor3fv(data->gridcolor); |
882 | glBegin(GL_LINES); |
883 | /* Boundary grid-lines */ |
884 | if (LX1draw == 1) |
885 | { |
886 | glVertex3fv(&(LX1[0])); |
887 | glVertex3fv(&(LX1[3])); |
888 | } |
889 | if (LX2draw == 1) |
890 | { |
891 | glVertex3fv(&(LX2[0])); |
892 | glVertex3fv(&(LX2[3])); |
893 | } |
894 | if (LX3draw == 1) |
895 | { |
896 | glVertex3fv(&(LX3[0])); |
897 | glVertex3fv(&(LX3[3])); |
898 | } |
899 | if (LY1draw == 1) |
900 | { |
901 | glVertex3fv(&(LY1[0])); |
902 | glVertex3fv(&(LY1[3])); |
903 | } |
904 | if (LY2draw == 1) |
905 | { |
906 | glVertex3fv(&(LY2[0])); |
907 | glVertex3fv(&(LY2[3])); |
908 | } |
909 | if (LY3draw == 1) |
910 | { |
911 | glVertex3fv(&(LY3[0])); |
912 | glVertex3fv(&(LY3[3])); |
913 | } |
914 | if (LZ1draw == 1) |
915 | { |
916 | glVertex3fv(&(LZ1[0])); |
917 | glVertex3fv(&(LZ1[3])); |
918 | } |
919 | if (LZ2draw == 1) |
920 | { |
921 | glVertex3fv(&(LZ2[0])); |
922 | glVertex3fv(&(LZ2[3])); |
923 | } |
924 | if (LZ3draw == 1) |
925 | { |
926 | glVertex3fv(&(LZ3[0])); |
927 | glVertex3fv(&(LZ3[3])); |
928 | } |
929 | glEnd(); |
930 | |
931 | /* Intermediate grid-lines */ |
932 | /* X-Grid lines */ |
933 | if (data->nbx > 0) |
934 | { |
935 | i = data->drawaxes ? 1 : 0; |
936 | step = fabsf(LX1[3] - LX1[0]) / (float) data->nbx; |
937 | while (i < data->nbx) |
938 | { |
939 | glBegin(GL_LINE_STRIP); |
940 | glVertex3f(LX1[0] + i * step, LX1[1], LX1[2]); |
941 | glVertex3f(LX2[0] + i * step, LX2[1], LX2[2]); |
942 | glVertex3f(LX3[0] + i * step, LX3[1], LX3[2]); |
943 | glEnd(); |
944 | i = i + 1; |
945 | } |
946 | } |
947 | /* Y-Grid lines */ |
948 | if (data->nby > 0) |
949 | { |
950 | i = data->drawaxes ? 1 : 0; |
951 | step = fabsf(LY1[4] - LY1[1]) / (float) data->nby; |
952 | while (i < data->nby) |
953 | { |
954 | glBegin(GL_LINE_STRIP); |
955 | glVertex3f(LY1[0], LY1[1] + i * step, LY1[2]); |
956 | glVertex3f(LY2[0], LY2[1] + i * step, LY2[2]); |
957 | glVertex3f(LY3[0], LY3[1] + i * step, LY3[2]); |
958 | glEnd(); |
959 | i = i + 1; |
960 | } |
961 | } |
962 | /* Z-Grid lines */ |
963 | if (data->nbz > 0) |
964 | { |
965 | i = data->drawaxes ? 1 : 0; |
966 | step = fabsf(LZ1[5] - LZ1[2]) / (float) data->nbz; |
967 | while (i < data->nbz) |
968 | { |
969 | glBegin(GL_LINE_STRIP); |
970 | glVertex3f(LZ1[0], LZ1[1], LZ1[2] + i * step); |
971 | glVertex3f(LZ2[0], LZ2[1], LZ2[2] + i * step); |
972 | glVertex3f(LZ3[0], LZ3[1], LZ3[2] + i * step); |
973 | glEnd(); |
974 | i = i + 1; |
975 | } |
976 | } |
977 | } |
978 | |
979 | /* Axes (arrows) */ |
980 | if (data->drawaxes) |
981 | { |
982 | /* X-axis */ |
983 | glColor3fv(data->xcolor); |
984 | drawArrow(xmin, ymin, zmin, xmax, ymin, zmin, normal[0], normal[1], normal[2]); |
985 | |
986 | /* Y-axis */ |
987 | glColor3fv(data->ycolor); |
988 | drawArrow(xmin, ymin, zmin, xmin, ymax, zmin, normal[0], normal[1], normal[2]); |
989 | |
990 | /* Z-axis */ |
991 | glColor3fv(data->zcolor); |
992 | drawArrow(xmin, ymin, zmin, xmin, ymin, zmax, normal[0], normal[1], normal[2]); |
993 | } |
994 | /* Names of axes & values*/ |
995 | |
996 | if (data->xdrawname || data->xdrawvalues) |
997 | { |
998 | /* Middle point of the first X-axis */ |
999 | m1[0] = 0.5f * (LX1[0] + LX1[3]); |
1000 | m1[1] = 0.5f * (LX1[1] + LX1[4]); |
1001 | m1[2] = 0.5f * (LX1[2] + LX1[5]); |
1002 | |
1003 | /* Middle point of the second X-axis */ |
1004 | m2[0] = 0.5f * (LX2[0] + LX2[3]); |
1005 | m2[1] = 0.5f * (LX2[1] + LX2[4]); |
1006 | m2[2] = 0.5f * (LX2[2] + LX2[5]); |
1007 | |
1008 | /* Apply offset to m1 */ |
1009 | dy = m1[1] - m2[1]; |
1010 | if (fabsf(dy) > 1.e-7f) |
1011 | { |
1012 | if (dy > 0.0f) |
1013 | dy = 1.0f; |
1014 | else |
1015 | dy = -1.0f; |
1016 | } |
1017 | dz = m1[2] - m2[2]; |
1018 | if (fabsf(dz) > 1.e-7f) |
1019 | { |
1020 | if (dz > 0.0f) |
1021 | dz = 1.0f; |
1022 | else |
1023 | dz = -1.0f; |
1024 | } |
1025 | |
1026 | m2[1] = dpix * dy; |
1027 | m2[2] = dpix * dz; |
1028 | |
1029 | /* Name of X-axis */ |
1030 | if (data->xdrawname) |
1031 | { |
1032 | glColor3fv(data->xnamecolor); |
1033 | offset = data->xaxisoffset + data->xtickmarklength; |
1034 | drawText(data->xname, data->fontOfNames, data->styleOfNames, data->sizeOfNames, |
1035 | m1[0], m1[1] + offset * m2[1], m1[2] + offset * m2[2]); |
1036 | } |
1037 | |
1038 | /* X-values */ |
1039 | if (data->xdrawvalues && data->nbx > 0) |
1040 | { |
1041 | glColor3fv(data->xcolor); |
1042 | |
1043 | i = 0; |
1044 | step = fabsf(LX1[3] - LX1[0]) / (float) data->nbx; |
1045 | offset = data->xoffset + data->xtickmarklength; |
1046 | while (i <= data->nbx) |
1047 | { |
1048 | sprintf(textValue, "%g", LX1[0] + i * step); |
1049 | drawText(textValue, data->fontOfValues, data->styleOfValues, data->sizeOfValues, |
1050 | LX1[0] + i * step, m1[1] + offset * m2[1], m1[2] + offset * m2[2]); |
1051 | i = i + 1; |
1052 | } |
1053 | } |
1054 | |
1055 | /* X-tickmark */ |
1056 | if (data->xdrawtickmarks && data->nbx > 0) |
1057 | { |
1058 | glColor3fv(data->gridcolor); |
1059 | |
1060 | i = 0; |
1061 | step = fabsf(LX1[3] - LX1[0]) / (float) data->nbx; |
1062 | while (i <= data->nbx) |
1063 | { |
1064 | glBegin(GL_LINES); |
1065 | glVertex3f(LX1[0] + i * step, m1[1], m1[2]); |
1066 | glVertex3f(LX1[0] + i * step, m1[1] + data->xtickmarklength * m2[1], m1[2] + data->xtickmarklength * m2[2]); |
1067 | glEnd(); |
1068 | i = i + 1; |
1069 | } |
1070 | } |
1071 | } |
1072 | |
1073 | if (data->ydrawname || data->ydrawvalues) |
1074 | { |
1075 | /* Middle point of the first Y-axis */ |
1076 | m1[0] = 0.5f * (LY1[0] + LY1[3]); |
1077 | m1[1] = 0.5f * (LY1[1] + LY1[4]); |
1078 | m1[2] = 0.5f * (LY1[2] + LY1[5]); |
1079 | |
1080 | /* Middle point of the second Y-axis */ |
1081 | m2[0] = 0.5f * (LY2[0] + LY2[3]); |
1082 | m2[1] = 0.5f * (LY2[1] + LY2[4]); |
1083 | m2[2] = 0.5f * (LY2[2] + LY2[5]); |
1084 | |
1085 | /* Apply offset to m1 */ |
1086 | dx = m1[0] - m2[0]; |
1087 | if (fabsf(dx) > 1.e-7f) |
1088 | { |
1089 | if (dx > 0.0f) |
1090 | dx = 1.0f; |
1091 | else |
1092 | dx = -1.0f; |
1093 | } |
1094 | dz = m1[2] - m2[2]; |
1095 | if (fabsf(dz) > 1.e-7f) |
1096 | { |
1097 | if (dz > 0.0f) |
1098 | dz = 1.0f; |
1099 | else |
1100 | dz = -1.0f; |
1101 | } |
1102 | |
1103 | m2[0] = dpix * dx; |
1104 | m2[2] = dpix * dz; |
1105 | |
1106 | /* Name of Y-axis */ |
1107 | if (data->ydrawname) |
1108 | { |
1109 | glColor3fv(data->ynamecolor); |
1110 | offset = data->yaxisoffset + data->ytickmarklength; |
1111 | drawText(data->yname, data->fontOfNames, data->styleOfNames, data->sizeOfNames, |
1112 | m1[0] + offset * m2[0], m1[1], m1[2] + offset * m2[2]); |
1113 | } |
1114 | |
1115 | /* Y-values */ |
1116 | if (data->ydrawvalues && data->nby > 0) |
1117 | { |
1118 | glColor3fv(data->ycolor); |
1119 | |
1120 | i = 0; |
1121 | step = fabsf(LY1[4] - LY1[1]) / (float) data->nby; |
1122 | offset = data->yoffset + data->ytickmarklength; |
1123 | while (i <= data->nby) |
1124 | { |
1125 | sprintf(textValue, "%g", LY1[1] + i * step); |
1126 | drawText(textValue, data->fontOfValues, data->styleOfValues, data->sizeOfValues, |
1127 | m1[0] + offset * m2[0], LY1[1] + i * step, m1[2] + offset * m2[2]); |
1128 | i = i + 1; |
1129 | } |
1130 | } |
1131 | |
1132 | /* Y-tickmark */ |
1133 | if (data->ydrawtickmarks && data->nby > 0) |
1134 | { |
1135 | glColor3fv(data->gridcolor); |
1136 | |
1137 | i = 0; |
1138 | step = fabsf(LY1[4] - LY1[1]) / (float) data->nby; |
1139 | while (i <= data->nby) |
1140 | { |
1141 | glBegin(GL_LINES); |
1142 | glVertex3f(m1[0], LY1[1] + i * step, m1[2]); |
1143 | glVertex3f(m1[0] + data->ytickmarklength * m2[0], LY1[1] + i * step, m1[2] + data->ytickmarklength * m2[2]); |
1144 | glEnd(); |
1145 | i = i + 1; |
1146 | } |
1147 | } |
1148 | } |
1149 | |
1150 | if (data->zdrawname || data->zdrawvalues) |
1151 | { |
1152 | /* Middle point of the first Z-axis */ |
1153 | m1[0] = 0.5f * (LZ1[0] + LZ1[3]); |
1154 | m1[1] = 0.5f * (LZ1[1] + LZ1[4]); |
1155 | m1[2] = 0.5f * (LZ1[2] + LZ1[5]); |
1156 | |
1157 | /* Middle point of the second Z-axis */ |
1158 | m2[0] = 0.5f * (LZ2[0] + LZ2[3]); |
1159 | m2[1] = 0.5f * (LZ2[1] + LZ2[4]); |
1160 | m2[2] = 0.5f * (LZ2[2] + LZ2[5]); |
1161 | |
1162 | /* Apply offset to m1 */ |
1163 | dx = m1[0] - m2[0]; |
1164 | if (fabsf(dx) > 1.e-7f) |
1165 | { |
1166 | if (dx > 0.0f) |
1167 | dx = 1.0f; |
1168 | else |
1169 | dx = -1.0f; |
1170 | } |
1171 | dy = m1[1] - m2[1]; |
1172 | if (fabsf(dy) > 1.e-7f) |
1173 | { |
1174 | if (dy > 0.0f) |
1175 | dy = 1.0f; |
1176 | else |
1177 | dy = -1.0f; |
1178 | } |
1179 | |
1180 | m2[0] = dpix * dx; |
1181 | m2[1] = dpix * dy; |
1182 | |
1183 | /* Name of Z-axis */ |
1184 | if (data->zdrawname) |
1185 | { |
1186 | glColor3fv(data->znamecolor); |
1187 | offset = data->zaxisoffset + data->ztickmarklength; |
1188 | drawText(data->zname, data->fontOfNames, data->styleOfNames, data->sizeOfNames, |
1189 | m1[0] + offset * m2[0], m1[1] + offset * m2[1], m1[2]); |
1190 | } |
1191 | |
1192 | /* Z-values */ |
1193 | if (data->zdrawvalues && data->nbz > 0) |
1194 | { |
1195 | glColor3fv(data->zcolor); |
1196 | |
1197 | i = 0; |
1198 | step = fabsf(LZ1[5] - LZ1[2]) / (float) data->nbz; |
1199 | offset = data->zoffset + data->ztickmarklength; |
1200 | while (i <= data->nbz) |
1201 | { |
1202 | sprintf(textValue, "%g", LZ1[2] + i * step); |
1203 | drawText(textValue, data->fontOfValues, data->styleOfValues, data->sizeOfValues, |
1204 | m1[0] + offset * m2[0], m1[1] + offset * m2[1], LZ1[2] + i * step); |
1205 | i = i + 1; |
1206 | } |
1207 | } |
1208 | |
1209 | /* Z-tickmark */ |
1210 | if (data->zdrawtickmarks && data->nbz > 0) |
1211 | { |
1212 | glColor3fv(data->gridcolor); |
1213 | |
1214 | i = 0; |
1215 | step = fabsf(LZ1[5] - LZ1[2]) / (float) data->nbz; |
1216 | while (i <= data->nbz) |
1217 | { |
1218 | glBegin(GL_LINES); |
1219 | glVertex3f(m1[0], m1[1], LZ1[2] + i * step); |
1220 | glVertex3f(m1[0] + data->ztickmarklength * m2[0], m1[1] + data->ztickmarklength * m2[1], LZ1[2] + i * step); |
1221 | glEnd(); |
1222 | i = i + 1; |
1223 | } |
1224 | } |
1225 | } |
1226 | |
1227 | /* Activate the lighting if it was turned off by this method call */ |
1228 | if (light) |
1229 | glEnable(GL_LIGHTING); |
1230 | |
1231 | return TSuccess; |
1232 | } |
1233 | |
1234 | TStatus call_graduatedtrihedron_minmaxvalues(const float xMin, |
1235 | const float yMin, |
1236 | const float zMin, |
1237 | const float xMax, |
1238 | const float yMax, |
1239 | const float zMax) |
1240 | { |
1241 | xmin = xMin; |
1242 | ymin = yMin; |
1243 | zmin = zMin; |
1244 | xmax = xMax; |
1245 | ymax = yMax; |
1246 | zmax = zMax; |
1247 | return TSuccess; |
1248 | } |