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 | |
c827ea3a | 16 | #include <OpenGl_Trihedron.hxx> |
2166f0fa | 17 | |
c827ea3a | 18 | #include <OpenGl_GlCore11.hxx> |
2166f0fa | 19 | |
e1c659da | 20 | #include <Graphic3d_ArrayOfSegments.hxx> |
21 | #include <Graphic3d_ArrayOfPolylines.hxx> | |
2166f0fa | 22 | #include <OpenGl_View.hxx> |
c827ea3a | 23 | #include <OpenGl_Workspace.hxx> |
536d98e2 | 24 | #include <Precision.hxx> |
2166f0fa | 25 | |
536d98e2 | 26 | namespace |
a174a3c5 | 27 | { |
536d98e2 | 28 | static const OpenGl_TextParam THE_LABEL_PARAMS = |
29 | { | |
30 | 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM | |
31 | }; | |
32 | } | |
2166f0fa | 33 | |
c827ea3a | 34 | // ======================================================================= |
e1c659da | 35 | // function : resetTransformations |
c827ea3a | 36 | // purpose : |
37 | // ======================================================================= | |
e1c659da | 38 | void OpenGl_Trihedron::resetTransformations (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 39 | { |
e1c659da | 40 | const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); |
41 | const Handle(OpenGl_View)& aView = theWorkspace->ActiveView(); | |
42 | GLdouble anU = 1.0; | |
43 | GLdouble aV = 1.0; | |
44 | if (aView->Height() < aView->Width()) | |
45 | { | |
46 | aV = aView->Width() / aView->Height(); | |
47 | } | |
48 | else | |
49 | { | |
50 | anU = aView->Height() / aView->Width(); | |
51 | } | |
c827ea3a | 52 | |
e1c659da | 53 | // Reading the transformation matrices and projection of sight |
54 | // to cancel translations (last columns of matrices). | |
c827ea3a | 55 | OpenGl_Mat4d aModelMatrix; |
c827ea3a | 56 | OpenGl_Mat4d aProjMatrix; |
e1c659da | 57 | aModelMatrix.Convert (aContext->WorldViewState.Current()); |
2166f0fa | 58 | |
e1c659da | 59 | // Cancel the translation that can be assigned to the view |
c827ea3a | 60 | aModelMatrix.ChangeValue (0, 3) = 0.0; |
61 | aModelMatrix.ChangeValue (1, 3) = 0.0; | |
62 | aModelMatrix.ChangeValue (2, 3) = 0.0; | |
63 | ||
e1c659da | 64 | aProjMatrix.ChangeValue (0, 0) = 2.0 / anU; |
c827ea3a | 65 | aProjMatrix.ChangeValue (1, 0) = 0.0; |
66 | aProjMatrix.ChangeValue (2, 0) = 0.0; | |
67 | aProjMatrix.ChangeValue (3, 0) = 0.0; | |
68 | ||
69 | aProjMatrix.ChangeValue (0, 1) = 0.0; | |
e1c659da | 70 | aProjMatrix.ChangeValue (1, 1) = 2.0 / aV; |
c827ea3a | 71 | aProjMatrix.ChangeValue (2, 1) = 0.0; |
72 | aProjMatrix.ChangeValue (3, 1) = 0.0; | |
73 | ||
74 | aProjMatrix.ChangeValue (0, 2) = 0.0; | |
75 | aProjMatrix.ChangeValue (1, 2) = 0.0; | |
e1c659da | 76 | aProjMatrix.ChangeValue (2, 2) = -2.0 * 0.01; |
77 | aProjMatrix.ChangeValue (3, 2) = 0.0; | |
78 | ||
c827ea3a | 79 | aProjMatrix.ChangeValue (0, 3) = 0.0; |
80 | aProjMatrix.ChangeValue (1, 3) = 0.0; | |
81 | aProjMatrix.ChangeValue (2, 3) = 0.0; | |
82 | aProjMatrix.ChangeValue (3, 3) = 1.0; | |
2166f0fa | 83 | |
e1c659da | 84 | // Define trihedron position in the view |
2166f0fa SK |
85 | switch (myPos) |
86 | { | |
e1c659da | 87 | case Aspect_TOTP_LEFT_LOWER: |
c827ea3a | 88 | { |
89 | OpenGl_Utils::Translate (aProjMatrix, | |
e1c659da | 90 | -0.5 * anU + myScale, -0.5 * aV + myScale, 0.0); |
91 | break; | |
c827ea3a | 92 | } |
e1c659da | 93 | case Aspect_TOTP_LEFT_UPPER: |
c827ea3a | 94 | { |
95 | OpenGl_Utils::Translate (aProjMatrix, | |
e1c659da | 96 | -0.5 * anU + myScale, 0.5 * aV - myScale - myScale / 3.0, 0.0); |
97 | break; | |
c827ea3a | 98 | } |
e1c659da | 99 | case Aspect_TOTP_RIGHT_LOWER: |
c827ea3a | 100 | { |
101 | OpenGl_Utils::Translate (aProjMatrix, | |
e1c659da | 102 | 0.5 * anU - myScale - myScale / 3.0, -0.5 * aV + myScale, 0.0); |
103 | break; | |
c827ea3a | 104 | } |
e1c659da | 105 | case Aspect_TOTP_RIGHT_UPPER: |
c827ea3a | 106 | { |
107 | OpenGl_Utils::Translate (aProjMatrix, | |
e1c659da | 108 | 0.5 * anU - myScale - myScale / 3.0, 0.5 * aV - myScale - myScale / 3.0, 0.0); |
109 | break; | |
c827ea3a | 110 | } |
e1c659da | 111 | //case Aspect_TOTP_CENTER: |
112 | default: | |
2166f0fa SK |
113 | break; |
114 | } | |
115 | ||
c827ea3a | 116 | aContext->ProjectionState.SetCurrent<Standard_Real> (aProjMatrix); |
c827ea3a | 117 | aContext->ApplyProjectionMatrix(); |
e1c659da | 118 | |
119 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix); | |
c827ea3a | 120 | aContext->ApplyWorldViewMatrix(); |
e1c659da | 121 | } |
c827ea3a | 122 | |
e1c659da | 123 | // ======================================================================= |
124 | // function : redraw | |
125 | // purpose : | |
126 | // ======================================================================= | |
127 | void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const | |
128 | { | |
129 | const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); | |
130 | aContext->WorldViewState.Push(); | |
131 | aContext->ProjectionState.Push(); | |
2166f0fa | 132 | |
e1c659da | 133 | resetTransformations (theWorkspace); |
134 | ||
135 | // Set trihedron size parameters | |
136 | GLdouble aScale = myScale; | |
137 | aScale *= myRatio; | |
138 | const Standard_Real aLineRatio = 0.75; | |
139 | const GLdouble aLineLength = aScale * aLineRatio; | |
140 | const GLdouble aConeDiametr = aScale * myDiameter; | |
141 | const GLdouble aConeLength = aScale * (1.0 - aLineRatio); | |
142 | const GLdouble aRayon = aScale / 30.0; | |
143 | ||
144 | // Create primitive line here for changing length | |
145 | if (!myLine.IsInitialized()) | |
146 | { | |
147 | Handle(Graphic3d_ArrayOfSegments) aGraphicArray = new Graphic3d_ArrayOfSegments (2); | |
148 | aGraphicArray->AddVertex (0.0, 0.0, 0.0); | |
149 | aGraphicArray->AddVertex (0.0, 0.0, aLineLength); | |
150 | myLine.InitBuffers (aContext, Graphic3d_TOPA_SEGMENTS, aGraphicArray->Indices(), | |
151 | aGraphicArray->Attributes(), | |
152 | aGraphicArray->Bounds()); | |
2166f0fa | 153 | } |
e1c659da | 154 | |
155 | if (!myCircle.IsInitialized()) | |
156 | { | |
157 | const Standard_Integer THE_CIRCLE_SERMENTS_NB = 24; | |
158 | Handle(Graphic3d_ArrayOfPolylines) anCircleArray = new Graphic3d_ArrayOfPolylines (THE_CIRCLE_SERMENTS_NB + 2); | |
159 | ||
160 | const Standard_Real THE_CIRCLE_SEGMENT_ANGLE = 2.0 * M_PI / THE_CIRCLE_SERMENTS_NB; | |
161 | for (Standard_Integer anIt = THE_CIRCLE_SERMENTS_NB; anIt >= 0; --anIt) | |
162 | { | |
163 | anCircleArray->AddVertex (aRayon * sin (anIt * THE_CIRCLE_SEGMENT_ANGLE), | |
164 | aRayon * cos (anIt * THE_CIRCLE_SEGMENT_ANGLE), 0.0); | |
165 | } | |
166 | anCircleArray->AddVertex (aRayon * sin (THE_CIRCLE_SERMENTS_NB * THE_CIRCLE_SEGMENT_ANGLE), | |
167 | aRayon * cos (THE_CIRCLE_SERMENTS_NB * THE_CIRCLE_SEGMENT_ANGLE), 0.0); | |
168 | ||
169 | myCircle.InitBuffers (aContext, Graphic3d_TOPA_POLYLINES, anCircleArray->Indices(), | |
170 | anCircleArray->Attributes(), anCircleArray->Bounds()); | |
2166f0fa | 171 | } |
e1c659da | 172 | |
536d98e2 | 173 | if (!myDisk.IsInitialized()) |
e1c659da | 174 | { |
175 | myDisk.Init (0.0, static_cast<GLfloat> (aConeDiametr), myNbFacettes, 1); | |
2166f0fa | 176 | } |
e1c659da | 177 | |
536d98e2 | 178 | if (!myCone.IsInitialized()) |
e1c659da | 179 | { |
180 | myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1); | |
bf75be98 | 181 | } |
2166f0fa | 182 | |
e1c659da | 183 | OpenGl_AspectFace anAspectX; |
184 | OpenGl_AspectFace anAspectY; | |
185 | OpenGl_AspectFace anAspectZ; | |
186 | OpenGl_AspectLine anAspectLine; | |
536d98e2 | 187 | memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.GetData(), sizeof (TEL_COLOUR)); |
188 | memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.GetData(), sizeof (TEL_COLOUR)); | |
189 | memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.GetData(), sizeof (TEL_COLOUR)); | |
e1c659da | 190 | OpenGl_Mat4d aModelMatrix; |
191 | aModelMatrix.Convert (aContext->WorldViewState.Current()); | |
192 | OpenGl_Mat4d aModelViewX (aModelMatrix); | |
193 | OpenGl_Mat4d aModelViewY (aModelMatrix); | |
194 | OpenGl_Mat4d aModelViewZ (aModelMatrix); | |
195 | ||
196 | // Set line aspect | |
197 | const OpenGl_AspectLine* aCurrentAspectLine = theWorkspace->AspectLine (Standard_True); | |
198 | CALL_DEF_CONTEXTLINE aLineAspect = {1, 1, { 1.F, 1.F, 1.F }, aCurrentAspectLine->Type(), aCurrentAspectLine->Width()}; | |
536d98e2 | 199 | aLineAspect.Color.r = myZColor.r(); |
200 | aLineAspect.Color.g = myZColor.g(); | |
201 | aLineAspect.Color.b = myZColor.b(); | |
e1c659da | 202 | anAspectLine.SetAspect (aLineAspect); |
203 | ||
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) | |
213 | { | |
214 | aContext->core11fwd->glEnable (GL_DEPTH_TEST); | |
215 | aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT); | |
216 | } | |
217 | if (!wasDepthMaskEnabled) | |
218 | { | |
219 | aContext->core11fwd->glDepthMask (GL_TRUE); | |
220 | } | |
221 | aContext->core11fwd->glCullFace (GL_BACK); | |
222 | if (!wasCullFaceEnabled) | |
223 | { | |
224 | aContext->core11fwd->glEnable (GL_CULL_FACE); | |
225 | } | |
226 | ||
227 | // Origin | |
228 | myCircle.Render (theWorkspace); | |
229 | ||
230 | // Z axis | |
231 | const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace(&anAspectZ); | |
232 | theWorkspace->SetAspectLine (&anAspectLine); | |
233 | myLine.Render (theWorkspace); | |
234 | OpenGl_Utils::Translate (aModelViewZ, 0.0, 0.0, aLineLength); | |
235 | aContext->WorldViewState.SetCurrent<Standard_Real>(aModelViewZ); | |
236 | aContext->ApplyWorldViewMatrix(); | |
237 | myDisk.Render (theWorkspace); | |
238 | myCone.Render (theWorkspace); | |
239 | ||
240 | // X axis | |
241 | theWorkspace->SetAspectFace (&anAspectX); | |
242 | OpenGl_Utils::Rotate (aModelViewX, 90.0, 0.0, aScale, 0.0); | |
243 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX); | |
244 | aContext->ApplyWorldViewMatrix(); | |
245 | ||
536d98e2 | 246 | aLineAspect.Color.r = myXColor.r(); |
247 | aLineAspect.Color.g = myXColor.g(); | |
248 | aLineAspect.Color.b = myXColor.b(); | |
e1c659da | 249 | anAspectLine.SetAspect (aLineAspect); |
250 | theWorkspace->SetAspectLine (&anAspectLine); | |
251 | myLine.Render (theWorkspace); | |
252 | OpenGl_Utils::Translate (aModelViewX, 0.0, 0.0, aLineLength); | |
253 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX); | |
254 | aContext->ApplyWorldViewMatrix(); | |
255 | myDisk.Render (theWorkspace); | |
256 | myCone.Render (theWorkspace); | |
257 | ||
258 | // Y axis | |
259 | theWorkspace->SetAspectFace (&anAspectY); | |
260 | OpenGl_Utils::Rotate (aModelViewY, -90.0, aScale, 0.0, 0.0); | |
261 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY); | |
262 | aContext->ApplyWorldViewMatrix(); | |
263 | ||
536d98e2 | 264 | aLineAspect.Color.r = myYColor.r(); |
265 | aLineAspect.Color.g = myYColor.g(); | |
266 | aLineAspect.Color.b = myYColor.b(); | |
e1c659da | 267 | anAspectLine.SetAspect (aLineAspect); |
268 | theWorkspace->SetAspectLine (&anAspectLine); | |
269 | myLine.Render (theWorkspace); | |
270 | OpenGl_Utils::Translate (aModelViewY, 0.0, 0.0, aLineLength); | |
271 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY); | |
272 | aContext->ApplyWorldViewMatrix(); | |
273 | myDisk.Render (theWorkspace); | |
274 | myCone.Render (theWorkspace); | |
275 | ||
276 | // Restore aspects | |
277 | theWorkspace->SetAspectFace (anOldAspectFace); | |
278 | ||
279 | if (!wasDepthEnabled) | |
280 | { | |
281 | aContext->core11fwd->glDisable (GL_DEPTH_TEST); | |
282 | } | |
283 | if (!wasDepthMaskEnabled) | |
284 | { | |
285 | aContext->core11fwd->glDepthMask (GL_FALSE); | |
286 | } | |
287 | if (!wasCullFaceEnabled) | |
288 | { | |
289 | aContext->core11fwd->glDisable (GL_CULL_FACE); | |
290 | } | |
291 | aContext->core11fwd->glCullFace (aCullFaceModeBack); | |
292 | ||
293 | // Always write the text | |
294 | aContext->core11fwd->glDepthFunc (GL_ALWAYS); | |
295 | ||
296 | // Render labels | |
297 | myLabelX.SetPosition (OpenGl_Vec3 (float (aScale + 2.0 * aRayon), 0.0f, float (-aRayon))); | |
298 | myLabelY.SetPosition (OpenGl_Vec3 (float (aRayon), float (aScale + 3.0 * aRayon), float (2.0 * aRayon))); | |
299 | myLabelZ.SetPosition (OpenGl_Vec3 (float (-2.0 * aRayon), float (0.5 * aRayon), float (aScale + 3.0 * aRayon))); | |
300 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix); | |
301 | aContext->ApplyWorldViewMatrix(); | |
a174a3c5 | 302 | myLabelX.Render (theWorkspace); |
303 | myLabelY.Render (theWorkspace); | |
304 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 305 | |
e1c659da | 306 | aContext->core11fwd->glDepthFunc (aDepthFuncBack); |
c827ea3a | 307 | aContext->WorldViewState.Pop(); |
308 | aContext->ProjectionState.Pop(); | |
309 | aContext->ApplyProjectionMatrix(); | |
2166f0fa SK |
310 | } |
311 | ||
c827ea3a | 312 | // ======================================================================= |
313 | // function : redrawZBuffer | |
314 | // purpose : | |
315 | // ======================================================================= | |
a174a3c5 | 316 | void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 317 | { |
536d98e2 | 318 | Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext(); |
c827ea3a | 319 | aContext->WorldViewState.Push(); |
320 | aContext->ProjectionState.Push(); | |
2166f0fa | 321 | |
e1c659da | 322 | resetTransformations (theWorkspace); |
2166f0fa | 323 | |
536d98e2 | 324 | const GLdouble aScale = myScale * myRatio; |
2166f0fa | 325 | |
c827ea3a | 326 | const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); |
327 | const TEL_COLOUR& aLineColor = anAspectLine->Color(); | |
2166f0fa | 328 | |
c827ea3a | 329 | // Create the trihedron |
330 | const Standard_Real THE_CYLINDER_LENGTH = 0.75; | |
331 | const GLdouble aCylinderLength = aScale * THE_CYLINDER_LENGTH; | |
332 | const GLdouble aCylinderDiametr = aScale * myDiameter; | |
333 | const GLdouble aConeDiametr = aCylinderDiametr * 2.0; | |
334 | const GLdouble aConeLength = aScale * (1.0 - THE_CYLINDER_LENGTH); | |
2166f0fa | 335 | |
c827ea3a | 336 | // Position des Axes |
337 | GLdouble aTriedronAxeX[3] = { aScale, 0.0, 0.0 }; | |
338 | GLdouble aTriedronAxeY[3] = { 0.0, aScale, 0.0 }; | |
536d98e2 | 339 | if (!myDisk.IsInitialized()) |
c827ea3a | 340 | { |
341 | myDisk.Init (static_cast<GLfloat> (aCylinderDiametr), | |
342 | static_cast<GLfloat> (aConeDiametr), | |
343 | myNbFacettes, 1); | |
344 | } | |
2166f0fa | 345 | |
536d98e2 | 346 | if (!mySphere.IsInitialized()) |
c827ea3a | 347 | { |
348 | mySphere.Init (static_cast<GLfloat> (aCylinderDiametr * 2.0), myNbFacettes, myNbFacettes); | |
2166f0fa | 349 | } |
2166f0fa | 350 | |
536d98e2 | 351 | if (!myCone.IsInitialized()) |
c827ea3a | 352 | { |
353 | myCone.Init (static_cast<GLfloat> (aConeDiametr), 0.0f, static_cast<GLfloat> (aConeLength), myNbFacettes, 1); | |
354 | } | |
2166f0fa | 355 | |
536d98e2 | 356 | if (!myCylinder.IsInitialized()) |
c827ea3a | 357 | { |
358 | myCylinder.Init (static_cast<GLfloat> (aCylinderDiametr), | |
359 | static_cast<GLfloat> (aCylinderDiametr), | |
360 | static_cast<GLfloat> (aCylinderLength), | |
361 | myNbFacettes, 1); | |
362 | } | |
2166f0fa | 363 | |
c827ea3a | 364 | GLboolean wasDepthMaskEnabled = GL_FALSE; |
365 | GLint aDepthFuncBack = 0, aCullFaceModeBack = GL_BACK; | |
366 | const GLboolean wasDepthEnabled = aContext->core11fwd->glIsEnabled (GL_DEPTH_TEST); | |
367 | const GLboolean wasCullFaceEnabled = aContext->core11fwd->glIsEnabled (GL_CULL_FACE); | |
368 | aContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFuncBack); | |
369 | aContext->core11fwd->glGetIntegerv (GL_CULL_FACE_MODE, &aCullFaceModeBack); | |
370 | aContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &wasDepthMaskEnabled); | |
371 | if (!wasDepthEnabled) | |
372 | { | |
373 | aContext->core11fwd->glEnable (GL_DEPTH_TEST); | |
374 | aContext->core11fwd->glClear (GL_DEPTH_BUFFER_BIT); | |
375 | } | |
376 | if (!wasDepthMaskEnabled) | |
377 | { | |
378 | aContext->core11fwd->glDepthMask (GL_TRUE); | |
379 | } | |
380 | aContext->core11fwd->glCullFace (GL_BACK); | |
381 | if (!wasCullFaceEnabled) | |
382 | { | |
383 | aContext->core11fwd->glEnable (GL_CULL_FACE); | |
384 | } | |
2166f0fa | 385 | |
c827ea3a | 386 | OpenGl_AspectFace anAspectC; |
387 | OpenGl_AspectFace anAspectX; | |
388 | OpenGl_AspectFace anAspectY; | |
389 | OpenGl_AspectFace anAspectZ; | |
536d98e2 | 390 | memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.GetData(), sizeof (TEL_COLOUR)); |
391 | memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.GetData(), sizeof (TEL_COLOUR)); | |
392 | memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.GetData(), sizeof (TEL_COLOUR)); | |
393 | memcpy (anAspectC.ChangeIntFront().matcol.rgb, aLineColor.rgb, sizeof (TEL_COLOUR)); | |
e1c659da | 394 | |
395 | OpenGl_Mat4d aModelMatrix; | |
396 | aModelMatrix.Convert (aContext->WorldViewState.Current()); | |
c827ea3a | 397 | for (Standard_Integer aPass = 0; aPass < 2; ++aPass) |
398 | { | |
399 | OpenGl_Mat4d aModelViewX (aModelMatrix); | |
400 | OpenGl_Mat4d aModelViewY (aModelMatrix); | |
401 | OpenGl_Mat4d aModelViewZ (aModelMatrix); | |
402 | aContext->core11fwd->glDepthFunc (aPass == 0 ? GL_ALWAYS : GL_LEQUAL); | |
2166f0fa | 403 | |
c827ea3a | 404 | const OpenGl_AspectFace* anOldAspect = theWorkspace->SetAspectFace (&anAspectC); |
2166f0fa | 405 | |
c827ea3a | 406 | // Origin |
407 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix); | |
408 | aContext->ApplyWorldViewMatrix(); | |
409 | mySphere.Render (theWorkspace); | |
2166f0fa | 410 | |
c827ea3a | 411 | // Z axis |
412 | theWorkspace->SetAspectFace (&anAspectZ); | |
413 | myCylinder.Render (theWorkspace); | |
414 | OpenGl_Utils::Translate (aModelViewZ, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH); | |
415 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewZ); | |
416 | aContext->ApplyWorldViewMatrix(); | |
417 | myDisk.Render (theWorkspace); | |
418 | myCone.Render (theWorkspace); | |
2166f0fa | 419 | |
c827ea3a | 420 | // X axis |
421 | theWorkspace->SetAspectFace (&anAspectX); | |
422 | OpenGl_Utils::Rotate (aModelViewX, 90.0, aTriedronAxeY[0], aTriedronAxeY[1], aTriedronAxeY[2]); | |
423 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX); | |
424 | aContext->ApplyWorldViewMatrix(); | |
425 | myCylinder.Render (theWorkspace); | |
426 | OpenGl_Utils::Translate (aModelViewX, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH); | |
427 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewX); | |
428 | aContext->ApplyWorldViewMatrix(); | |
429 | myDisk.Render (theWorkspace); | |
430 | myCone.Render (theWorkspace); | |
2166f0fa | 431 | |
c827ea3a | 432 | // Y axis |
433 | theWorkspace->SetAspectFace (&anAspectY); | |
434 | OpenGl_Utils::Rotate (aModelViewY, -90.0, aTriedronAxeX[0], aTriedronAxeX[1], aTriedronAxeX[2]); | |
435 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY); | |
436 | aContext->ApplyWorldViewMatrix(); | |
437 | myCylinder.Render (theWorkspace); | |
438 | OpenGl_Utils::Translate (aModelViewY, 0.0, 0.0, aScale * THE_CYLINDER_LENGTH); | |
439 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelViewY); | |
440 | aContext->ApplyWorldViewMatrix(); | |
441 | myDisk.Render (theWorkspace); | |
442 | myCone.Render (theWorkspace); | |
443 | ||
444 | theWorkspace->SetAspectFace (anOldAspect); | |
445 | } | |
446 | ||
447 | if (!wasDepthEnabled) | |
448 | { | |
449 | aContext->core11fwd->glDisable (GL_DEPTH_TEST); | |
450 | } | |
451 | if (!wasDepthMaskEnabled) | |
452 | { | |
453 | aContext->core11fwd->glDepthMask (GL_FALSE); | |
454 | } | |
455 | if (!wasCullFaceEnabled) | |
456 | { | |
457 | aContext->core11fwd->glDisable (GL_CULL_FACE); | |
458 | } | |
459 | aContext->core11fwd->glCullFace (aCullFaceModeBack); | |
460 | ||
461 | // Always write the text | |
462 | aContext->core11fwd->glDepthFunc (GL_ALWAYS); | |
2166f0fa | 463 | |
a174a3c5 | 464 | // draw axes labels |
c827ea3a | 465 | const GLdouble rayon = aScale / 30.0; |
466 | myLabelX.SetPosition (OpenGl_Vec3(float(aScale + 2.0 * rayon), 0.0f, float(-rayon))); | |
467 | myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(aScale + 3.0 * rayon), float(2.0 * rayon))); | |
468 | myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(aScale + 3.0 * rayon))); | |
469 | aContext->WorldViewState.SetCurrent<Standard_Real> (aModelMatrix); | |
470 | aContext->ApplyWorldViewMatrix(); | |
a174a3c5 | 471 | myLabelX.Render (theWorkspace); |
472 | myLabelY.Render (theWorkspace); | |
473 | myLabelZ.Render (theWorkspace); | |
2166f0fa | 474 | |
c827ea3a | 475 | aContext->core11fwd->glDepthFunc (aDepthFuncBack); |
2166f0fa | 476 | |
c827ea3a | 477 | aContext->WorldViewState.Pop(); |
478 | aContext->ProjectionState.Pop(); | |
479 | aContext->ApplyProjectionMatrix(); | |
2166f0fa SK |
480 | } |
481 | ||
c827ea3a | 482 | // ======================================================================= |
483 | // function : OpenGl_Trihedron | |
484 | // purpose : | |
485 | // ======================================================================= | |
536d98e2 | 486 | OpenGl_Trihedron::OpenGl_Trihedron() |
487 | : myPos (Aspect_TOTP_LEFT_LOWER), | |
488 | myScale (1.0), | |
489 | myIsWireframe (Standard_False), | |
490 | myXColor (1.0f, 0.0f, 0.0f, 0.6f), | |
491 | myYColor (0.0f, 1.0f, 0.0f, 0.6f), | |
492 | myZColor (0.0f, 0.0f, 1.0f, 0.6f), | |
493 | myRatio (0.8f), | |
494 | myDiameter (0.05f), | |
495 | myNbFacettes (12), | |
b64d84be | 496 | myLabelX ("X", OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS), |
497 | myLabelY ("Y", OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS), | |
e1c659da | 498 | myLabelZ ("Z", OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS), |
499 | myLine (NULL), // do not register arrays UID - trihedron is not intended to be drawn by Ray Tracing engine | |
500 | myCircle (NULL) | |
2166f0fa | 501 | { |
536d98e2 | 502 | const TEL_COLOUR aWhiteColor = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; |
503 | myAspectLine.ChangeColor() = aWhiteColor; | |
504 | myAspectText.ChangeColor() = aWhiteColor; | |
505 | myAspectText.ChangeFontName() = "Courier"; | |
2166f0fa SK |
506 | } |
507 | ||
c827ea3a | 508 | // ======================================================================= |
509 | // function : ~OpenGl_Trihedron | |
510 | // purpose : | |
511 | // ======================================================================= | |
a174a3c5 | 512 | OpenGl_Trihedron::~OpenGl_Trihedron() |
513 | { | |
e1c659da | 514 | // |
a174a3c5 | 515 | } |
516 | ||
517 | // ======================================================================= | |
518 | // function : Release | |
519 | // purpose : | |
520 | // ======================================================================= | |
10b9c7df | 521 | void OpenGl_Trihedron::Release (OpenGl_Context* theCtx) |
2166f0fa | 522 | { |
a174a3c5 | 523 | myLabelX.Release (theCtx); |
524 | myLabelY.Release (theCtx); | |
525 | myLabelZ.Release (theCtx); | |
30f0ad28 | 526 | myAspectLine.Release (theCtx); |
527 | myAspectText.Release (theCtx); | |
c827ea3a | 528 | myCone .Release (theCtx); |
529 | myDisk .Release (theCtx); | |
530 | mySphere .Release (theCtx); | |
531 | myCylinder.Release (theCtx); | |
e1c659da | 532 | myLine.Release (theCtx); |
533 | myCircle.Release (theCtx); | |
2166f0fa SK |
534 | } |
535 | ||
536d98e2 | 536 | // ======================================================================= |
537 | // function : invalidate | |
538 | // purpose : | |
539 | // ======================================================================= | |
540 | void OpenGl_Trihedron::invalidate() | |
541 | { | |
542 | myCone .Invalidate(); | |
543 | myDisk .Invalidate(); | |
544 | mySphere .Invalidate(); | |
545 | myCylinder.Invalidate(); | |
546 | myLine .Invalidate(); | |
547 | myCircle .Invalidate(); | |
548 | } | |
549 | ||
550 | // ======================================================================= | |
551 | // function : SetScale | |
552 | // purpose : | |
553 | // ======================================================================= | |
554 | void OpenGl_Trihedron::SetScale (const Standard_Real theScale) | |
555 | { | |
556 | if (Abs (myScale - theScale) > Precision::Confusion()) | |
557 | { | |
558 | invalidate(); | |
559 | } | |
560 | myScale = theScale; | |
561 | } | |
562 | ||
563 | // ======================================================================= | |
564 | // function : SetSizeRatio | |
565 | // purpose : | |
566 | // ======================================================================= | |
567 | void OpenGl_Trihedron::SetSizeRatio (const Standard_Real theRatio) | |
568 | { | |
569 | if (Abs (Standard_Real(myRatio) - theRatio) > Precision::Confusion()) | |
570 | { | |
571 | invalidate(); | |
572 | } | |
573 | myRatio = float(theRatio); | |
574 | } | |
575 | ||
576 | // ======================================================================= | |
577 | // function : SetArrowDiameter | |
578 | // purpose : | |
579 | // ======================================================================= | |
580 | void OpenGl_Trihedron::SetArrowDiameter (const Standard_Real theDiam) | |
581 | { | |
582 | if (Abs (Standard_Real(myDiameter) - theDiam) > Precision::Confusion()) | |
583 | { | |
584 | invalidate(); | |
585 | } | |
586 | myDiameter = float(theDiam); | |
587 | } | |
588 | ||
589 | // ======================================================================= | |
590 | // function : SetNbFacets | |
591 | // purpose : | |
592 | // ======================================================================= | |
593 | void OpenGl_Trihedron::SetNbFacets (const Standard_Integer theNbFacets) | |
594 | { | |
595 | if (Abs (myNbFacettes - theNbFacets) > 0) | |
596 | { | |
597 | invalidate(); | |
598 | } | |
599 | myNbFacettes = theNbFacets; | |
600 | } | |
601 | ||
602 | // ======================================================================= | |
603 | // function : SetLabelsColor | |
604 | // purpose : | |
605 | // ======================================================================= | |
606 | void OpenGl_Trihedron::SetLabelsColor (const Quantity_Color& theColor) | |
607 | { | |
608 | myAspectText.ChangeColor().rgb[0] = float(theColor.Red()); | |
609 | myAspectText.ChangeColor().rgb[1] = float(theColor.Green()); | |
610 | myAspectText.ChangeColor().rgb[2] = float(theColor.Blue()); | |
611 | } | |
612 | ||
613 | // ======================================================================= | |
614 | // function : SetArrowsColors | |
615 | // purpose : | |
616 | // ======================================================================= | |
617 | void OpenGl_Trihedron::SetArrowsColors (const Quantity_Color& theColorX, | |
618 | const Quantity_Color& theColorY, | |
619 | const Quantity_Color& theColorZ) | |
620 | { | |
621 | myXColor = OpenGl_Vec4 (float(theColorX.Red()), float(theColorX.Green()), float(theColorX.Blue()), 0.6f); | |
622 | myYColor = OpenGl_Vec4 (float(theColorY.Red()), float(theColorY.Green()), float(theColorY.Blue()), 0.6f); | |
623 | myZColor = OpenGl_Vec4 (float(theColorZ.Red()), float(theColorZ.Green()), float(theColorZ.Blue()), 0.6f); | |
624 | } | |
625 | ||
c827ea3a | 626 | // ======================================================================= |
627 | // function : Render | |
628 | // purpose : | |
629 | // ======================================================================= | |
bf75be98 | 630 | void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const |
2166f0fa | 631 | { |
bf75be98 | 632 | const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine); |
633 | const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText); | |
2166f0fa SK |
634 | |
635 | /* check if GL_LIGHTING should be disabled | |
bf75be98 | 636 | no enabling 'cause it will be done (if necessary: kinda Polygon types ) |
2166f0fa SK |
637 | during redrawing structures |
638 | */ | |
bf75be98 | 639 | if (!theWorkspace->UseGLLight()) |
640 | { | |
ca3c13d1 | 641 | #if !defined(GL_ES_VERSION_2_0) |
bf75be98 | 642 | glDisable (GL_LIGHTING); |
ca3c13d1 | 643 | #endif |
bf75be98 | 644 | } |
2166f0fa | 645 | |
bf75be98 | 646 | const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture(); |
30f0ad28 | 647 | theWorkspace->ActiveView()->EndTransformPersistence (theWorkspace->GetGlContext()); |
a86ce5a6 | 648 | theWorkspace->GetGlContext()->ApplyModelViewMatrix(); |
2166f0fa SK |
649 | |
650 | if (myIsWireframe) | |
bf75be98 | 651 | { |
a174a3c5 | 652 | redraw (theWorkspace); |
bf75be98 | 653 | } |
2166f0fa | 654 | else |
bf75be98 | 655 | { |
a174a3c5 | 656 | redrawZBuffer (theWorkspace); |
bf75be98 | 657 | } |
2166f0fa | 658 | |
bf75be98 | 659 | // restore aspects |
660 | if (!aPrevTexture.IsNull()) | |
661 | { | |
662 | theWorkspace->EnableTexture (aPrevTexture); | |
663 | } | |
2166f0fa | 664 | |
bf75be98 | 665 | theWorkspace->SetAspectText (aPrevAspectText); |
666 | theWorkspace->SetAspectLine (aPrevAspectLine); | |
2166f0fa | 667 | } |