1 // Created on: 2011-09-20
2 // Created by: Sergey ZERCHANINOV
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <OpenGl_Trihedron.hxx>
18 #include <OpenGl_GlCore11.hxx>
20 #include <Graphic3d_ArrayOfSegments.hxx>
21 #include <Graphic3d_ArrayOfPolylines.hxx>
22 #include <Graphic3d_GraphicDriver.hxx>
23 #include <Graphic3d_TransformUtils.hxx>
24 #include <OpenGl_View.hxx>
25 #include <OpenGl_Workspace.hxx>
26 #include <Precision.hxx>
30 static const OpenGl_TextParam THE_LABEL_PARAMS =
32 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
36 // =======================================================================
37 // function : resetTransformations
39 // =======================================================================
40 void OpenGl_Trihedron::resetTransformations (const Handle(OpenGl_Workspace)& theWorkspace) const
42 const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
43 const Handle(Graphic3d_Camera)& aCamera = theWorkspace->View()->Camera();
46 if (aCamera->ViewDimensions().X() < aCamera->ViewDimensions().Y())
48 aV = aCamera->ViewDimensions().Y() / aCamera->ViewDimensions().X();
52 anU = aCamera->ViewDimensions().X() / aCamera->ViewDimensions().Y();
55 // Reading the transformation matrices and projection of sight
56 // to cancel translations (last columns of matrices).
57 OpenGl_Mat4d aModelMatrix;
58 OpenGl_Mat4d aProjMatrix;
59 aModelMatrix.Convert (aContext->WorldViewState.Current());
61 // Cancel the translation that can be assigned to the view
62 aModelMatrix.ChangeValue (0, 3) = 0.0;
63 aModelMatrix.ChangeValue (1, 3) = 0.0;
64 aModelMatrix.ChangeValue (2, 3) = 0.0;
66 aProjMatrix.ChangeValue (0, 0) = 2.0 / anU;
67 aProjMatrix.ChangeValue (1, 0) = 0.0;
68 aProjMatrix.ChangeValue (2, 0) = 0.0;
69 aProjMatrix.ChangeValue (3, 0) = 0.0;
71 aProjMatrix.ChangeValue (0, 1) = 0.0;
72 aProjMatrix.ChangeValue (1, 1) = 2.0 / aV;
73 aProjMatrix.ChangeValue (2, 1) = 0.0;
74 aProjMatrix.ChangeValue (3, 1) = 0.0;
76 aProjMatrix.ChangeValue (0, 2) = 0.0;
77 aProjMatrix.ChangeValue (1, 2) = 0.0;
78 aProjMatrix.ChangeValue (2, 2) = -2.0 * 0.01;
79 aProjMatrix.ChangeValue (3, 2) = 0.0;
81 aProjMatrix.ChangeValue (0, 3) = 0.0;
82 aProjMatrix.ChangeValue (1, 3) = 0.0;
83 aProjMatrix.ChangeValue (2, 3) = 0.0;
84 aProjMatrix.ChangeValue (3, 3) = 1.0;
86 // Define trihedron position in the view
89 case Aspect_TOTP_LEFT_LOWER:
91 Graphic3d_TransformUtils::Translate (aProjMatrix,
92 -0.5 * anU + myScale, -0.5 * aV + myScale, 0.0);
95 case Aspect_TOTP_LEFT_UPPER:
97 Graphic3d_TransformUtils::Translate (aProjMatrix,
98 -0.5 * anU + myScale, 0.5 * aV - myScale - myScale / 3.0, 0.0);
101 case Aspect_TOTP_RIGHT_LOWER:
103 Graphic3d_TransformUtils::Translate (aProjMatrix,
104 0.5 * anU - myScale - myScale / 3.0, -0.5 * aV + myScale, 0.0);
107 case Aspect_TOTP_RIGHT_UPPER:
109 Graphic3d_TransformUtils::Translate (aProjMatrix,
110 0.5 * anU - myScale - myScale / 3.0, 0.5 * aV - myScale - myScale / 3.0, 0.0);
113 //case Aspect_TOTP_CENTER:
118 aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix);
119 aContext->ApplyProjectionMatrix();
121 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
122 aContext->ApplyWorldViewMatrix();
125 // =======================================================================
128 // =======================================================================
129 void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const
131 const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext();
132 aContext->WorldViewState.Push();
133 aContext->ProjectionState.Push();
135 resetTransformations (theWorkspace);
137 // Set trihedron size parameters
138 GLdouble aScale = myScale;
140 const Standard_Real aLineRatio = 0.75;
141 const GLdouble aLineLength = aScale * aLineRatio;
142 const GLdouble aConeDiametr = aScale * myDiameter;
143 const GLdouble aConeLength = aScale * (1.0 - aLineRatio);
144 const GLdouble aRayon = aScale / 30.0;
146 // Create primitive line here for changing length
147 if (!myLine.IsInitialized())
149 Handle(Graphic3d_ArrayOfSegments) aGraphicArray = new Graphic3d_ArrayOfSegments (2);
150 aGraphicArray->AddVertex (0.0, 0.0, 0.0);
151 aGraphicArray->AddVertex (0.0, 0.0, aLineLength);
152 myLine.InitBuffers (aContext, Graphic3d_TOPA_SEGMENTS, aGraphicArray->Indices(),
153 aGraphicArray->Attributes(),
154 aGraphicArray->Bounds());
157 if (!myCircle.IsInitialized())
159 const Standard_Integer THE_CIRCLE_SERMENTS_NB = 24;
160 Handle(Graphic3d_ArrayOfPolylines) anCircleArray = new Graphic3d_ArrayOfPolylines (THE_CIRCLE_SERMENTS_NB + 2);
162 const Standard_Real THE_CIRCLE_SEGMENT_ANGLE = 2.0 * M_PI / THE_CIRCLE_SERMENTS_NB;
163 for (Standard_Integer anIt = THE_CIRCLE_SERMENTS_NB; anIt >= 0; --anIt)
165 anCircleArray->AddVertex (aRayon * sin (anIt * THE_CIRCLE_SEGMENT_ANGLE),
166 aRayon * cos (anIt * THE_CIRCLE_SEGMENT_ANGLE), 0.0);
168 anCircleArray->AddVertex (aRayon * sin (THE_CIRCLE_SERMENTS_NB * THE_CIRCLE_SEGMENT_ANGLE),
169 aRayon * cos (THE_CIRCLE_SERMENTS_NB * THE_CIRCLE_SEGMENT_ANGLE), 0.0);
171 myCircle.InitBuffers (aContext, Graphic3d_TOPA_POLYLINES, anCircleArray->Indices(),
172 anCircleArray->Attributes(), anCircleArray->Bounds());
175 if (!myDisk.IsInitialized())
177 myDisk.Init (0.0, static_cast<GLfloat> (aConeDiametr), myNbFacettes, 1);
180 if (!myCone.IsInitialized())
182 myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1);
185 OpenGl_AspectFace anAspectX;
186 OpenGl_AspectFace anAspectY;
187 OpenGl_AspectFace anAspectZ;
188 OpenGl_AspectLine anAspectLine;
189 anAspectX.Aspect()->SetInteriorColor (Quantity_Color (myXColor.rgb()));
190 anAspectY.Aspect()->SetInteriorColor (Quantity_Color (myYColor.rgb()));
191 anAspectZ.Aspect()->SetInteriorColor (Quantity_Color (myZColor.rgb()));
193 OpenGl_Mat4d aModelMatrix;
194 aModelMatrix.Convert (aContext->WorldViewState.Current());
195 OpenGl_Mat4d aModelViewX (aModelMatrix);
196 OpenGl_Mat4d aModelViewY (aModelMatrix);
197 OpenGl_Mat4d aModelViewZ (aModelMatrix);
200 const OpenGl_AspectLine* aCurrentAspectLine = theWorkspace->ApplyAspectLine();
201 Handle(Graphic3d_AspectLine3d) anAspectLine3d = new Graphic3d_AspectLine3d (Quantity_Color(), aCurrentAspectLine->Aspect()->Type(), aCurrentAspectLine->Aspect()->Width());
202 anAspectLine.SetAspect (anAspectLine3d);
204 // Disable depth test and face culling
205 GLboolean wasDepthMaskEnabled = GL_FALSE;
206 GLint aDepthFuncBack = 0, aCullFaceModeBack = GL_BACK;
207 const GLboolean wasDepthEnabled = aContext->core11fwd->glIsEnabled (GL_DEPTH_TEST);
208 const GLboolean wasCullFaceEnabled = aContext->core11fwd->glIsEnabled (GL_CULL_FACE);
209 aContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncBack);
210 aContext->core11fwd->glGetIntegerv (GL_CULL_FACE_MODE, &aCullFaceModeBack);
211 aContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &wasDepthMaskEnabled);
212 if (!wasDepthEnabled)
214 aContext->core11fwd->glEnable (GL_DEPTH_TEST);
215 aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT);
217 if (!wasDepthMaskEnabled)
219 aContext->core11fwd->glDepthMask (GL_TRUE);
221 aContext->core11fwd->glCullFace (GL_BACK);
222 if (!wasCullFaceEnabled)
224 aContext->core11fwd->glEnable (GL_CULL_FACE);
228 myCircle.Render (theWorkspace);
231 const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace(&anAspectZ);
232 anAspectLine3d->SetColor (Quantity_Color (myZColor.rgb()));
233 theWorkspace->SetAspectLine (&anAspectLine);
234 myLine.Render (theWorkspace);
235 Graphic3d_TransformUtils::Translate (aModelViewZ, 0.0, 0.0, aLineLength);
236 aContext->WorldViewState.SetCurrent<Standard_Real>(aModelViewZ);
237 aContext->ApplyWorldViewMatrix();
238 myDisk.Render (theWorkspace);
239 myCone.Render (theWorkspace);
242 theWorkspace->SetAspectFace (&anAspectX);
243 Graphic3d_TransformUtils::Rotate (aModelViewX, 90.0, 0.0, aScale, 0.0);
244 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
245 aContext->ApplyWorldViewMatrix();
247 anAspectLine3d->SetColor (Quantity_Color (myXColor.rgb()));
248 theWorkspace->SetAspectLine (&anAspectLine);
249 myLine.Render (theWorkspace);
250 Graphic3d_TransformUtils::Translate (aModelViewX, 0.0, 0.0, aLineLength);
251 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
252 aContext->ApplyWorldViewMatrix();
253 myDisk.Render (theWorkspace);
254 myCone.Render (theWorkspace);
257 theWorkspace->SetAspectFace (&anAspectY);
258 Graphic3d_TransformUtils::Rotate (aModelViewY, -90.0, aScale, 0.0, 0.0);
259 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
260 aContext->ApplyWorldViewMatrix();
262 anAspectLine3d->SetColor (Quantity_Color (myYColor.rgb()));
263 theWorkspace->SetAspectLine (&anAspectLine);
264 myLine.Render (theWorkspace);
265 Graphic3d_TransformUtils::Translate (aModelViewY, 0.0, 0.0, aLineLength);
266 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
267 aContext->ApplyWorldViewMatrix();
268 myDisk.Render (theWorkspace);
269 myCone.Render (theWorkspace);
272 theWorkspace->SetAspectFace (anOldAspectFace);
274 if (!wasDepthEnabled)
276 aContext->core11fwd->glDisable (GL_DEPTH_TEST);
278 if (!wasDepthMaskEnabled)
280 aContext->core11fwd->glDepthMask (GL_FALSE);
282 if (!wasCullFaceEnabled)
284 aContext->core11fwd->glDisable (GL_CULL_FACE);
286 aContext->core11fwd->glCullFace (aCullFaceModeBack);
288 // Always write the text
289 aContext->core11fwd->glDepthFunc (GL_ALWAYS);
292 myLabelX.SetPosition (OpenGl_Vec3 (float (aScale + 2.0 * aRayon), 0.0f, float (-aRayon)));
293 myLabelY.SetPosition (OpenGl_Vec3 (float (aRayon), float (aScale + 3.0 * aRayon), float (2.0 * aRayon)));
294 myLabelZ.SetPosition (OpenGl_Vec3 (float (-2.0 * aRayon), float (0.5 * aRayon), float (aScale + 3.0 * aRayon)));
295 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
296 aContext->ApplyWorldViewMatrix();
297 myLabelX.Render (theWorkspace);
298 myLabelY.Render (theWorkspace);
299 myLabelZ.Render (theWorkspace);
301 aContext->core11fwd->glDepthFunc (aDepthFuncBack);
302 aContext->WorldViewState.Pop();
303 aContext->ProjectionState.Pop();
304 aContext->ApplyProjectionMatrix();
307 // =======================================================================
308 // function : redrawZBuffer
310 // =======================================================================
311 void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const
313 Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext();
314 aContext->WorldViewState.Push();
315 aContext->ProjectionState.Push();
317 resetTransformations (theWorkspace);
319 const GLdouble aScale = myScale * myRatio;
321 const OpenGl_AspectLine* anAspectLine = theWorkspace->ApplyAspectLine();
322 const OpenGl_Vec4& aLineColor = anAspectLine->Aspect()->ColorRGBA();
324 // Create the trihedron
325 const Standard_Real THE_CYLINDER_LENGTH = 0.75;
326 const GLdouble aCylinderLength = aScale * THE_CYLINDER_LENGTH;
327 const GLdouble aCylinderDiametr = aScale * myDiameter;
328 const GLdouble aConeDiametr = aCylinderDiametr * 2.0;
329 const GLdouble aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH);
332 GLdouble aTriedronAxeX[3] = { aScale, 0.0, 0.0 };
333 GLdouble aTriedronAxeY[3] = { 0.0, aScale, 0.0 };
334 if (!myDisk.IsInitialized())
336 myDisk.Init (static_cast<GLfloat> (aCylinderDiametr),
337 static_cast<GLfloat> (aConeDiametr),
341 if (!mySphere.IsInitialized())
343 mySphere.Init (static_cast<GLfloat> (aCylinderDiametr * 2.0), myNbFacettes, myNbFacettes);
346 if (!myCone.IsInitialized())
348 myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1);
351 if (!myCylinder.IsInitialized())
353 myCylinder.Init (static_cast<GLfloat> (aCylinderDiametr),
354 static_cast<GLfloat> (aCylinderDiametr),
355 static_cast<GLfloat> (aCylinderLength),
359 GLboolean wasDepthMaskEnabled = GL_FALSE;
360 GLint aDepthFuncBack = 0, aCullFaceModeBack = GL_BACK;
361 const GLboolean wasDepthEnabled = aContext->core11fwd->glIsEnabled (GL_DEPTH_TEST);
362 const GLboolean wasCullFaceEnabled = aContext->core11fwd->glIsEnabled (GL_CULL_FACE);
363 aContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncBack);
364 aContext->core11fwd->glGetIntegerv (GL_CULL_FACE_MODE, &aCullFaceModeBack);
365 aContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &wasDepthMaskEnabled);
366 if (!wasDepthEnabled)
368 aContext->core11fwd->glEnable (GL_DEPTH_TEST);
369 aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT);
371 if (!wasDepthMaskEnabled)
373 aContext->core11fwd->glDepthMask (GL_TRUE);
375 aContext->core11fwd->glCullFace (GL_BACK);
376 if (!wasCullFaceEnabled)
378 aContext->core11fwd->glEnable (GL_CULL_FACE);
381 OpenGl_AspectFace anAspectC;
382 OpenGl_AspectFace anAspectX;
383 OpenGl_AspectFace anAspectY;
384 OpenGl_AspectFace anAspectZ;
385 anAspectX.Aspect()->SetInteriorColor (Quantity_Color (myXColor.rgb()));
386 anAspectY.Aspect()->SetInteriorColor (Quantity_Color (myYColor.rgb()));
387 anAspectZ.Aspect()->SetInteriorColor (Quantity_Color (myZColor.rgb()));
388 anAspectC.Aspect()->SetInteriorColor (Quantity_Color (aLineColor.rgb()));
390 OpenGl_Mat4d aModelMatrix;
391 aModelMatrix.Convert (aContext->WorldViewState.Current());
392 for (Standard_Integer aPass = 0; aPass < 2; ++aPass)
394 OpenGl_Mat4d aModelViewX (aModelMatrix);
395 OpenGl_Mat4d aModelViewY (aModelMatrix);
396 OpenGl_Mat4d aModelViewZ (aModelMatrix);
397 aContext->core11fwd->glDepthFunc (aPass == 0 ? GL_ALWAYS : GL_LEQUAL);
399 const OpenGl_AspectFace* anOldAspect = theWorkspace->SetAspectFace (&anAspectC);
402 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
403 aContext->ApplyWorldViewMatrix();
404 mySphere.Render (theWorkspace);
407 theWorkspace->SetAspectFace (&anAspectZ);
408 myCylinder.Render (theWorkspace);
409 Graphic3d_TransformUtils::Translate (aModelViewZ, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
410 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewZ);
411 aContext->ApplyWorldViewMatrix();
412 myDisk.Render (theWorkspace);
413 myCone.Render (theWorkspace);
416 theWorkspace->SetAspectFace (&anAspectX);
417 Graphic3d_TransformUtils::Rotate (aModelViewX, 90.0, aTriedronAxeY[0], aTriedronAxeY[1], aTriedronAxeY[2]);
418 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
419 aContext->ApplyWorldViewMatrix();
420 myCylinder.Render (theWorkspace);
421 Graphic3d_TransformUtils::Translate (aModelViewX, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
422 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX);
423 aContext->ApplyWorldViewMatrix();
424 myDisk.Render (theWorkspace);
425 myCone.Render (theWorkspace);
428 theWorkspace->SetAspectFace (&anAspectY);
429 Graphic3d_TransformUtils::Rotate (aModelViewY, -90.0, aTriedronAxeX[0], aTriedronAxeX[1], aTriedronAxeX[2]);
430 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
431 aContext->ApplyWorldViewMatrix();
432 myCylinder.Render (theWorkspace);
433 Graphic3d_TransformUtils::Translate (aModelViewY, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH);
434 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY);
435 aContext->ApplyWorldViewMatrix();
436 myDisk.Render (theWorkspace);
437 myCone.Render (theWorkspace);
439 theWorkspace->SetAspectFace (anOldAspect);
442 if (!wasDepthEnabled)
444 aContext->core11fwd->glDisable (GL_DEPTH_TEST);
446 if (!wasDepthMaskEnabled)
448 aContext->core11fwd->glDepthMask (GL_FALSE);
450 if (!wasCullFaceEnabled)
452 aContext->core11fwd->glDisable (GL_CULL_FACE);
454 aContext->core11fwd->glCullFace (aCullFaceModeBack);
456 // Always write the text
457 aContext->core11fwd->glDepthFunc (GL_ALWAYS);
460 const GLdouble rayon = aScale / 30.0;
461 myLabelX.SetPosition (OpenGl_Vec3(float(aScale + 2.0 * rayon), 0.0f, float(-rayon)));
462 myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(aScale + 3.0 * rayon), float(2.0 * rayon)));
463 myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(aScale + 3.0 * rayon)));
464 aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix);
465 aContext->ApplyWorldViewMatrix();
466 myLabelX.Render (theWorkspace);
467 myLabelY.Render (theWorkspace);
468 myLabelZ.Render (theWorkspace);
470 aContext->core11fwd->glDepthFunc (aDepthFuncBack);
472 aContext->WorldViewState.Pop();
473 aContext->ProjectionState.Pop();
474 aContext->ApplyProjectionMatrix();
477 // =======================================================================
478 // function : OpenGl_Trihedron
480 // =======================================================================
481 OpenGl_Trihedron::OpenGl_Trihedron()
482 : myPos (Aspect_TOTP_LEFT_LOWER),
484 myIsWireframe (Standard_False),
485 myXColor (1.0f, 0.0f, 0.0f, 0.6f),
486 myYColor (0.0f, 1.0f, 0.0f, 0.6f),
487 myZColor (0.0f, 0.0f, 1.0f, 0.6f),
491 myLabelX ("X", OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS),
492 myLabelY ("Y", OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS),
493 myLabelZ ("Z", OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS),
494 myLine (NULL), // do not register arrays UID - trihedron is not intended to be drawn by Ray Tracing engine
497 myAspectLine.SetAspect (new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0));
498 myAspectText.Aspect()->SetColor (Quantity_NOC_WHITE);
499 myAspectText.Aspect()->SetFont ("Courier");
502 // =======================================================================
503 // function : ~OpenGl_Trihedron
505 // =======================================================================
506 OpenGl_Trihedron::~OpenGl_Trihedron()
511 // =======================================================================
512 // function : Release
514 // =======================================================================
515 void OpenGl_Trihedron::Release (OpenGl_Context* theCtx)
517 myLabelX.Release (theCtx);
518 myLabelY.Release (theCtx);
519 myLabelZ.Release (theCtx);
520 myAspectLine.Release (theCtx);
521 myAspectText.Release (theCtx);
522 myCone .Release (theCtx);
523 myDisk .Release (theCtx);
524 mySphere .Release (theCtx);
525 myCylinder.Release (theCtx);
526 myLine.Release (theCtx);
527 myCircle.Release (theCtx);
530 // =======================================================================
531 // function : invalidate
533 // =======================================================================
534 void OpenGl_Trihedron::invalidate()
536 myCone .Invalidate();
537 myDisk .Invalidate();
538 mySphere .Invalidate();
539 myCylinder.Invalidate();
540 myLine .Invalidate();
541 myCircle .Invalidate();
544 // =======================================================================
545 // function : SetScale
547 // =======================================================================
548 void OpenGl_Trihedron::SetScale (const Standard_Real theScale)
550 if (Abs (myScale - theScale) > Precision::Confusion())
557 // =======================================================================
558 // function : SetSizeRatio
560 // =======================================================================
561 void OpenGl_Trihedron::SetSizeRatio (const Standard_Real theRatio)
563 if (Abs (Standard_Real(myRatio) - theRatio) > Precision::Confusion())
567 myRatio = float(theRatio);
570 // =======================================================================
571 // function : SetArrowDiameter
573 // =======================================================================
574 void OpenGl_Trihedron::SetArrowDiameter (const Standard_Real theDiam)
576 if (Abs (Standard_Real(myDiameter) - theDiam) > Precision::Confusion())
580 myDiameter = float(theDiam);
583 // =======================================================================
584 // function : SetNbFacets
586 // =======================================================================
587 void OpenGl_Trihedron::SetNbFacets (const Standard_Integer theNbFacets)
589 if (Abs (myNbFacettes - theNbFacets) > 0)
593 myNbFacettes = theNbFacets;
596 // =======================================================================
597 // function : SetLabelsColor
599 // =======================================================================
600 void OpenGl_Trihedron::SetLabelsColor (const Quantity_Color& theColor)
602 myAspectText.Aspect()->SetColor (theColor);
605 // =======================================================================
606 // function : SetArrowsColors
608 // =======================================================================
609 void OpenGl_Trihedron::SetArrowsColors (const Quantity_Color& theColorX,
610 const Quantity_Color& theColorY,
611 const Quantity_Color& theColorZ)
613 myXColor = OpenGl_Vec4 (float(theColorX.Red()), float(theColorX.Green()), float(theColorX.Blue()), 0.6f);
614 myYColor = OpenGl_Vec4 (float(theColorY.Red()), float(theColorY.Green()), float(theColorY.Blue()), 0.6f);
615 myZColor = OpenGl_Vec4 (float(theColorZ.Red()), float(theColorZ.Green()), float(theColorZ.Blue()), 0.6f);
618 // =======================================================================
621 // =======================================================================
622 void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
624 const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine);
625 const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText);
627 /* check if GL_LIGHTING should be disabled
628 no enabling 'cause it will be done (if necessary: kinda Polygon types )
629 during redrawing structures
631 if (!theWorkspace->UseGLLight())
633 #if !defined(GL_ES_VERSION_2_0)
634 glDisable (GL_LIGHTING);
638 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
640 theWorkspace->GetGlContext()->ApplyModelViewMatrix();
644 redraw (theWorkspace);
648 redrawZBuffer (theWorkspace);
652 if (!aPrevTexture.IsNull())
654 theWorkspace->EnableTexture (aPrevTexture);
657 theWorkspace->SetAspectText (aPrevAspectText);
658 theWorkspace->SetAspectLine (aPrevAspectLine);