]>
Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-09-20 |
2 | // Created by: Sergey ZERCHANINOV | |
3 | // Copyright (c) 2011-2012 OPEN CASCADE SAS | |
4 | // | |
5 | // The content of this file is subject to the Open CASCADE Technology Public | |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
2166f0fa | 20 | |
5f8b738e | 21 | #include <OpenGl_GlCore11.hxx> |
22 | ||
2166f0fa | 23 | #include <OpenGl_View.hxx> |
bf75be98 | 24 | #include <OpenGl_Context.hxx> |
2166f0fa SK |
25 | #include <OpenGl_Workspace.hxx> |
26 | #include <OpenGl_Display.hxx> | |
27 | ||
bf75be98 | 28 | #include <OpenGl_Texture.hxx> |
2166f0fa SK |
29 | #include <OpenGl_Trihedron.hxx> |
30 | #include <OpenGl_GraduatedTrihedron.hxx> | |
31 | ||
32 | #include <OpenGl_transform_persistence.hxx> | |
33 | ||
bf75be98 | 34 | #include <Graphic3d_TextureEnv.hxx> |
35 | ||
5f8b738e | 36 | #include <GL/glu.h> // gluUnProject() |
37 | ||
2166f0fa SK |
38 | IMPLEMENT_STANDARD_HANDLE(OpenGl_View,MMgt_TShared) |
39 | IMPLEMENT_STANDARD_RTTIEXT(OpenGl_View,MMgt_TShared) | |
40 | ||
41 | /*----------------------------------------------------------------------*/ | |
42 | ||
43 | static const OPENGL_BG_TEXTURE myDefaultBgTexture = { 0, 0, 0, Aspect_FM_CENTERED }; | |
44 | static const OPENGL_BG_GRADIENT myDefaultBgGradient = { {{ 0.F, 0.F, 0.F, 1.F }}, {{ 0.F, 0.F, 0.F, 1.F }}, Aspect_GFM_NONE }; | |
45 | static const Tmatrix3 myDefaultMatrix = { { 1.F, 0.F, 0.F, 0.F }, { 0.F, 1.F, 0.F, 0.F }, { 0.F, 0.F, 1.F, 0.F }, { 0.F, 0.F, 0.F, 1.F } }; | |
46 | static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } }; | |
47 | static const OPENGL_EXTRA_REP myDefaultExtra = | |
48 | { | |
49 | //vrp | |
50 | { 0.F, 0.F, 0.F }, | |
51 | //vpn | |
52 | { 0.F, 0.F, 1.F }, | |
53 | //vup | |
54 | { 0.F, 1.F, 0.F }, | |
55 | //map | |
56 | { | |
57 | //window | |
58 | { 0.F, 0.F, 1.F, 1.F }, | |
59 | //viewport | |
60 | { 0.F, 0.F, 0.F, 1.F, 1.F, 1.F }, | |
61 | //proj | |
62 | TelParallel, | |
63 | //prp | |
64 | { 0.F, 0.F, 0.F }, | |
65 | //vpd | |
66 | 0.F, | |
67 | //fpd | |
68 | 0.F, | |
69 | //bpd | |
70 | -1.F | |
71 | }, | |
72 | //scaleFactors | |
73 | { 1.F, 1.F, 1.F } | |
74 | }; | |
75 | ||
76 | static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } }; | |
77 | static const TEL_TRANSFORM_PERSISTENCE myDefaultTransPers = { 0, 0.F, 0.F, 0.F }; | |
78 | ||
79 | /*----------------------------------------------------------------------*/ | |
80 | ||
81 | OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext) | |
bf75be98 | 82 | : mySurfaceDetail(Visual3d_TOD_NONE), |
2166f0fa SK |
83 | myBackfacing(0), |
84 | myBgTexture(myDefaultBgTexture), | |
85 | myBgGradient(myDefaultBgGradient), | |
86 | //myOrientationMatrix(myDefaultMatrix), | |
87 | //myMappingMatrix(myDefaultMatrix), | |
88 | //shield_indicator = TOn, | |
89 | //shield_colour = { { 0.F, 0.F, 0.F, 1.F } }, | |
90 | //border_indicator = TOff, | |
91 | //border_colour = { { 0.F, 0.F, 0.F, 1.F } }, | |
92 | //active_status = TOn, | |
93 | myZClip(myDefaultZClip), | |
94 | myExtra(myDefaultExtra), | |
95 | myFog(myDefaultFog), | |
96 | myVisualization(AContext.Visualization), | |
97 | myIntShadingMethod(TEL_SM_GOURAUD), | |
98 | myAntiAliasing(Standard_False), | |
99 | myAnimationListIndex(0), | |
100 | myAnimationListReady(Standard_False), | |
101 | myTransPers(&myDefaultTransPers), | |
102 | myIsTransPers(Standard_False), | |
103 | myResetFLIST(Standard_False) | |
104 | { | |
105 | // Initialize matrices | |
106 | memcpy(myOrientationMatrix,myDefaultMatrix,sizeof(Tmatrix3)); | |
107 | memcpy(myMappingMatrix,myDefaultMatrix,sizeof(Tmatrix3)); | |
108 | ||
109 | // Shading method | |
110 | switch (AContext.Model) | |
111 | { | |
112 | case 1 : /* VISUAL3D_TOM_INTERP_COLOR */ | |
113 | case 3 : /* VISUAL3D_TOM_VERTEX */ | |
114 | myIntShadingMethod = TEL_SM_GOURAUD; | |
115 | break; | |
116 | default : | |
117 | myIntShadingMethod = TEL_SM_FLAT; | |
118 | break; | |
119 | } | |
120 | } | |
121 | ||
122 | /*----------------------------------------------------------------------*/ | |
123 | ||
124 | OpenGl_View::~OpenGl_View () | |
125 | { | |
bf75be98 | 126 | ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context |
127 | } | |
128 | ||
129 | void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) | |
130 | { | |
131 | if (!myTextureEnv.IsNull()) | |
132 | { | |
133 | theCtx->DelayedRelease (myTextureEnv); | |
134 | myTextureEnv.Nullify(); | |
135 | } | |
136 | if (myBgTexture.TexId != 0) | |
137 | { | |
138 | glDeleteTextures (1, (GLuint*)&(myBgTexture.TexId)); | |
139 | myBgTexture.TexId = 0; | |
140 | } | |
2166f0fa | 141 | if (myAnimationListIndex) |
bf75be98 | 142 | { |
143 | glDeleteLists ((GLuint )myAnimationListIndex, 1); | |
144 | myAnimationListIndex = 0; | |
145 | } | |
146 | } | |
2166f0fa | 147 | |
bf75be98 | 148 | void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx, |
149 | const Handle(Graphic3d_TextureEnv)& theTexture) | |
150 | { | |
151 | if (!myTextureEnv.IsNull()) | |
152 | { | |
153 | theCtx->DelayedRelease (myTextureEnv); | |
154 | myTextureEnv.Nullify(); | |
155 | } | |
156 | ||
157 | if (theTexture.IsNull()) | |
158 | { | |
159 | return; | |
160 | } | |
161 | ||
162 | myTextureEnv = new OpenGl_Texture (theTexture->GetParams()); | |
163 | Handle(Image_PixMap) anImage = theTexture->GetImage(); | |
164 | myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type()); | |
2166f0fa SK |
165 | } |
166 | ||
167 | /*----------------------------------------------------------------------*/ | |
168 | ||
169 | void OpenGl_View::SetBackfacing (const Standard_Integer AMode) | |
170 | { | |
171 | myBackfacing = AMode; | |
172 | myResetFLIST = Standard_True; | |
173 | } | |
174 | ||
175 | /*----------------------------------------------------------------------*/ | |
176 | ||
177 | //call_togl_setlight | |
178 | void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT &AContext) | |
179 | { | |
180 | myLights.Clear(); | |
181 | ||
182 | const int nb_lights = AContext.NbActiveLight; | |
183 | ||
184 | int i = 0; | |
185 | const CALL_DEF_LIGHT *alight = &(AContext.ActiveLight[0]); | |
186 | for ( ; i < nb_lights; i++, alight++ ) | |
187 | { | |
188 | OpenGl_Light rep; | |
189 | ||
190 | switch( alight->LightType ) | |
191 | { | |
192 | case 0 : /* TOLS_AMBIENT */ | |
193 | rep.type = TLightAmbient; | |
194 | rep.col.rgb[0] = alight->Color.r; | |
195 | rep.col.rgb[1] = alight->Color.g; | |
196 | rep.col.rgb[2] = alight->Color.b; | |
197 | break; | |
198 | ||
199 | case 1 : /* TOLS_DIRECTIONAL */ | |
200 | rep.type = TLightDirectional; | |
201 | rep.col.rgb[0] = alight->Color.r; | |
202 | rep.col.rgb[1] = alight->Color.g; | |
203 | rep.col.rgb[2] = alight->Color.b; | |
204 | rep.dir[0] = alight->Direction.x; | |
205 | rep.dir[1] = alight->Direction.y; | |
206 | rep.dir[2] = alight->Direction.z; | |
207 | break; | |
208 | ||
209 | case 2 : /* TOLS_POSITIONAL */ | |
210 | rep.type = TLightPositional; | |
211 | rep.col.rgb[0] = alight->Color.r; | |
212 | rep.col.rgb[1] = alight->Color.g; | |
213 | rep.col.rgb[2] = alight->Color.b; | |
214 | rep.pos[0] = alight->Position.x; | |
215 | rep.pos[1] = alight->Position.y; | |
216 | rep.pos[2] = alight->Position.z; | |
217 | rep.atten[0] = alight->Attenuation[0]; | |
218 | rep.atten[1] = alight->Attenuation[1]; | |
219 | break; | |
220 | ||
221 | case 3 : /* TOLS_SPOT */ | |
222 | rep.type = TLightSpot; | |
223 | rep.col.rgb[0] = alight->Color.r; | |
224 | rep.col.rgb[1] = alight->Color.g; | |
225 | rep.col.rgb[2] = alight->Color.b; | |
226 | rep.pos[0] = alight->Position.x; | |
227 | rep.pos[1] = alight->Position.y; | |
228 | rep.pos[2] = alight->Position.z; | |
229 | rep.dir[0] = alight->Direction.x; | |
230 | rep.dir[1] = alight->Direction.y; | |
231 | rep.dir[2] = alight->Direction.z; | |
232 | rep.shine = alight->Concentration; | |
233 | rep.atten[0] = alight->Attenuation[0]; | |
234 | rep.atten[1] = alight->Attenuation[1]; | |
235 | rep.angle = alight->Angle; | |
236 | break; | |
237 | } | |
238 | ||
239 | rep.HeadLight = alight->Headlight; | |
240 | ||
241 | myLights.Append(rep); | |
242 | } | |
243 | } | |
244 | ||
245 | /*----------------------------------------------------------------------*/ | |
246 | ||
247 | //call_togl_setplane | |
248 | void OpenGl_View::SetClippingPlanes (const CALL_DEF_VIEWCONTEXT &AContext) | |
249 | { | |
250 | // clear clipping planes information | |
251 | myClippingPlanes.Clear(); | |
bf75be98 | 252 | // update information |
2166f0fa SK |
253 | int i = 0; |
254 | for (; i < AContext.NbActivePlane; i++) | |
255 | { | |
256 | const CALL_DEF_PLANE &aCPlane = AContext.ActivePlane[i]; | |
257 | if ( aCPlane.Active && aCPlane.PlaneId > 0 ) | |
258 | { | |
259 | OPENGL_CLIP_REP aPlane; | |
260 | aPlane.equation[0] = aCPlane.CoefA; | |
261 | aPlane.equation[1] = aCPlane.CoefB; | |
262 | aPlane.equation[2] = aCPlane.CoefC; | |
263 | aPlane.equation[3] = aCPlane.CoefD; | |
264 | myClippingPlanes.Append( aPlane ); | |
265 | } | |
266 | } | |
267 | } | |
268 | ||
269 | /*----------------------------------------------------------------------*/ | |
270 | ||
271 | //call_togl_setvisualisation | |
272 | void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext) | |
273 | { | |
274 | myVisualization = AContext.Visualization; | |
275 | // Shading method | |
276 | switch (AContext.Model) | |
277 | { | |
278 | case 1 : /* VISUAL3D_TOM_INTERP_COLOR */ | |
279 | case 3 : /* VISUAL3D_TOM_VERTEX */ | |
280 | myIntShadingMethod = TEL_SM_GOURAUD; | |
281 | break; | |
282 | default : | |
283 | myIntShadingMethod = TEL_SM_FLAT; | |
284 | break; | |
285 | } | |
286 | } | |
287 | ||
288 | /*----------------------------------------------------------------------*/ | |
289 | ||
290 | //call_togl_cliplimit | |
bf75be98 | 291 | void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView) |
2166f0fa SK |
292 | { |
293 | myZClip.Back.Limit = | |
bf75be98 | 294 | (theCView.Context.ZClipBackPlane - theCView.Mapping.BackPlaneDistance) / |
295 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa | 296 | myZClip.Front.Limit = |
bf75be98 | 297 | (theCView.Context.ZClipFrontPlane - theCView.Mapping.BackPlaneDistance) / |
298 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
299 | if (myZClip.Back.Limit < 0.0f) | |
300 | myZClip.Back.Limit = 0.0f; | |
301 | if (myZClip.Front.Limit > 1.0f) | |
302 | myZClip.Front.Limit = 1.0f; | |
303 | if (myZClip.Back.Limit > myZClip.Front.Limit) | |
2166f0fa | 304 | { |
bf75be98 | 305 | myZClip.Back.Limit = 0.0f; |
306 | myZClip.Front.Limit = 1.0f; | |
2166f0fa SK |
307 | } |
308 | ||
bf75be98 | 309 | myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0); |
310 | myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0); | |
2166f0fa SK |
311 | } |
312 | ||
313 | /*----------------------------------------------------------------------*/ | |
314 | ||
315 | //call_togl_viewmapping | |
bf75be98 | 316 | void OpenGl_View::SetMapping (const Graphic3d_CView& theCView) |
2166f0fa | 317 | { |
bf75be98 | 318 | const float ratio = theCView.DefWindow.dy / theCView.DefWindow.dx; |
319 | const float r_ratio = theCView.DefWindow.dx / theCView.DefWindow.dy; | |
2166f0fa SK |
320 | |
321 | TEL_VIEW_MAPPING Map; | |
322 | ||
bf75be98 | 323 | Map.window.xmin = theCView.Mapping.WindowLimit.um; |
324 | Map.window.ymin = theCView.Mapping.WindowLimit.vm; | |
325 | Map.window.xmax = theCView.Mapping.WindowLimit.uM; | |
326 | Map.window.ymax = theCView.Mapping.WindowLimit.vM; | |
2166f0fa SK |
327 | |
328 | Map.viewport.xmin = 0.F; | |
329 | Map.viewport.xmax = ( 1.F < r_ratio ? 1.F : r_ratio ); | |
330 | Map.viewport.ymin = 0.F; | |
331 | Map.viewport.ymax = ( 1.F < ratio ? 1.F : ratio ); | |
332 | Map.viewport.zmin = 0.F; | |
333 | Map.viewport.zmax = 1.F; | |
334 | ||
bf75be98 | 335 | // projection type |
336 | switch (theCView.Mapping.Projection) | |
2166f0fa SK |
337 | { |
338 | case 0 : | |
339 | Map.proj = TelPerspective; | |
340 | break; | |
341 | case 1 : | |
342 | Map.proj = TelParallel; | |
343 | break; | |
344 | } | |
345 | ||
bf75be98 | 346 | // projection reference point |
347 | Map.prp[0] = theCView.Mapping.ProjectionReferencePoint.x; | |
348 | Map.prp[1] = theCView.Mapping.ProjectionReferencePoint.y; | |
349 | Map.prp[2] = theCView.Mapping.ProjectionReferencePoint.z; | |
2166f0fa | 350 | if (!openglDisplay.IsNull() && !openglDisplay->Walkthrough()) |
bf75be98 | 351 | Map.prp[2] += theCView.Mapping.FrontPlaneDistance; |
2166f0fa | 352 | |
bf75be98 | 353 | // view plane distance |
354 | Map.vpd = theCView.Mapping.ViewPlaneDistance; | |
2166f0fa | 355 | |
bf75be98 | 356 | // back plane distance |
357 | Map.bpd = theCView.Mapping.BackPlaneDistance; | |
2166f0fa | 358 | |
bf75be98 | 359 | // front plane distance |
360 | Map.fpd = theCView.Mapping.FrontPlaneDistance; | |
2166f0fa SK |
361 | |
362 | Tint err_ind = 0; | |
363 | ||
bf75be98 | 364 | // use user-defined matrix |
365 | if (theCView.Mapping.IsCustomMatrix) | |
2166f0fa SK |
366 | { |
367 | int i, j; | |
368 | for( i = 0; i < 4; i++ ) | |
369 | for( j = 0; j < 4; j++ ) | |
bf75be98 | 370 | myMappingMatrix[i][j] = theCView.Mapping.ProjectionMatrix[i][j]; |
2166f0fa | 371 | } |
bf75be98 | 372 | else |
2166f0fa SK |
373 | TelEvalViewMappingMatrix( &Map, &err_ind, myMappingMatrix ); |
374 | ||
bf75be98 | 375 | if (!err_ind) |
2166f0fa SK |
376 | myExtra.map = Map; |
377 | } | |
378 | ||
379 | /*----------------------------------------------------------------------*/ | |
380 | ||
381 | //call_togl_vieworientation | |
bf75be98 | 382 | void OpenGl_View::SetOrientation (const Graphic3d_CView& theCView) |
2166f0fa SK |
383 | { |
384 | Tfloat Vrp[3]; | |
385 | Tfloat Vpn[3]; | |
386 | Tfloat Vup[3]; | |
387 | Tfloat ScaleFactors[3]; | |
388 | ||
bf75be98 | 389 | Vrp[0] = theCView.Orientation.ViewReferencePoint.x; |
390 | Vrp[1] = theCView.Orientation.ViewReferencePoint.y; | |
391 | Vrp[2] = theCView.Orientation.ViewReferencePoint.z; | |
2166f0fa | 392 | |
bf75be98 | 393 | Vpn[0] = theCView.Orientation.ViewReferencePlane.x; |
394 | Vpn[1] = theCView.Orientation.ViewReferencePlane.y; | |
395 | Vpn[2] = theCView.Orientation.ViewReferencePlane.z; | |
2166f0fa | 396 | |
bf75be98 | 397 | Vup[0] = theCView.Orientation.ViewReferenceUp.x; |
398 | Vup[1] = theCView.Orientation.ViewReferenceUp.y; | |
399 | Vup[2] = theCView.Orientation.ViewReferenceUp.z; | |
2166f0fa | 400 | |
bf75be98 | 401 | ScaleFactors[0] = theCView.Orientation.ViewScaleX; |
402 | ScaleFactors[1] = theCView.Orientation.ViewScaleY; | |
403 | ScaleFactors[2] = theCView.Orientation.ViewScaleZ; | |
2166f0fa SK |
404 | |
405 | Tint err_ind = 0; | |
406 | ||
407 | // use user-defined matrix | |
bf75be98 | 408 | if (theCView.Orientation.IsCustomMatrix) |
2166f0fa SK |
409 | { |
410 | int i, j; | |
411 | for( i = 0; i < 4; i++ ) | |
412 | for( j = 0; j < 4; j++ ) | |
bf75be98 | 413 | myOrientationMatrix[i][j] = theCView.Orientation.ModelViewMatrix[i][j]; |
2166f0fa SK |
414 | } |
415 | else | |
bf75be98 | 416 | { |
417 | TelEvalViewOrientationMatrix (Vrp, Vpn, Vup, ScaleFactors, &err_ind, myOrientationMatrix); | |
418 | } | |
2166f0fa | 419 | |
bf75be98 | 420 | if (!err_ind) |
2166f0fa SK |
421 | { |
422 | myExtra.vrp[0] = Vrp[0]; | |
423 | myExtra.vrp[1] = Vrp[1]; | |
424 | myExtra.vrp[2] = Vrp[2]; | |
425 | ||
426 | myExtra.vpn[0] = Vpn[0]; | |
427 | myExtra.vpn[1] = Vpn[1]; | |
428 | myExtra.vpn[2] = Vpn[2]; | |
429 | ||
430 | myExtra.vup[0] = Vup[0]; | |
431 | myExtra.vup[1] = Vup[1]; | |
432 | myExtra.vup[2] = Vup[2]; | |
433 | ||
434 | myExtra.scaleFactors[0] = ScaleFactors[0], | |
435 | myExtra.scaleFactors[1] = ScaleFactors[1], | |
436 | myExtra.scaleFactors[2] = ScaleFactors[2]; | |
437 | } | |
438 | } | |
439 | ||
440 | /*----------------------------------------------------------------------*/ | |
441 | ||
bf75be98 | 442 | void OpenGl_View::SetFog (const Graphic3d_CView& theCView, |
443 | const Standard_Boolean theFlag) | |
2166f0fa | 444 | { |
bf75be98 | 445 | if (!theFlag) |
2166f0fa SK |
446 | { |
447 | myFog.IsOn = Standard_False; | |
448 | } | |
449 | else | |
450 | { | |
451 | myFog.IsOn = Standard_True; | |
452 | ||
453 | myFog.Front = | |
bf75be98 | 454 | (theCView.Context.DepthFrontPlane - theCView.Mapping.BackPlaneDistance) / |
455 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa SK |
456 | |
457 | myFog.Back = | |
bf75be98 | 458 | (theCView.Context.DepthBackPlane - theCView.Mapping.BackPlaneDistance) / |
459 | (theCView.Mapping.FrontPlaneDistance - theCView.Mapping.BackPlaneDistance); | |
2166f0fa SK |
460 | |
461 | if (myFog.Front < 0.F) | |
462 | myFog.Front = 0.F; | |
463 | else if (myFog.Front > 1.F) | |
464 | myFog.Front = 1.F; | |
465 | ||
466 | if (myFog.Back < 0.F) | |
467 | myFog.Back = 0.F; | |
468 | else if (myFog.Back > 1.F) | |
469 | myFog.Back = 1.F; | |
470 | ||
471 | if (myFog.Back > myFog.Front) | |
472 | { | |
473 | myFog.Front = 1.F; | |
474 | myFog.Back = 0.F; | |
475 | } | |
476 | ||
bf75be98 | 477 | myFog.Color.rgb[0] = theCView.DefWindow.Background.r; |
478 | myFog.Color.rgb[1] = theCView.DefWindow.Background.g; | |
479 | myFog.Color.rgb[2] = theCView.DefWindow.Background.b; | |
480 | myFog.Color.rgb[3] = 1.0f; | |
2166f0fa SK |
481 | } |
482 | } | |
483 | ||
484 | /*----------------------------------------------------------------------*/ | |
485 | ||
486 | void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition, const Quantity_NameOfColor AColor, | |
487 | const Standard_Real AScale, const Standard_Boolean AsWireframe) | |
488 | { | |
489 | myTrihedron = new OpenGl_Trihedron (APosition, AColor, AScale, AsWireframe); | |
490 | } | |
491 | ||
492 | /*----------------------------------------------------------------------*/ | |
493 | ||
494 | void OpenGl_View::TriedronErase () | |
495 | { | |
496 | myTrihedron.Nullify(); | |
497 | } | |
498 | ||
499 | /*----------------------------------------------------------------------*/ | |
500 | ||
501 | void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_CGraduatedTrihedron &data) | |
502 | { | |
503 | myGraduatedTrihedron = new OpenGl_GraduatedTrihedron(data); | |
504 | } | |
505 | ||
506 | /*----------------------------------------------------------------------*/ | |
507 | ||
508 | void OpenGl_View::GraduatedTrihedronErase () | |
509 | { | |
510 | myGraduatedTrihedron.Nullify(); | |
511 | } | |
512 | ||
513 | /*----------------------------------------------------------------------*/ | |
514 | ||
515 | //transform_persistence_end | |
516 | void OpenGl_View::EndTransformPersistence () | |
517 | { | |
518 | if ( myIsTransPers ) | |
519 | { | |
520 | /* restore matrix */ | |
521 | glMatrixMode (GL_PROJECTION); | |
522 | glPopMatrix (); | |
523 | glMatrixMode (GL_MODELVIEW); | |
524 | glPopMatrix (); | |
525 | myIsTransPers = Standard_False; | |
526 | } | |
bf75be98 | 527 | } |
2166f0fa SK |
528 | |
529 | /*----------------------------------------------------------------------*/ | |
530 | ||
531 | //transform_persistence_begin | |
532 | const TEL_TRANSFORM_PERSISTENCE * OpenGl_View::BeginTransformPersistence (const TEL_TRANSFORM_PERSISTENCE *ATransPers) | |
533 | { | |
534 | const TEL_TRANSFORM_PERSISTENCE *TransPers_old = myTransPers; | |
535 | ||
e84189c5 | 536 | myTransPers = ATransPers; |
537 | ||
2166f0fa SK |
538 | if ( ATransPers->mode == 0 ) |
539 | { | |
540 | EndTransformPersistence(); | |
541 | return TransPers_old; | |
542 | } | |
543 | ||
2166f0fa SK |
544 | GLint viewport[4]; |
545 | glGetIntegerv (GL_VIEWPORT, viewport); | |
546 | GLdouble modelMatrix[4][4]; | |
547 | glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix ); | |
548 | GLdouble projMatrix[4][4]; | |
549 | glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix ); | |
550 | ||
551 | double W = viewport[2]; | |
552 | double H = viewport[3]; | |
553 | ||
554 | if ( myIsTransPers ) | |
555 | { | |
556 | /* restore matrix */ | |
557 | glMatrixMode (GL_PROJECTION); | |
558 | glPopMatrix (); | |
559 | glMatrixMode (GL_MODELVIEW); | |
560 | glPopMatrix (); | |
561 | } | |
562 | else | |
563 | myIsTransPers = Standard_True; | |
564 | ||
565 | glMatrixMode( GL_MODELVIEW ); | |
566 | glPushMatrix(); | |
567 | glLoadIdentity(); | |
568 | ||
569 | glMatrixMode( GL_PROJECTION ); | |
570 | glPushMatrix(); | |
571 | glLoadIdentity(); | |
572 | ||
573 | /*pre loading matrix*/ | |
574 | if( ATransPers->mode & TPF_PAN ) | |
575 | /* Annulate translate matrix */ | |
576 | { | |
577 | modelMatrix[3][0] = 0.; | |
578 | modelMatrix[3][1] = 0.; | |
579 | modelMatrix[3][2] = 0.; | |
580 | projMatrix[3][0] = 0.; | |
581 | projMatrix[3][1] = 0.; | |
582 | projMatrix[3][2] = 0.; | |
583 | } | |
584 | ||
585 | if( ATransPers->mode & TPF_ZOOM ) | |
586 | /* Annulate zoom matrix */ | |
587 | { | |
588 | const double scaleX = myExtra.scaleFactors[0]; | |
589 | const double scaleY = myExtra.scaleFactors[1]; | |
590 | const double scaleZ = myExtra.scaleFactors[2]; | |
591 | ||
592 | for (int i = 0; i < 3; ++i) | |
593 | { | |
594 | modelMatrix[0][i] /= scaleX; | |
595 | modelMatrix[1][i] /= scaleY; | |
596 | modelMatrix[2][i] /= scaleZ; | |
597 | } | |
598 | ||
599 | const double det2 = 0.002 / ( W > H ? projMatrix[1][1] : projMatrix[0][0]); | |
600 | projMatrix[0][0] *= det2; | |
601 | projMatrix[1][1] *= det2; | |
602 | } | |
603 | ||
604 | if( ATransPers->mode & TPF_ROTATE ) | |
605 | /* Annulate rotate matrix */ | |
606 | { | |
607 | modelMatrix[0][0] = 1.; | |
608 | modelMatrix[1][1] = 1.; | |
609 | modelMatrix[2][2] = 1.; | |
610 | ||
611 | modelMatrix[1][0] = 0.; | |
612 | modelMatrix[2][0] = 0.; | |
613 | modelMatrix[0][1] = 0.; | |
614 | modelMatrix[2][1] = 0.; | |
615 | modelMatrix[0][2] = 0.; | |
616 | modelMatrix[1][2] = 0.; | |
617 | } | |
618 | else if( ATransPers->mode & TPF_RELATIVE_ROTATE ) | |
619 | /* Initialize relative rotate matrix*/ | |
620 | { | |
621 | modelMatrix[3][0] = 0.; | |
622 | modelMatrix[3][1] = 0.; | |
623 | modelMatrix[3][2] = 0.; | |
624 | ||
625 | glMatrixMode( GL_MODELVIEW ); | |
626 | glLoadIdentity(); | |
bf75be98 | 627 | glTranslated( ATransPers->pointX, ATransPers->pointY, ATransPers->pointZ ); |
2166f0fa SK |
628 | } |
629 | ||
630 | if( ATransPers->mode == TPF_TRIEDRON ) | |
631 | { | |
632 | /* Annulate translation matrix */ | |
633 | modelMatrix[3][0] = 0.; | |
634 | modelMatrix[3][1] = 0.; | |
635 | modelMatrix[3][2] = 0.; | |
636 | ||
637 | projMatrix[3][0] = 0.; | |
638 | projMatrix[3][1] = 0.; | |
639 | projMatrix[3][2] = 0.; | |
640 | ||
641 | const double det2 = 0.002 / ( W > H ? projMatrix[1][1] : projMatrix[0][0]); | |
642 | projMatrix[0][0] *= det2; | |
643 | projMatrix[1][1] *= det2; | |
644 | } | |
645 | ||
646 | /* load matrix */ | |
647 | glMatrixMode (GL_MODELVIEW); | |
648 | glMultMatrixd ((GLdouble *) modelMatrix); | |
649 | ||
650 | glMatrixMode (GL_PROJECTION); | |
651 | glMultMatrixd ((GLdouble *) projMatrix); | |
652 | ||
653 | /*post loading matrix*/ | |
654 | if( ATransPers->mode == TPF_TRIEDRON ) | |
655 | { | |
656 | glMatrixMode( GL_PROJECTION ); | |
657 | ||
658 | double winx, winy, winz; | |
659 | const GLdouble idenMatrix[4][4] = { {1.,0.,0.,0.}, {0.,1.,0.,0.}, {0.,0.,1.,0.}, {0.,0.,0.,1.} }; | |
660 | ||
661 | gluUnProject( W/2., H/2., 0., (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz); | |
662 | double W1, H1; | |
663 | W1 = winx; | |
664 | H1 = winy; | |
665 | gluUnProject( -W/2., -H/2., 0., (GLdouble*)idenMatrix, (GLdouble*)projMatrix, (GLint*)viewport, &winx, &winy, &winz); | |
666 | double W2, H2; | |
667 | W2 = winx; | |
668 | H2 = winy; | |
669 | ||
670 | if( ATransPers->pointX == 0. && ATransPers->pointY == 0. ) | |
671 | { | |
672 | /*center*/ | |
673 | } | |
674 | else if( ATransPers->pointX > 0. && ATransPers->pointY > 0. ) | |
675 | { | |
676 | /*right upper*/ | |
677 | glTranslated( 0.5*(W1 - W2 - ATransPers->pointZ), 0.5*(H1 - H2 - ATransPers->pointZ), 0. ); | |
678 | } | |
679 | else if( ATransPers->pointX > 0. && ATransPers->pointY < 0. ) | |
680 | { | |
681 | /*right lower*/ | |
682 | glTranslated( 0.5*(W1 - W2 - ATransPers->pointZ), 0.5*(H2 - H1 + ATransPers->pointZ), 0. ); | |
683 | } | |
684 | else if( ATransPers->pointX < 0. && ATransPers->pointY > 0. ) | |
685 | { | |
686 | /*left upper*/ | |
687 | glTranslated( 0.5*(W2 - W1 + ATransPers->pointZ), 0.5*(H1 - H2 - ATransPers->pointZ), 0. ); | |
688 | } | |
689 | else if( ATransPers->pointX < 0 && ATransPers->pointY < 0 ) | |
690 | { | |
691 | /*left lower*/ | |
692 | glTranslated( -(W1 - W2)/2. + ATransPers->pointZ/2., -(H1-H2)/2. + ATransPers->pointZ/2., 0. ); | |
693 | } | |
694 | } | |
695 | ||
696 | return TransPers_old; | |
697 | } | |
698 | ||
699 | /*----------------------------------------------------------------------*/ |