Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
b311480e | 15 | |
5f8b738e | 16 | #include <OpenGl_GlCore11.hxx> |
2166f0fa SK |
17 | |
18 | #include <stddef.h> | |
19 | #include <stdio.h> | |
20 | #include <stdlib.h> | |
2166f0fa | 21 | |
2166f0fa SK |
22 | #include <InterfaceGraphic_Graphic3d.hxx> /* pour CALL_DEF_STRUCTURE */ |
23 | #include <InterfaceGraphic_Aspect.hxx> /* pour CALL_DEF_VIEW */ | |
24 | #include <InterfaceGraphic_Visual3d.hxx> | |
25 | ||
26 | #include <OpenGl_transform_persistence.hxx> | |
27 | ||
2166f0fa SK |
28 | #include <OpenGl_Workspace.hxx> |
29 | #include <OpenGl_View.hxx> | |
30 | #include <OpenGl_Trihedron.hxx> | |
31 | ||
a174a3c5 | 32 | static const OpenGl_TextParam THE_LABEL_PARAMS = |
33 | { | |
34 | 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM | |
35 | }; | |
2166f0fa | 36 | |
2166f0fa SK |
37 | static const CALL_DEF_CONTEXTLINE myDefaultContextLine = |
38 | { | |
39 | 1, //IsDef | |
40 | 1, //IsSet | |
41 | { 1.F, 1.F, 1.F }, //Color | |
42 | Aspect_TOL_SOLID, //LineType | |
43 | 1.F //Width | |
44 | }; | |
45 | ||
46 | static const CALL_DEF_CONTEXTTEXT myDefaultContextText = | |
47 | { | |
48 | 1, //IsDef | |
49 | 1, //IsSet | |
50 | "Courier", //Font | |
51 | 0.3F, //Space | |
52 | 1.0F, //Expan | |
53 | { 1.F, 1.F, 1.F }, //Color | |
54 | Aspect_TOST_NORMAL, //Style | |
55 | Aspect_TODT_NORMAL, //DisplayType | |
56 | { 1.F, 1.F, 1.F }, //ColorSubTitle | |
57 | 0, //TextZoomable | |
58 | 0.F, //TextAngle | |
eeaaaefb | 59 | Font_FA_Regular //TextFontAspect |
2166f0fa SK |
60 | }; |
61 | ||
62 | /*----------------------------------------------------------------------*/ | |
63 | /* | |
64 | * Variables statiques | |
65 | */ | |
66 | ||
67 | /* Default parameters for ZBUFFER triheron */ | |
68 | static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }}; | |
69 | static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }}; | |
70 | static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }}; | |
71 | static float theRatio = 0.8f; | |
72 | static float theDiameter = 0.05f; | |
73 | static int theNbFacettes = 12; | |
74 | ||
75 | /*----------------------------------------------------------------------*/ | |
76 | ||
77 | /* | |
78 | * affichage d'un triedre non zoomable a partir des index dans les tables | |
79 | * des structures non zoomables. | |
80 | * | |
81 | * Triedre = Objet non Zoomable : | |
82 | * on recalcule ses dimensions et son origine en fonction de la taille | |
83 | * de la fenetre; on positionne selon le choix de l'init; | |
84 | * et on inhibe seulement les translations. | |
85 | * | |
86 | */ | |
87 | ||
88 | //call_triedron_redraw | |
a174a3c5 | 89 | void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 90 | { |
a174a3c5 | 91 | const Standard_Real U = theWorkspace->ActiveView()->Height(); |
92 | const Standard_Real V = theWorkspace->ActiveView()->Width(); | |
2166f0fa SK |
93 | |
94 | /* la taille des axes est 1 proportion (fixee a l'init du triedre) */ | |
bf75be98 | 95 | /* de la dimension la plus petite de la window. */ |
2166f0fa SK |
96 | const GLdouble L = ( U < V ? U : V ) * myScale; |
97 | ||
98 | /* | |
99 | * On inhibe les translations; on conserve les autres transformations. | |
100 | */ | |
101 | ||
102 | /* on lit les matrices de transformation et de projection de la vue */ | |
103 | /* pour annuler les translations (dernieres colonnes des matrices). */ | |
104 | GLdouble modelMatrix[4][4]; | |
105 | glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix ); | |
106 | GLdouble projMatrix[4][4]; | |
107 | glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix ); | |
108 | ||
109 | /* on annule la translation qui peut etre affectee a la vue */ | |
110 | modelMatrix[3][0] = 0.; | |
111 | modelMatrix[3][1] = 0.; | |
112 | modelMatrix[3][2] = 0.; | |
b5ac8292 | 113 | |
114 | projMatrix[0][0] = 2.0 / U; | |
115 | projMatrix[0][1] = 0.0; | |
116 | projMatrix[0][2] = 0.0; | |
117 | projMatrix[0][3] = 0.0; | |
118 | ||
119 | projMatrix[1][0] = 0.0; | |
120 | projMatrix[1][1] = 2.0 / V; | |
121 | projMatrix[1][2] = 0.0; | |
122 | projMatrix[1][3] = 0.0; | |
123 | ||
124 | projMatrix[2][0] = 0.0; | |
125 | projMatrix[2][1] = 0.0; | |
126 | projMatrix[2][2] = -2.0 * 1e-7; | |
127 | projMatrix[2][3] = 0.0; | |
128 | ||
129 | projMatrix[3][0] = 0.0; | |
130 | projMatrix[3][1] = 0.0; | |
131 | projMatrix[3][2] = 0.0; | |
132 | projMatrix[3][3] = 1.0; | |
2166f0fa SK |
133 | |
134 | /* sauvegarde du contexte des matrices avant chargement */ | |
135 | glMatrixMode (GL_MODELVIEW); | |
136 | glPushMatrix (); | |
137 | glLoadMatrixd( (GLdouble *) modelMatrix ); | |
138 | glMatrixMode ( GL_PROJECTION ); | |
139 | glPushMatrix (); | |
140 | glLoadMatrixd( (GLdouble *) projMatrix ); | |
141 | ||
142 | /* | |
143 | * Positionnement de l'origine du triedre selon le choix de l'init | |
144 | */ | |
145 | ||
146 | /* on fait uniquement une translation de l'origine du Triedre */ | |
147 | ||
148 | switch (myPos) | |
149 | { | |
150 | case Aspect_TOTP_LEFT_LOWER : | |
151 | glTranslated( -0.5*U + L , -0.5*V + L , 0. ); | |
152 | break; | |
153 | ||
154 | case Aspect_TOTP_LEFT_UPPER : | |
155 | glTranslated( -0.5*U + L , +0.5*V - L -L/3., 0. ); | |
156 | break; | |
157 | ||
158 | case Aspect_TOTP_RIGHT_LOWER : | |
159 | glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. ); | |
160 | break; | |
161 | ||
162 | case Aspect_TOTP_RIGHT_UPPER : | |
163 | glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. ); | |
164 | break; | |
165 | ||
166 | //case Aspect_TOTP_CENTER : | |
167 | default : | |
168 | break; | |
169 | } | |
170 | ||
bf75be98 | 171 | /* |
172 | * Creation du triedre | |
2166f0fa | 173 | */ |
2166f0fa | 174 | |
bf75be98 | 175 | /* Fotis Sioutis 2007-11-14 15:06 |
176 | I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode | |
177 | changes colors depending on the state of the view. This behaviour can be easily | |
2166f0fa | 178 | corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl. |
bf75be98 | 179 | The only change needed is to erase glDisable(GL_LIGHTING) that is called before the |
2166f0fa | 180 | Axis name drawing and move this function call just before the initial axis drawing. |
bf75be98 | 181 | Below is the code portion with the modification.I don't know if this is considered to |
2166f0fa SK |
182 | be a bug but anyway i believe it might help some of you out there.*/ |
183 | glDisable(GL_LIGHTING); | |
2166f0fa SK |
184 | |
185 | /* Position de l'origine */ | |
186 | const GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 }; | |
187 | ||
188 | /* Position des Axes */ | |
189 | GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 }; | |
190 | GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 }; | |
191 | GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 }; | |
192 | TriedronAxeX[0] = L ; | |
193 | TriedronAxeY[1] = L ; | |
194 | TriedronAxeZ[2] = L ; | |
195 | ||
196 | /* dessin des axes */ | |
197 | glBegin(GL_LINES); | |
198 | glVertex3dv( TriedronOrigin ); | |
199 | glVertex3dv( TriedronAxeX ); | |
200 | ||
201 | glVertex3dv( TriedronOrigin ); | |
202 | glVertex3dv( TriedronAxeY ); | |
203 | ||
204 | glVertex3dv( TriedronOrigin ); | |
205 | glVertex3dv( TriedronAxeZ ); | |
206 | glEnd(); | |
207 | ||
208 | /* fleches au bout des axes (= cones de la couleur demandee) */ | |
209 | const GLdouble l = 0.75*L; /* distance a l'origine */ | |
210 | const GLdouble rayon = L/30. ; /* rayon de la base du cone */ | |
211 | const int NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */ | |
212 | const double Angle = 2. * M_PI/ NbFacettes; | |
213 | ||
214 | int ii; | |
215 | GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 }; | |
216 | ||
217 | /* solution FILAIRE des cones au bout des axes : une seule ligne */ | |
218 | glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); | |
219 | /* (la couleur est deja initialisee dans AspectLine) */ | |
220 | /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */ | |
221 | ||
222 | /* fleche en X */ | |
223 | glBegin(GL_TRIANGLE_FAN); | |
224 | glVertex3dv( TriedronAxeX ); | |
225 | TriedronCoord[0] = l; | |
226 | ii = NbFacettes; | |
227 | while (ii >= 0 ) { | |
228 | TriedronCoord[1] = rayon * sin(ii * Angle); | |
229 | TriedronCoord[2] = rayon * cos(ii * Angle); | |
230 | glVertex3dv( TriedronCoord ); | |
231 | ii--; | |
232 | } | |
233 | glEnd(); | |
234 | ||
235 | /* fleche en Y */ | |
236 | glBegin(GL_TRIANGLE_FAN); | |
237 | glVertex3dv( TriedronAxeY ); | |
238 | TriedronCoord[1] = l; | |
239 | ii = NbFacettes; | |
240 | while (ii >= 0 ) { | |
241 | TriedronCoord[0] = rayon * cos(ii * Angle); | |
242 | TriedronCoord[2] = rayon * sin(ii * Angle); | |
243 | glVertex3dv( TriedronCoord ); | |
244 | ii--; | |
245 | } | |
246 | glEnd(); | |
247 | ||
248 | /* fleche en Z */ | |
249 | glBegin(GL_TRIANGLE_FAN); | |
250 | glVertex3dv( TriedronAxeZ ); | |
251 | TriedronCoord[2] = l; | |
252 | ii = NbFacettes; | |
253 | while (ii >= 0 ) { | |
254 | TriedronCoord[0] = rayon * sin(ii * Angle); | |
255 | TriedronCoord[1] = rayon * cos(ii * Angle); | |
256 | glVertex3dv( TriedronCoord ); | |
257 | ii--; | |
258 | } | |
259 | glEnd(); | |
260 | ||
261 | /* dessin de l'origine */ | |
262 | TriedronCoord[2] = 0.0 ; | |
263 | ii = 24 ; | |
264 | const double Angle1 = 2. * M_PI/ ii; | |
265 | glBegin(GL_LINE_LOOP); | |
266 | while (ii >= 0 ) { | |
267 | TriedronCoord[0] = rayon * sin(ii * Angle1); | |
268 | TriedronCoord[1] = rayon * cos(ii * Angle1); | |
269 | glVertex3dv( TriedronCoord ); | |
270 | ii--; | |
bf75be98 | 271 | } |
2166f0fa SK |
272 | glEnd(); |
273 | ||
a174a3c5 | 274 | // draw axes labels |
275 | myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon))); | |
276 | myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon))); | |
277 | myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon))); | |
278 | myLabelX.Render (theWorkspace); | |
279 | myLabelY.Render (theWorkspace); | |
280 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 281 | |
bf75be98 | 282 | /* |
2166f0fa SK |
283 | * restauration du contexte des matrices |
284 | */ | |
285 | glMatrixMode (GL_PROJECTION); | |
286 | glPopMatrix (); | |
287 | glMatrixMode (GL_MODELVIEW); | |
288 | glPopMatrix (); | |
289 | } | |
290 | ||
291 | ||
292 | /******************************************************* | |
293 | * Draws ZBUFFER trihedron mode | |
294 | *******************************************************/ | |
295 | //call_zbuffer_triedron_redraw | |
a174a3c5 | 296 | void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 297 | { |
a174a3c5 | 298 | const Standard_Real U = theWorkspace->ActiveView()->Height(); |
299 | const Standard_Real V = theWorkspace->ActiveView()->Width(); | |
2166f0fa SK |
300 | |
301 | GLdouble modelMatrix[4][4]; | |
302 | glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix ); | |
303 | GLdouble projMatrix[4][4]; | |
304 | glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix ); | |
305 | ||
306 | /* Check position in the ViewPort */ | |
5f8b738e | 307 | /* PCD 29/09/2008 */ |
2166f0fa SK |
308 | /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey */ |
309 | /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER */ | |
310 | /* which causes the glyph to jump around the screen when the origin moves offscreen. */ | |
311 | GLboolean isWithinView = GL_FALSE; | |
2166f0fa SK |
312 | |
313 | /* la taille des axes est 1 proportion (fixee a l'init du triedre) */ | |
bf75be98 | 314 | /* de la dimension la plus petite de la window. */ |
2166f0fa SK |
315 | GLdouble L = ( U < V ? U : V ) * myScale; |
316 | ||
317 | if (!isWithinView) | |
318 | { | |
319 | /* Annulate translation matrix */ | |
320 | modelMatrix[3][0] = 0.; | |
321 | modelMatrix[3][1] = 0.; | |
322 | modelMatrix[3][2] = 0.; | |
b5ac8292 | 323 | |
324 | projMatrix[0][0] = 2.0 / U; | |
325 | projMatrix[0][1] = 0.0; | |
326 | projMatrix[0][2] = 0.0; | |
327 | projMatrix[0][3] = 0.0; | |
328 | ||
329 | projMatrix[1][0] = 0.0; | |
330 | projMatrix[1][1] = 2.0 / V; | |
331 | projMatrix[1][2] = 0.0; | |
332 | projMatrix[1][3] = 0.0; | |
333 | ||
334 | projMatrix[2][0] = 0.0; | |
335 | projMatrix[2][1] = 0.0; | |
336 | projMatrix[2][2] = -2.0 * 1e-7; | |
337 | projMatrix[2][3] = 0.0; | |
338 | ||
339 | projMatrix[3][0] = 0.0; | |
340 | projMatrix[3][1] = 0.0; | |
341 | projMatrix[3][2] = 0.0; | |
342 | projMatrix[3][3] = 1.0; | |
2166f0fa SK |
343 | |
344 | /* save matrix */ | |
345 | glMatrixMode (GL_MODELVIEW); | |
346 | glPushMatrix (); | |
347 | //glLoadIdentity (); | |
348 | glLoadMatrixd( (GLdouble *) modelMatrix); | |
349 | glMatrixMode ( GL_PROJECTION ); | |
350 | glPushMatrix (); | |
351 | //glLoadIdentity(); | |
352 | glLoadMatrixd( (GLdouble *) projMatrix); | |
353 | ||
354 | /* | |
355 | * Define position in the view | |
356 | */ | |
357 | switch (myPos) | |
358 | { | |
bf75be98 | 359 | case Aspect_TOTP_LEFT_LOWER : |
2166f0fa SK |
360 | glTranslated( -0.5*U + L , -0.5*V + L , 0. ); |
361 | break; | |
362 | ||
363 | case Aspect_TOTP_LEFT_UPPER : | |
364 | glTranslated( -0.5*U + L , +0.5*V - L -L/3. , 0. ); | |
365 | break; | |
366 | ||
367 | case Aspect_TOTP_RIGHT_LOWER : | |
368 | glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. ); | |
369 | break; | |
370 | ||
371 | case Aspect_TOTP_RIGHT_UPPER : | |
372 | glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. ); | |
373 | break; | |
374 | ||
375 | //case Aspect_TOTP_CENTER : | |
376 | default : | |
377 | break; | |
378 | } | |
379 | L *= myRatio; | |
380 | } | |
381 | ||
a174a3c5 | 382 | const OpenGl_AspectLine *AspectLine = theWorkspace->AspectLine( Standard_True ); |
2166f0fa SK |
383 | const TEL_COLOUR &aLineColor = AspectLine->Color(); |
384 | ||
bf75be98 | 385 | /* |
2166f0fa SK |
386 | * Creation the trihedron |
387 | */ | |
388 | #define CYLINDER_LENGTH 0.75f | |
389 | ||
390 | const GLuint startList = glGenLists(4); | |
391 | GLUquadricObj* aQuadric = gluNewQuadric(); | |
392 | ||
393 | const GLboolean aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST); | |
394 | ||
2166f0fa | 395 | GLboolean aIsDepthMaskEnabled; |
5f8b738e | 396 | /*PCD 02/07/07 */ |
2166f0fa SK |
397 | /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the */ |
398 | /* original code is shown to be broken when run under an OpenGL debugger */ | |
399 | /* like GLIntercept. This is the correct way to retrieve the mask value. */ | |
bf75be98 | 400 | glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled); |
2166f0fa SK |
401 | |
402 | const GLdouble aCylinderLength = L * CYLINDER_LENGTH; | |
403 | const GLdouble aCylinderDiametr = L * myDiameter; | |
404 | const GLdouble aConeDiametr = aCylinderDiametr * 2.; | |
405 | const GLdouble aConeLength = L * (1 - CYLINDER_LENGTH); | |
406 | /* Correct for owerlapping */ | |
407 | /* aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/ | |
408 | ||
409 | /* Create cylinder for axis */ | |
410 | gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */ | |
411 | gluQuadricNormals(aQuadric, GLU_FLAT); | |
412 | /* Axis */ | |
413 | glNewList(startList, GL_COMPILE); | |
414 | gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, myNbFacettes, 1); | |
415 | glEndList(); | |
416 | /* Cone */ | |
417 | glNewList(startList + 1, GL_COMPILE); | |
418 | gluCylinder(aQuadric, aConeDiametr, 0., aConeLength, myNbFacettes, 1); | |
419 | glEndList(); | |
420 | /* Central sphere */ | |
421 | glNewList(startList + 2, GL_COMPILE); | |
422 | gluSphere(aQuadric, aCylinderDiametr * 2., myNbFacettes, myNbFacettes); | |
423 | glEndList(); | |
424 | /* End disk */ | |
425 | gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/ | |
426 | glNewList(startList + 3, GL_COMPILE); | |
427 | gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, myNbFacettes, 1/*szv:2*/); | |
428 | glEndList(); | |
429 | ||
430 | /* Store previous attributes */ | |
431 | glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT); | |
432 | glEnable(GL_LIGHTING); | |
433 | ||
434 | glCullFace(GL_BACK); | |
435 | glEnable(GL_CULL_FACE); | |
436 | ||
5f8b738e | 437 | /*Fotis Sioutis | 2008-01-21 10:55 |
bf75be98 | 438 | In the function call_zbuffer_triedron_redraw of TKOpengl, |
439 | the z buffered trihedron changes colors in case there | |
440 | is an object in the scene that has an explicit material | |
441 | attached to it.In the trihedron display loop, | |
442 | GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE | |
2166f0fa | 443 | parameter is utilized in glColorMaterial(...). |
bf75be98 | 444 | This causes the last ambient,specular and emission values |
2166f0fa SK |
445 | used, to stay at the stack and applied to the trihedron |
446 | (which causes the color change). | |
bf75be98 | 447 | A fix is proposed , to change GL_DIFFUSE to |
448 | GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in | |
449 | line 946.The above of course will leave unchanged | |
2166f0fa | 450 | the SPECULAR and EMISSION values. |
bf75be98 | 451 | Another proposal which would fix 100% the problem |
452 | is to use glMaterial instead of glColor on the trihedron | |
2166f0fa SK |
453 | drawing loop. */ |
454 | const GLfloat aNULLColor[] = { 0.f, 0.f, 0.f, 0.f }; /* FS 21/01/08 */ | |
455 | glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor); | |
456 | glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor); | |
457 | glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor); | |
458 | glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.f); | |
2166f0fa SK |
459 | |
460 | glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); | |
461 | glEnable(GL_COLOR_MATERIAL); | |
462 | ||
463 | if (!aIsDepthEnabled) { | |
464 | glEnable(GL_DEPTH_TEST); | |
2166f0fa | 465 | glClear(GL_DEPTH_BUFFER_BIT); |
2166f0fa | 466 | } |
2166f0fa | 467 | |
2166f0fa SK |
468 | if (!aIsDepthMaskEnabled) { |
469 | /* This is how the depthmask needs to be re-enabled...*/ | |
470 | glDepthMask(GL_TRUE); | |
471 | /* ...and not this stuff below */ | |
472 | } | |
2166f0fa SK |
473 | |
474 | /* Position des Axes */ | |
475 | GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 }; | |
476 | GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 }; | |
2166f0fa SK |
477 | TriedronAxeX[0] = L; |
478 | TriedronAxeY[1] = L; | |
2166f0fa SK |
479 | |
480 | glMatrixMode(GL_MODELVIEW); | |
481 | ||
5f8b738e | 482 | /* PCD 17/06/07 */ |
2166f0fa | 483 | GLint df; |
bf75be98 | 484 | glGetIntegerv (GL_DEPTH_FUNC, &df); |
2166f0fa | 485 | |
2166f0fa SK |
486 | int i; |
487 | for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */ | |
488 | { | |
489 | if (i == 0) /* First pass */ | |
bf75be98 | 490 | { |
491 | glDepthFunc(GL_ALWAYS); | |
2166f0fa SK |
492 | } |
493 | else | |
494 | { | |
bf75be98 | 495 | glDepthFunc(GL_LEQUAL); |
2166f0fa | 496 | } |
2166f0fa SK |
497 | |
498 | glPushMatrix(); | |
499 | glPushMatrix(); | |
500 | glPushMatrix(); | |
501 | ||
502 | glColor3fv(aLineColor.rgb); | |
503 | glCallList(startList+2); | |
504 | ||
505 | // Z axis | |
506 | glColor4fv(myZColor.rgb); | |
507 | glCallList(startList); | |
508 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
509 | glCallList(startList + 3); | |
510 | glCallList(startList + 1); | |
bf75be98 | 511 | glPopMatrix(); |
2166f0fa SK |
512 | |
513 | // X axis | |
514 | glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]); | |
515 | glColor4fv(myXColor.rgb); | |
516 | glCallList(startList); | |
517 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
518 | glCallList(startList + 3); | |
519 | glCallList(startList + 1); | |
bf75be98 | 520 | glPopMatrix(); |
2166f0fa SK |
521 | |
522 | // Y axis | |
523 | glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]); | |
524 | glColor4fv(myYColor.rgb); | |
525 | glCallList(startList); | |
526 | glTranslated(0, 0, L * CYLINDER_LENGTH); | |
527 | glCallList(startList + 3); | |
528 | glCallList(startList + 1); | |
529 | glPopMatrix(); | |
2166f0fa | 530 | } |
2166f0fa | 531 | |
bf75be98 | 532 | if (!aIsDepthEnabled) |
2166f0fa | 533 | glDisable(GL_DEPTH_TEST); |
2166f0fa | 534 | |
5f8b738e | 535 | if (!aIsDepthMaskEnabled) |
2166f0fa | 536 | glDepthMask(GL_FALSE); |
2166f0fa | 537 | |
2166f0fa SK |
538 | glDisable(GL_CULL_FACE); |
539 | glDisable(GL_COLOR_MATERIAL); | |
540 | ||
541 | gluDeleteQuadric(aQuadric); | |
542 | glColor3fv (aLineColor.rgb); | |
543 | ||
2166f0fa | 544 | /* Always write the text */ |
bf75be98 | 545 | glDepthFunc(GL_ALWAYS); |
2166f0fa SK |
546 | |
547 | glPopAttrib(); | |
548 | ||
549 | /* fleches au bout des axes (= cones de la couleur demandee) */ | |
550 | //const GLdouble l = 0.75*L; /* distance a l'origine */ | |
551 | const GLdouble rayon = L/30. ; /* rayon de la base du cone */ | |
552 | //const double Angle = 2. * M_PI/ myNbFacettes; | |
553 | ||
bf75be98 | 554 | glDeleteLists(startList, 4); |
2166f0fa SK |
555 | |
556 | glDisable(GL_LIGHTING); | |
557 | ||
a174a3c5 | 558 | // draw axes labels |
559 | myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon))); | |
560 | myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon))); | |
561 | myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon))); | |
562 | myLabelX.Render (theWorkspace); | |
563 | myLabelY.Render (theWorkspace); | |
564 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 565 | |
2166f0fa SK |
566 | /*PCD 17/06/07 */ |
567 | glDepthFunc(df); | |
2166f0fa SK |
568 | |
569 | if (!isWithinView) { /* restore matrix */ | |
570 | glMatrixMode (GL_PROJECTION); | |
571 | glPopMatrix (); | |
572 | glMatrixMode (GL_MODELVIEW); | |
573 | glPopMatrix (); | |
574 | } | |
575 | } | |
576 | ||
577 | ||
578 | /*----------------------------------------------------------------------*/ | |
579 | ||
580 | /*----------------------------------------------------------------------*/ | |
581 | /* | |
bf75be98 | 582 | * Fonctions publiques |
2166f0fa SK |
583 | */ |
584 | ||
585 | ||
586 | /* | |
587 | * initialisation d'un triedre non zoomable dans une vue. | |
588 | * ou modification des valeurs deja initialisees. | |
589 | */ | |
590 | ||
591 | //call_triedron_init | |
a174a3c5 | 592 | OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition, |
593 | const Quantity_NameOfColor theColor, | |
594 | const Standard_Real theScale, | |
595 | const Standard_Boolean theAsWireframe) | |
596 | : myPos (thePosition), | |
597 | myScale (theScale), | |
598 | myIsWireframe (theAsWireframe), | |
599 | myLabelX (TCollection_ExtendedString ("X"), OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS), | |
600 | myLabelY (TCollection_ExtendedString ("Y"), OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS), | |
601 | myLabelZ (TCollection_ExtendedString ("Z"), OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS) | |
2166f0fa SK |
602 | { |
603 | Standard_Real R,G,B; | |
a174a3c5 | 604 | Quantity_Color aColor (theColor); |
605 | aColor.Values (R, G, B, Quantity_TOC_RGB); | |
2166f0fa | 606 | |
fd4a6963 | 607 | CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine; |
608 | aLineAspect.Color.r = (float)R; | |
609 | aLineAspect.Color.g = (float)G; | |
610 | aLineAspect.Color.b = (float)B; | |
611 | myAspectLine.SetAspect (aLineAspect); | |
612 | ||
613 | CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText; | |
614 | aTextAspect.Color.r = (float)R; | |
615 | aTextAspect.Color.g = (float)G; | |
616 | aTextAspect.Color.b = (float)B; | |
617 | myAspectText.SetAspect (aTextAspect); | |
2166f0fa SK |
618 | |
619 | myXColor = theXColor; | |
620 | myYColor = theYColor; | |
621 | myZColor = theZColor; | |
622 | ||
623 | myRatio = theRatio; | |
624 | myDiameter = theDiameter; | |
625 | myNbFacettes = theNbFacettes; | |
626 | } | |
627 | ||
628 | /*----------------------------------------------------------------------*/ | |
629 | ||
630 | /* | |
631 | * destruction du triedre non zoomable d'une vue. | |
632 | */ | |
633 | ||
634 | //call_triedron_erase | |
a174a3c5 | 635 | OpenGl_Trihedron::~OpenGl_Trihedron() |
636 | { | |
637 | } | |
638 | ||
639 | // ======================================================================= | |
640 | // function : Release | |
641 | // purpose : | |
642 | // ======================================================================= | |
643 | void OpenGl_Trihedron::Release (const Handle(OpenGl_Context)& theCtx) | |
2166f0fa | 644 | { |
a174a3c5 | 645 | myLabelX.Release (theCtx); |
646 | myLabelY.Release (theCtx); | |
647 | myLabelZ.Release (theCtx); | |
30f0ad28 | 648 | myAspectLine.Release (theCtx); |
649 | myAspectText.Release (theCtx); | |
2166f0fa SK |
650 | } |
651 | ||
652 | /*----------------------------------------------------------------------*/ | |
653 | ||
654 | /* | |
bf75be98 | 655 | * affichage d'un triedre non zoomable dans la wks awsid |
2166f0fa SK |
656 | * |
657 | * Triedre = Objet non Zoomable; | |
bf75be98 | 658 | * on cree cette fonction pour pouvoir travailler par les structures |
2166f0fa SK |
659 | * utilisees par les fonctions Tsm* et TEL_VIEW_REP |
660 | * | |
661 | */ | |
662 | ||
663 | //call_triedron_redraw_from_wsid | |
bf75be98 | 664 | void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 665 | { |
bf75be98 | 666 | const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine); |
667 | const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText); | |
2166f0fa SK |
668 | |
669 | /* check if GL_LIGHTING should be disabled | |
bf75be98 | 670 | no enabling 'cause it will be done (if necessary: kinda Polygon types ) |
2166f0fa SK |
671 | during redrawing structures |
672 | */ | |
bf75be98 | 673 | if (!theWorkspace->UseGLLight()) |
674 | { | |
675 | glDisable (GL_LIGHTING); | |
676 | } | |
2166f0fa | 677 | |
bf75be98 | 678 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); |
2166f0fa SK |
679 | |
680 | /* affichage du Triedre Non Zoomable */ | |
30f0ad28 | 681 | theWorkspace->ActiveView()->EndTransformPersistence (theWorkspace->GetGlContext()); |
2166f0fa SK |
682 | |
683 | if (myIsWireframe) | |
bf75be98 | 684 | { |
a174a3c5 | 685 | redraw (theWorkspace); |
bf75be98 | 686 | } |
2166f0fa | 687 | else |
bf75be98 | 688 | { |
a174a3c5 | 689 | redrawZBuffer (theWorkspace); |
bf75be98 | 690 | } |
2166f0fa | 691 | |
bf75be98 | 692 | // restore aspects |
693 | if (!aPrevTexture.IsNull()) | |
694 | { | |
695 | theWorkspace->EnableTexture (aPrevTexture); | |
696 | } | |
2166f0fa | 697 | |
bf75be98 | 698 | theWorkspace->SetAspectText (aPrevAspectText); |
699 | theWorkspace->SetAspectLine (aPrevAspectLine); | |
2166f0fa SK |
700 | } |
701 | ||
702 | /*----------------------------------------------------------------------*/ | |
703 | //call_ztriedron_setup | |
704 | void OpenGl_Trihedron::Setup (const Quantity_NameOfColor XColor, const Quantity_NameOfColor YColor, const Quantity_NameOfColor ZColor, | |
705 | const Standard_Real SizeRatio, const Standard_Real AxisDiametr, const Standard_Integer NbFacettes) | |
706 | { | |
707 | Standard_Real R,G,B; | |
708 | ||
709 | Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB); | |
710 | theXColor.rgb[0] = float (R); | |
711 | theXColor.rgb[1] = float (G); | |
712 | theXColor.rgb[2] = float (B); | |
713 | ||
714 | Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB); | |
715 | theYColor.rgb[0] = float (R); | |
716 | theYColor.rgb[1] = float (G); | |
717 | theYColor.rgb[2] = float (B); | |
718 | ||
719 | Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB); | |
720 | theZColor.rgb[0] = float (R); | |
721 | theZColor.rgb[1] = float (G); | |
722 | theZColor.rgb[2] = float (B); | |
723 | ||
724 | theRatio = float (SizeRatio); | |
725 | theDiameter = float (AxisDiametr); | |
726 | theNbFacettes = NbFacettes; | |
727 | } |