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