Commit | Line | Data |
---|---|---|
2166f0fa SK |
1 | // File: OpenGl_GraduatedTrihedron.cxx |
2 | // Created: 20 September 2011 | |
13a22457 | 3 | // Author: Sergey ZERCHANINOV |
2166f0fa | 4 | // Copyright: OPEN CASCADE 2011 |
13a22457 | 5 | |
5f8b738e | 6 | #include <OpenGl_GlCore11.hxx> |
7fd59977 | 7 | |
8 | #include <stddef.h> | |
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include <math.h> | |
12 | ||
7fd59977 | 13 | #include <InterfaceGraphic_Graphic3d.hxx> |
14 | #include <InterfaceGraphic_Aspect.hxx> | |
15 | #include <InterfaceGraphic_Visual3d.hxx> | |
16 | ||
5f8b738e | 17 | #include <GL/glu.h> // gluUnProject() |
18 | ||
7fd59977 | 19 | #ifdef HAVE_CONFIG_H |
20 | #include <config.h> | |
21 | #endif | |
22 | #ifdef HAVE_STRING_H | |
23 | #include <string.h> | |
24 | #endif | |
25 | ||
2166f0fa SK |
26 | #include <OpenGl_Workspace.hxx> |
27 | #include <OpenGl_View.hxx> | |
28 | #include <OpenGl_GraduatedTrihedron.hxx> | |
29 | #include <OpenGl_AspectLine.hxx> | |
7fd59977 | 30 | |
2166f0fa SK |
31 | IMPLEMENT_STANDARD_HANDLE(OpenGl_GraduatedTrihedron,MMgt_TShared) |
32 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron,MMgt_TShared) | |
13a22457 | 33 | |
2166f0fa | 34 | const OpenGl_AspectLine myDefaultAspectLine; |
7fd59977 | 35 | |
2166f0fa SK |
36 | /* Bounding box */ |
37 | float xmin = 0.0f, ymin = 0.0f, zmin = 0.0f, xmax = 100.0f, ymax = 100.0f, zmax = 100.0f; | |
7fd59977 | 38 | |
39 | /* Normal of the view (not normalized!) */ | |
40 | static float getNormal(float* normal) | |
41 | { | |
2166f0fa SK |
42 | GLint viewport[4]; |
43 | GLdouble model_matrix[16], proj_matrix[16]; | |
44 | ||
45 | glGetDoublev(GL_MODELVIEW_MATRIX, model_matrix); | |
46 | glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix); | |
47 | glGetIntegerv(GL_VIEWPORT, viewport); | |
48 | ||
49 | double x1, y1, z1, x2, y2, z2, x3, y3, z3; | |
50 | gluUnProject(viewport[0], viewport[1], 0., model_matrix, proj_matrix, viewport, &x1, &y1, &z1); | |
51 | gluUnProject(viewport[0] + viewport[2], viewport[1], 0., model_matrix, proj_matrix, viewport, &x2, &y2, &z2); | |
52 | gluUnProject(viewport[0], viewport[1] + viewport[3], 0., model_matrix, proj_matrix, viewport, &x3, &y3, &z3); | |
53 | ||
54 | /* Normal out of user is p1p3^p1p2 */ | |
55 | const double dx1 = x3 - x1; | |
56 | const double dy1 = y3 - y1; | |
57 | const double dz1 = z3 - z1; | |
58 | const double dx2 = x2 - x1; | |
59 | const double dy2 = y2 - y1; | |
60 | const double dz2 = z2 - z1; | |
61 | normal[0] = (float) (dy1 * dz2 - dz1 * dy2); | |
62 | normal[1] = (float) (dz1 * dx2 - dx1 * dz2); | |
63 | normal[2] = (float) (dx1 * dy2 - dy1 * dx2); | |
64 | ||
65 | /* Distance corresponding to 1 pixel */ | |
66 | const float width = (float) sqrt(dx2 * dx2 + dy2 * dy2 + dz2 * dz2); | |
67 | return width / (float) viewport[2]; | |
7fd59977 | 68 | } |
69 | ||
70 | static float getDistance2Corner(float* normal, float* center, float x, float y, float z) | |
71 | { | |
72 | return normal[0] * (x - center[0]) + normal[1] * (y - center[1]) + normal[2] * (z - center[2]); | |
73 | } | |
74 | ||
75 | static char getFarestCorner(float d000, float d100, float d010, float d001, | |
76 | float d110, float d101, float d011, float d111) | |
77 | { | |
78 | if (d000 > 0.0f && | |
79 | d000 > d100 && d000 > d010 && d000 > d001 && d000 > d110 && | |
80 | d000 > d101 && d000 > d011 && d000 > d111) | |
81 | { | |
82 | return 1; | |
83 | } | |
84 | else if (d100 > 0.0f && | |
85 | d100 > d000 && d100 > d010 && d100 > d001 && d100 > d110 && | |
86 | d100 > d101 && d100 > d011 && d100 > d111) | |
87 | { | |
88 | return 2; | |
89 | } | |
90 | else if (d010 > 0.0f && | |
91 | d010 > d000 && d010 > d100 && d010 > d001 && d010 > d110 && | |
92 | d010 > d101 && d010 > d011 && d010 > d111) | |
93 | { | |
94 | return 3; | |
95 | } | |
96 | else if (d001 > 0.0f && | |
97 | d001 > d000 && d001 > d100 && d001 > d010 && d001 > d110 && | |
98 | d001 > d101 && d001 > d011 && d001 > d111) | |
99 | { | |
100 | return 4; | |
101 | } | |
102 | else if (d110 > 0.0f && | |
103 | d110 > d000 && d110 > d100 && d110 > d010 && d110 > d001 && | |
104 | d110 > d101 && d110 > d011 && d110 > d111) | |
105 | { | |
106 | return 5; | |
107 | } | |
108 | else if (d101 > 0.0f && | |
109 | d101 > d000 && d101 > d100 && d101 > d010 && d101 > d001 && | |
110 | d101 > d110 && d101 > d011 && d101 > d111) | |
111 | { | |
112 | return 6; | |
113 | } | |
114 | else if (d011 > 0.0f && | |
115 | d011 > d000 && d011 > d100 && d011 > d010 && d011 > d001 && | |
116 | d011 > d110 && d011 > d101 && d011 > d111) | |
117 | { | |
118 | return 7; | |
119 | } | |
120 | return 8; /* d111 */ | |
121 | } | |
122 | ||
2166f0fa | 123 | static void drawText(const Handle(OpenGl_Workspace) &AWorkspace, const wchar_t* text, const char* font, OSD_FontAspect style, int size, float x, float y, float z) |
7fd59977 | 124 | { |
2166f0fa SK |
125 | AWorkspace->FindFont(font, style, size); |
126 | AWorkspace->RenderText(text, 0, x, y, z); | |
7fd59977 | 127 | |
128 | /* 4 OCC 6.3.1 and older: | |
129 | GLuint fontBase; | |
130 | ||
131 | #ifndef WNT | |
132 | fontBase = tXfmsetfont (1.0F, 1.0F); | |
133 | #else | |
134 | fontBase = WNTSetFont (1.0F, 1.0F); | |
135 | #endif | |
136 | ||
137 | #ifndef WNT | |
138 | tXfmprstr(text, fontBase, x, y, z); | |
139 | #else | |
140 | WNTPuts(text, fontBase, 0, x, y, z); | |
141 | #endif | |
142 | */ | |
143 | } | |
144 | ||
145 | static void drawArrow(float x1, float y1, float z1, | |
146 | float x2, float y2, float z2, | |
147 | float xn, float yn, float zn) | |
148 | { | |
149 | float h, r; | |
150 | float xa, ya, za; | |
151 | float x0, y0, z0; | |
152 | float xr, yr, zr; | |
153 | float xa1, ya1, za1, xa2, ya2, za2; | |
154 | ||
155 | /* Start of arrow: at 10% from the end */ | |
156 | x0 = x1 + 0.9f * (x2 - x1); y0 = y1 + 0.9f * (y2 - y1); z0 = z1 + 0.9f * (z2 - z1); | |
157 | ||
158 | /* Base of the arrow */ | |
159 | xa = (x2 - x0); ya = (y2 - y0); za = (z2 - z0); | |
160 | ||
161 | /* Height of the arrow */ | |
162 | h = sqrtf(xa * xa + ya * ya + za * za); | |
163 | if (h <= 0.0f) | |
164 | return; | |
165 | xa = xa / h; ya = ya / h; za = za / h; | |
166 | ||
167 | /* Radial direction to the arrow */ | |
168 | xr = ya * zn - za * yn; | |
169 | yr = za * xn - xa * zn; | |
170 | zr = xa * yn - ya * xn; | |
171 | ||
172 | /* Normalize the radial vector */ | |
173 | r = sqrtf(xr * xr + yr * yr + zr * zr); | |
174 | if (r <= 0.0f) | |
175 | return; | |
176 | xr = xr / r; yr = yr / r; zr = zr / r; | |
177 | ||
178 | /* First point of the base of the arrow */ | |
179 | r = 0.2f * h; | |
180 | xr = r * xr; yr = r * yr; zr = r * zr; | |
181 | xa1 = x0 + xr; ya1 = y0 + yr; za1 = z0 + zr; | |
182 | ||
183 | /* Second point of the base of the arrow */ | |
184 | xa2 = x0 - xr; ya2 = y0 - yr; za2 = z0 - zr; | |
185 | ||
186 | /* Draw a line to the arrow */ | |
187 | glBegin(GL_LINES); | |
188 | glVertex3f(x1, y1, z1); | |
189 | glVertex3f(x0, y0, z0); | |
190 | glEnd(); | |
191 | ||
192 | /* Draw a triangle of the arrow */ | |
193 | glBegin(GL_LINE_LOOP); | |
194 | glVertex3f(xa1, ya1, za1); | |
195 | glVertex3f(xa2, ya2, za2); | |
196 | glVertex3f(x2, y2, z2); | |
197 | glEnd(); | |
198 | } | |
199 | ||
2166f0fa SK |
200 | OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_CGraduatedTrihedron &AData) |
201 | : myXName(NULL), myYName(NULL), myZName(NULL), | |
202 | myDrawXName(AData.xdrawname), myDrawYName(AData.ydrawname), myDrawZName(AData.zdrawname), | |
203 | myDrawXValues(AData.xdrawvalues), myDrawYValues(AData.ydrawvalues), myDrawZValues(AData.zdrawvalues), | |
204 | myDrawGrid(AData.drawgrid), myDrawAxes(AData.drawaxes), | |
205 | myNbX(AData.nbx), myNbY(AData.nby), myNbZ(AData.nbz), | |
206 | myXOffset(AData.xoffset), myYOffset(AData.yoffset), myZOffset(AData.zoffset), | |
207 | myXAxisOffset(AData.xaxisoffset), myYAxisOffset(AData.yaxisoffset), myZAxisOffset(AData.zaxisoffset), | |
208 | myDrawXTickmarks(AData.xdrawtickmarks), myDrawYTickmarks(AData.ydrawtickmarks), myDrawZTickmarks(AData.zdrawtickmarks), | |
209 | myXTickmarkLength(AData.xtickmarklength), myYTickmarkLength(AData.ytickmarklength), myZTickmarkLength(AData.ztickmarklength), | |
210 | myFontOfNames(NULL), | |
211 | myStyleOfNames(AData.styleOfNames), | |
212 | mySizeOfNames(AData.sizeOfNames), | |
213 | myFontOfValues(NULL), | |
214 | myStyleOfValues(AData.styleOfValues), | |
215 | mySizeOfValues(AData.sizeOfValues), | |
216 | myCbCubicAxes(AData.cbCubicAxes), | |
217 | myPtrVisual3dView(AData.ptrVisual3dView) | |
7fd59977 | 218 | { |
2166f0fa SK |
219 | /* Names of axes */ |
220 | /* X-name */ | |
221 | int len = AData.xname.Length(); | |
222 | if (len) | |
13a22457 | 223 | { |
2166f0fa SK |
224 | Standard_ExtString iname = AData.xname.ToExtString(); |
225 | wchar_t *xname = new wchar_t[len+1]; | |
226 | len = 0; while (xname[len] = (wchar_t)(iname[len])) len++; | |
227 | myXName = xname; | |
13a22457 | 228 | } |
2166f0fa SK |
229 | /* Y-name */ |
230 | len = AData.yname.Length(); | |
231 | if (len) | |
13a22457 | 232 | { |
2166f0fa SK |
233 | Standard_ExtString iname = AData.yname.ToExtString(); |
234 | wchar_t *yname = new wchar_t[len+1]; | |
235 | len = 0; while (yname[len] = (wchar_t)(iname[len])) len++; | |
236 | myYName = yname; | |
13a22457 | 237 | } |
2166f0fa SK |
238 | /* Z-name */ |
239 | len = AData.zname.Length(); | |
240 | if (len) | |
13a22457 | 241 | { |
2166f0fa SK |
242 | Standard_ExtString iname = AData.zname.ToExtString(); |
243 | wchar_t *zname = new wchar_t[len+1]; | |
244 | len = 0; while (zname[len] = (wchar_t)(iname[len])) len++; | |
245 | myZName = zname; | |
13a22457 | 246 | } |
2166f0fa SK |
247 | /* Grid color */ |
248 | myGridColor[0] = (float) AData.gridcolor.Red(); | |
249 | myGridColor[1] = (float) AData.gridcolor.Green(); | |
250 | myGridColor[2] = (float) AData.gridcolor.Blue(); | |
251 | /* X name color */ | |
252 | myXNameColor[0] = (float) AData.xnamecolor.Red(); | |
253 | myXNameColor[1] = (float) AData.xnamecolor.Green(); | |
254 | myXNameColor[2] = (float) AData.xnamecolor.Blue(); | |
255 | /* Y name color */ | |
256 | myYNameColor[0] = (float) AData.ynamecolor.Red(); | |
257 | myYNameColor[1] = (float) AData.ynamecolor.Green(); | |
258 | myYNameColor[2] = (float) AData.ynamecolor.Blue(); | |
259 | /* Z name color */ | |
260 | myZNameColor[0] = (float) AData.znamecolor.Red(); | |
261 | myZNameColor[1] = (float) AData.znamecolor.Green(); | |
262 | myZNameColor[2] = (float) AData.znamecolor.Blue(); | |
263 | /* X color of axis and values */ | |
264 | myXColor[0] = (float) AData.xcolor.Red(); | |
265 | myXColor[1] = (float) AData.xcolor.Green(); | |
266 | myXColor[2] = (float) AData.xcolor.Blue(); | |
267 | /* Y color of axis and values */ | |
268 | myYColor[0] = (float) AData.ycolor.Red(); | |
269 | myYColor[1] = (float) AData.ycolor.Green(); | |
270 | myYColor[2] = (float) AData.ycolor.Blue(); | |
271 | /* Z color of axis and values */ | |
272 | myZColor[0] = (float) AData.zcolor.Red(); | |
273 | myZColor[1] = (float) AData.zcolor.Green(); | |
274 | myZColor[2] = (float) AData.zcolor.Blue(); | |
275 | /* Font name of names of axes: Courier, Arial, ... */ | |
276 | len = AData.fontOfNames.Length(); | |
277 | char *fontOfNames = new char[len+1]; | |
278 | if (len) | |
279 | strcpy(fontOfNames, AData.fontOfNames.ToCString()); | |
280 | else | |
281 | fontOfNames[0] = '\0'; | |
282 | myFontOfNames = fontOfNames; | |
283 | /* Font name of values: Courier, Arial, ... */ | |
284 | len = AData.fontOfValues.Length(); | |
285 | char *fontOfValues = new char[len+1]; | |
286 | if (len) | |
287 | strcpy(fontOfValues, AData.fontOfValues.ToCString()); | |
288 | else | |
289 | fontOfValues[0] = '\0'; | |
290 | myFontOfValues = fontOfValues; | |
7fd59977 | 291 | } |
292 | ||
2166f0fa | 293 | OpenGl_GraduatedTrihedron::~OpenGl_GraduatedTrihedron () |
7fd59977 | 294 | { |
2166f0fa SK |
295 | // Names of axes |
296 | if (myXName) | |
297 | delete[] myXName; | |
298 | if (myYName) | |
299 | delete[] myYName; | |
300 | if (myZName) | |
301 | delete[] myZName; | |
302 | ||
303 | // Fonts | |
304 | if (myFontOfNames) | |
305 | delete[] myFontOfNames; | |
306 | if (myFontOfValues) | |
307 | delete[] myFontOfValues; | |
308 | } | |
13a22457 | 309 | |
2166f0fa SK |
310 | //call_graduatedtrihedron_redraw |
311 | void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspace) const | |
312 | { | |
313 | const OpenGl_AspectLine *oldAspectLine = AWorkspace->SetAspectLine(&myDefaultAspectLine); | |
314 | AWorkspace->AspectLine(Standard_True); | |
13a22457 S |
315 | |
316 | /* Update boundary box */ | |
2166f0fa SK |
317 | if (myCbCubicAxes) |
318 | myCbCubicAxes(myPtrVisual3dView); | |
13a22457 S |
319 | |
320 | /* Disable lighting for lines */ | |
321 | GLboolean light = glIsEnabled(GL_LIGHTING); | |
322 | if (light) | |
323 | glDisable(GL_LIGHTING); | |
2166f0fa | 324 | |
13a22457 | 325 | /* Find the farest point of bounding box */ |
7fd59977 | 326 | |
13a22457 S |
327 | /* Get normal of the view out of user. */ |
328 | /* Also, the method return distance corresponding to 1 pixel */ | |
329 | float normal[3]; | |
330 | float dpix = getNormal(normal); | |
2166f0fa | 331 | |
13a22457 S |
332 | /* Normalize normal */ |
333 | float d = sqrtf(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); | |
334 | normal[0] /= d; | |
335 | normal[1] /= d; | |
336 | normal[2] /= d; | |
337 | ||
338 | /* Get central point of bounding box */ | |
339 | float center[3]; | |
340 | center[0] = 0.5f * (xmin + xmax); | |
341 | center[1] = 0.5f * (ymin + ymax); | |
342 | center[2] = 0.5f * (zmin + zmax); | |
343 | ||
344 | /* Check distance to corners of bounding box along the normal */ | |
345 | float d000 = getDistance2Corner(normal, center, xmin, ymin, zmin); | |
346 | float d100 = getDistance2Corner(normal, center, xmax, ymin, zmin); | |
347 | float d010 = getDistance2Corner(normal, center, xmin, ymax, zmin); | |
348 | float d001 = getDistance2Corner(normal, center, xmin, ymin, zmax); | |
349 | float d110 = getDistance2Corner(normal, center, xmax, ymax, zmin); | |
350 | float d101 = getDistance2Corner(normal, center, xmax, ymin, zmax); | |
351 | float d011 = getDistance2Corner(normal, center, xmin, ymax, zmax); | |
352 | float d111 = getDistance2Corner(normal, center, xmax, ymax, zmax); | |
353 | unsigned char farestCorner = getFarestCorner(d000, d100, d010, d001, d110, d101, d011, d111); | |
354 | ||
355 | /* Choose axes for the grid. */ | |
356 | float LX1[6], LX2[6], LX3[6]; /* Lines along X direction */ | |
357 | float LY1[6], LY2[6], LY3[6]; /* Lines along Y direction */ | |
358 | float LZ1[6], LZ2[6], LZ3[6]; /* Lines along Z direction */ | |
359 | unsigned char LX1draw, LX2draw, LX3draw; /* Allows drawing of X-line (000 - 100 is forbidden) */ | |
360 | unsigned char LY1draw, LY2draw, LY3draw; /* Allows drawing of Y-line (000 - 010 is forbidden) */ | |
361 | unsigned char LZ1draw, LZ2draw, LZ3draw; /* Allows drawing of Z-line (000 - 001 is forbidden) */ | |
362 | ||
363 | /* The first axis will be used for drawing the text and the values. */ | |
364 | switch (farestCorner) | |
365 | { | |
366 | case 1: /* d000 */ | |
367 | { | |
368 | /* 001 - 101 */ | |
369 | LX1draw = 1; | |
370 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; | |
371 | /* 000 - 100 */ | |
372 | LX2draw = 0; /* forbidden! */ | |
373 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; | |
374 | /* 010 - 110 */ | |
375 | LX3draw = 1; | |
376 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; | |
377 | ||
378 | /* 100 - 110 */ | |
379 | LY1draw = 1; | |
380 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; | |
381 | /* 000 - 010 */ | |
382 | LY2draw = 0; /* forbidden! */ | |
383 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; | |
384 | /* 001 - 011 */ | |
385 | LY3draw = 1; | |
386 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; | |
387 | ||
388 | /* 100 - 101 */ | |
389 | LZ1draw = 1; | |
390 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; | |
391 | /* 000 - 001 */ | |
392 | LZ2draw = 0; /* forbidden! */ | |
393 | LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; | |
394 | /* 010 - 011 */ | |
395 | LZ3draw = 1; | |
396 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; | |
397 | ||
398 | break; | |
399 | } | |
400 | case 2: /* d100 */ | |
401 | { | |
402 | /* 001 - 101 */ | |
403 | LX1draw = 1; | |
404 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; | |
405 | /* 000 - 100 */ | |
406 | LX2draw = 0; /* forbidden! */ | |
407 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; | |
408 | /* 010 - 110 */ | |
409 | LX3draw = 1; | |
410 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; | |
411 | ||
412 | /* 000 - 010 */ | |
413 | LY1draw = 0; /* forbidden! */ | |
414 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; | |
415 | /* 100 - 110 */ | |
416 | LY2draw = 1; | |
417 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; | |
418 | /* 101 - 111 */ | |
419 | LY3draw = 1; | |
420 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; | |
421 | ||
422 | /* 000 - 001 */ | |
423 | LZ1draw = 0; /* forbidden! */ | |
424 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; | |
425 | /* 100 - 101 */ | |
426 | LZ2draw = 1; | |
427 | LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; | |
428 | /* 110 - 111 */ | |
429 | LZ3draw = 1; | |
430 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; | |
431 | ||
432 | break; | |
433 | } | |
434 | case 3: /* d010 */ | |
435 | { | |
436 | /* 000 - 100 */ | |
437 | LX1draw = 0; /* forbidden */ | |
438 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; | |
439 | /* 010 - 110 */ | |
440 | LX2draw = 1; | |
441 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; | |
442 | /* 011 - 111 */ | |
443 | LX3draw = 1; | |
444 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; | |
445 | ||
446 | /* 100 - 110 */ | |
447 | LY1draw = 1; | |
448 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; | |
449 | /* 000 - 010 */ | |
450 | LY2draw = 0; /* forbidden */ | |
451 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; | |
452 | /* 001 - 011 */ | |
453 | LY3draw = 1; | |
454 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; | |
455 | ||
456 | /* 110 - 111 */ | |
457 | LZ1draw = 1; | |
458 | LZ1[0] = xmax; LZ1[1] = ymax; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymax; LZ1[5] = zmax; | |
459 | /* 010 - 011 */ | |
460 | LZ2draw = 1; | |
461 | LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; | |
462 | /* 000 - 001 */ | |
463 | LZ3draw = 0; /* forbidden */ | |
464 | LZ3[0] = xmin; LZ3[1] = ymin; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymin; LZ3[5] = zmax; | |
465 | ||
466 | break; | |
467 | } | |
468 | case 4: /* d001 */ | |
469 | { | |
470 | /* 000 - 100 */ | |
471 | LX1draw = 0; /* forbidden */ | |
472 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; | |
473 | /* 001 - 101 */ | |
474 | LX2draw = 1; | |
475 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; | |
476 | /* 011 - 111 */ | |
477 | LX3draw = 1; | |
478 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; | |
479 | ||
480 | /* 000 - 010 */ | |
481 | LY1draw = 0; /* forbidden */ | |
482 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; | |
483 | /* 001 - 011 */ | |
484 | LY2draw = 1; | |
485 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; | |
486 | /* 101 - 111 */ | |
487 | LY3draw = 1; | |
488 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; | |
489 | ||
490 | /* 100 - 101 */ | |
491 | LZ1draw = 1; | |
492 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; | |
493 | /* 000 - 001 */ | |
494 | LZ2draw = 0; /* forbidden */ | |
495 | LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; | |
496 | /* 010 - 011 */ | |
497 | LZ3draw = 1; | |
498 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; | |
499 | ||
500 | break; | |
501 | } | |
502 | case 5: /* d110 */ | |
503 | { | |
504 | /* 000 - 100 */ | |
505 | LX1draw = 0; /* forbidden */ | |
506 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; | |
507 | /* 010 - 110 */ | |
508 | LX2draw = 1; | |
509 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; | |
510 | /* 011 - 111 */ | |
511 | LX3draw = 1; | |
512 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; | |
513 | ||
514 | /* 000 - 010 */ | |
515 | LY1draw = 0; /* forbidden */ | |
516 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; | |
517 | /* 100 - 110 */ | |
518 | LY2draw = 1; | |
519 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; | |
520 | /* 101 - 111 */ | |
521 | LY3draw = 1; | |
522 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; | |
523 | ||
524 | /* 100 - 101 */ | |
525 | LZ1draw = 1; | |
526 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; | |
527 | /* 110 - 111 */ | |
528 | LZ2draw = 1; | |
529 | LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; | |
530 | /* 010 - 011 */ | |
531 | LZ3draw = 1; | |
532 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; | |
533 | ||
534 | break; | |
535 | } | |
536 | case 6: /* d101 */ | |
537 | { | |
538 | /* 000 - 100 */ | |
539 | LX1draw = 0; /* forbidden */ | |
540 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; | |
541 | /* 001 - 101 */ | |
542 | LX2draw = 1; | |
543 | LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; | |
544 | /* 011 - 111 */ | |
545 | LX3draw = 1; | |
546 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; | |
547 | ||
548 | /* 100 - 110 */ | |
549 | LY1draw = 1; | |
550 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; | |
551 | /* 101 - 111 */ | |
552 | LY2draw = 1; | |
553 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; | |
554 | /* 001 - 011 */ | |
555 | LY3draw = 1; | |
556 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; | |
557 | ||
558 | /* 000 - 001 */ | |
559 | LZ1draw = 0; /* forbidden */ | |
560 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; | |
561 | /* 100 - 101 */ | |
562 | LZ2draw = 1; | |
563 | LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; | |
564 | /* 110 - 111 */ | |
565 | LZ3draw = 1; | |
566 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; | |
567 | ||
568 | break; | |
569 | } | |
570 | case 7: /* d011 */ | |
571 | { | |
572 | /* 001 - 101 */ | |
573 | LX1draw = 1; | |
574 | LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; | |
575 | /* 011 - 111 */ | |
576 | LX2draw = 1; | |
577 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; | |
578 | /* 010 - 110 */ | |
579 | LX3draw = 1; | |
580 | LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; | |
581 | ||
582 | /* 000 - 010 */ | |
583 | LY1draw = 0; /* forbidden */ | |
584 | LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; | |
585 | /* 001 - 011 */ | |
586 | LY2draw = 1; | |
587 | LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; | |
588 | /* 101 - 111 */ | |
589 | LY3draw = 1; | |
590 | LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; | |
591 | ||
592 | /* 000 - 001 */ | |
593 | LZ1draw = 0; /* forbidden */ | |
594 | LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; | |
595 | /* 010 - 011 */ | |
596 | LZ2draw = 1; | |
597 | LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; | |
598 | /* 110 - 111 */ | |
599 | LZ3draw = 1; | |
600 | LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; | |
601 | ||
602 | break; | |
603 | } | |
604 | case 8: /* d111 */ | |
605 | { | |
606 | /* 010 - 110 */ | |
607 | LX1draw = 1; | |
608 | LX1[0] = xmin; LX1[1] = ymax; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymax; LX1[5] = zmin; | |
609 | /* 011 - 111 */ | |
610 | LX2draw = 1; | |
611 | LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; | |
612 | /* 001 - 101 */ | |
613 | LX3draw = 1; | |
614 | LX3[0] = xmin; LX3[1] = ymin; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymin; LX3[5] = zmax; | |
615 | ||
616 | /* 100 - 110 */ | |
617 | LY1draw = 1; | |
618 | LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; | |
619 | /* 101 - 111 */ | |
620 | LY2draw = 1; | |
621 | LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; | |
622 | /* 001 - 011 */ | |
623 | LY3draw = 1; | |
624 | LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; | |
625 | ||
626 | /* 100 - 101 */ | |
627 | LZ1draw = 1; | |
628 | LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; | |
629 | /* 110 - 111 */ | |
630 | LZ2draw = 1; | |
631 | LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; | |
632 | /* 010 - 011 */ | |
633 | LZ3draw = 1; | |
634 | LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; | |
635 | ||
636 | break; | |
637 | } | |
638 | } | |
639 | ||
640 | /* Draw the graduated trihedron */ | |
641 | unsigned int i, j, offset; | |
642 | float m1[3], m2[3]; | |
643 | float step, dx, dy, dz; | |
644 | ||
645 | /* Grid */ | |
2166f0fa | 646 | if (myDrawGrid) |
13a22457 | 647 | { |
2166f0fa | 648 | glColor3fv(myGridColor); |
13a22457 S |
649 | glBegin(GL_LINES); |
650 | /* Boundary grid-lines */ | |
651 | if (LX1draw == 1) | |
652 | { | |
653 | glVertex3fv(&(LX1[0])); | |
654 | glVertex3fv(&(LX1[3])); | |
655 | } | |
656 | if (LX2draw == 1) | |
657 | { | |
658 | glVertex3fv(&(LX2[0])); | |
659 | glVertex3fv(&(LX2[3])); | |
660 | } | |
661 | if (LX3draw == 1) | |
662 | { | |
663 | glVertex3fv(&(LX3[0])); | |
664 | glVertex3fv(&(LX3[3])); | |
665 | } | |
666 | if (LY1draw == 1) | |
667 | { | |
668 | glVertex3fv(&(LY1[0])); | |
669 | glVertex3fv(&(LY1[3])); | |
670 | } | |
671 | if (LY2draw == 1) | |
672 | { | |
673 | glVertex3fv(&(LY2[0])); | |
674 | glVertex3fv(&(LY2[3])); | |
675 | } | |
676 | if (LY3draw == 1) | |
677 | { | |
678 | glVertex3fv(&(LY3[0])); | |
679 | glVertex3fv(&(LY3[3])); | |
680 | } | |
681 | if (LZ1draw == 1) | |
682 | { | |
683 | glVertex3fv(&(LZ1[0])); | |
684 | glVertex3fv(&(LZ1[3])); | |
685 | } | |
686 | if (LZ2draw == 1) | |
687 | { | |
688 | glVertex3fv(&(LZ2[0])); | |
689 | glVertex3fv(&(LZ2[3])); | |
690 | } | |
691 | if (LZ3draw == 1) | |
692 | { | |
693 | glVertex3fv(&(LZ3[0])); | |
694 | glVertex3fv(&(LZ3[3])); | |
695 | } | |
696 | glEnd(); | |
697 | ||
698 | /* Intermediate grid-lines */ | |
699 | /* X-Grid lines */ | |
2166f0fa | 700 | if (myNbX > 0) |
13a22457 | 701 | { |
2166f0fa SK |
702 | i = myDrawAxes ? 1 : 0; |
703 | step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; | |
704 | while (i < myNbX) | |
13a22457 S |
705 | { |
706 | glBegin(GL_LINE_STRIP); | |
707 | glVertex3f(LX1[0] + i * step, LX1[1], LX1[2]); | |
708 | glVertex3f(LX2[0] + i * step, LX2[1], LX2[2]); | |
709 | glVertex3f(LX3[0] + i * step, LX3[1], LX3[2]); | |
710 | glEnd(); | |
711 | i++; | |
712 | } | |
713 | } | |
714 | /* Y-Grid lines */ | |
2166f0fa | 715 | if (myNbY > 0) |
13a22457 | 716 | { |
2166f0fa SK |
717 | i = myDrawAxes ? 1 : 0; |
718 | step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; | |
719 | while (i < myNbY) | |
13a22457 S |
720 | { |
721 | glBegin(GL_LINE_STRIP); | |
722 | glVertex3f(LY1[0], LY1[1] + i * step, LY1[2]); | |
723 | glVertex3f(LY2[0], LY2[1] + i * step, LY2[2]); | |
724 | glVertex3f(LY3[0], LY3[1] + i * step, LY3[2]); | |
725 | glEnd(); | |
726 | i++; | |
727 | } | |
728 | } | |
729 | /* Z-Grid lines */ | |
2166f0fa | 730 | if (myNbZ > 0) |
13a22457 | 731 | { |
2166f0fa SK |
732 | i = myDrawAxes ? 1 : 0; |
733 | step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; | |
734 | while (i < myNbZ) | |
13a22457 S |
735 | { |
736 | glBegin(GL_LINE_STRIP); | |
737 | glVertex3f(LZ1[0], LZ1[1], LZ1[2] + i * step); | |
738 | glVertex3f(LZ2[0], LZ2[1], LZ2[2] + i * step); | |
739 | glVertex3f(LZ3[0], LZ3[1], LZ3[2] + i * step); | |
740 | glEnd(); | |
741 | i++; | |
742 | } | |
743 | } | |
744 | } | |
745 | ||
746 | /* Axes (arrows) */ | |
2166f0fa | 747 | if (myDrawAxes) |
13a22457 S |
748 | { |
749 | /* X-axis */ | |
2166f0fa | 750 | glColor3fv(myXColor); |
13a22457 S |
751 | drawArrow(xmin, ymin, zmin, xmax, ymin, zmin, normal[0], normal[1], normal[2]); |
752 | ||
753 | /* Y-axis */ | |
2166f0fa | 754 | glColor3fv(myYColor); |
13a22457 S |
755 | drawArrow(xmin, ymin, zmin, xmin, ymax, zmin, normal[0], normal[1], normal[2]); |
756 | ||
757 | /* Z-axis */ | |
2166f0fa | 758 | glColor3fv(myZColor); |
13a22457 S |
759 | drawArrow(xmin, ymin, zmin, xmin, ymin, zmax, normal[0], normal[1], normal[2]); |
760 | } | |
761 | ||
762 | /* Names of axes & values */ | |
763 | char textValue[128]; | |
764 | wchar_t wtextValue[128]; | |
765 | ||
2166f0fa | 766 | if (myDrawXName || myDrawXValues) |
13a22457 S |
767 | { |
768 | /* Middle point of the first X-axis */ | |
769 | m1[0] = 0.5f * (LX1[0] + LX1[3]); | |
770 | m1[1] = 0.5f * (LX1[1] + LX1[4]); | |
771 | m1[2] = 0.5f * (LX1[2] + LX1[5]); | |
772 | ||
773 | /* Middle point of the second X-axis */ | |
774 | m2[0] = 0.5f * (LX2[0] + LX2[3]); | |
775 | m2[1] = 0.5f * (LX2[1] + LX2[4]); | |
776 | m2[2] = 0.5f * (LX2[2] + LX2[5]); | |
777 | ||
778 | /* Apply offset to m1 */ | |
779 | dy = m1[1] - m2[1]; | |
780 | if (fabsf(dy) > 1.e-7f) | |
7fd59977 | 781 | { |
13a22457 | 782 | dy = (dy > 0.0f)? 1.0f : -1.0f; |
7fd59977 | 783 | } |
13a22457 S |
784 | dz = m1[2] - m2[2]; |
785 | if (fabsf(dz) > 1.e-7f) | |
786 | { | |
787 | dz = (dz > 0.0f)? 1.0f : -1.0f; | |
788 | } | |
789 | m2[1] = dpix * dy; | |
790 | m2[2] = dpix * dz; | |
7fd59977 | 791 | |
13a22457 | 792 | /* Name of X-axis */ |
2166f0fa | 793 | if (myDrawXName) |
13a22457 | 794 | { |
2166f0fa SK |
795 | glColor3fv(myXNameColor); |
796 | offset = myXAxisOffset + myXTickmarkLength; | |
797 | drawText(AWorkspace, myXName, myFontOfNames, myStyleOfNames, mySizeOfNames, | |
13a22457 S |
798 | m1[0], m1[1] + offset * m2[1], m1[2] + offset * m2[2]); |
799 | } | |
7fd59977 | 800 | |
13a22457 | 801 | /* X-values */ |
2166f0fa | 802 | if (myDrawXValues && myNbX > 0) |
7fd59977 | 803 | { |
2166f0fa | 804 | glColor3fv(myXColor); |
13a22457 S |
805 | |
806 | i = 0; | |
2166f0fa SK |
807 | step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; |
808 | offset = myXOffset + myXTickmarkLength; | |
809 | while (i <= myNbX) | |
13a22457 S |
810 | { |
811 | sprintf(textValue, "%g", LX1[0] + i * step); | |
812 | j = 0; while (wtextValue[j] = textValue[j]) j++; | |
2166f0fa | 813 | drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, |
13a22457 S |
814 | LX1[0] + i * step, m1[1] + offset * m2[1], m1[2] + offset * m2[2]); |
815 | i++; | |
816 | } | |
817 | } | |
818 | ||
819 | /* X-tickmark */ | |
2166f0fa | 820 | if (myDrawXTickmarks && myNbX > 0) |
13a22457 | 821 | { |
2166f0fa | 822 | glColor3fv(myGridColor); |
13a22457 S |
823 | |
824 | i = 0; | |
2166f0fa SK |
825 | step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; |
826 | while (i <= myNbX) | |
13a22457 | 827 | { |
7fd59977 | 828 | glBegin(GL_LINES); |
2166f0fa SK |
829 | glVertex3f(LX1[0] + i * step, m1[1], m1[2]); |
830 | glVertex3f(LX1[0] + i * step, m1[1] + myXTickmarkLength * m2[1], m1[2] + myXTickmarkLength * m2[2]); | |
7fd59977 | 831 | glEnd(); |
13a22457 S |
832 | i++; |
833 | } | |
834 | } | |
835 | } | |
836 | ||
2166f0fa | 837 | if (myDrawYName || myDrawYValues) |
13a22457 S |
838 | { |
839 | /* Middle point of the first Y-axis */ | |
840 | m1[0] = 0.5f * (LY1[0] + LY1[3]); | |
841 | m1[1] = 0.5f * (LY1[1] + LY1[4]); | |
842 | m1[2] = 0.5f * (LY1[2] + LY1[5]); | |
843 | ||
844 | /* Middle point of the second Y-axis */ | |
845 | m2[0] = 0.5f * (LY2[0] + LY2[3]); | |
846 | m2[1] = 0.5f * (LY2[1] + LY2[4]); | |
847 | m2[2] = 0.5f * (LY2[2] + LY2[5]); | |
848 | ||
849 | /* Apply offset to m1 */ | |
850 | dx = m1[0] - m2[0]; | |
851 | if (fabsf(dx) > 1.e-7f) | |
852 | { | |
853 | dx = (dx > 0.0f)? 1.0f : -1.0f; | |
854 | } | |
855 | dz = m1[2] - m2[2]; | |
856 | if (fabsf(dz) > 1.e-7f) | |
857 | { | |
858 | dz = (dz > 0.0f)? 1.0f : -1.0f; | |
859 | } | |
860 | ||
861 | m2[0] = dpix * dx; | |
862 | m2[2] = dpix * dz; | |
7fd59977 | 863 | |
13a22457 | 864 | /* Name of Y-axis */ |
2166f0fa | 865 | if (myDrawYName) |
13a22457 | 866 | { |
2166f0fa SK |
867 | glColor3fv(myYNameColor); |
868 | offset = myYAxisOffset + myYTickmarkLength; | |
869 | drawText(AWorkspace, myYName, myFontOfNames, myStyleOfNames, mySizeOfNames, | |
13a22457 | 870 | m1[0] + offset * m2[0], m1[1], m1[2] + offset * m2[2]); |
7fd59977 | 871 | } |
872 | ||
13a22457 | 873 | /* Y-values */ |
2166f0fa | 874 | if (myDrawYValues && myNbY > 0) |
7fd59977 | 875 | { |
2166f0fa | 876 | glColor3fv(myYColor); |
13a22457 S |
877 | |
878 | i = 0; | |
2166f0fa SK |
879 | step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; |
880 | offset = myYOffset + myYTickmarkLength; | |
881 | while (i <= myNbY) | |
13a22457 S |
882 | { |
883 | sprintf(textValue, "%g", LY1[1] + i * step); | |
884 | j = 0; while (wtextValue[j] = textValue[j]) j++; | |
2166f0fa | 885 | drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, |
13a22457 S |
886 | m1[0] + offset * m2[0], LY1[1] + i * step, m1[2] + offset * m2[2]); |
887 | i++; | |
888 | } | |
7fd59977 | 889 | } |
7fd59977 | 890 | |
13a22457 | 891 | /* Y-tickmark */ |
2166f0fa | 892 | if (myDrawYTickmarks && myNbY > 0) |
13a22457 | 893 | { |
2166f0fa | 894 | glColor3fv(myGridColor); |
13a22457 S |
895 | |
896 | i = 0; | |
2166f0fa SK |
897 | step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; |
898 | while (i <= myNbY) | |
13a22457 S |
899 | { |
900 | glBegin(GL_LINES); | |
2166f0fa SK |
901 | glVertex3f(m1[0], LY1[1] + i * step, m1[2]); |
902 | glVertex3f(m1[0] + myYTickmarkLength * m2[0], LY1[1] + i * step, m1[2] + myYTickmarkLength * m2[2]); | |
13a22457 S |
903 | glEnd(); |
904 | i++; | |
905 | } | |
906 | } | |
907 | } | |
908 | ||
2166f0fa | 909 | if (myDrawZName || myDrawZValues) |
13a22457 S |
910 | { |
911 | /* Middle point of the first Z-axis */ | |
912 | m1[0] = 0.5f * (LZ1[0] + LZ1[3]); | |
913 | m1[1] = 0.5f * (LZ1[1] + LZ1[4]); | |
914 | m1[2] = 0.5f * (LZ1[2] + LZ1[5]); | |
915 | ||
916 | /* Middle point of the second Z-axis */ | |
917 | m2[0] = 0.5f * (LZ2[0] + LZ2[3]); | |
918 | m2[1] = 0.5f * (LZ2[1] + LZ2[4]); | |
919 | m2[2] = 0.5f * (LZ2[2] + LZ2[5]); | |
920 | ||
921 | /* Apply offset to m1 */ | |
922 | dx = m1[0] - m2[0]; | |
923 | if (fabsf(dx) > 1.e-7f) | |
924 | { | |
925 | dx = (dx > 0.0f)? 1.0f : -1.0f; | |
926 | } | |
927 | dy = m1[1] - m2[1]; | |
928 | if (fabsf(dy) > 1.e-7f) | |
7fd59977 | 929 | { |
13a22457 | 930 | dy = (dy > 0.0f)? 1.0f : -1.0f; |
7fd59977 | 931 | } |
932 | ||
13a22457 S |
933 | m2[0] = dpix * dx; |
934 | m2[1] = dpix * dy; | |
935 | ||
936 | /* Name of Z-axis */ | |
2166f0fa | 937 | if (myDrawZName) |
7fd59977 | 938 | { |
2166f0fa SK |
939 | glColor3fv(myZNameColor); |
940 | offset = myZAxisOffset + myZTickmarkLength; | |
941 | drawText(AWorkspace, myZName, myFontOfNames, myStyleOfNames, mySizeOfNames, | |
13a22457 | 942 | m1[0] + offset * m2[0], m1[1] + offset * m2[1], m1[2]); |
7fd59977 | 943 | } |
944 | ||
13a22457 | 945 | /* Z-values */ |
2166f0fa | 946 | if (myDrawZValues && myNbZ > 0) |
7fd59977 | 947 | { |
2166f0fa | 948 | glColor3fv(myZColor); |
13a22457 S |
949 | |
950 | i = 0; | |
2166f0fa SK |
951 | step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; |
952 | offset = myZOffset + myZTickmarkLength; | |
953 | while (i <= myNbZ) | |
13a22457 S |
954 | { |
955 | sprintf(textValue, "%g", LZ1[2] + i * step); | |
956 | j = 0; while (wtextValue[j] = textValue[j]) j++; | |
2166f0fa | 957 | drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, |
13a22457 S |
958 | m1[0] + offset * m2[0], m1[1] + offset * m2[1], LZ1[2] + i * step); |
959 | i++; | |
960 | } | |
7fd59977 | 961 | } |
962 | ||
13a22457 | 963 | /* Z-tickmark */ |
2166f0fa | 964 | if (myDrawZTickmarks && myNbZ > 0) |
13a22457 | 965 | { |
2166f0fa | 966 | glColor3fv(myGridColor); |
13a22457 S |
967 | |
968 | i = 0; | |
2166f0fa SK |
969 | step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; |
970 | while (i <= myNbZ) | |
13a22457 S |
971 | { |
972 | glBegin(GL_LINES); | |
2166f0fa SK |
973 | glVertex3f(m1[0], m1[1], LZ1[2] + i * step); |
974 | glVertex3f(m1[0] + myZTickmarkLength * m2[0], m1[1] + myZTickmarkLength * m2[1], LZ1[2] + i * step); | |
13a22457 S |
975 | glEnd(); |
976 | i++; | |
977 | } | |
978 | } | |
979 | } | |
980 | ||
981 | /* Activate the lighting if it was turned off by this method call */ | |
982 | if (light) | |
983 | glEnable(GL_LIGHTING); | |
2166f0fa SK |
984 | |
985 | AWorkspace->SetAspectLine(oldAspectLine); | |
7fd59977 | 986 | } |
987 | ||
2166f0fa SK |
988 | //call_graduatedtrihedron_minmaxvalues |
989 | void OpenGl_GraduatedTrihedron::SetMinMax (const Standard_ShortReal xMin, const Standard_ShortReal yMin, const Standard_ShortReal zMin, | |
990 | const Standard_ShortReal xMax, const Standard_ShortReal yMax, const Standard_ShortReal zMax) | |
7fd59977 | 991 | { |
2166f0fa SK |
992 | xmin = xMin; |
993 | ymin = yMin; | |
994 | zmin = zMin; | |
995 | xmax = xMax; | |
996 | ymax = yMax; | |
997 | zmax = zMax; | |
13a22457 | 998 | } |